Internet Roadtrip - Remember radio volume

Preserve the volume of the Internet Roadtrip radio

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Internet Roadtrip - Remember radio volume
// @namespace   jdranczewski.github.io
// @match       https://neal.fun/internet-roadtrip/*
// @version     0.0.2
// @author      jdranczewski
// @description Preserve the volume of the Internet Roadtrip radio
// @license     MIT
// @icon         https://jdranczewski.dev/irt/images/radio.png
// @grant        GM.setValue
// @grant        GM.getValue
// @require     https://cdn.jsdelivr.net/npm/[email protected]
// ==/UserScript==

// This works together with irf.d.ts to give us type hints
/**
 * Internet Roadtrip Framework
 * @typedef {typeof import('internet-roadtrip-framework')} IRF
 */

(async function() {
    // Get the radio object and stored options
    const radio = await IRF.vdom.radio;
    const volume = await GM.getValue("radio_volume_angle");

    // Set the volume to the stored value
    if (volume) {
        radio.methods.updateVolumeFromAngle(volume);
    }

    // Override the volume setting method to store the angle
    radio.state.updateVolumeFromAngle = new Proxy(radio.methods.updateVolumeFromAngle, {
        apply(og_method, thisArg, args) {
            GM.setValue("radio_volume_angle", args[0])
            return og_method.apply(thisArg, args);
        }
    });

    
})();