如何使用Greasemonkey选择性地从网站删除内容? [英] How to use Greasemonkey to selectively remove content from a website?

查看:94
本文介绍了如何使用Greasemonkey选择性地从网站删除内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾尝试从具有 uBlock起源的此网站中删除内容(付费内容) em>, Greasemonkey 和Anti-Adblock Killer脚本.

I have tried removing content (paid content) from this website with uBlock origin, Greasemonkey and Anti-Adblock Killer script.

我尝试运行此脚本,但没有成功.
我要删除的(付费")内容如下:

I have tried running this script but without success.
The ("paid") content I want to remove looks like this:

<div class="news" info="398825">
    <div class="normal" ...>
        <div class="supertitle">
            <a href="http://www.monitor.hr/marketing/sponzorirana.html" target="_blank">Sponzorirana vijest</a>
        </div>
        ...

我可以通过以下元素将付费内容"与其余内容区分开来:

I can differentiate "paid content" from rest of the content with this element:

<a href="http://www.monitor.hr/marketing/sponzorirana.html" target="_blank">Sponzorirana vijest</a>

我想从链接的网站上删除每个付费内容"("Sponzorirana vijest")部分.

I would like to remove every "paid content" ("Sponzorirana vijest") section from the linked website.

推荐答案

该内容似乎是静态.因此,只需像这样利用页面的jQuery:

That content appears to be static. So just leverage the page's jQuery like so:

// ==UserScript==
// @name     _Remove sponsored content
// @match    *://www.monitor.hr/*
// @grant    none
// ==/UserScript==

$(".supertitle > a[href*='marketing/sponzorirana']").closest (".news").remove ();


如果要动态地添加更多的这些区块,请使用waitForKeyElements(),如此答案.像这样(在GM4中未经测试):

If more of those blocks are added dynamically, use waitForKeyElements() as shown in this answer. Something like this (untested in GM4):

// ==UserScript==
// @name     _Remove sponsored content
// @match    *://www.monitor.hr/*
// @require  https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant    none
// ==/UserScript==
waitForKeyElements (".supertitle > a[href*='marketing/sponzorirana']", removeNewsNode);

function removeNewsNode (jNode) {
    jNode.closest (".news").remove ();
}


最后,根据Greasemonkey自己的开发人员,切换到Tampermonkey或Violentmonkey. Greasemonkey 4+具有严重缺陷.

Finally, per Greasemonkey's own developers, switch to Tampermonkey or Violentmonkey. Greasemonkey 4+ has serious deficiencies.

这篇关于如何使用Greasemonkey选择性地从网站删除内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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