Play / Pause with spacebar on Bandcamp

Use spacebar on Bandcamp to control music playback

目前為 2020-11-03 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Play / Pause with spacebar on Bandcamp
// @namespace    https://openuserjs.org/users/burn
// @version      0.1.1
// @description  Use 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
// ==/UserScript==

// ==OpenUserJS==
// @author burn
// ==/OpenUserJS==

(function() {
    'use strict';
    const DBG = false;

    let log = function(s) {
            DBG && console.log(s);
        },
        elmTarget = "#trackInfoInner > div.inline_player > table > tbody > tr:nth-child(1) > td.play_cell > a > div",
        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;
        };
    window.addEventListener('keydown', function(e) {
        log("in keydown: " + e.target);
        if(e.keyCode == 32 && e.target == document.body) {
            log("keydown ok");
            e.preventDefault();
        }
    });
    qS('body').addEventListener("keyup", function(e) {
        log("in keyup: " + e.target);
        log(qS(elmTarget));
        if (e.keyCode == 32 && e.target == document.body) {
            log("keyup ok");
            e.preventDefault();
            qS(elmTarget).click();
        }
    });
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址