Есть ли способ хранить Trie в расширении Chrome с глубоко вложенным корнем?Javascript

Форум по Javascript
Ответить
Anonymous
 Есть ли способ хранить Trie в расширении Chrome с глубоко вложенным корнем?

Сообщение 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?

Подробнее здесь: https://stackoverflow.com/questions/796 ... ested-root
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Javascript»