Kick.com - Auto select best quality

Auto select best quality

目前為 2024-09-11 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Kick.com - Auto select best quality
// @namespace    https://greasyfork.org/en/users/1200587-trilla-g
// @version   3.0
// @author       Trilla_G
// @description  Auto select best quality
// @match        *://kick.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=kick.com
// @grant        GM_addStyle
// @run-at       document-start
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to check if a quality option is selected and click it if not
    let checkQuality = (quality) => {
        // Select all divs with the given class
        let buttons = document.querySelectorAll("div[class*='betterhover\\:hover:text-primary'].relative.flex.h-\\[30px\\].cursor-pointer.select-none.items-center.rounded-\\[3px\\].px-\\[15px\\].pl-\\[20px\\].text-sm.font-medium.leading-none.text-white.outline-none");

        for (let button of buttons) {
            if (button.textContent.includes(quality)) {
                if (button.getAttribute('aria-checked') === 'true' && button.getAttribute('data-state') === 'checked') {
                    return true; // Already selected, stop further checks
                }
                // Modify attributes to simulate selection
                button.setAttribute('aria-checked', 'true');
                button.setAttribute('data-state', 'checked');
                button.click(); // Simulate the click to select the quality
                return true;
            }
        }
        return false;
    };

    // Function to set the stream quality
    let setStreamQuality = () => {
        // Try to select the best available quality and stop the interval if successful
        if (checkQuality('1080p60') ||
            checkQuality('1080p') ||
            checkQuality('936p60') ||
            checkQuality('720p60') ||
            checkQuality('720p') ||
            checkQuality('Auto')) {
            clearInterval(qualityCheckInterval); // Stop checking once the quality is set
            return true;
        }
        return false;
    };

    // Run the setStreamQuality function every 500 ms until the quality is set
    let qualityCheckInterval = setInterval(() => {
        setStreamQuality();
    }, 500);

})();