(id, defaultVal, switchCallback, posCallback)
| 1261 | } |
| 1262 | |
| 1263 | function createServiceOption(id, defaultVal, switchCallback, posCallback) { |
| 1264 | const name = id.replace(/^./, (c) => c.toUpperCase()); |
| 1265 | |
| 1266 | const container = document.createElement("div"); |
| 1267 | container.dataset.id = id; |
| 1268 | container.innerHTML = ` |
| 1269 | <div class="setting-row"> |
| 1270 | <h3 class="col description">${name}</h3> |
| 1271 | <div class="col action"> |
| 1272 | <button class="switch small"> |
| 1273 | <svg height="10" width="10" viewBox="0 0 16 16" fill="currentColor"> |
| 1274 | ${Spicetify.SVGIcons["chart-up"]} |
| 1275 | </svg> |
| 1276 | </button> |
| 1277 | <button class="switch small"> |
| 1278 | <svg height="10" width="10" viewBox="0 0 16 16" fill="currentColor"> |
| 1279 | ${Spicetify.SVGIcons["chart-down"]} |
| 1280 | </svg> |
| 1281 | </button> |
| 1282 | <button class="switch"> |
| 1283 | <svg height="16" width="16" viewBox="0 0 16 16" fill="currentColor"> |
| 1284 | ${Spicetify.SVGIcons.check} |
| 1285 | </svg> |
| 1286 | </button> |
| 1287 | </div> |
| 1288 | </div> |
| 1289 | <span>${defaultVal.desc}</span>`; |
| 1290 | |
| 1291 | if (id === "musixmatch") { |
| 1292 | container.append(musixmatchTokenElements(defaultVal)); |
| 1293 | } |
| 1294 | |
| 1295 | const [up, down, slider] = container.querySelectorAll("button"); |
| 1296 | |
| 1297 | slider.classList.toggle("disabled", !defaultVal.on); |
| 1298 | slider.onclick = () => { |
| 1299 | const state = slider.classList.contains("disabled"); |
| 1300 | slider.classList.toggle("disabled"); |
| 1301 | switchCallback(container, state); |
| 1302 | }; |
| 1303 | |
| 1304 | up.onclick = () => posCallback(container, -1); |
| 1305 | down.onclick = () => posCallback(container, 1); |
| 1306 | |
| 1307 | return container; |
| 1308 | } |
| 1309 | } |
no test coverage detected