如何使用Tampermonkey删除CSS类? [英] How to remove CSS Class with Tampermonkey?

查看:465
本文介绍了如何使用Tampermonkey删除CSS类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

I am trying to remove the class disable-stream from each of the div elements under the div class="stream-notifications". (See image, below)

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

I have tried the following in Tampermonkey, but it doesn't seem to work:

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

推荐答案

这似乎是AJAX驱动的网页,因此您需要使用AJAX感知技术来处理它. EG waitForKeyElements MutationObserver或类似名称.

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.

这是应该起作用的完整脚本:

// ==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中.


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

这篇关于如何使用Tampermonkey删除CSS类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆