|
1 | 1 | // ==UserScript== |
2 | 2 | // @name Spotifuck v6 |
3 | 3 | // @namespace https://github.com/Myst1cX/spotifuck-userscript |
4 | | -// @version 6.2 |
| 4 | +// @version 6.3 |
5 | 5 | // @description Full Spotifuck 1.6.4 UI hack (with minor tweaks) + playback control + silent ad blocking port on open.spotify.com |
6 | 6 | // @author Myst1cX (adapted from Spotifuck app) |
7 | 7 | // @match https://open.spotify.com/* |
|
35 | 35 | let ulFlag = false; // Unlock flag |
36 | 36 | let ffDone = false; // First fuck done (firstFuck initialization complete) |
37 | 37 | let pfint = null; // Primary features interval |
| 38 | + let libButtonSetup = false; // Library button initialized flag |
| 39 | + let libGridSetup = false; // Library grid initialized flag |
38 | 40 |
|
39 | 41 | // Constants for library button states and timing |
40 | 42 | const LIBRARY_BUTTON_COLLAPSED = 'Collapse Your Library'; |
|
146 | 148 | }, 5000); |
147 | 149 | }; |
148 | 150 |
|
| 151 | + /** |
| 152 | + * Collapse library after initialization |
| 153 | + * Ensures library is always closed on startup |
| 154 | + */ |
| 155 | + const collapseLibraryOnStartup = () => { |
| 156 | + if (libButtonSetup && libGridSetup && window.lBtn) { |
| 157 | + // Check if library is currently expanded |
| 158 | + if (window.lBtn.getAttribute('aria-label') === LIBRARY_BUTTON_COLLAPSED) { |
| 159 | + console.log('✓ Library initialized - collapsing to default closed state'); |
| 160 | + // Click the button to collapse library |
| 161 | + window.lBtn.click(); |
| 162 | + } else { |
| 163 | + console.log('✓ Library already in collapsed state on startup'); |
| 164 | + } |
| 165 | + } |
| 166 | + }; |
| 167 | + |
149 | 168 | /** |
150 | 169 | * addCSSJSHack - Add CSS modifications and event listeners |
151 | 170 | * From r0/e.java line 200: window.addCSSJSHack=function(){...} |
152 | 171 | */ |
153 | 172 | window.addCSSJSHack = function() { |
154 | 173 | // Setup library button once |
155 | 174 | const setupLibraryButton = () => { |
| 175 | + // Skip if already set up |
| 176 | + if (libButtonSetup) return; |
| 177 | + |
156 | 178 | // Use aria-label to identify the correct library button (not back button) |
157 | 179 | // Library button has aria-label containing "Your Library" (either "Open Your Library" or "Collapse Your Library") |
158 | 180 | // Back button has aria-label="Go back" which doesn't contain "Your Library" |
|
167 | 189 | libBtn.addEventListener('click', function() { |
168 | 190 | setTimeout(() => switchLs(), 0); |
169 | 191 | }); |
170 | | - |
171 | | - // Collapse library on startup if it's expanded |
172 | | - // Check if button says "Collapse" (meaning library is currently expanded) |
173 | | - if (libBtn.getAttribute('aria-label') === LIBRARY_BUTTON_COLLAPSED) { |
174 | | - console.log('Library is expanded on startup, collapsing it...'); |
175 | | - // Click the button to let Spotify update its state properly |
176 | | - // This ensures the button will show "Open your library" after collapse |
177 | | - libBtn.click(); |
178 | | - } |
| 192 | + |
| 193 | + libButtonSetup = true; |
| 194 | + console.log('✓ Library button setup complete'); |
| 195 | + |
| 196 | + // Try to collapse library if grid is also ready |
| 197 | + collapseLibraryOnStartup(); |
179 | 198 | } |
180 | 199 | }; |
181 | 200 |
|
182 | 201 | // Setup library grid click handler once |
183 | 202 | const setupLibraryGrid = () => { |
| 203 | + // Skip if already set up |
| 204 | + if (libGridSetup) return; |
| 205 | + |
184 | 206 | const libGrid = document.querySelector('#Desktop_LeftSidebar_Id div[role=grid]:not(.fuckd)'); |
185 | 207 | if (libGrid) { |
186 | 208 | libGrid.classList.add('fuckd'); |
|
227 | 249 | }, PLAYLIST_NAVIGATION_DELAY_MS); |
228 | 250 | } |
229 | 251 | }); |
| 252 | + |
| 253 | + libGridSetup = true; |
| 254 | + console.log('✓ Library grid setup complete'); |
| 255 | + |
| 256 | + // Try to collapse library if button is also ready |
| 257 | + collapseLibraryOnStartup(); |
230 | 258 | } |
231 | 259 | }; |
232 | 260 |
|
|
272 | 300 | setupSearchInput(); |
273 | 301 | setupUserButton(); |
274 | 302 |
|
275 | | - // Use a short retry mechanism for elements that might not be ready yet |
276 | | - // Check once more after 2 seconds for any missed elements |
277 | | - setTimeout(() => { |
278 | | - setupLibraryButton(); |
279 | | - setupLibraryGrid(); |
| 303 | + // Use a more robust retry mechanism for elements that might not be ready yet |
| 304 | + // Check multiple times with increasing delays to ensure initialization |
| 305 | + const retrySetup = () => { |
| 306 | + // Only retry if not fully initialized |
| 307 | + if (!libButtonSetup || !libGridSetup) { |
| 308 | + setupLibraryButton(); |
| 309 | + setupLibraryGrid(); |
| 310 | + } |
280 | 311 | setupHomeButton(); |
281 | 312 | setupSearchInput(); |
282 | 313 | setupUserButton(); |
283 | | - }, 2000); |
| 314 | + }; |
| 315 | + |
| 316 | + setTimeout(retrySetup, 1000); // First retry after 1 second |
| 317 | + setTimeout(retrySetup, 2000); // Second retry after 2 seconds |
| 318 | + setTimeout(retrySetup, 3000); // Third retry after 3 seconds |
284 | 319 | }; |
285 | 320 |
|
286 | 321 | /** |
|
0 commit comments