// ==UserScript==
// @name 纯净版斗鱼(douyu)
// @namespace https://github.com/ljezio
// @version 4.3.0
// @author ljezio
// @description 斗鱼纯净版(douyu.com)。只保留直播和弹幕【斗鱼精简版、斗鱼极简版、斗鱼清爽版】;支持按钮切换关闭脚本;支持自动切换最高画质;
// @license MIT
// @icon https://www.douyu.com/favicon.ico
// @homepage https://github.com/ljezio/pure-douyu
// @match *://*.douyu.com/0*
// @match *://*.douyu.com/1*
// @match *://*.douyu.com/2*
// @match *://*.douyu.com/3*
// @match *://*.douyu.com/4*
// @match *://*.douyu.com/5*
// @match *://*.douyu.com/6*
// @match *://*.douyu.com/7*
// @match *://*.douyu.com/8*
// @match *://*.douyu.com/9*
// @match *://*.douyu.com/topic/*
// @match *://*.douyu.com/beta/*
// @grant GM_addStyle
// @downloadURL none
// ==/UserScript==
(function () {
'use strict';
const d=new Set;const importCSS = async e=>{d.has(e)||(d.add(e),(t=>{typeof GM_addStyle=="function"?GM_addStyle(t):document.head.appendChild(document.createElement("style")).append(t);})(e));};
const restyleCss = "header,aside,.wm-general,.bc-wrapper,.RechangeJulyPopups,#js-bottom-left,#bc3,#bc3-bgblur,#js-player-dialog,#js-player-above-controller,#js-layout-fixed-buff,[class^=snapbar__],[class^=sidebar__],[class^=title__],[class^=interactive__],[class^=toggle__]{display:none!important}#root,#js-player-main{margin:0!important}[class^=stream__]{bottom:0!important;top:0!important}[class^=case__]{padding:0!important}#js-player-main:before{content:none!important}[class^=player__]:before{padding-top:0!important;padding-bottom:calc(100vh - 16px)!important}";
importCSS(restyleCss);
const switchKey = "pure_douyu_switch";
const autoHighestImageKey$1 = "pure_douyu_auto_highest";
const switchSvg = '';
const autoHighestImageSvg = '';
function functionButtons() {
const buttonGroup = document.createElement("div");
buttonGroup.style.cssText = "z-index: 999; position: fixed; top: 0; right: 0;";
document.body.appendChild(buttonGroup);
const switchButton = document.createElement("button");
switchButton.title = localStorage.getItem(switchKey) ? "启用脚本" : "关闭脚本";
switchButton.innerHTML = switchSvg;
switchButton.onclick = () => {
if (localStorage.getItem(switchKey)) {
localStorage.removeItem(switchKey);
} else {
localStorage.setItem(switchKey, "off");
}
location.reload();
};
buttonGroup.appendChild(switchButton);
if (!localStorage.getItem(switchKey)) {
const autoHighestImageButton = document.createElement("button");
autoHighestImageButton.title = localStorage.getItem(autoHighestImageKey$1) ? "开启自动切换最高画质" : "关闭自动切换最高画质";
autoHighestImageButton.innerHTML = autoHighestImageSvg;
autoHighestImageButton.onclick = () => {
if (localStorage.getItem(autoHighestImageKey$1)) {
autoHighestImageButton.title = "关闭自动切换最高画质";
localStorage.removeItem(autoHighestImageKey$1);
} else {
autoHighestImageButton.title = "开启自动切换最高画质";
localStorage.setItem(autoHighestImageKey$1, "off");
}
};
buttonGroup.appendChild(autoHighestImageButton);
}
[...buttonGroup.children].forEach((button) => {
button.style.cssText = "display: block; cursor: pointer; opacity: 0.5; transition: opacity 0.3s ease;";
button.onmouseover = () => button.style.opacity = "1";
button.onmouseout = () => button.style.opacity = "0.5";
});
return buttonGroup;
}
(function() {
window.onload = () => {
const buttonGroup = functionButtons();
if (localStorage.getItem(switchKey)) return;
avoidSmallWindow();
autoFullWindow().then(() => autoHighestImage());
dbClick(buttonGroup);
};
})();
function avoidSmallWindow() {
const observer = new MutationObserver(() => {
document.querySelector("#js-player-video-widgets .roomSmallPlayerFloatLayout-closeBtn")?.click();
observer.disconnect();
});
observer.observe(document.querySelector("#js-player-video-case"), {
attributes: true,
attributeFilter: ["class", "style"]
});
}
function autoFullWindow() {
return new Promise((resolve) => {
const fullWindowInterval = setInterval(() => {
if (!controlBar.fullWindow()) return;
setTimeout(() => {
document.querySelector('#js-player-main [class^="toggle__"] button')?.click();
}, 10);
clearInterval(fullWindowInterval);
resolve();
}, 300);
});
}
function autoHighestImage() {
if (localStorage.getItem(autoHighestImageKey)) return;
let times = 0;
const highestImageInterval = setInterval(() => {
if (times++ >= 10) {
clearInterval(highestImageInterval);
return;
}
const highestImageButton = document.querySelector('#js-player-controlbar [class^="tipItem-"]:nth-child(2) li:first-child');
if (!highestImageButton) return;
setTimeout(() => {
if (!highestImageButton.className.startsWith("selected-")) {
highestImageButton.click();
}
}, 5e3);
clearInterval(highestImageInterval);
}, 1e3);
}
function dbClick(buttonGroup) {
document.body.ondblclick = (event) => {
event.stopPropagation();
if (!document.fullscreenElement) {
controlBar.fullScreen();
} else {
document.exitFullscreen().then();
}
};
document.onfullscreenchange = () => {
if (!document.fullscreenElement) {
setTimeout(() => controlBar.fullWindow(), 0);
buttonGroup.style.display = "block";
} else {
buttonGroup.style.display = "none";
}
};
}
const controlBar = {
fullWindow() {
return this._clickControlButton(2);
},
fullScreen() {
return this._clickControlButton(1);
},
_clickControlButton(nthLast) {
const parent = "#js-player-controlbar";
const nth = `:nth-last-child(${nthLast})`;
const button = document.querySelector(`${parent} [class^="right-"] > ${nth}, ${parent} [class^="right__"] > ${nth}`);
if (!button) return false;
button.click();
return true;
}
};
})();