-
Notifications
You must be signed in to change notification settings - Fork 0
/
xTAutoWatch.user.js
73 lines (65 loc) · 2.22 KB
/
xTAutoWatch.user.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
// ==UserScript==
// @name 学堂在线 自动播放
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://next.xuetangx.com/learn/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
function covertTimeToSeconds(time) {
var a = time.split(':'); // split it at the colons
// minutes are worth 60 seconds. Hours are worth 60 minutes.
var seconds = (+a[0]) * 60 * 60 + (+a[1]) * 60 + (+a[2]);
return seconds
}
function checkVideo() {
if (jQuery('.white').text() == "") {
console.log("没有检测到时间,可能不是视频?")
return false
} else {
return true
}
}
function checkEnd() {
// https://next.xuetangx.com/learn/jluzh61021002425/jluzh61021002425/1520618/quiz/1486062
var curURL = document.location.toString();
if (curURL.indexOf("quiz/1486062") != -1) {
return true
} else {
return false
}
}
function getWatchPercent() {
var curWatchTime = jQuery('.white').text()
var totaWatchlTime = jQuery('.white').next().text()
var curWatchTimeSeconds = covertTimeToSeconds(curWatchTime)
var totaWatchlTimeSeconds = covertTimeToSeconds(totaWatchlTime)
// console.log(curWatchTimeSeconds)
// console.log(totaWatchlTimeSeconds)
var watchPercent = curWatchTimeSeconds / totaWatchlTimeSeconds
// console.log(watchPercent)
return watchPercent
}
var interval = setInterval(function () {
if (checkVideo()) {
if (getWatchPercent() == 1) {
console.log("已看完")
jQuery('.next').click()
return
} else {
console.log("还没有看完,当前进度: " + getWatchPercent())
}
} else {
if (checkEnd()) {
console.log("已经是最后一章,结束执行")
clearInterval(interval);
} else {
console.log("直接跳转")
jQuery('.next').click()
}
}
}, 5 * 1000)
})();