-
Notifications
You must be signed in to change notification settings - Fork 3
/
youtube-filter-subscriptions-page.user.js
99 lines (83 loc) · 3.3 KB
/
youtube-filter-subscriptions-page.user.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
87
88
89
90
91
92
93
94
95
96
97
98
99
// ==UserScript==
// @name YouTube - Filter Subscriptions Page
// @namespace https://zachhardesty.com
// @author Zach Hardesty <[email protected]> (https://github.com/zachhardesty7)
// @description hide videos with given title keywords
// @copyright 2019-2024, Zach Hardesty (https://zachhardesty.com/)
// @license GPL-3.0-only; http://www.gnu.org/licenses/gpl-3.0.txt
// @version 2.1.0
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_registerMenuCommand
// @homepageURL https://github.com/zachhardesty7/tamper-monkey-scripts-collection/raw/master/youtube-filter-subscriptions-page.user.js
// @homepage https://github.com/zachhardesty7/tamper-monkey-scripts-collection/raw/master/youtube-filter-subscriptions-page.user.js
// @homepageURL https://openuserjs.org/scripts/zachhardesty7/YouTube_-_Filter_Subscriptions_Page
// @homepage https://openuserjs.org/scripts/zachhardesty7/YouTube_-_Filter_Subscriptions_Page
// @supportURL https://github.com/zachhardesty7/tamper-monkey-scripts-collection/issues
// @updateURL https://openuserjs.org/meta/zachhardesty7/YouTube_-_Filter_Subscriptions_Page.meta.js
// @downloadURL https://openuserjs.org/src/scripts/zachhardesty7/YouTube_-_Filter_Subscriptions_Page.user.js
// @match https://www.youtube.com/*
// @require https://greasyfork.org/scripts/419640-onelementready/code/onElementReady.js?version=887637
// ==/UserScript==
/* global onElementReady */
const HIDDEN_CLASSNAME = "zh-hidden"
let keywords = GM_getValue("yt-filter-page", "")
const stylesheet = document.createElement("style")
const head = document.head || document.querySelectorAll("head")[0]
stylesheet.id = "hiding" // to edit later
stylesheet.type = "text/css"
stylesheet.append(
document.createTextNode(`
.zh-hidden {
display: none !important;
}
`),
)
head.append(stylesheet)
// runs on youtube.com/feed/subscriptions
onElementReady(
"#dismissible.style-scope.ytd-grid-video-renderer",
{ findOnce: false },
(el) => {
const videoTitle = el
.querySelector("#details #meta")
.firstElementChild.textContent.toLowerCase()
const parentContainer = el.parentElement
for (const keyword of keywords.toLowerCase().split(",")) {
if (keyword && videoTitle.includes(keyword)) {
parentContainer.classList.add(HIDDEN_CLASSNAME)
return
}
}
parentContainer.classList.remove(HIDDEN_CLASSNAME)
},
)
// runs on youtube.com
onElementReady(
"#dismissible.style-scope.ytd-rich-grid-media",
{ findOnce: false },
(el) => {
const videoTitle = el
.querySelector("#details #meta")
.firstElementChild.textContent.toLowerCase()
const parentContainer = el.parentElement.parentElement.parentElement
for (const keyword of keywords.toLowerCase().split(",")) {
if (keyword && videoTitle.includes(keyword)) {
parentContainer.classList.add(HIDDEN_CLASSNAME)
return
}
}
parentContainer.classList.remove(HIDDEN_CLASSNAME)
},
)
GM_registerMenuCommand("Set YT Filter Subscriptions Page Keywords", () => {
// eslint-disable-next-line no-alert
const val = prompt(
"input a comma separated list of keywords (case insensitive)",
keywords,
)
if (val !== null) {
keywords = val
GM_setValue("yt-filter-page", val)
}
})