Twitch Clip Quality

Automatically change twitch clip quality on embedded and native

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Twitch Clip Quality
// @version      1.5
// @description  Automatically change twitch clip quality on embedded and native
// @author       ArsenicBismuth
// @match        https://clips.twitch.tv/*
// @grant        none
// @namespace    https://www.github.com/ArsenicBismuth
// @license BSD
// ==/UserScript==


(function() {
    'use strict';

    const quality = "480p" // The desired quality

    // Function to observe DOM changes
    function waitForElement(selector, modifyFn) {
        const observer = new MutationObserver((mutations, observer) => {
            const element = document.querySelector(selector);
            if (element) {
                modifyFn(element)
                observer.disconnect() // Stop observing once the element is found
            }
        });

        observer.observe(document.body, { childList: true, subtree: true })
    }

    // Wait for targets to appear (multiple waitForElement are in parallel)
    let gear = null
    waitForElement("[data-a-target='player-settings-button']", (element) => {
        // Click gear
        element.click()
        gear = element
    })

    waitForElement("[data-a-target='player-settings-menu-item-quality']", (element) => {
        // Click quality
        element.click()
    })

    waitForElement("[name='player-settings-submenu-quality-option']", (element) => {
        // Find and choose quality
        const aTags = document.getElementsByTagName("label")
        let found = aTags[0]

        for (var i = 0; i < aTags.length; i++) {
            if (aTags[i].textContent == quality) {
                found = aTags[i]
                break
            }
        }
        found.click()
        gear.click() // Close the menu after
    })

})();