Skip to content

Commit b0e5f23

Browse files
committed
Converted homeObserver back to adObserver, automated configStyle updates
1 parent 6cd2770 commit b0e5f23

1 file changed

Lines changed: 23 additions & 26 deletions

File tree

youtube-classic/youtube-classic.user.js

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ==UserScript==
22
// @name YouTube™ Classic 📺 — (Remove rounded design + Return YouTube dislikes)
3-
// @version 2025.10.18.1
3+
// @version 2025.10.18.2
44
// @author Adam Lui, Magma_Craft, Anarios, JRWR, Fuim & hoothin
55
// @namespace https://github.com/adamlui
66
// @description Reverts YouTube to its classic design (before all the rounded corners & hidden dislikes) + redirects YouTube Shorts
@@ -90,16 +90,19 @@
9090

9191
// Init SELECTORS for options
9292
const domSelectors = {
93-
ads: { masthead: 'div#masthead-ad' }, // https://imgur.com/a/kOWzh3O
93+
ad: { masthead: 'div#masthead-ad' }, // https://imgur.com/a/kOWzh3O
94+
ai: {
95+
askBtn: 'button:has(path[d*=M480-80q0-83])',
96+
summary: 'div#header[class*=expandable-metadata]:has(path[d*=M480-80q0-83])'
97+
},
98+
playables: { shelf: 'ytd-rich-section-renderer:has(a[href*="/playables/"])' },
9499
shorts: {
95100
navEntry: 'a#endpoint[title=Shorts]',
96101
shelf: {
97102
homepage: 'div.ytd-rich-shelf-renderer:has(a[href*="/shorts/"])', // https://imgur.com/a/LMdO92M
98103
results: 'grid-shelf-view-model:has(a[href*="/shorts/"])' // https://imgur.com/a/vVzoEfH
99104
}
100-
},
101-
aiSummary: 'div#header[class*=expandable-metadata]:has(path[d*=M480-80q0-83]),' // AI summary
102-
+ 'button:has(path[d*=M480-80q0-83])' // Ask AI button
105+
}
103106
}
104107

105108
// Define FUNCTIONS
@@ -293,12 +296,12 @@
293296
if (options?.updatedKey == 'disableShorts')
294297
shortsObserver[config.disableShorts ? 'observe' : 'disconnect'](document.body, obsConfig)
295298
else if (options?.updatedKey == 'adBlock')
296-
homeObserver[config.adBlock ? 'observe' : 'disconnect'](document.documentElement, obsConfig)
299+
adObserver[config.adBlock ? 'observe' : 'disconnect'](document.documentElement, obsConfig)
297300
if (options?.updatedKey.includes('Block'))
298-
window.configStyle.textContent = `
299-
${ !config.shortsBlock ? '' : `${extractSelectors(domSelectors.shorts).join(',')} { display: none }` }
300-
${ !config.adBlock ? '' : `${extractSelectors(domSelectors.ads).join(',')} { display: none }` }
301-
${ !config.aiBlock ? '' : `${domSelectors.aiSummary} { display: none }` }`
301+
window.configStyle.textContent = Object.entries(domSelectors)
302+
.map(([key, selectors]) => !config[`${key}Block`] ? ''
303+
: `${extractSelectors(selectors).join(',')} { display: none }`
304+
).join('')
302305
toolbarMenu.refresh() // prefixes/suffixes
303306
}
304307

@@ -2222,28 +2225,22 @@
22222225
if (config.disableShorts) getLoadedElem('body').then(() => shortsObserver.observe(document.body, obsConfig))
22232226

22242227
// Remove homepage ads/rich sections
2225-
const homeObserver = new MutationObserver(() => {
2228+
const adObserver = new MutationObserver(() => {
22262229
if (location.pathname != locationPath) { // nav'd to diff page, re-observe
2227-
locationPath = location.pathname ; homeObserver.disconnect()
2228-
getLoadedElem('html').then(() => homeObserver.observe(document.documentElement, obsConfig))
2229-
} else if (locationPath == '/') { // remove homepage stuff
2230-
const adSlot = document.querySelector('ytd-ad-slot-renderer')
2231-
const richSection = document.querySelector(
2232-
`ytd-rich-section-renderer${ !config.shortsBlock ? ':not(:has(a[href*="/shorts/"]))' : '' }${
2233-
!config.playablesBlock ? ':not(:has(a[href*="/playables/"]))' : '' }`
2234-
)
2235-
adSlot?.closest('[rendered-from-rich-grid]')?.remove() ; richSection?.remove()
2236-
}
2230+
locationPath = location.pathname ; adObserver.disconnect()
2231+
getLoadedElem('html').then(() => adObserver.observe(document.documentElement, obsConfig))
2232+
} else if (locationPath == '/') // remove ads
2233+
document.querySelector('ytd-ad-slot-renderer')?.closest('[rendered-from-rich-grid]')?.remove()
22372234
})
22382235
if (config.shortsBlock || config.playablesBlock || config.adBlock)
2239-
getLoadedElem('html').then(() => homeObserver.observe(document.documentElement, obsConfig))
2236+
getLoadedElem('html').then(() => adObserver.observe(document.documentElement, obsConfig))
22402237

22412238
// Block stuff
22422239
document.head.append(window.configStyle ??= document.createElement('style'))
2243-
window.configStyle.textContent = `
2244-
${ !config.shortsBlock ? '' : `${extractSelectors(domSelectors.shorts).join(',')} { display: none }` }
2245-
${ !config.adBlock ? '' : `${extractSelectors(domSelectors.ads).join(',')} { display: none }` }
2246-
${ !config.aiBlock ? '' : `${domSelectors.aiSummary} { display: none }` }`
2240+
window.configStyle.textContent = Object.entries(domSelectors)
2241+
.map(([key, selectors]) => !config[`${key}Block`] ? ''
2242+
: `${extractSelectors(selectors).join(',')} { display: none }`
2243+
).join('')
22472244
function extractSelectors(obj) {
22482245
return Object.values(obj).flatMap(val => typeof val == 'object' ? extractSelectors(val) : val) }
22492246

0 commit comments

Comments
 (0)