gpt4 book ai didi

javascript - 如何使用 Tampermonkey 删除 CSS 类?

转载 作者:行者123 更新时间:2023-11-30 11:27:21 26 4
gpt4 key购买 nike

我对 CSS 和 javascript 还很陌生,所以请放轻松。

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

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

(function() {
'use strict';
disable-stream.classList.remove("disable-stream");})();

screen shot of page structure

最佳答案

这看起来是一个 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");
}

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

关于javascript - 如何使用 Tampermonkey 删除 CSS 类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47539905/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com