R34 Auto Max Quality

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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);
})();