问题
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