From 90e930290ab9d33586fafc330ef77572e9e5d0aa Mon Sep 17 00:00:00 2001 From: Julien <182520+JulienMaille@users.noreply.github.com> Date: Sun, 27 Dec 2020 18:59:57 +0100 Subject: [PATCH] add: ability to hide sidebar item (cherry picked) --- DribbblishDynamic/dribbblish-dynamic.js | 43 +++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/DribbblishDynamic/dribbblish-dynamic.js b/DribbblishDynamic/dribbblish-dynamic.js index f5e71bf..b25844a 100644 --- a/DribbblishDynamic/dribbblish-dynamic.js +++ b/DribbblishDynamic/dribbblish-dynamic.js @@ -1,6 +1,37 @@ // Hide popover message document.getElementById("popover-container").style.height = 0; +let appHiddenList = []; +try { + const rawList = JSON.parse(localStorage.getItem("sidebar-app-hide-list")); + if (!Array.isArray(rawList)) throw 0; + appHiddenList.push(...rawList); +} catch { + localStorage.setItem("sidebar-app-hide-list", "[]") +} + +new Spicetify.ContextMenu.Item( + "Hide", + ([uri]) => { + appHiddenList.push(uri.replace("spotify:special:sidebarapp:", "")); + localStorage.setItem("sidebar-app-hide-list", JSON.stringify(appHiddenList)); + window.location.reload(); + }, + ([uri]) => uri.startsWith("spotify:special:sidebarapp:") +).register(); + +for (const app of appHiddenList) { + new Spicetify.ContextMenu.Item( + "Show " + app.replace("spotify:app:", ""), + () => { + appHiddenList = appHiddenList.filter(item => item !== app); + localStorage.setItem("sidebar-app-hide-list", JSON.stringify(appHiddenList)); + window.location.reload(); + }, + ([uri]) => uri.startsWith("spotify:special:sidebarapp:") + ).register(); +} + function waitForElement(els, func, timeout = 100) { const queries = els.map(el => document.querySelector(el)); if (queries.every(a => a)) { @@ -82,11 +113,23 @@ waitForElement([".LeftSidebar", ".LeftSidebar__section--rootlist .SidebarList__l */ function replaceTextWithIcon(el, iconName) { + const href = el.parentNode.href; + if (appHiddenList.indexOf(href) !== -1) { + let parent = el; + while (parent.tagName !== "LI") { + parent = parent.parentNode; + } + parent.remove(); + return; + } + if (iconName) { el.classList.add(`spoticon-${iconName}-24`); } el.parentNode.setAttribute("data-tooltip", el.innerText); + el.parentNode.setAttribute("data-contextmenu", ""); + el.parentNode.setAttribute("data-uri", "spotify:special:sidebarapp:" + href); el.innerText = ""; }