Last active
September 9, 2022 05:40
-
-
Save SomeBottle/aaa1497bffba9adb944542fbb032ef47 to your computer and use it in GitHub Desktop.
U校园刷时长油猴脚本
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name U校园增加时长(修复必修弹窗) | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1.2 | |
// @description 生命短暂而美好,没时间纠结,没时间计较 | |
// @author handsometaoa | |
// @match https://ucontent.unipus.cn/_pc_default/pc.html?cid=* | |
// @grant none | |
// @license GPL-3.0 | |
// @compatible chrome | |
// ==/UserScript== | |
//表示每个页面停留[minMinute分minSeconds秒,maxMinute分钟maxSeconds秒],可以自己设置 | |
var minMinute = 4;//最小分钟 | |
var minSeconds = 30;//最小秒数 | |
var maxMinute = 5;//最大分钟 | |
var maxSeconds = 30;//最大秒数 | |
var timer, counter = 0, retry = 0; | |
//计算实际停留时间,防止每个页面停留时间相同 | |
function realTime() { | |
let rate = Math.random(); | |
return (minMinute * 60 + minSeconds + ((maxMinute - minMinute) * 60 + maxSeconds - minSeconds) * rate) * 1000; | |
} | |
function setTimer() { | |
if (retry >= 10) { | |
location.reload(); | |
} | |
timer = setInterval(() => { | |
console.log('Going to close dialog after ' + (10 - counter) + ' seconds'); | |
if (counter >= 10) { | |
console.log('Trying to close the dialog'); | |
clearInterval(timer); | |
counter = 0; | |
try { | |
var x = document.getElementsByClassName("dialog-header-pc--close-yD7oN"); | |
x[0].click(); | |
document.querySelector("div.dialog-header-pc--dialog-header-2qsXD").parentElement.querySelector('button').click(); | |
console.log('Close the dialog successfully.'); | |
} catch (e) { | |
console.log('Fail to close the dialog, try again.Retry time(s):' + retry); | |
retry += 1; | |
setTimer(); | |
} | |
} else { | |
counter++; | |
} | |
}, 1000) | |
} | |
//自动点击必修弹窗和麦克风弹窗 | |
setTimer(); | |
//跳转下一节 | |
function switch_next(selector, classFlag) { | |
let flag = false; | |
for (let [index, unit] of document.querySelectorAll(selector).entries()) { | |
if (flag) { | |
unit.click(); | |
//防止必修弹窗失效,跳转便刷新页面,1000表示跳转1秒后刷新页面 | |
setTimeout(() => { | |
location.reload(); | |
}, 1000); | |
flag = false; | |
break; | |
} | |
if (unit.classList.contains(classFlag)) { | |
flag = true; | |
} | |
} | |
} | |
setTimeout(() => { | |
switch_next('.layoutHeaderStyle--circleTabsBox-jQdMo a', 'selected'); | |
switch_next('#header .TabsBox li', 'active'); | |
switch_next('#sidemenu li.group', 'active'); | |
}, realTime()); | |
// U校园请求错误弹窗就直接页面重载 | |
window.alert = function () { | |
location.reload(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment