-
Notifications
You must be signed in to change notification settings - Fork 63
/
auto_live_fullscreen.js
77 lines (71 loc) · 3.12 KB
/
auto_live_fullscreen.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// ==UserScript==
// @name 直播平台自动网页全屏/关闭弹幕
// @namespace http://tampermonkey.net/
// @homeurl https://github.com/xiandanin/LardMonkeyScripts
// @homeurl https://greasyfork.org/zh-CN/scripts/377547
// @version 1.1
// @description 直播平台进入直播间后自动网页全屏和关闭弹幕
// @author xiandanin
// @match https://www.douyu.com/*
// @match https://www.panda.tv/*
// @match https://www.huya.com/*
// @match https://cc.163.com/*
// @grant none
// ==/UserScript==
(function () {
let time = 0
/**
* 需要的节点加载完成的检测
*/
function lazyLoadingDetection (selectors, callback) {
const intervalTime = 300
let interval = setInterval(function () {
//检测节点已经加载完成或者超过最大检测时间 都停止
if (document.querySelector(selectors)) {
console.log('%dms,检测节点加载完成,可以执行操作', time)
clearInterval(interval);
callback()
} else if (time >= 8000) {
console.log('%dms,计时器超时', time)
clearInterval(interval);
}
time += intervalTime;
}, intervalTime);
}
function checkAndClickSwitch (delayClickTime, checkFunc, ...clickSelectors) {
lazyLoadingDetection(clickSelectors[0], function () {
for (let i = 0; i < clickSelectors.length; i++) {
const clickElement = document.querySelector(clickSelectors[i]);
// 检查当前状态是否需要点击
if (checkFunc(clickElement)) {
setTimeout(function () {
clickElement.click()
}, delayClickTime)
}
}
})
}
const host = window.location.host
if (host.indexOf("douyu.com") !== -1) {
//斗鱼
checkAndClickSwitch(0, clickElement => {
// 检测是开关状态
return !clickElement.classList.contains("removed-9d4c42")
//网页全屏 弹幕
}, ".wfs-2a8e83", '.showdanmu-42b0ac')
// 自动选择最高清的
const quality = document.querySelector('.tip-e3420a > ul').children
quality[0].click()
} else if (host.indexOf("huya.com") !== -1) {
//虎牙
checkAndClickSwitch(0, clickElement => {
return clickElement.className === 'player-fullpage-btn' || clickElement.className === 'danmu-show-btn'
}, "#player-fullpage-btn", '#player-danmu-btn')
} else if (host.indexOf("cc.163.com") !== -1) {
//cc 点击事件延迟1秒
checkAndClickSwitch(1000, clickElement => {
return !clickElement.classList.contains("theater") || !clickElement.classList.contains("on") || !clickElement.classList.contains("selected")
//CC需要先检测其它开关
}, '.ban-effect-list > li:nth-child(3)', '.ban-effect-list > li:nth-child(4)', '.ban-effect-list > li:nth-child(5)', ".video-player-theater-control", '.video-player-comment')
}
})();