|
1 | 1 | // ==UserScript== |
2 | 2 | // @name YouTube™ Classic 📺 — (Remove rounded design + Return YouTube dislikes) |
3 | | -// @version 2025.10.18.1 |
| 3 | +// @version 2025.10.18.2 |
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 |
|
90 | 90 |
|
91 | 91 | // Init SELECTORS for options |
92 | 92 | 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/"])' }, |
94 | 99 | shorts: { |
95 | 100 | navEntry: 'a#endpoint[title=Shorts]', |
96 | 101 | shelf: { |
97 | 102 | homepage: 'div.ytd-rich-shelf-renderer:has(a[href*="/shorts/"])', // https://imgur.com/a/LMdO92M |
98 | 103 | results: 'grid-shelf-view-model:has(a[href*="/shorts/"])' // https://imgur.com/a/vVzoEfH |
99 | 104 | } |
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 | + } |
103 | 106 | } |
104 | 107 |
|
105 | 108 | // Define FUNCTIONS |
|
293 | 296 | if (options?.updatedKey == 'disableShorts') |
294 | 297 | shortsObserver[config.disableShorts ? 'observe' : 'disconnect'](document.body, obsConfig) |
295 | 298 | else if (options?.updatedKey == 'adBlock') |
296 | | - homeObserver[config.adBlock ? 'observe' : 'disconnect'](document.documentElement, obsConfig) |
| 299 | + adObserver[config.adBlock ? 'observe' : 'disconnect'](document.documentElement, obsConfig) |
297 | 300 | 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('') |
302 | 305 | toolbarMenu.refresh() // prefixes/suffixes |
303 | 306 | } |
304 | 307 |
|
|
2222 | 2225 | if (config.disableShorts) getLoadedElem('body').then(() => shortsObserver.observe(document.body, obsConfig)) |
2223 | 2226 |
|
2224 | 2227 | // Remove homepage ads/rich sections |
2225 | | - const homeObserver = new MutationObserver(() => { |
| 2228 | + const adObserver = new MutationObserver(() => { |
2226 | 2229 | 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() |
2237 | 2234 | }) |
2238 | 2235 | 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)) |
2240 | 2237 |
|
2241 | 2238 | // Block stuff |
2242 | 2239 | 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('') |
2247 | 2244 | function extractSelectors(obj) { |
2248 | 2245 | return Object.values(obj).flatMap(val => typeof val == 'object' ? extractSelectors(val) : val) } |
2249 | 2246 |
|
|
0 commit comments