Search code examples
javascriptuserscripts

Getting Started with User Scripts and Finding a JavaScript API Similar to JavaDocs, Along with Getting the HTML Attributes of a Variable


Currently I have this:

enter (function move() {
// ==UserScript==
// @name          DriversEd Time Saver!
// @namespace     pandather@gmail.com
// @description   Automatically goes to the next slide once the timer is done.
// @copyright     2014+, Marque Kuem
// @license       GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
// @license       (CC); http://creativecommons.org/licenses/by-nc-sa/3.0/
// @version       0.1
// @icon          https://driversed.com/img/logo.png

// @homepageURL   https://duckduckgo.com/
// @supportURL    https://duckduckgo.com/

// @include       https://driversed.com/dashboard/course/*

// ==/UserScript==
     var timer=document.getElementById("timerValue");
     if(timer instanceof timer hide) {
         alert('Next is clickable');
     }
     setTimeout(move, 500);
})();

I am trying to poll every half second if the variable on the page of the id timerValue has the attributes timer and hide. This is the line in HTML when I should get an alert:

<div id="timerValue" class="timer hide">00:01</div>

And this is the line in which I should not:

<div id="timerValue" class="timer">99:99</div>

How would I go about checking if timer the HTML attributes timer and hide" Also, is there documentation on Javascript like the Java API?


Solution

  • Use querySelector to find the element if it matches all the criteria you want. If it doesn't have the classes, the selector won't match anything.

    setInterval(function() {
        var timer = document.querySelector("#timerValue.timer.hide");
        if (timer) {
            alert('Next is clickable');
        }
    }, 500);