-
Notifications
You must be signed in to change notification settings - Fork 1
/
copytoclipboard.js
1 lines (1 loc) · 9.38 KB
/
copytoclipboard.js
1
!async function(){for(;!Spicetify.React||!Spicetify.ReactDOM;)await new Promise(e=>setTimeout(e,10));var o,l,c,d,p,u,e,t,i,r,a,f,m,s,n;o=Object.create,l=Object.defineProperty,c=Object.getOwnPropertyDescriptor,d=Object.getOwnPropertyNames,p=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty,i=(e=(e,t)=>function(){return t||(0,e[d(e)[0]])((t={exports:{}}).exports,t),t.exports})({"external-global-plugin:react-dom"(e,t){t.exports=Spicetify.ReactDOM}}),r=(t=(e,t,i)=>{i=null!=e?o(p(e)):{};var a=!t&&e&&e.__esModule?i:l(i,"default",{value:e,enumerable:!0}),s=e,n=void 0,r=void 0;if(s&&"object"==typeof s||"function"==typeof s)for(let e of d(s))u.call(a,e)||e===n||l(a,e,{get:()=>s[e],enumerable:!(r=c(s,e))||r.enumerable});return a})(e({"external-global-plugin:react"(e,t){t.exports=Spicetify.React}})()),a=t(i()),f=class{constructor(e,t,i={}){this.name=e,this.settingsId=t,this.initialSettingsFields=i,this.settingsFields=this.initialSettingsFields,this.setRerender=null,this.pushSettings=async()=>{for(Object.entries(this.settingsFields).forEach(([e,t])=>{"button"!==t.type&&void 0===this.getFieldValue(e)&&this.setFieldValue(e,t.defaultValue)});!Spicetify?.Platform?.History?.listen;)await new Promise(e=>setTimeout(e,100));this.stopHistoryListener&&this.stopHistoryListener(),this.stopHistoryListener=Spicetify.Platform.History.listen(e=>{"/preferences"===e.pathname&&this.render()}),"/preferences"===Spicetify.Platform.History.location.pathname&&await this.render()},this.rerender=()=>{this.setRerender&&this.setRerender(Math.random())},this.render=async()=>{for(;!document.getElementById("desktop.settings.selectLanguage");){if("/preferences"!==Spicetify.Platform.History.location.pathname)return;await new Promise(e=>setTimeout(e,100))}var e=document.querySelector(".main-view-container__scroll-node-child main div");if(!e)return console.error("[spcr-settings] settings container not found");let t=Array.from(e.children).find(e=>e.id===this.settingsId);t?console.log(t):((t=document.createElement("div")).id=this.settingsId,e.appendChild(t)),a.default.render(r.default.createElement(this.FieldsContainer,null),t)},this.addButton=(e,t,i,a,s)=>{this.settingsFields[e]={type:"button",description:t,value:i,events:{onClick:a,...s}}},this.addInput=(e,t,i,a,s,n)=>{this.settingsFields[e]={type:"input",description:t,defaultValue:i,inputType:s,events:{onChange:a,...n}}},this.addHidden=(e,t)=>{this.settingsFields[e]={type:"hidden",defaultValue:t}},this.addToggle=(e,t,i,a,s)=>{this.settingsFields[e]={type:"toggle",description:t,defaultValue:i,events:{onChange:a,...s}}},this.addDropDown=(e,t,i,a,s,n)=>{this.settingsFields[e]={type:"dropdown",description:t,defaultValue:i[a],options:i,events:{onSelect:s,...n}}},this.getFieldValue=e=>JSON.parse(Spicetify.LocalStorage.get(this.settingsId+"."+e)||"{}")?.value,this.setFieldValue=(e,t)=>{Spicetify.LocalStorage.set(this.settingsId+"."+e,JSON.stringify({value:t}))},this.FieldsContainer=()=>{var[e,t]=(0,r.useState)(0);return this.setRerender=t,r.default.createElement("div",{className:"x-settings-section",key:e},r.default.createElement("h2",{className:"TypeElement-cello-textBase-type"},this.name),Object.entries(this.settingsFields).map(([e,t])=>r.default.createElement(this.Field,{nameId:e,field:t})))},this.Field=i=>{var e=this.settingsId+"."+i.nameId;let t;if(t="button"===i.field.type?i.field.value:this.getFieldValue(i.nameId),"hidden"===i.field.type)return r.default.createElement(r.default.Fragment,null);const[a,s]=(0,r.useState)(t),n=e=>{void 0!==e&&(s(e),this.setFieldValue(i.nameId,e))};return r.default.createElement("div",{className:"x-settings-row"},r.default.createElement("div",{className:"x-settings-firstColumn"},r.default.createElement("label",{className:"TypeElement-viola-textSubdued-type",htmlFor:e},i.field.description||"")),r.default.createElement("div",{className:"x-settings-secondColumn"},"input"===i.field.type?r.default.createElement("input",{className:"x-settings-input",id:e,dir:"ltr",value:a,type:i.field.inputType||"text",...i.field.events,onChange:e=>{n(e.currentTarget.value);var t=i.field.events?.onChange;t&&t(e)}}):"button"===i.field.type?r.default.createElement("span",null,r.default.createElement("button",{id:e,className:"Button-sc-y0gtbx-0 Button-small-buttonSecondary-useBrowserDefaultFocusStyle x-settings-button",...i.field.events,onClick:e=>{n();var t=i.field.events?.onClick;t&&t(e)},type:"button"},a)):"toggle"===i.field.type?r.default.createElement("label",{className:"x-settings-secondColumn x-toggle-wrapper"},r.default.createElement("input",{id:e,className:"x-toggle-input",type:"checkbox",checked:a,...i.field.events,onClick:e=>{n(e.currentTarget.checked);var t=i.field.events?.onClick;t&&t(e)}}),r.default.createElement("span",{className:"x-toggle-indicatorWrapper"},r.default.createElement("span",{className:"x-toggle-indicator"}))):"dropdown"===i.field.type?r.default.createElement("select",{className:"main-dropDown-dropDown",id:e,...i.field.events,onChange:e=>{n(i.field.options[e.currentTarget.selectedIndex]);var t=i.field.events?.onChange;t&&t(e)}},i.field.options.map((e,t)=>r.default.createElement("option",{selected:e===a,value:t+1},e))):r.default.createElement(r.default.Fragment,null)))}}},s={ru:{error:"Ошибка",text:"Скопировать текст",songAndArtist:"Cкопировать трек и артиста",copied:"Скопировано",settings:{name:"Copy to clipboard settings",separator:"Separator between Song name and Artist names"}},en:{error:"Error",text:"Copy Text",songAndArtist:"Copy Song & Artist names",copied:"Copied",settings:{name:(m={ID:"settings-copy-to-clipboard",NAME:"Copy to clipboard settings",SEPARATOR:{KEY:"ctc-separator",DESCRIPTION:"Separator between Song name and Artist names",DEFAULT:"; "}}).NAME,separator:m.SEPARATOR.DESCRIPTION}},vi:{copied:"Đã sao chép",error:"Lỗi",settings:{name:"Cài đặt Copy to clipboard",separator:"Phân cách giữa tên bài hát và tên nghệ sĩ"},songAndArtist:"Sao chép tên bài hát & nghệ sĩ",text:"Sao chép tên"}},n=async function(){for(;!Spicetify||"complete"!==document.readyState;)await new Promise(e=>setTimeout(e,1e3));await new Promise(e=>setTimeout(e,1e3)),e=Spicetify.Locale?Spicetify.Locale.getLocale():"en";var e=await(Object.keys(s).includes(e)?s[e]:s.en),t=new f(e.settings.name,m.ID);t.addInput(m.SEPARATOR.KEY,e.settings.separator,m.SEPARATOR.DEFAULT),t.pushSettings(),g(e)},(async()=>{await n()})();async function y(e){var t=Spicetify.GraphQL.Definitions["getTrackName"];try{var i=(await Spicetify.GraphQL.Request(t,{uri:e,offset:0,limit:10}))["data"];return i.trackUnion.name}catch(e){throw console.log(e),new Error(e.message)}}function g(n){function r(e){e&&(Spicetify.showNotification(n.copied+": "+e),Spicetify.Platform.ClipboardAPI.copy(e))}new Spicetify.ContextMenu.Item(n.text,async e=>{var t=Spicetify.URI["Type"],i=Spicetify.URI.fromString(e[0]);const a=i._base62Id||i.id;try{switch(i.type){case t.TRACK:r(await y(i.toURI()));break;case t.LOCAL:var s=[];i.track&&s.push(i.track),i.artist&&s.push(i.artist),i.album&&s.push(i.album),r(s.join("; "));break;case t.LOCAL_ARTIST:r(""+(i.artist||""));break;case t.LOCAL_ALBUM:r(""+(i.album||""));break;case t.ALBUM:r(await async function(e){try{return(await Spicetify.CosmosAsync.get("https://api.spotify.com/v1/albums/"+e)).name}catch(e){throw console.log(e),new Error(e.message)}}(i.id));break;case t.ARTIST:r(await async function(e){var t=Spicetify.GraphQL.Definitions["queryArtistOverview"];try{var i=Spicetify.Locale?Spicetify.Locale.getLocale():"en",a=(await Spicetify.GraphQL.Request(t,{uri:e,includePrerelease:!1,locale:i,offset:0,limit:10}))["data"];return a.artistUnion.profile.name}catch(e){throw console.log(e),new Error(e.message)}}(i.toURI()));break;case t.PLAYLIST:case t.PLAYLIST_V2:r((await Spicetify.CosmosAsync.get("sp://core-playlist/v1/playlist/spotify:playlist:"+a)).playlist.name);break;case t.SHOW:r((await Spicetify.CosmosAsync.get(`sp://core-show/v1/shows/${a}?responseFormat=protobufJson`)).header.showMetadata.name);break;case t.EPISODE:r((await Spicetify.Platform.ShowAPI.getEpisodeOrChapter("spotify:episode:"+a)).name);break;case t.PROFILE:r((await Spicetify.CosmosAsync.get("sp://core-profile/v1/profiles",{usernames:i.username})).profiles[0].name);break;case t.FOLDER:r((await Spicetify.Platform.RootlistAPI.getContents()).items.filter(e=>"folder"===e.type&&e.uri.includes(a))[0].name)}}catch(e){Spicetify.showNotification(n.error+": "+e.message)}},e=>{if(1!==e.length)return!1;var t=Spicetify.URI["Type"];switch(Spicetify.URI.fromString(e[0]).type){case t.TRACK:case t.LOCAL:case t.LOCAL_ARTIST:case t.LOCAL_ALBUM:case t.ALBUM:case t.ARTIST:case t.PLAYLIST:case t.PLAYLIST_V2:case t.SHOW:case t.EPISODE:case t.PROFILE:case t.FOLDER:return!0;default:return!1}},"copy").register(),new Spicetify.ContextMenu.Item(n.songAndArtist,async e=>{var t,i,a,s=Spicetify.URI["Type"],e=Spicetify.URI.fromString(e[0]);try{e.type===s.TRACK&&([t,i]=await Promise.allSettled([y(e.toURI()),async function(e){var t=Spicetify.GraphQL.Definitions["queryTrackArtists"];try{var i=(await Spicetify.GraphQL.Request(t,{uri:e,offset:0,limit:10}))["data"];return i.trackUnion.artists.items.map(e=>e.profile.name).join(", ")}catch(e){throw console.log(e),new Error(e.message)}}(e.toURI())]),"fulfilled"===t.status)&&"fulfilled"===i.status&&(a=new f(m.NAME,m.ID),r(t.value+a.getFieldValue(m.SEPARATOR.KEY)+i.value))}catch(e){Spicetify.showNotification(n.error+": "+e.message)}},e=>{var t;return 1===e.length&&(t=Spicetify.URI["Type"],Spicetify.URI.fromString(e[0]).type===t.TRACK)},"artist").register()}}();