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

105
Visualizações
Why is Greasemonkey javascript reporting an element has a class when web developer tools indicates that it doesnt seem to have

I'm trying to write a greasemonkey script that automtically presses a button on a page, but only if a tab is disabled, the tab shows duplicates records and when I inspect the page in firefox using Web Devloper Tools/Inspector I find that when we have duplicates records and the tab is enabled that we have

<li class="ui-state-default ui-corner-top" role="tab" tabindex="-1" aria-controls="duplicates-tab" aria-labelledby="ui-id-2" aria-selected="false"><a href="#duplicates-tab" class="ui-tabs-anchor" role="presentation" tabindex="-1" id="ui-id-2">Release Duplicates</a></li>

but when it is disabled i have

<li class="ui-state-default ui-corner-top ui-state-disabled" role="tab" tabindex="-1" aria-controls="duplicates-tab" aria-labelledby="ui-id-2" aria-selected="false" aria-disabled="true"><a href="#duplicates-tab" class="ui-tabs-anchor" role="presentation" tabindex="-1" id="ui-id-2">Release Duplicates</a></li>

i.e when disabled the enclosing list element of the link has an additional ui-state-disabled class (this was the only difference I could find when i inspected the html)

So I write my greasemonkey script as follows

// ==UserScript==
// @name     AutoContinueAddRelease
// @version  
// @grant    none
// @include  https://musicbrainz.org/release/add
// ==/UserScript==
window.addEventListener ("load", Greasemonkey_main, false);

function Greasemonkey_main () 
{
  var as = document.getElementsByTagName("a");
  for(a of as)
  {
    if(a.href=='https://musicbrainz.org/release/add#duplicates-tab')
    {
      alert(a.parentElement.classList);  
      if(a.parentElement.classList.contains('ui-state-disabled'))
      {
        var button = document.getElementById("enter-edit");   
        if(button!=null)
        {
          button.click();
        }
      }
      break;
    }
  }
}

But in both cases it finds the ui-state-disabled class and submits the form, which is not what i want, I dont understand why.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Solved the problem by setting timeout to delay running the script until a bit after page loaded based on @Ourobirus comment

// ==UserScript==
// @name     AutoContinueAddRelease
// @version  
// @grant    none
// @include  https://musicbrainz.org/release/add
// ==/UserScript==
setTimeout(check, 5000);
function check()
{
  var as = document.getElementsByTagName("a");
  for(a of as)
  {
    if(a.href=='https://musicbrainz.org/release/add#duplicates-tab')
    {
      if(a.parentElement.classList.contains('ui-state-disabled'))
      {
        var button = document.getElementById("enter-edit");   
        if(button!=null)
        {
          button.click();
        }        
      }
      else
      {
          alert('duplicatesFound');
      }
      break;
    }
  }
}
about 4 years ago · Juan Pablo Isaza 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