Bilibili 视频默认选择最高清晰度

try to take over the world!

Versão de: 27/12/2018. Veja: a última versão.

// ==UserScript==
// @name         Bilibili 视频默认选择最高清晰度
// @namespace    http://tampermonkey.net/
// @version      0.2018.12.27
// @description  try to take over the world!
// @author       You
// @match        *://www.bilibili.com/video/av*
// @grant        none
// @license      GPL-3.0-or-later
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    var MO = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
    function vip(element, observer) {
        if (element.click() !== undefined) observer.disconnect();
    }
    function novip(a, e, u, observer) {
        for (var i=1; document.querySelector(a + i + ")") !== null; i++) {
            if (document.querySelector(a + i + e) === null && document.querySelector(a + i + u) === null) {
                vip(document.querySelector(a + i + ")"), observer);
                break;
            }
        }
    }
    new MO(function (elements, observer) {
        elements[0] = document.querySelector("div.bui-select-list-wrap li:first-child");
        elements[1] = document.querySelector("i.legalize.vip");
        elements[2] = document.getElementById("bilibiliPlayer");
        elements[3] = "div.bui-select-list-wrap li:nth-of-type(";
        if (document.querySelector(".fr a.t") !== null && elements[2].hasAttribute("data-login") && /自动/.test(document.querySelector("span.bui-select-result").innerHTML)) {
            if (elements[1] !== null ) vip(elements[0], observer);
            else if (elements[2].getAttribute("data-login") == 'true') novip(elements[3], ") span.bilibili-player-bigvip", ") span.bilibili-player-bigvip", observer);
            else if (elements[2].getAttribute("data-login") == 'false') novip(elements[3], ") span.bilibili-player-needlogin", ") span.bilibili-player-bigvip", observer);
        }
    }).observe(document.body,{'childList': true});
})();