Kick.com Auto Select 1080p60

Tries full interaction: focus, pointer events, then click to open settings menu and select 1080p60 (or fallback) on kick.com

目前為 2025-06-17 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 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 1080p60
// @namespace    http://tampermonkey.net/
// @version      1.5
// @description  Tries full interaction: focus, pointer events, then click to open settings menu and select 1080p60 (or fallback) on kick.com
// @match        https://kick.com/*
// @author       Paradox109
// @icon         https://www.google.com/s2/favicons?sz=64&domain=kick.com
// @license MIT
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    const preferredQualities = ['1080p60', '720p60'];

    function findCogButton() {
        const buttons = document.querySelectorAll('button[aria-haspopup="menu"]');
        for (const btn of buttons) {
            const svg = btn.querySelector('svg path');
            if (!svg) continue;
            const pathD = svg.getAttribute('d');
            if (!pathD) continue;

            if (pathD.startsWith('M25.7,17.3c0.1-0.4')) {
                return btn;
            }
        }
        return null;
    }

    function simulateFullClick(el) {
        if (!el) return;

        el.focus();

        ['pointerover', 'pointerenter', 'pointerdown', 'mousedown', 'pointerup', 'mouseup', 'click'].forEach(type => {
            const event = new PointerEvent(type, {
                bubbles: true,
                cancelable: true,
                composed: true,
                pointerId: 1,
                pointerType: 'mouse',
                isPrimary: true,
            });
            el.dispatchEvent(event);
        });

        // Also call native click as a fallback
        el.click();
    }

    function selectQuality() {
        const items = document.querySelectorAll('[role="menuitemradio"]');
        if (items.length === 0) {
            console.log('Quality options not available yet.');
            return false;
        }

        for (const quality of preferredQualities) {
            const match = Array.from(items).find(item => item.textContent.trim() === quality);
            if (match) {
                console.log(`Selecting quality: ${quality}`);
                match.click();
                return true;
            }
        }
        return false;
    }

    function observeMenuAndSelect() {
        const menuContainer = document.querySelector('div[role="menu"]') || document.body;

        const observer = new MutationObserver((mutations, obs) => {
            if (selectQuality()) {
                console.log('Quality selected, disconnecting observer and stopping script.');
                obs.disconnect();
                clearInterval(mainInterval);
            }
        });

        observer.observe(menuContainer, { childList: true, subtree: true });
    }

    function trySelectQuality() {
        const cogButton = findCogButton();
        if (!cogButton) {
            console.log('Cog button not found yet.');
            return;
        }

        console.log('Cog button found, simulating full interaction click...');
        simulateFullClick(cogButton);

        observeMenuAndSelect();
    }

    // Try every 50 ms until successful
    const mainInterval = setInterval(() => {
        trySelectQuality();
    }, 50);

})();