Appearance
拦截广告
移动端,某网站 https://m.a.cn/ 一堆下载 APP 按钮,经常误触。
// ==UserScript==
// @name 拦截广告ACN
// @namespace Monkey
// @version 2049-10-01
// @description 拦截广告
// @author 白马
// @run-at document-end
// @match https://m.a.cn/*
// ==/UserScript==
(function() {
'use strict';
const adSelectors = [
'div[data-type="dl"]',
];
for (let s of adSelectors) {
const elements = document.querySelectorAll(s);
for (let e of elements) {
// 隐藏
e.style.display = 'none';
}
}
})();应对延迟加载广告。
// ==UserScript==
// @name 拦截广告ACN
// @namespace Monkey
// @version 2049-10-01
// @description 拦截广告
// @author 白马
// @run-at document-end
// @match https://m.a.cn/*
// ==/UserScript==
(function() {
'use strict';
const adSelectors = [
'div[data-type="dl"]',
];
// 移除广告
function removeAds() {
for (let s of adSelectors) {
const elements = document.querySelectorAll(s);
for (let e of elements) {
// 隐藏
e.style.display = 'none';
}
}
}
// 运行两次
removeAds();
setTimeout(removeAds, 2000);
})();多站点拦截广告。
// ==UserScript==
// @name 拦截广告
// @namespace Monkey
// @version 2049-10-01
// @description 拦截广告
// @author 白马
// @run-at document-end
// @match https://m.a.cn/*
// @match https://b.com/*
// ==/UserScript==
// 移除广告
function removeAds(adSelectors) {
for (let s of adSelectors) {
const elements = document.querySelectorAll(s);
for (let e of elements) {
// 隐藏
e.style.display = 'none';
}
}
}
// 站点1
const a = [
'div[data-type="dl"]',
];
// 站点2
const b = [
'#btn-call-app',
];
(function() {
'use strict';
const hostname = window.location.hostname;
const dict = {
'm.a.cn': a,
'b.com': b,
};
if (dict.hasOwnProperty(hostname)) {
const adSelectors = dict[hostname];
// 运行两次
removeAds(adSelectors);
setTimeout(() => removeAds(adSelectors), 2000);
}
})();