XHamster - auto-select highest quality stream - TEST

auto-select highest quality stream from https://greasyfork.org/fr/scripts/546708-xhamster-mobile-html5-player/code

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         XHamster - auto-select highest quality stream - TEST
// @version      2.00
// @description  auto-select highest quality stream from https://greasyfork.org/fr/scripts/546708-xhamster-mobile-html5-player/code
// @icon         https://external-content.duckduckgo.com/ip3/fr.xhamster.com.ico
// @author       janvier57
// @namespace    https://greasyfork.org/fr/users/7434-janvier56?sort=updated
// @license MIT
// @match        *://xhamster.com/*
// @match        *://*.xhamster.com/*
// @grant        none
// @run-at       document-end

// ==/UserScript==

(function() {
    'use strict';

    function checkAndSelectHighestQuality() {
        const qualitySelector = document.querySelector('.quality.chooser-control');
        if (!qualitySelector) {
            setTimeout(checkAndSelectHighestQuality, 1000);
            return;
        }

        console.log('checkAndSelectHighestQuality');
        const qualityOptions = Array.from(qualitySelector.children);
        console.log('qualityOptions:', qualityOptions);
        if (qualityOptions.length === 0) {
            setTimeout(checkAndSelectHighestQuality, 1000);
            return;
        }

        const hdOptions = qualityOptions.filter(option => option.classList.contains('HD'));
        console.log('hdOptions:', hdOptions);
        const chosenOption = qualitySelector.querySelector('.chosen');
        console.log('chosenOption:', chosenOption);
        if (hdOptions.length > 0 && (!chosenOption || !chosenOption.classList.contains('HD'))) {
            hdOptions.sort((a, b) => parseInt(b.textContent.trim().replace('p', '')) - parseInt(a.textContent.trim().replace('p', '')));
            console.log('Selecting highest quality option:', hdOptions[0]);
            hdOptions[0].click();
        }
    }

    checkAndSelectHighestQuality();
})();