如何转换jQuery过滤器以使用waitForKeyElements
How to convert a jQuery filter for use with waitForKeyElements?
这段代码删除了转发少于3次的tweet,但是现在我有刷新(AJAX)问题。我如何添加waitForKeyElements
函数来修复它?
$('.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()
使用并不太难:
-
你的基本选择器只是成为选择器参数。如:
waitForKeyElements (".js-stream-item:has(span.ProfileTweet-action--retweet)"...
-
filter(function()
内部几乎按原样转移到waitForKeyElements回调。
请注意,当使用parseInt()
时,您应该始终指定基,以避免意外的("定时炸弹")行为。
这是一个完整的脚本显示了该过滤器到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 ();
}
相关文章:
- 为什么我的d3.jsselectAll+过滤器没有过滤
- Angularjs-utils高亮过滤器在搜索时破坏应用程序
- Angular-表的多列过滤器
- 如何“;过滤器”;或者以其他方式重构该数据
- Angularjs通过过滤器获取indexOf
- ui网格日期单元格过滤器,过滤日期格式导致显示错误的日期
- 使用按钮的Angular UI网格过滤器
- KendoUI网格行过滤器,带有布尔值下拉列表
- 如何在angular.js中动态应用自定义过滤器
- 角度过滤器和ng点击不起作用
- SVG过滤器可以'不能在React中呈现
- 使用javascript或angularjs特定过滤器搜索字符串中第一个img标记的json值
- 在表单中创建一个黑名单过滤器以避免某些单词
- 如何应用带过滤器的ng if来过滤记录,并在同一页面中显示两个不同的视图
- 过滤器返回true或false
- angularjs ng基于点击时的数组值重复过滤器
- DC.js带过滤器的订购
- 使用angularjs内置过滤器过滤代码中的特定属性
- 让我自己的过滤器不工作
- 添加到角度过滤器中的索引