// ==UserScript== // @name Play / Pause with spacebar on Bandcamp // @namespace https://openuserjs.org/users/burn // @version 0.1.2 // @description Press spacebar on Bandcamp to control music playback // @author burn // @copyright 2020, burn (https://openuserjs.org//users/burn) // @license MIT // @match https://*.bandcamp.com/album/* // @match https://*.bandcamp.com/track/* // @include https://*.bandcamp.com/album/* // @include https://*.bandcamp.com/track/* // @grant none // @run-at document-end // @downloadURL none // ==/UserScript== // ==OpenUserJS== // @author burn // ==/OpenUserJS== (function() { 'use strict'; const DBG = false; let log = function(s) { DBG && console.log(s); }, qS = function(el, scope) { scope = (typeof scope == 'object') ? scope : document; return scope.querySelector(el) || false; }, qSall = function(els, scope) { scope = (typeof scope == 'object') ? scope : document; return scope.querySelectorAll(els) || false; }, elmTarget = qS("#trackInfoInner > div.inline_player > table > tbody > tr:nth-child(1) > td.play_cell > a > div"); if (!elmTarget) { log('main play button not found, exiting'); return; } window.addEventListener('keydown', function(e) { log("in keydown"); if(e.keyCode == 32 && e.target == document.body) { log("keydown ok"); e.preventDefault(); } }); qS('body').addEventListener("keyup", function(e) { log("in keyup"); if (e.keyCode == 32 && e.target == document.body) { log("keyup ok"); e.preventDefault(); elmTarget.focus(); elmTarget.click(); elmTarget.blur(); } }); })();