javascript 允许在Adblock Plus中将特定频道列入白名单,方法是在URL中添加频道名称,并构建过滤器以添加自定义过滤器
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 允许在Adblock Plus中将特定频道列入白名单,方法是在URL中添加频道名称,并构建过滤器以添加自定义过滤器相关的知识,希望对你有一定的参考价值。
// ==UserScript==
// @name YouTube - Whitelist Channel Name in AdblockPlus
// @namespace https://drjest.xyz/tampermonkey
// @author DrJest
// @credits Gantt
// @description Helps whitelist YouTube channels in Adblock Plus
// @include http://*.youtube.com/*
// @include https://*.youtube.com/*
// @version 1.0
// @grant none
// @license http://creativecommons.org/licenses/by-sa/4.0/
// @supportURL https://drjest.xyz
// ==/UserScript==
(() => {
const activate = () => {
if(document.querySelector('yt-formatted-string#owner-name') === null || document.querySelector('yt-formatted-string#owner-name').offsetParent === null) {
return false;
}
addButton();
let url = new URL(location.href);
if(url.searchParams.get('channel')) {
return false;
}
let channel_name = document.querySelector('yt-formatted-string#owner-name a').innerText;
url.searchParams.set('channel', channel_name);
history.replaceState({}, document.title, url.href);
};
const addButton = () => {
if(document.querySelector('yt-formatted-string#owner-name') === null || document.querySelector('yt-formatted-string#owner-name #abp-filter')) {
return;
}
let btn = document.createElement('button');
btn.id = 'abp-filter';
btn.innerText = 'ABP Filter';
btn.style.marginLeft = '10px';
btn.addEventListener('click', e => {
e.preventDefault();
let url = new URL(location.href), t = [];
for(let i of url.searchParams.keys()) {
if(i !== 'channel') {
t.push(i);
}
}
t.forEach(i => url.searchParams.delete(i));
prompt('Copy this in your ABP custom filters list', `@@${url.href.replace('?', '*')}^$document`);
})
document.querySelector('yt-formatted-string#owner-name').appendChild(btn);
};
document.body.addEventListener('yt-page-data-updated', activate);
})();
以上是关于javascript 允许在Adblock Plus中将特定频道列入白名单,方法是在URL中添加频道名称,并构建过滤器以添加自定义过滤器的主要内容,如果未能解决你的问题,请参考以下文章
Adblock Plus 阻止本地主机上的 css
这个正则表达式是啥意思 - “\pLu”?
adblock plus怎么用
已经在firefox上装了Adblock Plus还要装Adblock Plus Pop-up Addon 、
火狐adblock plus怎么不能使用了?
adblock plus过滤规则?