Skip to content

Commit df7e9fb

Browse files
committed
Restored adObserver to homeObserver to avoid gaps when shelves hidden
1 parent ce5a202 commit df7e9fb

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

youtube-classic/youtube-classic.user.js

Lines changed: 14 additions & 8 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.3
3+
// @version 2025.10.18.4
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
@@ -299,7 +299,7 @@
299299
if (options?.updatedKey == 'disableShorts')
300300
shortsObserver[config.disableShorts ? 'observe' : 'disconnect'](document.body, obsConfig)
301301
else if (options?.updatedKey == 'adBlock')
302-
adObserver[config.adBlock ? 'observe' : 'disconnect'](document.documentElement, obsConfig)
302+
homeObserver[config.adBlock ? 'observe' : 'disconnect'](document.documentElement, obsConfig)
303303
if (options?.updatedKey.includes('Block'))
304304
window.configStyle.textContent = Object.entries(domSelectors)
305305
.map(([key, selectors]) => !config[`${key}Block`] ? ''
@@ -2228,15 +2228,21 @@
22282228
if (config.disableShorts) getLoadedElem('body').then(() => shortsObserver.observe(document.body, obsConfig))
22292229

22302230
// Remove homepage ads/rich sections
2231-
const adObserver = new MutationObserver(() => {
2231+
const homeObserver = new MutationObserver(() => {
22322232
if (location.pathname != locationPath) { // nav'd to diff page, re-observe
2233-
locationPath = location.pathname ; adObserver.disconnect()
2234-
getLoadedElem('html').then(() => adObserver.observe(document.documentElement, obsConfig))
2235-
} else if (locationPath == '/') // remove ads
2236-
document.querySelector('ytd-ad-slot-renderer')?.closest('[rendered-from-rich-grid]')?.remove()
2233+
locationPath = location.pathname ; homeObserver.disconnect()
2234+
getLoadedElem('html').then(() => homeObserver.observe(document.documentElement, obsConfig))
2235+
} else if (locationPath == '/') { // remove homepage shelves (for no gaps) + ads
2236+
const adSlot = document.querySelector('ytd-ad-slot-renderer')
2237+
const richSection = document.querySelector(
2238+
`ytd-rich-section-renderer${ !config.shortsBlock ? ':not(:has(a[href*="/shorts/"]))' : '' }${
2239+
!config.playablesBlock ? ':not(:has(a[href*="/playables/"]))' : '' }`
2240+
)
2241+
adSlot?.closest('[rendered-from-rich-grid]')?.remove() ; richSection?.remove()
2242+
}
22372243
})
22382244
if (config.shortsBlock || config.playablesBlock || config.adBlock)
2239-
getLoadedElem('html').then(() => adObserver.observe(document.documentElement, obsConfig))
2245+
getLoadedElem('html').then(() => homeObserver.observe(document.documentElement, obsConfig))
22402246

22412247
// Block stuff
22422248
document.head.append(window.configStyle ??= document.createElement('style'))

0 commit comments

Comments
 (0)