Allows hotkeys and media keys to control the Spotify web player from any tab
目前為
// ==UserScript== // @name Spotify hotkeys // @version 1.5.1 // @description Allows hotkeys and media keys to control the Spotify web player from any tab // @author CennoxX // @contact [email protected] // @homepage https://twitter.com/CennoxX // @namespace https://greasyfork.org/users/21515 // @include * // @grant GM_getValue // @grant GM_setValue // ==/UserScript== const pauseButton = "[data-testid='control-button-pause']"; document.addEventListener('keydown', function (e) { if (e.ctrlKey && e.altKey && e.key == "p" || e.key == "MediaPlayPause") GM_setValue("ctrl", ":nth-child(3)"); if (e.ctrlKey && e.altKey && e.key == "s" || e.key == "MediaStop") GM_setValue("ctrl", pauseButton); if (e.ctrlKey && e.altKey && e.key == "," || e.key == "MediaTrackPrevious") GM_setValue("ctrl", ":nth-child(2)"); if (e.ctrlKey && e.altKey && e.key == "." || e.key == "MediaTrackNext") GM_setValue("ctrl", ":nth-child(4)"); }, false); if (document.domain == "open.spotify.com") { setInterval(function () { let ctrl = GM_getValue("ctrl"); if (ctrl && (ctrl != pauseButton || document.title.includes(" · "))){ document.querySelector("div.player-controls__buttons button" + ctrl).click(); GM_setValue("ctrl", ""); } }, 100); }