// NAME: Copy Playlists // AUTHOR: einzigartigerName // DESCRIPTION: copy/combine playlist/queue directly in Spotify (function CopyPlaylist() { const { CosmosAPI, BridgeAPI, LocalStorage, PlaybackControl, ContextMenu, URI } = Spicetify if (!(CosmosAPI || BridgeAPI)) { setTimeout(CopyPlaylist, 1000); return; } const STORAGE_KEY = "combine_buffer_spicetify" const TOP_BTN_TOOLTIP = "Combine Playlists" const MENU_BTN_CREATE_NEW = "Create Playlist" const MENU_BTN_INSERT_BUFFER = "Copy to Buffer" class PlaylistCollection { constructor() { const menu = createMenu() this.container = menu.container this.items = menu.menu this.lastScroll = 0 this.container.onclick = () => { this.storeScroll() this.container.remove() } this.pattern this.apply() } apply() { this.items.textContent = '' // Remove all childs this.items.append(createMenuItem("Create Playlist", () => highjackCreateDialog(mergePlaylists(this.pattern)))) this.items.append(createMenuItem("Clear Buffer", () => LIST.clearStorage())) const select = createPatternSelect(this.filter); select.onchange = (event) => { this.pattern = event.srcElement.selectedIndex; } this.items.append(select); const collection = this.getStorage(); collection.forEach((item) => this.items.append(new CardContainer(item))) } getStorage() { const storageRaw = LocalStorage.get(STORAGE_KEY); let storage = []; if (storageRaw) { storage = JSON.parse(storageRaw); } else { LocalStorage.set(STORAGE_KEY, "[]") } return storage; } addToStorage(data) { /** @type {Object[]} */ const storage = this.getStorage(); storage.push(data); LocalStorage.set(STORAGE_KEY, JSON.stringify(storage)); this.apply() } removeFromStorage(id) { const storage = this.getStorage() .filter(item => item.id !== id) LocalStorage.set(STORAGE_KEY, JSON.stringify(storage)); this.apply() } clearStorage() { LocalStorage.set(STORAGE_KEY, "[]"); this.apply() } moveItem(uri, direction) { var storage = this.getStorage() var from; for (var i = 0; i < storage.length; i++) { if (storage[i].uri === uri) { from = i break; } } if (!from) { return } var to = from + direction if (to < 0 || to >= storage.length) { return } var tmp = storage[from] storage[from] = storage[to] storage[to] = tmp LocalStorage.set(STORAGE_KEY, JSON.stringify(storage)); this.apply() } changePosition(x, y) { this.items.style.left = x + "px" this.items.style.top = y + 10 + "px" } storeScroll() { this.lastScroll = this.items.scrollTop } setScroll() { this.items.scrollTop = this.lastScroll } } /* * Displays Stored Playlist * {id, uri, name, tracks, imgUri, owner} */ class CardContainer extends HTMLElement { constructor(info) { super() this.innerHTML = `