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

后端 未结 1 353
渐次进展
渐次进展 2021-01-25 16:55

I want to hide the comments with some words inside by a (Tampermonkey) user script. As an example, I tried to apply a script

// ==UserScript==
// @name       H         


        
相关标签:
1条回答
  • 2021-01-25 17:23

    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 ();
    }
    
    0 讨论(0)
提交回复
热议问题