// ==UserScript== // @name Wavez Open in Spotify // @namespace https://wavez.fm/ // @author fluteds // @icon https://wavez.fm/favicon.ico // @version 1.4 // @updateURL https://raw.githubusercontent.com/fluteds/wavez/main/userscripts/wavez-open-in-spotify.user.js // @downloadURL https://raw.githubusercontent.com/fluteds/wavez/main/userscripts/wavez-open-in-spotify.user.js // @description Adds an "Open in Spotfify" button next to the currently playing song to search for it on Spotify. // @match https://wavez.fm/* // @match https://wavez.fm/~/* // @grant none // @run-at document-idle // ==/UserScript== (function () { var KEY = 'wavez-tools:'; var SPEC = { id: 'spotify', label: 'Open in Spotify', cat: 'Music', settings: [] }; function setting(id, name, dflt) { try { var v = localStorage.getItem(KEY + id + ":" + name); return v === null ? dflt : JSON.parse(v); } catch (e) { return dflt; } } function announce() { document.dispatchEvent(new CustomEvent('wavez-tools:addon', { detail: JSON.stringify(SPEC) })); } document.addEventListener('wavez-tools:ping', announce); announce(); if (localStorage.getItem(KEY + SPEC.id) === 'off') return; (function () { 'use strict'; const log = (...a) => console.log('%c[wz-spotify]', 'color:#1DB954;font-weight:bold', ...a); const ID = 'wavez-open-spotify-btn'; const stripNoise = (s) => (s || '') .replace(/[([][^)\]]*\b(officials?|video|audio|lyrics?|visuali[sz]er|m\/?v|hd|4k|remaster(?:ed)?|explicit)\b[^)\]]*[)\]]/gi, '') .replace(/\s{2,}/g, ' ') .trim(); function spotifyUrl(titleEl) { const pb = window.WavezFM?.version === '1' ? window.WavezFM.room.getState()?.playback : null; const query = stripNoise(pb?.title || titleEl.textContent); return 'https://open.spotify.com/search/' + encodeURIComponent(query); } function addButton() { const title = document.querySelector('#wavezfm-current-track-title-desktop'); const yt = document.querySelector('a[aria-label="Open on YouTube"]'); if (!title || !yt || document.getElementById(ID)) return; const row = title.closest('.flex'); if (!row) return; const wrap = document.createElement('div'); wrap.className = 'inline-flex shrink-0'; wrap.id = ID; const link = yt.cloneNode(false); link.href = '#'; link.setAttribute('aria-label', 'Open on Spotify'); link.title = 'Open on Spotify'; link.style.color = '#ffffff'; link.style.display = 'inline-flex'; link.style.visibility = 'visible'; link.style.opacity = '1'; link.innerHTML = ` `; link.onclick = (e) => { e.preventDefault(); e.stopPropagation(); window.open(spotifyUrl(title), '_blank'); }; wrap.appendChild(link); const titleBox = title.parentElement; row.insertBefore(wrap, titleBox); } setInterval(addButton, 500); if (location.hash === '#wz-spotify-test') { const cases = [ ['Groove Is In The Heart (Official Video)', 'Groove Is In The Heart'], ['Song [Official Audio]', 'Song'], ['Track (Official Music Video) [HD]', 'Track'], ['Title (Lyrics)', 'Title'], ['Da Funk (Remastered)', 'Da Funk'], ['Power (feat. Dwele)', 'Power (feat. Dwele)'], ]; cases.forEach(([raw, want]) => console.assert(stripNoise(raw) === want, 'stripNoise:', raw, '->', stripNoise(raw), 'want', want)); log('self-check passed'); } })(); })();