Skip to content

Commit e8a5f20

Browse files
committed
Moved right-align sub btn from CSS to JS, replaced setTimeout w/ rquestAnimationFrame ↞ [auto-sync from https://github.com/adamlui/youtube-classic]
1 parent 14e9b16 commit e8a5f20

1 file changed

Lines changed: 16 additions & 15 deletions

File tree

youtube-classic/youtube-classic.user.js

Lines changed: 16 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 2026.1.27.4
3+
// @version 2026.1.27.5
44
// @author Adam Lui, Magma_Craft, 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
@@ -1029,9 +1029,6 @@
10291029
10301030
/* Hide Edit your custom feed chip */
10311031
yt-chip-cloud-chip-renderer:has(path[d^="M5 0a5 5"]) { display: none }
1032-
1033-
@media only screen and (min-width: 768px) { /* align sub btn right */
1034-
div#subscribe-button { position: absolute ; right: 0 }}
10351032
`)}
10361033
dom.get.loadedElem('head').then(() => document.head.append(app.styles.fixes))
10371034

@@ -1073,20 +1070,24 @@
10731070
})
10741071
dom.get.loadedElem('html').then(() => homeObserver.observe(document.documentElement, obsConfig))
10751072

1076-
// Set actions div padding + update when needed
1073+
// Set/update subscribe button pos
10771074
dom.get.loadedElem('ytd-subscribe-button-renderer button').then(subBtn => {
1078-
setTimeout(updateActionsDivPadding, 5000)
1079-
new MutationObserver(updateActionsDivPadding).observe(subBtn, { childList: true, subtree: true })
1080-
window.addEventListener('resize', updateActionsDivPadding)
1075+
requestAnimationFrame(updateSubBtnPos)
1076+
new MutationObserver(updateSubBtnPos).observe(subBtn, { childList: true, subtree: true })
1077+
window.addEventListener('resize', updateSubBtnPos)
10811078
})
1082-
function updateActionsDivPadding() {
1083-
if (updateActionsDivPadding.timeout) clearTimeout(updateActionsDivPadding.timeout)
1084-
updateActionsDivPadding.timeout = setTimeout(async () => {
1085-
const actionsDiv = await dom.get.loadedElem('div#actions'),
1079+
function updateSubBtnPos() {
1080+
if (updateSubBtnPos.timeout) clearTimeout(updateSubBtnPos.timeout)
1081+
updateSubBtnPos.timeout = setTimeout(async () => {
1082+
const primaryDiv = await dom.get.loadedElem('div#primary'),
1083+
actionsDiv = await dom.get.loadedElem('div#actions'),
1084+
subBtn = await dom.get.loadedElem('div#subscribe-button'),
10861085
bellIcon = await dom.get.loadedElem('[animated-icon-type=NOTIFICATION_BELL] svg'),
1087-
bellWidth = getComputedStyle(bellIcon).width,
1088-
idealActionsRpadding = !window.matchMedia('(min-width: 768px)').matches ? ''
1089-
: `${125 + (bellWidth.endsWith('px') ? parseInt(bellWidth.slice(0, -2)) : 0)}px`
1086+
bellWidth = parseInt(getComputedStyle(bellIcon).width),
1087+
primaryWidth = parseInt(getComputedStyle(primaryDiv).width),
1088+
idealActionsRpadding = primaryWidth < 768 ? '' : `${ 125 +( bellWidth == 100 ? 0 : bellWidth )}px`
1089+
Object.assign(subBtn.style,
1090+
primaryWidth > 768 ? { position: 'absolute', right: 0 } : { position: '', right: '' })
10901091
if (getComputedStyle(actionsDiv).paddingRight != idealActionsRpadding)
10911092
actionsDiv.style.paddingRight = idealActionsRpadding
10921093
}, 50)

0 commit comments

Comments
 (0)