"use strict";(()=>{function e(e){return function(e){return e.charAt(0).toUpperCase()+e.slice(1)}(e.toLowerCase().replace(/[^a-zA-Z0-9]+(.)/g,((e,t)=>t.toUpperCase())))}var t=(e,...t)=>{console[e]("[better-spotify-genres]",...t)},n=e=>new Promise((t=>setTimeout(t,e)));!async function r(){if(!(Spicetify.CosmosAsync&&Spicetify.Platform&&Spicetify.URI&&Spicetify.Player.data))return void setTimeout(r,300);window.genrePopup=()=>v(),window.artistPageGenreOnClick=e=>function(e){Spicetify.Platform.History.push(`/search/${e}/playlists`)}(e),window._onGenreItemMouseOver=e=>{e.style.setProperty("color","var(--spice-text)")},window._onGenreItemMouseOut=e=>{e.style.setProperty("color","var(--spice-subtext)")};let i=[],o=[];const a=Spicetify.React;function s(e,t){Spicetify.LocalStorage.set(e,t)}function c(){try{return JSON.parse((e="showGenre:settings",Spicetify.LocalStorage.get(e)??"{}"))}catch{return s("showGenre:settings","{}"),{}}var e}const l={cached:{pop:"spotify:playlist:6gS3HhOiI17QNojjPuPzqc"}};let p=c();function u(e,t){if(e){let n=c();return n[e]=t,void s("showGenre:settings",JSON.stringify(n))}s("showGenre:settings",JSON.stringify(p))}async function d(e,t=null,n=document.body){return new Promise((r=>{if(document.querySelector(e))return r(document.querySelector(e));const i=new MutationObserver((()=>{document.querySelector(e)?(r(document.querySelector(e)),i.disconnect()):"number"==typeof t&&setTimeout((()=>{i.disconnect(),r(null)}),t)}));i.observe(n,{childList:!0,subtree:!0})}))}async function m(t){const n=p.cached[e(t)];if(null!=n)return{uri:n,genre:t};const r=new RegExp(`^the sound of ${t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}$`,"i"),i=await Spicetify.CosmosAsync.get(`https://api.spotify.com/v1/search?q=${encodeURIComponent("The Sound of "+t)}&type=playlist`);for(const n of i.playlists.items)return"thesoundsofspotify"===n.owner.id&&r.test(n.name)?(p.cached[e(t)]=n.uri,u("cached",p.cached),{uri:n.uri,genre:t}):{uri:n.uri+"|||",genre:t};return{uri:null,genre:t}}async function f(e,t=null){const n=e.map((e=>async function(e){return(await Spicetify.CosmosAsync.get(`https://api.spotify.com/v1/artists/${e}`)).genres}(e.split(":")[2])));let r=(await Promise.allSettled(n)).map((e=>{if("fulfilled"===e.status)return e.value})).filter(Boolean).flat();if(0===r.length){let n;if("artist"===t)n=e[0].split(":")[2];else{if("recursive"===t)return[];n=Spicetify.Player.data.item.metadata.artist_uri.split(":")[2]}const i=await Spicetify.CosmosAsync.get(`wg://artist/v1/${n}/desktop?format=json`).catch((()=>null));if(!i)return[];if(!i.related_artists?.artists)return[];const o=i.related_artists.artists.map((e=>e.uri));let a=5;for(;25!==a;)r=await f(o.slice(a-5,a),"recursive"),0!=r.length?a=25:a+=5}return r=Array.from(new Set(r)),t||(i=r),r.slice(0,5)}async function y(){let e=function(){const e=Spicetify.Player.data.item.metadata,t=[e.artist_uri];for(let n=1;n<10;n++){const r=e[`artist_uri:${n}`];if(!r)break;t.push(r)}return t}(),n=await f(e);if(!n)return t("warn","No genres found for the current track, removing genres from UI..."),i=[],void k();const r=(await Promise.all(n.map((e=>m(e))))).filter((e=>null!==e.uri)).map((e=>`${e.genre.replace(/(^\w{1})|([\s-]+\w{1})/g,(e=>e.toUpperCase()))}`)).join(", ");if(P||(P=document.createElement("div")),P.innerHTML=r,await S(),null!==x){P.style.fontSize="12px",P.style.color="var(--spice-misc)",P.style.setProperty("color","var(--spice-subtext)"),P.classList.add("ellipsis-one-line"),P.style.setProperty("grid-area","genres"),P.addEventListener("contextmenu",v);{let[e,t]=window.getComputedStyle(x).getPropertyValue("grid-template").split("/").map((e=>e.trim()));const n='"genres genres"';e.endsWith(n)||(e+=` ${n}`);const r=`${e} / ${t}`;x.style.setProperty("grid-template",r)}x.appendChild(P)}}Object.keys(l).forEach((e=>{const t=e;void 0===p[t]&&(p={...p,[t]:l[t]})})),u();const g=a.createElement("style",null,'.popup-row::after {\n content: "";\n display: table;\n clear: both;\n }\n .popup-row .col {\n display: flex;\n padding: 10px 0;\n align-items: center;\n }\n .popup-row .col.description {\n float: left;\n padding-right: 15px;\n }\n .popup-row .col.action {\n float: right;\n text-align: right;\n }\n .popup-row .div-title {\n color: var(--spice-text);\n }\n .popup-row .divider {\n height: 2px;\n border-width: 0;\n background-color: var(--spice-button-disabled);\n }\n .popup-row .space {\n margin-bottom: 20px;\n visibility: hidden;\n }\n .popup-row .info {\n /* font-size: 13px; */\n }\n .popup-row .red {\n font-size: 13px;\n color: #59CE8F;\n }\n .popup-row .demo {\n font-size: 13px;\n color: #59CE8F;\n }\n .popup-row .little-space {\n margin-bottom: 10px;\n }\n .popup-row .inputbox {\n padding: 10px;\n border-radius: 15px;\n border: 0;\n box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.06);\n }\n button.checkbox {\n align-items: center;\n color: var(--spice-text);\n cursor: pointer;\n display: flex;\n margin-inline-start: 12px;\n }\n button.checkbox.disabled {\n color: rgba(var(--spice-rgb-text), 0.3);\n }\n select {\n color: var(--spice-text);\n background: rgba(var(--spice-rgb-shadow), 0.7);\n border: 0;\n height: 32px;\n }\n ::-webkit-scrollbar {\n width: 8px;\n }\n .login-button {\n background-color: var(--spice-button);\n border-radius: 8px;\n border-style: none;\n color: var(--spice-text);\n cursor: pointer;\n font-size: 14px;\n height: 40px;\n margin: 10px;\n padding: 5px 10px;\n text-align: center;\n }\n .green {\n background-color: #76ba99;\n color: #25316D;\n }\n .red {\n background-color: #A9555E;\n }\n .small-button.red {\n background-color: #A9555E !important;\n }\n input.small-input {\n padding: 5px !important;\n border-radius: 6px !important;\n right: 0px !important;\n margin: 5px;\n }\n .small-button {\n margin-right: 20px;\n }\n .popup-row .inputbox[type="color"] {\n background-color: var(--spice-custom-main-secondary) !important;\n padding: 0px;\n border-radius: 5px !important;\n border: none;\n margin-right: 10px;\n }\n .popup-row .inputbox[type="color"]::-webkit-color-swatch {\n border-radius: 5px !important;\n border: none;\n }\n .popup-row.search-div .col {\n position: relative;\n }\n .popup-row .nord-search-container {\n width: 100%;\n }\n .popup-row .nord-search-icon {\n position: absolute;\n margin: 10px;\n }\n .popup-row .nord-search {\n padding: 10px 36px !important;\n width: 100%;\n }\n .popup-row .display-none {\n display: none !important;\n }\n .GenericModal[aria-label*="Genres of"] .main-trackCreditsModal-header {\n color: var(--spice-custom-success);\n }\n .GenericModal[aria-label*="Genres of"] .main-trackCreditsModal-header {\n color: var(--spice-custom-link-hover);\n }');function h({name:e="",color:t="",onclickFun:n=()=>{}}){return a.createElement("button",{className:`login-button${t}`,onClick:()=>n()},e)}async function w(){const{artist_name:e,title:t}=Spicetify.Player.data.item.metadata;o=[];const n=await async function(e,t){const n=`https://ws.audioscrobbler.com/2.0/?method=track.getInfo&api_key=44654ea047786d90338c17331a5f5d95&artist=${encodeURIComponent(e)}&track=${encodeURIComponent(t)}&format=json`;try{const e=await fetch(n),t=await e.json();return"error"in t?null:t}catch{return null}}(e,t);if(!n)return;const r=n.track.toptags.tag;if(r)for(const e of r)/\d/.test(e.name)||o.push(e.name)}const b=a.createElement("div",null,g,a.createElement("p",{className:"popup-row"},'Tip: You can right click on genres in the "Player Bar" to open this popup.'),a.createElement("div",{className:"popup-row"},a.createElement("hr",{className:"space"},null)),a.createElement((function(){const[e,t]=a.useState(i);return Spicetify.Player.addEventListener("songchange",(()=>{setTimeout((()=>t(i)),500)})),e.map((e=>a.createElement(h,{name:e.replace(/(^\w{1})|([\s-]+\w{1})/g,(e=>e.toUpperCase())),onclickFun:async()=>{const t=await m(e);null===t.uri||t.uri.includes("|||")?Spicetify.Platform.History.push(`/search/${e}/playlists`):Spicetify.Platform.History.push(`/playlist/${t.uri.split(":")[2]}`),Spicetify.PopupModal.hide()}})))}),null,null),a.createElement((function(){if(0===o.length)return a.createElement("div",null,null);const[e,t]=a.useState(o);return Spicetify.Player.addEventListener("songchange",(()=>{setTimeout((()=>t(o)),500)})),a.createElement("div",null,a.createElement("div",{className:"popup-row"},a.createElement("hr",{className:"space"},null)),a.createElement("div",{className:"popup-row"},a.createElement("h1",{className:"div-title"},"Last FM Tags")),e.map((e=>a.createElement(h,{name:e.replace(/(^\w{1})|([\s-]+\w{1})/g,(e=>e.toUpperCase())),onclickFun:async()=>{Spicetify.Platform.History.push(`/search/${e}/playlists`),Spicetify.PopupModal.hide()}}))))}),null,null));function v(){Spicetify.PopupModal.display({title:'Genres of "'+Spicetify.Player.data.item.metadata.title.replace(/\(.+?\)/g,"").replace(/\[.+?\]/g,"").replace(/\s\-\s.+?$/,"").replace(/,.+?$/,"").trim()+'"',content:b,isLarge:!0})}let x=null;const S=async()=>{const e=(await Promise.all([d("div.main-trackInfo-container",1e3),d("div.main-nowPlayingWidget-trackInfo",1e3)])).find((e=>null!==e));if(!e)return t("error","Couldn't find the info container, genres will not be displayed."),void(x=null);x=e};let P=null;async function k(){await S();try{if(null===x||null===P)return;x.style.removeProperty("grid-template"),x.removeChild(P),P=null,x=null}catch{}}async function E(){if(Spicetify.Player.data.item.metadata.is_local||"track"!==Spicetify.URI.fromString(Spicetify.Player.data.item.uri).type)return t("warn","Current track is local, removing genres from UI..."),void k();await w(),await y()}async function C(e){let t=e.split("/");"artist"==t[1]&&3==t.length&&async function(e){if(!e)return;const t=e.map((async e=>{const t=await m(e);if(null!==t.uri)return[[`${e.replace(/(^\w{1})|([\s-]+\w{1})/g,(e=>e.toUpperCase()))}`],[", "]]}));let n=(await Promise.all(t)).flat(1/0);", "==n[n.length-1]&&n.pop(),n.unshift("Artist Genres : ");const r=n.join("");let i=document.createElement("div");i.className="main-entityHeader-detailsText genre-container",i.innerHTML=r;try{document.querySelector(".genre-container")?.remove()}catch{}let o=await d("div.main-entityHeader-headerText",1e3),a=await d("span.main-entityHeader-detailsText",1e3);o?.insertBefore(i,a)}(await f(["spotify:artist:"+t[2]],"artist"))}for(;!Spicetify.Player.data;)await n(1e3);E(),Spicetify.Player.addEventListener("songchange",E),C(Spicetify.Platform.History.location.pathname),Spicetify.Platform.History.listen((e=>{C(e.pathname)})),t("info","Initialized")}()})();