Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

106
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda