To convert a static jQuery filter, like that, to an AJAX-aware waitForKeyElements()
use is not too hard:
Your base selector just becomes the selector parameter. EG:
waitForKeyElements (".js-stream-item:has(span.ProfileTweet-action--retweet)"...
The filter(function()
internals transfer to the waitForKeyElements callback almost as-is. See the script, below.
Note that when using parseInt()
, you should always specify the base to avoid unexpected ("time bomb") behavior.
Here's a complete script showing the port, of that filter, to waitForKeyElements
:
// ==UserScript==
// @name _Remove or hide nodes based on jQuery filter
// @include http://YOUR_SERVER.COM/YOUR_PATH/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a design change
introduced in GM 1.0. It restores the sandbox.
*/
waitForKeyElements (
".js-stream-item:has(span.ProfileTweet-action--retweet)", removeFilteredNode
);
function removeFilteredNode (jNode) {
var twtCnt = parseInt (
jNode.find ('span.ProfileTweet-actionCount').attr ('data-tweet-stat-count')
, 10
)
if (twtCnt < 3)
jNode.remove ();
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…