Refactor: split 303-line buildStylesheet() into named sub-functions#105
Open
w6a8w8 wants to merge 12 commits intoZren:masterfrom
Open
Refactor: split 303-line buildStylesheet() into named sub-functions#105w6a8w8 wants to merge 12 commits intoZren:masterfrom
w6a8w8 wants to merge 12 commits intoZren:masterfrom
Conversation
Removed version 140 entry from changelog.
Removed HistoryEvent class (unused; native yt-navigate-finish handles SPA routing). Removed ytwp.html5PlayerFix (unreachable code block due to early return). Removed window 'keypress' listener (deprecated API; 'keydown' handles the logic).
Added early return inside the else block to accurately report when the DOM has changed. Prevents the loop from cascading fake errors against a stuck parent node. Enhanced the error log to output the actual mismatched parent element.
Replaced 60fps rAF polling with targeted, debounced MutationObservers to reduce redundant DOM queries. Added lifecycle management to disconnect existing observers before re-attaching, preventing memory leaks. Deferred observer attachment until ytwp.initialized is true to fix silent failures on homepage cold starts. Slowed the fallback setInterval safety net from 2500ms to 5000ms.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
buildStylesheet()was a single 303-line function containing rules for every visual concern in the script—scrollbars, player sizing, sidebar, masthead, guide, miniplayer, playlist bar, and Material/Flexy UI. There was no way to locate, read, or modify one concern without scrolling past all the others.Solution
Extracted 8 named sub-functions as sibling properties on
ytwp.event:_styleScrollbar()_stylePlayer()_styleSidebar()_styleMasthead()_styleMiniplayer()_styleMisc()_stylePlaylistBar()_styleMaterialUI()buildStylesheet()now delegates to all eight in order and remains the single call site, so the SPF duplication path ininitStyle()is unchanged.What did not change
Zero CSS rules were added, removed, or reordered. The
appendRuleandappendRawcall count is identical (64) in both versions. Each sub-function that used the shareddvariable now declares its own locald—there was no shared state between sections.