Skip to content

Commit

Permalink
feat: add advance ads filters
Browse files Browse the repository at this point in the history
  • Loading branch information
yujinpan committed Jan 30, 2023
1 parent 0d8c5fd commit 4e488df
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion scripts/x-google-ads.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,45 @@
// ==/UserScript==

(() => {
// 1. intercept ads trigger
const script = document.createElement('script');
script.innerHTML = `
interceptProp(window, 'adsbygoogle', {push: () => {}});
interceptProp(window, 'dataLayer', {push: () => {}});
function interceptProp(obj, prop, overrideVal) {
let _val;
Object.defineProperty(obj, prop, {
get() {return _val;},
set(val) {
_val = val;
Object.assign(_val, overrideVal)
}
})
}
`;
document.head.prepend(script);

// 2. remove exist ads first
const style = document.createElement('style');
style.innerHTML = '* [data-adsbygoogle-status] {display: none !important}';
style.innerHTML = '* [data-ad-client] {display: none !important}';
document.head.append(style);


// 3. disable ads scripts add
new MutationObserver((mutations) => {
mutations.forEach(item => {
if (item.type === 'childList') {
item.addedNodes.forEach(node => {
if (
node.src &&
node.src.includes('ads')
) {
node.remove();
console.log(node);
}
});
}
});
}).observe(document.head, {childList: true});
})();

0 comments on commit 4e488df

Please sign in to comment.