MCPcopy
hub / github.com/spicetify/cli / injectInteraction

Function injectInteraction

jsHelper/sidebarConfig.js:98–147  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

96 container.append(style, up, down, hide, stick);
97
98 function injectInteraction() {
99 function onSwap(item, dir) {
100 container.remove();
101 const curPos = ordered.findIndex((e) => e[0] === item);
102 const newPos = curPos + dir;
103 if (newPos < 0 || newPos > ordered.length - 1) return;
104
105 [ordered[curPos], ordered[newPos]] = [ordered[newPos], ordered[curPos]];
106 appendItems();
107 }
108
109 function onChangeStatus(item, status) {
110 container.remove();
111 const curPos = ordered.findIndex((e) => e[0] === item);
112 ordered[curPos][1] = ordered[curPos][1] === status ? SHOW : status;
113 appendItems();
114 }
115
116 YLXSidebarState = Spicetify.Platform.LocalStorageAPI.getItem("ylx-sidebar-state");
117 if (YLXSidebarState === 1) document.querySelector(".main-yourLibraryX-collapseButton > button")?.click();
118
119 document.documentElement.style.setProperty("--nav-bar-width", "280px");
120
121 hiddenList.classList.remove("hidden-visually");
122 for (const el of ordered) {
123 el[0].onmouseover = () => {
124 const [item, status] = el;
125 const index = ordered.findIndex((a) => a === el);
126 if (index === 0 || ordered[index][1] !== ordered[index - 1][1]) {
127 up.disabled = true;
128 } else {
129 up.disabled = false;
130 up.onclick = () => onSwap(item, -1);
131 }
132 if (index === ordered.length - 1 || ordered[index][1] !== ordered[index + 1][1]) {
133 down.disabled = true;
134 } else {
135 down.disabled = false;
136 down.onclick = () => onSwap(item, 1);
137 }
138
139 stick.innerText = status === STICKY ? "Unstick" : "Stick";
140 hide.innerText = status === HIDDEN ? "Unhide" : "Hide";
141 hide.onclick = () => onChangeStatus(item, HIDDEN);
142 stick.onclick = () => onChangeStatus(item, STICKY);
143
144 item.append(container);
145 };
146 }
147 }
148
149 function removeInteraction() {
150 hiddenList.classList.add("hidden-visually");

Callers 1

sidebarConfig.jsFile · 0.70

Calls 2

onSwapFunction · 0.70
onChangeStatusFunction · 0.70

Tested by

no test coverage detected