Skip to content

Commit 0a7487a

Browse files
committed
Replaced Shorts redir observer w/ requestAnimationFrame() (fixes adamlui/youtube-classic#106)
1 parent c9ea126 commit 0a7487a

1 file changed

Lines changed: 10 additions & 15 deletions

File tree

youtube-classic/youtube-classic.user.js

Lines changed: 10 additions & 15 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.19
3+
// @version 2025.10.19.1
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
@@ -297,9 +297,7 @@
297297
}
298298

299299
function syncConfigToUI(options) {
300-
if (options?.updatedKey == 'disableShorts')
301-
shortsObserver[config.disableShorts ? 'observe' : 'disconnect'](document.body, obsConfig)
302-
else if (options?.updatedKey == 'adBlock')
300+
if (options?.updatedKey == 'adBlock')
303301
homeObserver[config.adBlock ? 'observe' : 'disconnect'](document.documentElement, obsConfig)
304302
if (options?.updatedKey.includes('Block'))
305303
window.configStyle.textContent = Object.entries(domSelectors)
@@ -2214,19 +2212,16 @@
22142212

22152213
// CONFIG hacks
22162214

2217-
// Redirect Shorts to classic player
22182215
let locationPath = location.pathname // to track nav
22192216
const obsConfig = { childList: true, subtree: true }
2220-
const shortsObserver = new MutationObserver(() => {
2221-
if (location.pathname != locationPath) { // nav'd to diff page, re-observe if no redir
2222-
locationPath = location.pathname ; shortsObserver.disconnect()
2223-
getLoadedElem('body').then(() => shortsObserver.observe(document.body, obsConfig))
2224-
} else if (location.pathname.startsWith('/shorts')) {
2225-
const vidID = location.pathname.split('/')[2]
2226-
if (vidID && /^[\w-]{11}$/.test(vidID)) location.replace(`https://www.youtube.com/watch?v=${vidID}`)
2227-
}
2228-
})
2229-
if (config.disableShorts) getLoadedElem('body').then(() => shortsObserver.observe(document.body, obsConfig))
2217+
2218+
// Redirect Shorts to classic player
2219+
if (config.disableShorts)
2220+
(function checkShorts() {
2221+
if (location.pathname.startsWith('/shorts/'))
2222+
return location.replace(`https://www.youtube.com/watch?v=${location.pathname.split('/')[2]}`)
2223+
requestAnimationFrame(checkShorts)
2224+
})()
22302225

22312226
// Remove homepage ads/rich sections
22322227
const homeObserver = new MutationObserver(() => {

0 commit comments

Comments
 (0)