Skip to content

Commit d7204b7

Browse files
authored
Update spotifuck-v6.user.js
1 parent ac2ec92 commit d7204b7

1 file changed

Lines changed: 51 additions & 16 deletions

File tree

spotifuck-v6.user.js

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ==UserScript==
22
// @name Spotifuck v6
33
// @namespace https://github.com/Myst1cX/spotifuck-userscript
4-
// @version 6.2
4+
// @version 6.3
55
// @description Full Spotifuck 1.6.4 UI hack (with minor tweaks) + playback control + silent ad blocking port on open.spotify.com
66
// @author Myst1cX (adapted from Spotifuck app)
77
// @match https://open.spotify.com/*
@@ -35,6 +35,8 @@
3535
let ulFlag = false; // Unlock flag
3636
let ffDone = false; // First fuck done (firstFuck initialization complete)
3737
let pfint = null; // Primary features interval
38+
let libButtonSetup = false; // Library button initialized flag
39+
let libGridSetup = false; // Library grid initialized flag
3840

3941
// Constants for library button states and timing
4042
const LIBRARY_BUTTON_COLLAPSED = 'Collapse Your Library';
@@ -146,13 +148,33 @@
146148
}, 5000);
147149
};
148150

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+
149168
/**
150169
* addCSSJSHack - Add CSS modifications and event listeners
151170
* From r0/e.java line 200: window.addCSSJSHack=function(){...}
152171
*/
153172
window.addCSSJSHack = function() {
154173
// Setup library button once
155174
const setupLibraryButton = () => {
175+
// Skip if already set up
176+
if (libButtonSetup) return;
177+
156178
// Use aria-label to identify the correct library button (not back button)
157179
// Library button has aria-label containing "Your Library" (either "Open Your Library" or "Collapse Your Library")
158180
// Back button has aria-label="Go back" which doesn't contain "Your Library"
@@ -167,20 +189,20 @@
167189
libBtn.addEventListener('click', function() {
168190
setTimeout(() => switchLs(), 0);
169191
});
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();
179198
}
180199
};
181200

182201
// Setup library grid click handler once
183202
const setupLibraryGrid = () => {
203+
// Skip if already set up
204+
if (libGridSetup) return;
205+
184206
const libGrid = document.querySelector('#Desktop_LeftSidebar_Id div[role=grid]:not(.fuckd)');
185207
if (libGrid) {
186208
libGrid.classList.add('fuckd');
@@ -227,6 +249,12 @@
227249
}, PLAYLIST_NAVIGATION_DELAY_MS);
228250
}
229251
});
252+
253+
libGridSetup = true;
254+
console.log('✓ Library grid setup complete');
255+
256+
// Try to collapse library if button is also ready
257+
collapseLibraryOnStartup();
230258
}
231259
};
232260

@@ -272,15 +300,22 @@
272300
setupSearchInput();
273301
setupUserButton();
274302

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+
}
280311
setupHomeButton();
281312
setupSearchInput();
282313
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
284319
};
285320

286321
/**

0 commit comments

Comments
 (0)