Greasy Fork

radiko ワンクリックプレイ

選局したらすぐ再生する。

当前为 2023-05-28 提交的版本,查看 最新版本

// ==UserScript==
// @name         radiko ワンクリックプレイ
// @namespace    https://yyya-nico.co/
// @version      1.3
// @description  選局したらすぐ再生する。
// @author       yyya_nico
// @license      MIT License
// @match        https://radiko.jp/
// @icon         https://www.google.com/s2/favicons?sz=64&domain=radiko.jp
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 監視ターゲットの取得
    const target = document.getElementById('contents');

    // オブザーバーの作成
    const observer = new MutationObserver(records => {
        records.forEach(record => {
            if (record.target.id == 'now-programs-list') {
                const playBtn = Array.from(record.addedNodes)
                    .filter(node => {
                        if (node.nodeType == 1/*ELEMENT*/ ) {
                            return node.classList.contains('live-detail__body');
                        }
                    })[0].querySelector('.live-detail__play .btn--play');
                if (playBtn != null) {
                    setTimeout(() => {playBtn.click();}, 50);
                }
                observer.disconnect();
            }
        });
    });

    const options = { //監視オプション
        childList: true, //直接の子の変更を監視
        subtree: true //全ての子要素を監視
    }

    window.addEventListener('hashchange', () => {
        if(/live/.test(location.hash)) {
            // 監視の開始
            observer.observe(target, options);
        }
    });
})();