Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

103
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!