// ==UserScript== // @name Bilibili 视频默认选择最高清晰度 // @namespace http://tampermonkey.net/ // @version 0.2018.12.28 // @description try to take over the world! // @author Zimongmu // @match *://www.bilibili.com/video/av* // @grant none // @license GPL-3.0-or-later // @downloadURL none // ==/UserScript== (function() { 'use strict'; // Your code here... var MO = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver; function vip(element, observer) { setTimeout(function () { element.click(); observer.takeRecords(); }, window.location.search === '' ? 0 : 1000); } 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("div.i-face") !== 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, {'attributes': true, 'subtree': true, 'attributeFilter': ['src']}); })();