How to remove CSS Class with Tampermonkey?

后端 未结 3 1185
孤街浪徒
孤街浪徒 2021-01-26 21:07

I am very new to CSS and javascript, so take it easy on me.

I am trying to remove the class disable-stream from each of the div elements under the div class

3条回答
  •  北荒
    北荒 (楼主)
    2021-01-26 21:41

    That looks to be an AJAX-driven web page, so you need to use AJAX-aware techniques to deal with it. EG waitForKeyElements, or MutationObserver, or similar.

    Here's a complete script that should work:

    // ==UserScript==
    // @name     _Remove a select class from nodes
    // @match    *://app.hubspot.com/reports-dashboard/*
    // @match    *://app.hubspot.com/sales-notifications-embedded/*
    // @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 restore the proper sandbox.
    console.log ("Do you see this?");
    
    waitForKeyElements (".disable-stream", removeDSclass);
    
    function removeDSclass (jNode) {
        console.log ("Cleaned node: ", jNode);
        jNode.removeClass ("disable-stream");
    }
    

    Note that there are two @match statements because the nodes, that the OP cared about, turned out to be in an iframe.

提交回复
热议问题