本文介绍了如何转换jQuery过滤器以与waitForKeyElements一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 此代码删除少于3转推的推文,但现在我有刷新(AJAX)问题。如何添加 waitForKeyElements 功能来修复它?This code removes tweets with less than 3 retweets, but now I have the refresh (AJAX) issue. How can I add the waitForKeyElements function to fix it?$('.js-stream-item:has(span.ProfileTweet-action--retweet)').filter(function() { return parseInt($(this).find('span.ProfileTweet-actionCount').attr('data-tweet-stat-count')) < 3;}).remove();推荐答案要将静态jQuery过滤器转换为一个支持AJAX的 waitForKeyElements()使用并不太难:To convert a static jQuery filter, like that, to an AJAX-aware waitForKeyElements() use is not too hard: 您的基本选择器才会成为选择器参数。 EG: waitForKeyElements(。js-stream-item:has(span.ProfileTweet-action - retweet)... 过滤器(function()内部传递到waitForKeyElements回调几乎是原样。请参阅下面的脚本。The filter(function() internals transfer to the waitForKeyElements callback almost as-is. See the script, below.注意当使用 parseInt()时,你应该总是指定基数以避免意外(定时炸弹)行为。Note that when using parseInt(), you should always specify the base to avoid unexpected ("time bomb") behavior.这是一个 完整脚本 ,显示该过滤器的端口为 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 ();} 这篇关于如何转换jQuery过滤器以与waitForKeyElements一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
06-15 04:08