syntax.fm

syntax 控制

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         syntax.fm
// @namespace    ziggy chen
// @license MIT
// @version      0.2
// @description  syntax 控制
// @author       Ziggy chen
// @match        *://syntax.fm/*
// @icon         https://syntax.fm/favicon.png
// @run-at       document-start
// @grant        GM_addStyle
// ==/UserScript==

(function() {
    'use strict';
    // 创建控制按钮
    const btn = document.createElement('button');
    btn.id = 'speedControlBtn';
    btn.style.cssText = `
        position: fixed;
        bottom: 110px;
        right: 20px;
        z-index: 9999;
        padding: 4x 8px 4px 8px !important;
        background-color: #4CAF50;
        color: white;
        border: none;
        font-size: 12px;
        border-radius: 4px;
        cursor: pointer;
        box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    `;
    // 状态管理
    let isActive = false;
    let intervalId = null;
  
    // 更新按钮状态
    function updateButtonState() {
        btn.textContent = isActive ? '0.8x': '1x';
        btn.style.backgroundColor = isActive ? '#4CAF50' : '#f44336';
    }
    // 主控制函数
    function toggleSpeedControl() {
        isActive = !isActive;
  
        if (isActive) {
            // 创建定时器
            intervalId = setInterval(() => {
                const audio = document.querySelector('audio');
                if (audio && audio.playbackRate !== 0.8) {
                    audio.playbackRate = 0.8;
                }
            }, 1000);
        } else {
            // 清除定时器
            if (intervalId) {
                clearInterval(intervalId);
                 const audio = document.querySelector('audio');
                if (audio && audio.playbackRate === 0.8) {
                    audio.playbackRate = 1;
                }
                intervalId = null;
            }
        }
  
        updateButtonState();
    }
    // 初始化
    btn.addEventListener('click', toggleSpeedControl);
    updateButtonState();
    document.body.appendChild(btn);
    // 自动检测新添加的audio元素
    new MutationObserver(() => {
        if (isActive) {
            const audio = document.querySelector('audio');
            if (audio && audio.playbackRate !== 0.8) {
                audio.playbackRate = 0.8;
            }
        }
    }).observe(document.body, {
        childList: true,
        subtree: true
    });
    // 快进 退后
    let changeSeek = false
    const seekTimer = setInterval(() => {
        if (changeSeek)  {
            clearInterval(seekTimer)
            return
        }

        const seekBtns =document.querySelectorAll("*[seekoffset]")
        console.log("🚀 ~ seekBtns:", seekBtns)
        if (seekBtns?.length) {
            changeSeek = true
            for (const btn of seekBtns) {
                btn.setAttribute('seekoffset', 2)
                console.log(btn)
            }
        }
    }, 1000)
  })();