如何使用 Tampermonkey 删除 CSS 类?

inp*_*hip 1 html javascript css jquery tampermonkey

我对 CSS 和 javascript 很陌生,所以别着急。

我试图disable-stream从 div class="stream-notifications" 下的每个 div 元素中删除该类。(见下图)

我在 Tampermonkey 中尝试了以下方法,但似乎不起作用:

(function() {
'use strict';
disable-stream.classList.remove("disable-stream");})();
Run Code Online (Sandbox Code Playgroud)

页面结构的屏幕截图

Bro*_*ams 5

这看起来是一个 AJAX 驱动的网页,因此您需要使用 AJAX 感知技术来处理它。EG waitForKeyElements、或MutationObserver、或类似的。

这是一个应该可以工作的完整脚本

// ==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");
}
Run Code Online (Sandbox Code Playgroud)

请注意,有两个@match语句,因为 OP 关心的节点原来位于 iframe 中。