如何使用 Tampermonkey 删除 CSS Class?
How to remove CSS Class with Tampermonkey?
我是 CSS 和 javascript 的新手,请放心。
我正在尝试从 div class="stream-notifications" 下的每个 div 元素中删除 class disable-stream
。 (见下图)
我在 Tampermonkey 中尝试了以下方法,但似乎不起作用:
(function() {
'use strict';
disable-stream.classList.remove("disable-stream");})();
使用类似这样的东西 jQuery
$(".disable-stream div").removeClass("disable-stream");
var divs =document.getElementsByClassName("stream-notifications");
divs=Array.from(divs);
divs.forEach(function(div){
div.classList.remove('disable-stream');
});
这看起来像是一个 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 中。
我是 CSS 和 javascript 的新手,请放心。
我正在尝试从 div class="stream-notifications" 下的每个 div 元素中删除 class disable-stream
。 (见下图)
我在 Tampermonkey 中尝试了以下方法,但似乎不起作用:
(function() {
'use strict';
disable-stream.classList.remove("disable-stream");})();
使用类似这样的东西 jQuery
$(".disable-stream div").removeClass("disable-stream");
var divs =document.getElementsByClassName("stream-notifications");
divs=Array.from(divs);
divs.forEach(function(div){
div.classList.remove('disable-stream');
});
这看起来像是一个 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 中。