Различия
Показаны различия между двумя версиями страницы.
Предыдущая версия справа и слева Предыдущая версия Следующая версия | Предыдущая версия | ||
js:chrome:storages [2023/11/21 00:32] – 192.168.1.159 | js:chrome:storages [2023/11/21 00:34] (текущий) – 192.168.1.159 | ||
---|---|---|---|
Строка 17: | Строка 17: | ||
const store = db.createObjectStore(' | const store = db.createObjectStore(' | ||
store.createIndex(' | store.createIndex(' | ||
+ | } | ||
+ | |||
+ | // Добавляем ссылку на сайт в базу данных | ||
+ | function addBookmark(title, | ||
+ | const db = openDatabase.result; | ||
+ | const transaction = db.transaction([' | ||
+ | const store = transaction.objectStore(' | ||
+ | |||
+ | const bookmark = { | ||
+ | title: title, | ||
+ | url: url, | ||
+ | id: url.hashCode() | ||
+ | }; | ||
+ | |||
+ | store.put(bookmark); | ||
+ | } | ||
+ | |||
+ | String.prototype.hashCode = function() { | ||
+ | let hash = 0, i, chr; | ||
+ | for (i = 0; i < this.length; | ||
+ | chr = this.charCodeAt(i); | ||
+ | hash = ((hash << 5) - hash) + chr; | ||
+ | hash |= 0; | ||
+ | } | ||
+ | return hash; | ||
+ | }; | ||
+ | |||
+ | // Получаем все ссылки на сайты из базы данных | ||
+ | function getBookmarks() { | ||
+ | const db = openDatabase.result; | ||
+ | const transaction = db.transaction([' | ||
+ | const store = transaction.objectStore(' | ||
+ | |||
+ | const request = store.getAll(); | ||
+ | |||
+ | request.onsuccess = function() { | ||
+ | // Отображаем ссылки на сайты в списке | ||
+ | const bookmarks = this.result; | ||
+ | // ... | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // Удаляем ссылку на сайт из базы данных | ||
+ | function removeBookmark(id) { | ||
+ | const db = openDatabase.result; | ||
+ | const transaction = db.transaction([' | ||
+ | const store = transaction.objectStore(' | ||
+ | |||
+ | store.delete(id); | ||
} | } | ||
</ | </ |