简体   繁体   English

使用 GreaseMonkey 从网站隐藏 DIV 的问题

[英]Problem with hiding DIV from website using GreaseMonkey

There's one site, where without ads you cannot view the content.有一个网站,如果没有广告,您将无法查看内容。 I tried Anti-Ad Blocker already, but scripts made all links unusable.我已经尝试过 Anti-Ad Blocker,但脚本使所有链接都无法使用。

I tried writing Greasemonkey script to hide those few ads by hand, but so far it doesn't work (and I have no idea why).我尝试编写 Greasemonkey 脚本来手动隐藏那几个广告,但到目前为止它不起作用(我不知道为什么)。

// ==UserScript==
// @name     Hide annoying shinden ads
// @include  https://shinden.pl/*
// @grant    GM_addStyle
// ==/UserScript==



var div = document.getElementById("banner-outer");
if (div) {
    div.style.display = "none";
}

And element I want to delete:我想删除的元素:

<div id="banner-inner" style="transform: matrix(0.99999, 0.00087, -0.00087, 0.99999, 0, 0);">
            ...
        </div>

Also sometimes different div appears out of random, that blocks whole site:有时也会随机出现不同的 div,这会阻止整个站点:

<div style="position: fixed; display: block; width: 100%; height: 100%; inset: 0px; background-color: rgba(0, 0, 0, 0); z-index: 300000;"></div>

I don't know how to remove it, as thus it doesn't have an ID.我不知道如何删除它,因为它没有 ID。

PS Site is as follows: https://shinden.pl/ PS网站如下: https : //shinden.pl/

You can remove Div from webpage using code below.您可以使用以下代码从网页中删除 Div。

If the random Div is creating inside the "banner-inner Div" then above solution helps creating such Divs.如果在“横幅内部 Div”内创建随机 Div,则上述解决方案有助于创建此类 Div。

If it is creating outside then have to find the Div by available properties like width, hieght , z-index along with grand parent of the Div(which has ID) to pinpoint and delete the created div.如果是在外部创建,则必须通过可用属性(如 width、hieght、z-index 以及 Div(具有 ID)的祖父级)找到 Div,以查明并删除创建的 div。

// ==UserScript==
// @name     RemoveDiv
// @version  1.0
// @grant    none
// ==/UserScript==

var toBeRemoved = document.getElementById('banner-inner');
if (toBeRemoved) {
    toBeRemoved.parentNode.removeChild(toBeRemoved);
}

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

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