forked from dodying/UserJs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhvTrainer.user.js
289 lines (280 loc) · 9.19 KB
/
hvTrainer.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
// ==UserScript==
// @name [HV]Trainer
// @author dodying
// @namespace https://github.com/dodying/Dodying-UserJs
// @supportURL https://github.com/dodying/Dodying-UserJs/issues
// @icon https://cdn.jsdelivr.net/gh/dodying/UserJs@master/Logo.png
// @include http*://hentaiverse.org/*
// @include http://alt.hentaiverse.org/*
// @version 1.02b
// @grant GM_registerMenuCommand
// @run-at document-end
// ==/UserScript==
(function () {
if (!gE('#navbar')) return
var countdownBox = gE('body').appendChild(cE('a'))
countdownBox.href = '?s=Character&ss=tr'
countdownBox.style.cssText = 'font-weight:bold;font-size:large;position:absolute;top:2px;right:2px'
var timeLast
var trainList = {
'Adept Learner': {
id: 50,
time: 1
},
'Assimilator': {
'id': '51',
'time': 24
},
'Ability Boost': {
'id': '80',
'time': 2
},
'Manifest Destiny': {
'id': '81',
'time': 24
},
'Scavenger': {
'id': '70',
'time': 4
},
'Luck of the Draw': {
'id': '71',
'time': 8
},
'Quartermaster': {
'id': '72',
'time': 12
},
'Archaeologist': {
'id': '', //
'time': 24
},
'Metabolism': {
'id': '84',
'time': 24
},
'Inspiration': {
'id': '85',
'time': 24
},
'Scholar of War': {
'id': '90',
'time': 0
},
'Tincture': {
'id': '91',
'time': 0
},
'Pack Rat': {
'id': '98',
'time': 0
},
'Dissociation': {
'id': '88',
'time': 24
},
'Set Collector': {
'id': '96',
'time': 12
}
}
var trainList2 = {
'50': 1,
'51': 24,
'70': 4,
'71': 8,
'72': 12,
'80': 2,
'81': 24,
'84': 24,
'85': 24,
'88': 24,
'90': 0,
'91': 0,
'96': 12,
'98': 0,
'': 24
}
var lang = navigator.language
var timeOption = { hour12: false }
GM_registerMenuCommand('Train List', function () {
var time = countdownBox.value || new Date().getTime()
var trainTask
var trainWindow = window.open('', 'trainWindow', 'resizable,scrollbars,width=550,height=250')
var doc = trainWindow.document
var style = gE('head', doc).appendChild(cE('style'))
style.textContent = '*{margin:5px;text-align:center;}table{border:2px solid #000;border-collapse:collapse;margin:0 auto;}table>tbody>tr>td{border:1px solid #000;}input{text-align:right;width:60px;}'
var table = gE('body', doc).appendChild(cE('table'))
var tbody = table.appendChild(cE('tbody'))
var tr = tbody.appendChild(cE('tr'))
tr.innerHTML = '<td></td><td>Project</td><td>Freq</td><td>Start Time - End Time</td>'
var select = [
'<select>',
'<option value="-1"></option>',
'<option value="50">Adept Learner</option>',
'<option value="51">Assimilator</option>',
'<option value="80">Ability Boost</option>',
'<option value="81">Manifest Destiny</option>',
'<option value="70">Scavenger</option>',
'<option value="71">Luck of the Draw</option>',
'<option value="72">Quartermaster</option>',
'<option value="">Archaeologist</option>',
'<option value="84">Metabolism</option>',
'<option value="85">Inspiration</option>',
'<option value="90">Scholar of War</option>',
'<option value="91">Tincture</option>',
'<option value="98">Pack Rat</option>',
'<option value="88">Dissociation</option>',
'<option value="96">Set Collector</option>',
'</select>'
].join('')
var order = 1
var i, _time, _select, _input
var buttonNew = gE('body', doc).appendChild(cE('button'))
buttonNew.textContent = 'New Task'
buttonNew.onclick = function () {
tr = tbody.appendChild(cE('tr'))
tr.innerHTML = '<td>' + (order++) + '</td><td>' + select + '</td><td><input type="number" value="1" placeholder="1" min="1"></td><td></td>'
gE('select', tr).value = '-1'
}
var buttonSave = gE('body', doc).appendChild(cE('button'))
buttonSave.textContent = 'Save Task'
buttonSave.onclick = function () {
var input = gE('select,input', 'all', tbody)
trainTask = []
for (i = 0; i < input.length; i = i + 2) {
if (input[i].value !== '-1') {
trainTask.push({
id: input[i].value,
freq: (input[i + 1].value || input[i + 1].placeholder) * 1
})
}
}
setValue('trainTask', trainTask)
trainWindow.close()
window.location.href = window.location.href
}
if (getValue('trainTask') && getValue('trainTask') !== '[]') {
trainTask = getValue('trainTask', true)
for (i = 0; i < trainTask.length; i++) {
tr = tbody.appendChild(cE('tr'))
tr.innerHTML = '<td>' + (order++) + '</td><td>' + select + '</td><td><input type="number" value="' + trainTask[i].freq + '" placeholder="1" min="1"></td><td></td>'
gE('select', tr).value = trainTask[i].id
}
timeChange()
} else {
buttonNew.click()
}
tbody.onclick = changeEvent
tbody.onkeyup = changeEvent
function timeChange () {
_time = gE('tr>td:nth-child(4)', 'all', tbody)
_select = gE('select', 'all', tbody)
_input = gE('input', 'all', tbody)
for (i = 0; i < _select.length; i++) {
_time[i + 1].textContent = _select[i].value === '-1' ? '' : timeStr(_input[i].value * 1 * trainList2[_select[i].value])
}
}
function timeStr (hour) {
var start = time
time = start + hour * 60 * 60 * 1000
return new Date(start).toLocaleString(lang, timeOption) + ' - ' + new Date(time).toLocaleString(lang, timeOption)
}
function changeEvent (e) {
if (e.target.tagName !== 'SELECT' && e.target.tagName !== 'INPUT') return
time = countdownBox.value || new Date().getTime()
timeChange()
}
}, 'T')
post('?s=Character&ss=tr', function (data) {
if (gE('#train_progcnt', data)) {
var nowTraining = gE('#train_progress>div>strong', data).innerText
var nowTrainingProcess = gE('#train_progcnt', data).innerText
var timeAll = trainList[nowTraining].time
timeLast = parseInt(timeAll * (1 - 0.01 * nowTrainingProcess) * 60 * 60)
var timeEnd = new Date(new Date().getTime() + timeLast * 1000)
countdownBox.title = 'Now Train: ' + nowTraining + '\nTrain End: ' + timeEnd.toLocaleString(lang, timeOption)
countdownBox.value = timeEnd.getTime()
timeUpdate()
} else {
if (getValue('trainTask') && getValue('trainTask') !== '[]') {
var trainTask = getValue('trainTask', true)
if (trainTask[0].freq <= 0) trainTask.splice(0, 1)
if (trainTask.length > 0) {
trainTask[0].freq--
post('?s=Character&ss=tr', function () {
window.location.href = window.location.href
}, 'start_train=' + trainTask[0].id)
}
setValue('trainTask', trainTask)
}
countdownBox.innerHTML = 'Train Completed'
document.title = 'Train Completed'
}
})
function timeUpdate () {
var h, m, s
setInterval(function () {
timeLast--
if (timeLast <= 0) {
window.location.href = window.location.href
} else {
s = Math.floor(timeLast % 60)
if (s < 10) s = '0' + s.toString()
m = Math.floor((timeLast / 60) % 60)
if (m < 10) m = '0' + m.toString()
h = Math.floor((timeLast / 3600) % 24)
if (h < 10) h = '0' + h.toString()
countdownBox.innerText = h + ':' + m + ':' + s
}
}, 1000)
setTimeout(function () {
window.location.href = window.location.href
}, 1000 * 60 * 10)
}
})()
function setValue (item, value) {
window.localStorage[item] = (typeof value === 'string') ? value : JSON.stringify(value)
}
function getValue (item, toJSON) {
return (window.localStorage[item]) ? ((toJSON) ? JSON.parse(window.localStorage[item]) : window.localStorage[item]) : null
}
function gE (ele, mode, parent) { // 获取元素
if (typeof ele === 'object') {
return ele
} else if (mode === undefined && parent === undefined) {
return (isNaN(ele * 1)) ? document.querySelector(ele) : document.getElementById(ele)
} else if (mode === 'all') {
return (parent === undefined) ? document.querySelectorAll(ele) : parent.querySelectorAll(ele)
} else if (typeof mode === 'object' && parent === undefined) {
return mode.querySelector(ele)
}
}
function cE (name) { // 创建元素
return document.createElement(name)
}
function post (href, func, parm) { // post
var xhr = new window.XMLHttpRequest()
xhr.open(parm ? 'POST' : 'GET', href)
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8')
xhr.responseType = 'document'
xhr.onerror = function () {
xhr = null
post(href, func, parm)
}
xhr.onload = function (e) {
if (e.target.status >= 200 && e.target.status < 400 && typeof func === 'function') {
var data = e.target.response
if (xhr.responseType === 'document' && gE('#messagebox', data)) {
if (gE('#messagebox')) {
gE('#csp').replaceChild(gE('#messagebox', data), gE('#messagebox'))
} else {
gE('#csp').appendChild(gE('#messagebox', data))
}
}
func(data, e)
}
xhr = null
}
xhr.send(parm)
}