这是我创建右键菜单的代码:
chrome.contextMenus.create({
title: "copy '%s' to clipboard",
contexts: ["selection"],
onclick: function(info) {
wordObject[wordObject.length] = {
word: info.selectionText,
definition: " 'add definition' "
};
runArray();
chrome.storage.sync.set({"myValue": wordObject});
}
});
问题是每次我刷新页面时都会在我的菜单下创建另一个选择。
编辑
我修复了它,但每次单击时都需要刷新页面。有什么办法吗?
chrome.contextMenus.create({
title: "copy '%s' to clipboard",
contexts: ["selection"],
onclick: function(info) {
wordObject[wordObject.length] = {
word: info.selectionText,
definition: " 'add definition' "
};
runArray();
chrome.storage.sync.set({"myValue": wordObject});
chrome.contextMenus.removeAll();
location.reload(); // Refreshes page! Probably not good
}
});