我想通过(Tampermonkey)用户脚本隐藏其中包含一些单词的注释。作为一个例子,我尝试应用一个脚本
// ==UserScript==
// @name Hide CNN
// @match http://www.cnn.com/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @grant GM_addStyle
// @run-at document-end
// ==/UserScript==
$('div.post-body:contains("Abbas")').hide()
到页面http://www.cnn.com/2014/07/08/world/meast/mideast-tensions/index.html?hpt=hp_t1使用以下帖子代码
<div class="post-body">
<header>
...
</header>
<div class="post-body-inner">
<div class="post-message-container" data-role="message-container">
<div class="publisher-anchor-color" data-role="message-content">
<div class="post-message " data-role="message" dir="auto">
<p>Abbas is nothing but puppet dog of Western savages and Nazis who want to enslave entire world.</p>
</div>
...
</div>
但脚本似乎没有做任何事情。我究竟做错了什么?是否有可能使用用户脚本过滤网页的动态加载部分?
UPD:问题是评论是从另一个域加载到 iframe 中的。如何使用 Tampermonkey 隐藏此类 iframe 的子节点?我需要使用吗GM_xmlhttpRequest
不知何故?
Disqus-powered 评论通常加载在
此外,这些评论是 AJAX 驱动的。所以你必须使用AJAX 精通技术.
像这样的脚本应该可以工作(选择器可能需要调整):
// ==UserScript==
// @name Hide select CNN comments
// @match http://disqus.com/embed/comments/*
// @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.
*/
//--- Only run on comments for CNN pages
if (/&f=cnn&/i.test (location.search) ) {
waitForKeyElements ('li.post:contains("Abbas")', hideComment);
}
function hideComment (jNode) {
jNode.hide ();
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)