Skip to content

Commit 36cdece

Browse files
committed
Added/used dom.js ↞ [auto-sync from https://github.com/adamlui/youtube-classic]
1 parent 4f92c19 commit 36cdece

1 file changed

Lines changed: 13 additions & 27 deletions

File tree

youtube-classic/youtube-classic.user.js

Lines changed: 13 additions & 27 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 2026.1.20.12
3+
// @version 2026.1.21
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
@@ -15,6 +15,7 @@
1515
// @match *://*.youtube.com/*
1616
// @connect gm.ytclassic.com
1717
// @connect raw.githubusercontent.com
18+
// @require https://cdn.jsdelivr.net/gh/adamlui/ai-web-extensions@2063df6/assets/js/lib/dom.js/dist/dom.min.js#sha256-xovdxRnmYD/eCgBiGCu5+Vd3+WWIvLUKVtU/MnRueeU=
1819
// @grant GM_registerMenuCommand
1920
// @grant GM_unregisterMenuCommand
2021
// @grant GM_getValue
@@ -290,19 +291,6 @@
290291
function extractSelectors(obj) {
291292
return Object.values(obj).flatMap(val => typeof val == 'object' ? extractSelectors(val) : val) }
292293

293-
function getLoadedElem(selector, timeout = null) {
294-
const timeoutPromise = timeout ? new Promise(resolve => setTimeout(() => resolve(null), timeout)) : null
295-
const isLoadedPromise = new Promise(resolve => {
296-
const elem = document.querySelector(selector)
297-
if (elem) resolve(elem)
298-
else new MutationObserver((_, obs) => {
299-
const elem = document.querySelector(selector)
300-
if (elem) { obs.disconnect() ; resolve(elem) }
301-
}).observe(document.documentElement, { childList: true, subtree: true })
302-
})
303-
return ( timeoutPromise ? Promise.race([isLoadedPromise, timeoutPromise]) : isLoadedPromise )
304-
}
305-
306294
const toolbarMenu = {
307295
state: {
308296
symbols: ['❌', '✔️'], separator: env.scriptManager.name == 'Tampermonkey' ? ' — ' : ': ',
@@ -331,7 +319,7 @@
331319
}
332320
}
333321

334-
function notify(msg, pos = '', notifDuration = '', shadow = '') {
322+
function notify(msg, pos = '', notifDuration = '', shadow = '') { // requires dom.js
335323
if (config.notifDisabled && !msg.includes(settings.controls.notifDisabled.label)) return
336324

337325
// Strip state word to append colored one later
@@ -345,12 +333,11 @@
345333
// Tweak styles
346334
notif.style.fontSize = '385%'
347335
if (foundState) { // append styled state word
348-
const styledStateSpan = document.createElement('span')
349-
styledStateSpan.style.cssText = `color: ${
336+
const styledStateSpan = dom.create.elem('span', { style: `color: ${
350337
foundState == toolbarMenu.state.words[0] ?
351338
'#ef4848 ; text-shadow: rgba(255,169,225,0.44) 2px 1px 5px'
352339
: '#5cef48 ; text-shadow: rgba(255,250,169,0.38) 2px 1px 5px'
353-
}`
340+
}`})
354341
styledStateSpan.append(foundState) ; notif.append(styledStateSpan)
355342
}
356343
}
@@ -435,8 +422,7 @@
435422
'darker-dark-theme', 'darker-dark-theme-deprecate' ]
436423
unsafeWindow.addEventListener('yt-page-data-updated', function tmp() {
437424
const ytLogo = document.getElementById('logo-icon'),
438-
classicLogo = document.createElement('img')
439-
classicLogo.style.marginLeft = '5px' ; classicLogo.height = 65
425+
classicLogo = dom.create.elem('img', { style: 'margin-left: 5px', height: 65 })
440426
classicLogo.src = document.querySelector('ytd-masthead').getAttribute('dark') != null
441427
? 'https://i.imgur.com/brCETJj.png' // Dark mode
442428
: 'https://i.imgur.com/rHLcxEs.png' // Light mode
@@ -451,8 +437,8 @@
451437
YTP.setExpMulti(EXPFLAGS)
452438
YTP.setPlyrFlags(PLYRFLAGS)
453439

454-
getLoadedElem('#items.ytd-guide-section-renderer').then(restoreTrending)
455-
getLoadedElem('#items.ytd-mini-guide-section-renderer').then(restoreTrending)
440+
dom.get.loadedElem('#items.ytd-guide-section-renderer').then(restoreTrending)
441+
dom.get.loadedElem('#items.ytd-mini-guide-section-renderer').then(restoreTrending)
456442

457443
function restoreTrending() {
458444
const trendingData = {
@@ -570,7 +556,7 @@
570556
commentObserver.observe(document.querySelector('ytd-app'), { childList: true, subtree: true }))
571557

572558
// CSS adjustments and UI fixes
573-
app.styles = { fixes: document.createElement('style') }
559+
app.styles = { fixes: dom.create.style() }
574560
app.styles.fixes.innerText = `
575561
yt-thumbnail-view-model { border-radius: 0 !important } /* square homepage thumbs */
576562
@@ -1115,7 +1101,7 @@
11151101
div#subscribe-button { position: absolute ; right: 0 } div#actions { padding-right: 125px } /* align right */
11161102
}
11171103
`
1118-
getLoadedElem('head').then(() => document.head.append(app.styles.fixes))
1104+
dom.get.loadedElem('head').then(() => document.head.append(app.styles.fixes))
11191105

11201106
Object.defineProperties(document, {
11211107
'hidden': {value: false}, 'webkitHidden': {value: false}, 'visibilityState': {value: 'visible'},
@@ -1142,7 +1128,7 @@
11421128
const homeObserver = new MutationObserver(() => {
11431129
if (location.pathname != locationPath) { // nav'd to diff page, re-observe
11441130
locationPath = location.pathname ; homeObserver.disconnect()
1145-
getLoadedElem('html').then(() => homeObserver.observe(document.documentElement, obsConfig))
1131+
dom.get.loadedElem('html').then(() => homeObserver.observe(document.documentElement, obsConfig))
11461132
} else if (locationPath == '/') { // remove regenerating homepage stuff
11471133
if (config.adBlock) // remove ads
11481134
document.querySelector('ytd-ad-slot-renderer')?.closest('[rendered-from-rich-grid]')?.remove()
@@ -1153,10 +1139,10 @@
11531139
)?.remove()
11541140
}
11551141
})
1156-
getLoadedElem('html').then(() => homeObserver.observe(document.documentElement, obsConfig))
1142+
dom.get.loadedElem('html').then(() => homeObserver.observe(document.documentElement, obsConfig))
11571143

11581144
// Block stuff
1159-
document.head.append(window.configStyle ??= document.createElement('style'))
1145+
document.head.append(window.configStyle ??= dom.create.style())
11601146
window.configStyle.textContent = Object.entries(domSelectors).map(([key, selectors]) =>
11611147
!config[`${key}Block`] ? '' : `${extractSelectors(selectors).join(',')} { display: none }`).join('')
11621148
})()

0 commit comments

Comments
 (0)