Bijan
Bijan

Reputation: 8602

Add class in jQuery in Greasemonkey script

I Asked a question earlier and was given a Working solution. One thing I want to do is incorporate jQuery to remove a class F-link-secondary and replace it with F-rank-good/bad/neutral depending on the value of deltaText.

On most pages this is what I see:

enter image description here

But on a certain page, the F-rank-XXX class is not there and instead there is just a single F-link-secondary which has no style.

enter image description here

Here is what I want to do but I am not sure how to incorporate it with the Greasemonkey script.

function getRank(deltaText) {
    if((1 <= deltaText) && (deltaText <= 10))
        $("???").removeClass("F-link-secondary").addClass("F-rank-good");
    if((11 <= deltaText) && (deltaText <= 22))
        $("???").removeClass("F-link-secondary").addClass("F-rank-neutral");
    if((23 <= deltaText) && (deltaText <= 32))
        $("???").removeClass("F-link-secondary").addClass("F-rank-bad");
}

Upvotes: 1

Views: 357

Answers (1)

Brock Adams
Brock Adams

Reputation: 93483

In this case, just add the code inside the delinkChangeStat function.
From:

//-- Change the link
if (deltaText) {
    jNode.text (jNode.text () + " - " + deltaText);
}

To:

//-- Change the link
if (deltaText) {
    jNode.text (jNode.text () + " - " + deltaText);

    var deltaVal = parseInt (deltaText, 10);

    if ( (1 <= deltaVal)  &&  (deltaVal <= 10) )
        jNode.removeClass ("F-link-secondary").addClass ("F-rank-good");
    else if ( (11 <= deltaVal) && (deltaVal <= 22) )
        jNode.removeClass ("F-link-secondary").addClass ("F-rank-neutral");
    else if ( (23 <= deltaVal) && (deltaVal <= 32) )
        jNode.removeClass ("F-link-secondary").addClass ("F-rank-bad");
}

Upvotes: 1

Related Questions