R34 Auto Max Quality

Auto-select max quality up to limit / Автовыбор макс. качества

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         R34 Auto Max Quality
// @namespace    r34-auto-max-quality
// @version      1.1
// @description  Auto-select max quality up to limit / Автовыбор макс. качества
// @match        https://rule34video.com/video/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=rule34video.com
// @run-at       document-idle
// ==/UserScript==

(function () {
    'use strict';

    // USER SETTING / НАСТРОЙКА ПОЛЬЗОВАТЕЛЯ
    // 1 = 360p | 2 = 480p | 3 = 720p | 4 = 1080p | 5 = 4k
    const MAX_QUALITY = 4; // change here / менять здесь

    let locked = false;
    let lastUrl = location.href;

    function apply() {
        if (locked) return;

        const list = document.querySelector('.fp-settings-list');
        if (!list) return;

        const best = [...list.querySelectorAll('a[data-format]')]
            .map(a => ({ a, f: +a.dataset.format }))
            .filter(x => x.f <= MAX_QUALITY)
            .sort((a, b) => b.f - a.f)[0];

        if (best && !best.a.parentElement.classList.contains('is-selected')) {
            best.a.click();
        }
    }

    // manual selection → lock / ручной выбор → блокировка
    document.addEventListener('click', e => {
        const a = e.target.closest('.fp-settings-list a[data-format]');
        if (!a) return;

        const f = +a.dataset.format;
        if (f <= MAX_QUALITY) locked = true;
    });

    // video change → unlock / новое видео → сброс
    const obs = new MutationObserver(() => {
        if (location.href !== lastUrl) {
            lastUrl = location.href;
            locked = false;
            setTimeout(apply, 300);
        }
    });

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

    setTimeout(apply, 500);
})();