Auto Full HD Resolution for Viu.com Video Playing

The script is to auto click the "全高清" Button for viu.com videos (only avaliable for paid member)

当前为 2021-06-16 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Auto Full HD Resolution for Viu.com Video Playing
// @version      0.3
// @description  The script is to auto click the "全高清" Button for viu.com videos (only avaliable for paid member)
// @match        https://www.viu.com/ott/*/vod/*
// @icon         https://www.google.com/s2/favicons?domain=viu.com
// @grant        none
// @namespace https://greasyfork.org/users/371179
// ==/UserScript==
(function $$() {
    'use strict';

    if (!document || !document.documentElement) return window.requestAnimationFrame($$);

    var fn = function() {
        this.setAttribute('__userscript_viu_force_selected', 'true')
    };
    var t = 0;
    var cid = 0;
    var mDate = 0;
    const TIMEOUT = 8000;

    var gn = function() {

        mDate = +new Date + TIMEOUT;
        if (cid > 0) clearInterval(cid);
        cid = setInterval(function() {
            if (mDate < +new Date) clearInterval(cid);
            var btn1080 = document.querySelector('.vjs-menu-item[data-r="1080"]');
            if (btn1080) {
                clearInterval(cid);
                if(btn1080.matches('[__userscript_viu_loaded]'))return;
                btn1080.setAttribute('__userscript_viu_loaded', 'true');
                const bool = btn1080.matches(':not([aria-disabled=""]):not([aria-disabled="true"]):not([aria-checked="true"]):not([aria-checked=""])');
                if (bool) {
                    const menuBtns = btn1080.parentNode.querySelectorAll('.vjs-menu-item[data-r]');
                    queueMicrotask(() => {
                        btn1080.click();
                        queueMicrotask(() => {
                            for (const menuBtn of menuBtns) menuBtn.addEventListener("click", fn, true)
                        })
                    })
                }
            }
        }, 33);
    }


    document.addEventListener('loadedmetadata', ()=>queueMicrotask(gn), true)
    document.addEventListener('playing', ()=>queueMicrotask(gn), true)
    document.addEventListener('pause', ()=>queueMicrotask(gn), true)


    // Your code here...
})();