-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathone-punch-manhuabudang.js
95 lines (94 loc) · 3.4 KB
/
one-punch-manhuabudang.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// ==UserScript==
// @name ONE PUNCH MANHUABUDANG
// @namespace https://github.com/makaria/Tampermonkey-script/blob/master/one-punch-manhuabudang.js
// @version 1.0
// @description Auto punch for manhuabudang.com
// @author maka
// @match https://www.manhuabudang.com
// @match https://www.manhuabudang.com/index.php
// @match https://www.manhuabudang.com/u.php
// @match http://www.manhuabudang.com
// @match http://www.manhuabudang.com/index.php
// @match http://www.manhuabudang.com/u.php
// @grant none
// @run-at document-start
// ==/UserScript==
(function() {
'use strict';
var mockPunch = function() {
console.log('punch---mock punch');
var userInit = {
credentials: "include"
};
var userUrl = location.protocol + '//' + location.host + '/u.php';
fetch(userUrl, userInit)
.then((req) => {
return req.text();
}).then((data) => {
var doneReg = /card card_old" disabled/;
if (doneReg.test(data)) {
console.info('punch---你已经打过卡啦~');
return false;
}
var verifyReg = /verifyhash = '(.*?)'/;
var verifyResult = data.match(verifyReg);
var verifyhash = verifyResult && verifyResult[1];
var punchInit = {
credentials: 'include',
method: 'post',
headers: new Headers({
'Content-Type': 'application/x-www-form-urlencoded'
}),
body: 'step=2'
};
var punchUrl = location.protocol + '//' + location.host + '/jobcenter.php?action=punch&verify=' + verifyhash;
fetch(punchUrl, punchInit)
.then((req) => {
return req.blob();
}).then((blob) => {
var reader = new FileReader();
reader.onload = function(e) {
var text = reader.result;
var flag = text.match(/"flag":'(.*?)'/);
if (flag && flag[1]) {
console.info('punch---打卡成功');
} else {
var message = text.match(/"message":'(.*?)'/);
console.info('punch---' + message[1]);
}
};
reader.readAsText(blob, 'GBK');
});
});
};
var realPunch = function() {
console.log('punch---real punch!');
var disabled = document.querySelectorAll('.card.card_old')[0].disabled;
if (!disabled) {
var money = document.getElementById('money').innerText;
punchJob(money);
} else {
console.info('punch---已经打过卡啦~');
}
};
var start = function() {
// console.log('punch---start');
var path = location.pathname;
var reg = /u\.php/;
var result = reg.test(path);
if (result) {
realPunch();
} else {
mockPunch();
}
};
var domReady = function(callback) {
// console.log('dom ready');
if (document.readyState === "complete" || document.readyState === "interactive") {
setTimeout(callback, 1);
} else {
addEventListener('DOMContentLoaded', callback, false);
}
};
domReady(start);
})();