Я пытаюсь создать расширение 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