繁体   English   中英

如何使用Tampermonkey删除CSS类?

[英]How to remove CSS Class with Tampermonkey?

我是CSS和javascript的新手,所以请放轻松。

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

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

(function() {
'use strict';
disable-stream.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中。

var divs =document.getElementsByClassName("stream-notifications");

divs=Array.from(divs);

divs.forEach(function(div){
  div.classList.remove('disable-stream');
 });

使用jQuery使用类似的东西

$(".disable-stream div").removeClass("disable-stream");

Plunker演示

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM