Я пытаюсь создать расширение Chrome, в котором пользователь добавляет текстовые фрагменты в расширение, тогда, когда он вводит в TextARea/Input/AtteDeedtable/Rich-Text Editors, выпадает с выбором с автозаполненными предложениями.
Я использую трип Если я использую json.stringify. < /p>
// In content.js
class TrieNode {
constructor() {
this.children = {};
this.wordEnd = false;
}
}
class Trie {
constructor(tree) {
this.root = tree || new TrieNode();
};
// Trie methods here
}
trieInsert(key) {
this.trie.insert(key);
chrome.runtime.sendMessage({
action: "saveTrie",
data: this.trie.root
});
}
async _loadTrieFromStorage() {
return new Promise((resolve) => {
chrome.runtime.sendMessage({ action: "getTrie" }, (response) => {
if (response && response.data) {
this.trie = new Trie(response.data);
} else {
this.trie = new Trie();
}
resolve();
});
});
}
< /code>
// In background.js
if (request.action === "getTrie") {
chrome.storage.local.get("trie", (data) => {
sendResponse({data: data.trie});
});
return true; // Keep message channel open for async response
}
if (request.action === "saveTrie") {
chrome.storage.local.set({"trie": request.data});
sendResponse({success: true});
return true;
}
< /code>
My question is, is it possible to store a deeply nested trie in storage in chrome extensions? or should I re-insert each string everytime the content.js is loaded in pages and iframes, or should I be using Trie at all in this case?
Подробнее здесь: https://stackoverflow.com/questions/796 ... ested-root
Есть ли способ хранить Trie в расширении Chrome с глубоко вложенным корнем? ⇐ Javascript
Форум по Javascript
1749030882
Anonymous
Я пытаюсь создать расширение Chrome, в котором пользователь добавляет текстовые фрагменты в расширение, тогда, когда он вводит в TextARea/Input/AtteDeedtable/Rich-Text Editors, выпадает с выбором с автозаполненными предложениями.
Я использую трип Если я использую json.stringify. < /p>
// In content.js
class TrieNode {
constructor() {
this.children = {};
this.wordEnd = false;
}
}
class Trie {
constructor(tree) {
this.root = tree || new TrieNode();
};
// Trie methods here
}
trieInsert(key) {
this.trie.insert(key);
chrome.runtime.sendMessage({
action: "saveTrie",
data: this.trie.root
});
}
async _loadTrieFromStorage() {
return new Promise((resolve) => {
chrome.runtime.sendMessage({ action: "getTrie" }, (response) => {
if (response && response.data) {
this.trie = new Trie(response.data);
} else {
this.trie = new Trie();
}
resolve();
});
});
}
< /code>
// In background.js
if (request.action === "getTrie") {
chrome.storage.local.get("trie", (data) => {
sendResponse({data: data.trie});
});
return true; // Keep message channel open for async response
}
if (request.action === "saveTrie") {
chrome.storage.local.set({"trie": request.data});
sendResponse({success: true});
return true;
}
< /code>
My question is, is it possible to store a deeply nested trie in storage in chrome extensions? or should I re-insert each string everytime the content.js is loaded in pages and iframes, or should I be using Trie at all in this case?
Подробнее здесь: [url]https://stackoverflow.com/questions/79652523/is-there-a-way-to-store-trie-in-chrome-extension-with-a-deeply-nested-root[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия