Add class in jQuery in Greasemonkey script

南笙酒味 提交于 2020-01-14 03:24:13

问题


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:

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.

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");
}

回答1:


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");
}


来源:https://stackoverflow.com/questions/26539230/add-class-in-jquery-in-greasemonkey-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!