-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrime Notifications Remover.js
More file actions
109 lines (99 loc) · 4.3 KB
/
Prime Notifications Remover.js
File metadata and controls
109 lines (99 loc) · 4.3 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// ==UserScript==
// @name Twitch.tv Amazon Prime Ad Remover
// @namespace https://github.com/mirbyte/TwitchTV-Userscripts
// @match https://www.twitch.tv/*
// @grant none
// @version 1.4
// @author mirbyte
// @description Removes amazon prime ad/button on twitch.tv. Check GitHub page for the demonstration image.
// @icon https://www.twitch.tv/favicon.ico
// ==/UserScript==
(function() {
'use strict';
function removePrime() {
// Direct targeting of prime elements
const directSelectors = [
'.top-nav__prime',
'.prime-offers',
'[class*="prime-offers"]',
'[data-a-target="prime-offers-icon"]',
'[data-a-target*="prime"]',
'[data-target*="prime"]'
];
// Remove elements using direct selectors
directSelectors.forEach(selector => {
const elements = document.querySelectorAll(selector);
elements.forEach(element => {
if (element) {
element.remove();
console.log("Prime element removed via direct selector:", selector);
}
});
});
// Additional targeting by aria-label (for internationalized versions)
const ariaElements = document.querySelectorAll('[aria-label]');
ariaElements.forEach(element => {
const ariaLabel = element.getAttribute('aria-label')?.toLowerCase() || '';
if (ariaLabel.includes('prime') || ariaLabel.includes('amazon')) {
// Check if it's in the top navigation area
const isInTopNav = element.closest('[class*="top-nav"]') ||
element.closest('[class*="prime"]') ||
element.closest('[data-a-target*="prime"]');
if (isInTopNav) {
const container = element.closest('[class*="Layout"]') || element;
container.remove();
console.log("Prime element removed via aria-label:", ariaLabel);
}
}
});
// Target buttons with Prime-related data attributes
const primeButtons = document.querySelectorAll('button[data-a-target*="prime"], button[data-target*="prime"]');
primeButtons.forEach(button => {
const container = button.closest('[class*="Layout"]') ||
button.closest('[class*="prime"]') ||
button.parentElement;
if (container) {
container.remove();
console.log("Prime button container removed");
}
});
// Fallback: Look for elements containing Prime icon SVGs
const svgElements = document.querySelectorAll('svg');
svgElements.forEach(svg => {
const paths = svg.querySelectorAll('path');
// Look for the crown/prime icon path pattern
paths.forEach(path => {
const d = path.getAttribute('d');
if (d && d.includes('13.798 10.456')) { // Part of the Prime crown icon path
const primeContainer = svg.closest('[class*="Layout"]') ||
svg.closest('button') ||
svg.closest('div[class*="prime"]');
if (primeContainer) {
primeContainer.remove();
console.log("Prime element removed via SVG detection");
}
}
});
});
}
// Run on load
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', removePrime);
} else {
removePrime();
}
// Enhanced observer with throttling
let debounceTimeout;
const observer = new MutationObserver(function(mutations) {
clearTimeout(debounceTimeout);
debounceTimeout = setTimeout(removePrime, 100);
});
if (document.body) {
observer.observe(document.body, {
subtree: true,
childList: true,
attributes: true,
attributeFilter: ['class', 'style', 'data-a-target', 'aria-label']
});
}
})();