()
| 89 | let elem = []; |
| 90 | |
| 91 | function injectInteraction() { |
| 92 | const main = document.querySelector(".main-home-content"); |
| 93 | elem = [...main.querySelectorAll("section")]; |
| 94 | for (const [index, item] of elem.entries()) { |
| 95 | item.dataset.uri = list[index]?.uri ?? list[index].item?.uri; |
| 96 | } |
| 97 | |
| 98 | function appendItems() { |
| 99 | const stick = []; |
| 100 | const low = []; |
| 101 | const normal = []; |
| 102 | for (const el of elem) { |
| 103 | if (statusDic[el.dataset.uri] === STICKY) stick.push(el); |
| 104 | else if (statusDic[el.dataset.uri] === LOWERED) low.push(el); |
| 105 | else normal.push(el); |
| 106 | } |
| 107 | |
| 108 | localStorage.setItem( |
| 109 | "spicetify-home-config:stick", |
| 110 | stick.map((a) => a.dataset.uri) |
| 111 | ); |
| 112 | localStorage.setItem( |
| 113 | "spicetify-home-config:low", |
| 114 | low.map((a) => a.dataset.uri) |
| 115 | ); |
| 116 | |
| 117 | elem = [...stick, ...normal, ...low]; |
| 118 | main.append(...elem); |
| 119 | } |
| 120 | |
| 121 | function onSwap(item, dir) { |
| 122 | container.remove(); |
| 123 | const curPos = elem.findIndex((e) => e === item); |
| 124 | const newPos = curPos + dir; |
| 125 | if (newPos < 0 || newPos > elem.length - 1) return; |
| 126 | |
| 127 | [elem[curPos], elem[newPos]] = [elem[newPos], elem[curPos]]; |
| 128 | [list[curPos], list[newPos]] = [list[newPos], list[curPos]]; |
| 129 | appendItems(); |
| 130 | } |
| 131 | |
| 132 | function onChangeStatus(item, status) { |
| 133 | container.remove(); |
| 134 | const isToggle = statusDic[item.dataset.uri] === status; |
| 135 | statusDic[item.dataset.uri] = isToggle ? NORMAL : status; |
| 136 | appendItems(); |
| 137 | } |
| 138 | |
| 139 | for (const el of elem) { |
| 140 | el.onmouseover = () => { |
| 141 | const status = statusDic[el.dataset.uri]; |
| 142 | const index = elem.findIndex((a) => a === el); |
| 143 | |
| 144 | if (!status || index === 0 || status !== statusDic[elem[index - 1]?.dataset.uri]) { |
| 145 | up.disabled = true; |
| 146 | } else { |
| 147 | up.disabled = false; |
| 148 | up.onclick = () => onSwap(el, -1); |
no test coverage detected