Okay. So I am very, very new to JavaScript (as in: barely knew any before, and just started actually learning today so I could work on this project). I have a pretty good knowledge of Java, but that's not very useful with the more functional aspects of JS.
I'm currently working on some scripting for a Firefox extension, specifically the context menu part. I'm trying to make an anonymous function (I think that's what it's called; correct me if I'm wrong) so if the right-clicked tab is found in an array in localStorage, then this function returns true and sets the variable to true, therefore making the context menu item have a check next to it.
My issue comes from how the ...onClicked.addListener() returns a prompt
Here's the contextMenus.create() call:
browser.contextMenus.create({
id: "idPlaceholder",
type: "checkbox",
title: "titlePlaceholder",
contexts: [
"page",
"link",
"tab"
],
checked: checkedState,
}, onCreated);
And here's what I have so far for the problem child — I mean, the checkedState variable declaration:
var checkedState = () => {
if (JSON.parse(localStorage.getItem('tabs')
.includes(browser.contextMenus.onClicked.addListener(function (info, tab) {
//somehow return "info.pageUrl" to .includes() method
})))) {
}
};
There's bound to be another way to do this, I just can't seem to find it by looking online. So, I turn to you, Internet.
If you need any more information on what I'm attempting to do, let me know. I tried to not make it too long.
Figured the issue out with help from wOxxOm.
browser.contextMenus.onShown.addListener(function (info, tab) {
if (JSON.parse(localStorage.getItem('tabs')).includes(info.pageUrl)) {
browser.contextMenus.update("idPlaceholder", {
checked: true,
});
}
browser.contextMenus.refresh();
})