-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTurbo Subscription Button Remover.js
More file actions
87 lines (72 loc) · 3.06 KB
/
Turbo Subscription Button Remover.js
File metadata and controls
87 lines (72 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// ==UserScript==
// @name Turbo Subscription Button Remover
// @namespace https://github.com/mirbyte/TwitchTV-Userscripts
// @match *://www.twitch.tv/*
// @grant none
// @version 2.2
// @author mirbyte
// @description Edits the Turbo ad banner to be a transparent placeholder. Check GitHub page for the demonstration image.
// @icon https://www.twitch.tv/favicon.ico
// @downloadURL https://update.greasyfork.org/scripts/524848/Turbo%20Subscription%20Button%20Remover.user.js
// @updateURL https://update.greasyfork.org/scripts/524848/Turbo%20Subscription%20Button%20Remover.meta.js
// ==/UserScript==
(function () {
'use strict';
const HANDLED_ATTR = 'data-turbo-removed';
const AD_TEXTS = [
"Go Ad-Free for Free",
"Poista mainokset ilmaiseksi",
"Poista mainokset",
"Get Ad-Free",
"Go Ad-Free",
"Try Turbo",
"Get Turbo"
];
function editAdBanner() {
document.querySelectorAll(
`[data-a-target="tw-core-button-label-text"]:not([${HANDLED_ATTR}])`
).forEach(label => {
const text = label.textContent?.trim() ?? '';
if (!AD_TEXTS.some(t => text.includes(t))) return;
label.setAttribute(HANDLED_ATTR, '1');
const button = label.closest('button');
if (!button) return;
button.setAttribute(HANDLED_ATTR, '1');
let navSlot = button;
for (let i = 0; i < 4; i++) {
if (navSlot.parentElement && navSlot.parentElement.tagName !== 'BODY') {
navSlot = navSlot.parentElement;
}
}
const target = navSlot.offsetWidth < 300 ? navSlot : button;
target.style.setProperty('display', 'none', 'important');
target.setAttribute(HANDLED_ATTR, '1');
console.debug('[TurboRemover] Hidden:', text);
});
document.querySelectorAll(`button:not([${HANDLED_ATTR}])`).forEach(button => {
const text = button.textContent?.trim() ?? '';
if (!AD_TEXTS.some(t => text.includes(t))) return;
button.setAttribute(HANDLED_ATTR, '1');
let navSlot = button;
for (let i = 0; i < 4; i++) {
if (navSlot.parentElement && navSlot.parentElement.tagName !== 'BODY') {
navSlot = navSlot.parentElement;
}
}
const target = navSlot.offsetWidth < 300 ? navSlot : button;
target.style.setProperty('display', 'none', 'important');
target.setAttribute(HANDLED_ATTR, '1');
console.debug('[TurboRemover] Fallback hidden:', text);
});
}
editAdBanner();
let debounce;
const observer = new MutationObserver(() => {
clearTimeout(debounce);
debounce = setTimeout(editAdBanner, 150);
});
observer.observe(document.body ?? document.documentElement, {
subtree: true,
childList: true
});
})();