Userscript to hide a child node of a cross-domain iframe

偶尔善良 提交于 2019-12-02 03:52:51
Brock Adams

Disqus-powered comments are typically loaded in an <iframe>. So rather than set your script to run on the main site, you set it to run on the iframe src URL. In this case, http://disqus.com/embed/comments/...

Also, these comments are AJAX driven. So you must use AJAX savvy techniques.

A script like this should work (selector might need tuning):

// ==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 ();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!