Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

155
Visualizações
How to return result of nested function in JavaScript when using addListener?

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.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

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();
})
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda