|
1 | 1 | // ==UserScript== |
2 | 2 | // @name YouTube™ Classic 📺 — (Remove rounded design + Return YouTube dislikes) |
3 | | -// @version 2026.1.20.12 |
| 3 | +// @version 2026.1.21 |
4 | 4 | // @author Adam Lui, Magma_Craft, Anarios, JRWR, Fuim & hoothin |
5 | 5 | // @namespace https://github.com/adamlui |
6 | 6 | // @description Reverts YouTube to its classic design (before all the rounded corners & hidden dislikes) + redirects YouTube Shorts |
|
15 | 15 | // @match *://*.youtube.com/* |
16 | 16 | // @connect gm.ytclassic.com |
17 | 17 | // @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= |
18 | 19 | // @grant GM_registerMenuCommand |
19 | 20 | // @grant GM_unregisterMenuCommand |
20 | 21 | // @grant GM_getValue |
|
290 | 291 | function extractSelectors(obj) { |
291 | 292 | return Object.values(obj).flatMap(val => typeof val == 'object' ? extractSelectors(val) : val) } |
292 | 293 |
|
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 | | - |
306 | 294 | const toolbarMenu = { |
307 | 295 | state: { |
308 | 296 | symbols: ['❌', '✔️'], separator: env.scriptManager.name == 'Tampermonkey' ? ' — ' : ': ', |
|
331 | 319 | } |
332 | 320 | } |
333 | 321 |
|
334 | | - function notify(msg, pos = '', notifDuration = '', shadow = '') { |
| 322 | + function notify(msg, pos = '', notifDuration = '', shadow = '') { // requires dom.js |
335 | 323 | if (config.notifDisabled && !msg.includes(settings.controls.notifDisabled.label)) return |
336 | 324 |
|
337 | 325 | // Strip state word to append colored one later |
|
345 | 333 | // Tweak styles |
346 | 334 | notif.style.fontSize = '385%' |
347 | 335 | 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: ${ |
350 | 337 | foundState == toolbarMenu.state.words[0] ? |
351 | 338 | '#ef4848 ; text-shadow: rgba(255,169,225,0.44) 2px 1px 5px' |
352 | 339 | : '#5cef48 ; text-shadow: rgba(255,250,169,0.38) 2px 1px 5px' |
353 | | - }` |
| 340 | + }`}) |
354 | 341 | styledStateSpan.append(foundState) ; notif.append(styledStateSpan) |
355 | 342 | } |
356 | 343 | } |
|
435 | 422 | 'darker-dark-theme', 'darker-dark-theme-deprecate' ] |
436 | 423 | unsafeWindow.addEventListener('yt-page-data-updated', function tmp() { |
437 | 424 | 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 }) |
440 | 426 | classicLogo.src = document.querySelector('ytd-masthead').getAttribute('dark') != null |
441 | 427 | ? 'https://i.imgur.com/brCETJj.png' // Dark mode |
442 | 428 | : 'https://i.imgur.com/rHLcxEs.png' // Light mode |
|
451 | 437 | YTP.setExpMulti(EXPFLAGS) |
452 | 438 | YTP.setPlyrFlags(PLYRFLAGS) |
453 | 439 |
|
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) |
456 | 442 |
|
457 | 443 | function restoreTrending() { |
458 | 444 | const trendingData = { |
|
570 | 556 | commentObserver.observe(document.querySelector('ytd-app'), { childList: true, subtree: true })) |
571 | 557 |
|
572 | 558 | // CSS adjustments and UI fixes |
573 | | - app.styles = { fixes: document.createElement('style') } |
| 559 | + app.styles = { fixes: dom.create.style() } |
574 | 560 | app.styles.fixes.innerText = ` |
575 | 561 | yt-thumbnail-view-model { border-radius: 0 !important } /* square homepage thumbs */ |
576 | 562 |
|
|
1115 | 1101 | div#subscribe-button { position: absolute ; right: 0 } div#actions { padding-right: 125px } /* align right */ |
1116 | 1102 | } |
1117 | 1103 | ` |
1118 | | - getLoadedElem('head').then(() => document.head.append(app.styles.fixes)) |
| 1104 | + dom.get.loadedElem('head').then(() => document.head.append(app.styles.fixes)) |
1119 | 1105 |
|
1120 | 1106 | Object.defineProperties(document, { |
1121 | 1107 | 'hidden': {value: false}, 'webkitHidden': {value: false}, 'visibilityState': {value: 'visible'}, |
|
1142 | 1128 | const homeObserver = new MutationObserver(() => { |
1143 | 1129 | if (location.pathname != locationPath) { // nav'd to diff page, re-observe |
1144 | 1130 | 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)) |
1146 | 1132 | } else if (locationPath == '/') { // remove regenerating homepage stuff |
1147 | 1133 | if (config.adBlock) // remove ads |
1148 | 1134 | document.querySelector('ytd-ad-slot-renderer')?.closest('[rendered-from-rich-grid]')?.remove() |
|
1153 | 1139 | )?.remove() |
1154 | 1140 | } |
1155 | 1141 | }) |
1156 | | - getLoadedElem('html').then(() => homeObserver.observe(document.documentElement, obsConfig)) |
| 1142 | + dom.get.loadedElem('html').then(() => homeObserver.observe(document.documentElement, obsConfig)) |
1157 | 1143 |
|
1158 | 1144 | // Block stuff |
1159 | | - document.head.append(window.configStyle ??= document.createElement('style')) |
| 1145 | + document.head.append(window.configStyle ??= dom.create.style()) |
1160 | 1146 | window.configStyle.textContent = Object.entries(domSelectors).map(([key, selectors]) => |
1161 | 1147 | !config[`${key}Block`] ? '' : `${extractSelectors(selectors).join(',')} { display: none }`).join('') |
1162 | 1148 | })() |
0 commit comments