-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
86 lines (76 loc) · 3.15 KB
/
script.js
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
// ==UserScript==
// @name Hide Paid Options on Amazon Prime Video
// @namespace https://github.com/HaroldPetersInskipp
// @version 1.1.0
// @homepageURL https://github.com/HaroldPetersInskipp/hide-paid-prime-content
// @supportURL https://github.com/HaroldPetersInskipp/hide-paid-prime-content/issues
// @description Hides list items on Amazon Prime Video that contain paid options (Buy, Rent, Trial).
// @author Inskipp
// @copyright 2024+, HaroldPetersInskipp (https://github.com/HaroldPetersInskipp)
// @license MIT; https://github.com/HaroldPetersInskipp/hide-paid-prime-content/blob/main/LICENSE
// @match https://www.amazon.com/*
// @match https://www.primevideo.com/*
// @grant none
// @icon https://raw.githubusercontent.com/HaroldPetersInskipp/hide-paid-prime-content/main/icon.png
// @run-at document-idle
// ==/UserScript==
(function() {
'use strict';
// Function to hide list items with paid options
function hidePaidListItems() {
document.querySelectorAll('li').forEach(li => {
const hasPaidIcon = li.querySelector('article > section > div > div > div > svg');
if (hasPaidIcon) {
li.style.display = 'none'; // Hide the list item
}
});
}
// Function to hide specific categories
function hideSpecificCategories() {
const categoryNames = [
'Home Premiere movies',
'New release movies – Sponsored',
'Top 10 purchases in the US'
];
document.querySelectorAll('section, div').forEach(el => {
const titleElement = el.querySelector('h2, .category-title, .title');
if (titleElement && categoryNames.includes(titleElement.innerText.trim())) {
el.style.display = 'none'; // Hide the entire category section
}
});
}
// Function to remove empty categories
function removeEmptyCategories() {
document.querySelectorAll('section, div').forEach(el => {
const listItems = el.querySelectorAll('li');
if (listItems.length > 0) {
const allHidden = Array.from(listItems).every(li => li.style.display === 'none');
if (allHidden) {
el.style.display = 'none'; // Hide the entire section if all items are hidden
}
}
});
}
// Function to perform all hiding operations
function performHidingOperations() {
hidePaidListItems();
hideSpecificCategories();
removeEmptyCategories();
}
// Run the hiding operations initially on page load
performHidingOperations();
// MutationObserver to track dynamic content loading on Prime Video
const observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.addedNodes.length) {
// Run hiding operations for newly added content
performHidingOperations();
}
});
});
// Start observing changes in the body
observer.observe(document.body, {
childList: true,
subtree: true
});
})();