Internet Roadtrip Radio - WBOR

Replace default station with WBOR and show now playing along with live show info

目前為 2025-05-23 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Internet Roadtrip Radio - WBOR
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Replace default station with WBOR and show now playing along with live show info
// @author       TotallyNotSamm
// @license      MIT
// @match        https://neal.fun/internet-roadtrip/*
// @grant        GM_xmlhttpRequest
// @connect      azura.wbor.org
// ==/UserScript==


(function () {
    'use strict';

    const radioStreamURL = "https://listen.wbor.org/";
    const audio = new Audio(radioStreamURL);
    audio.crossOrigin = "anonymous";
    audio.loop = true;
    audio.volume = 0.3;
    audio.style.display = "none";
    document.body.appendChild(audio);

    const originalPlay = HTMLMediaElement.prototype.play;
    HTMLMediaElement.prototype.play = function () {
        if (this === audio) return originalPlay.call(this);
        this.pause(); this.src = '';
        return Promise.resolve();
    };

    // Cached DOM nodes for efficiency
    let stationName, stationInfo;

    function safeSetText(node, text) {
        if (node && node.textContent !== text) node.textContent = text;
    }

    function fetchNowPlayingFromAPI() {
        GM_xmlhttpRequest({
            method: 'GET',
            url: 'https://azura.wbor.org/api/nowplaying/1',
            onload: function (response) {
                try {
                    const data = JSON.parse(response.responseText);
                    if (Array.isArray(data) && data.length > 0) {
                        const nowPlayingData = data[0].now_playing;
                        const live = nowPlayingData.live || {};

                        const liveShow = (live.is_live)
                            ? live.title || live.streamer_name || 'Live Show'
                            : 'No live shows';

                        const title = nowPlayingData.song?.title || 'Unknown Title';
                        const artist = nowPlayingData.song?.artist || 'Unknown Artist';

                        safeSetText(stationName, `WBOR - ${liveShow}`);
                        safeSetText(stationInfo, `${title} | ${artist}`);
                    } else {
                        safeSetText(stationName, 'WBOR - No live shows');
                        safeSetText(stationInfo, '91.1 FM Brunswick');
                    }
                } catch {
                    safeSetText(stationName, 'WBOR - No live shows');
                    safeSetText(stationInfo, '91.1 FM Brunswick');
                }
            },
            onerror: function () {
                safeSetText(stationName, 'WBOR - No live shows');
                safeSetText(stationInfo, '91.1 FM Brunswick');
            }
        });
    }

    function initWhenReady() {
        const powerBtn = document.querySelector('.power-button');
        const volumeKnob = document.querySelector('.knob-body');
        const volumeBar = document.querySelector('.volume-bar');
        stationName = document.querySelector('.station-name');
        stationInfo = document.querySelector('.station-info');

        if (!powerBtn || !volumeKnob || !volumeBar || !stationName || !stationInfo) {
            requestAnimationFrame(initWhenReady);
            return;
        }

        safeSetText(stationName, 'WBOR - No live shows');
        safeSetText(stationInfo, '91.1 FM Brunswick');

        let isOn = false;
        powerBtn.addEventListener('click', () => {
            isOn = !isOn;
            if (isOn) {
                audio.play();
            } else {
                audio.pause();
            }
        });

        const knobObserver = new MutationObserver(() => {
            const rotation = parseFloat(volumeKnob.style.transform.replace(/[^\d.-]/g, '')) || -120;
            const volume = Math.min(Math.max((rotation + 120) / 240, 0), 1);
            audio.volume = volume;
            volumeBar.style.height = `${Math.round(volume * 100)}%`;
        });
        knobObserver.observe(volumeKnob, { attributes: true, attributeFilter: ['style'] });

        const audioObserver = new MutationObserver(() => {
            document.querySelectorAll('audio').forEach(el => {
                if (el !== audio) {
                    el.pause();
                    el.src = '';
                    el.remove();
                }
            });
        });
        audioObserver.observe(document.body, { childList: true, subtree: true });

        fetchNowPlayingFromAPI();
        setInterval(fetchNowPlayingFromAPI, 30000);
    }

    window.addEventListener('load', initWhenReady);
})();

QingJ © 2025

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