BetterTTV Plus

It's BetterTTV but the settings are stored by the Script Manager.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name            BetterTTV Plus
// @description     It's BetterTTV but the settings are stored by the Script Manager.
// @icon            https://cdn.betterttv.net/assets/logos/bttv_logo.png
// @author          SkauOfArcadia
// @homepage        https://skau.neocities.org/
// @match           https://*.twitch.tv/*
// @version         2025.11.24
// @grant           GM.getValue
// @grant           GM.setValue
// @require         https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js
// @run-at          document-start
// @namespace https://greasyfork.org/users/751327
// ==/UserScript==
(function() {
    const BTTV_CDN = 'https://cdn.betterttv.net';
    const SETTINGS_KEY = 'bttv_settings';
    const DEFAULT_SETTINGS = '{\"emoteMenu\":2,\"emotes\":[55,16],\"channelPoints\":[7,2],\"autoClaim\":[1,1]}';
    const POLLING_INTERVAL = 1000; // Time in milliseconds for checking updates

    // Load BetterTTV script
    window.addEventListener("DOMContentLoaded", function() {
        const jsNode = document.createElement('script');
        jsNode.setAttribute('src', `${BTTV_CDN}/betterttv.js`);
        document.body.appendChild(jsNode);
    });

    // Variables for tracking the last known settings
    let lastSettings = localStorage.getItem(SETTINGS_KEY) || DEFAULT_SETTINGS;

    function logWithTimestamp(message) {
        const timestamp = new Date().toLocaleTimeString();
        console.log(`[${timestamp}] BTTV Plus: ${message}`);
    }

    // Function to save settings to GM
    function saveSettings(settings) {
        GM.setValue(SETTINGS_KEY, settings);
        logWithTimestamp("Settings saved!");
    }

    // Load settings from GM and set them to localStorage
    async function loadSettings() {
        const savedSettings = await GM.getValue(SETTINGS_KEY, lastSettings);
        localStorage.setItem(SETTINGS_KEY, savedSettings);
        logWithTimestamp("Settings loaded!");
    }

    // Initialize settings on script load
    loadSettings();

    // First use save
    GM.getValue(SETTINGS_KEY, null).then(value => {
        if (value === null) {
            saveSettings(lastSettings);
        }
    });

    // Periodically check for changes in localStorage
    setInterval(() => {
        const currentSettings = localStorage.getItem(SETTINGS_KEY);
        if (currentSettings === null) {
            currentSettings = lastSettings;
            localStorage.setItem(SETTINGS_KEY, currentSettings);
        }
        if (currentSettings !== lastSettings) {
            lastSettings = currentSettings;
            saveSettings(currentSettings);
        }
    }, POLLING_INTERVAL);
})();