forked from dodying/UserJs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhvSellEquipment.user.js
88 lines (86 loc) · 3.17 KB
/
hvSellEquipment.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
// ==UserScript==
// @name [HV]SellEquipment
// @description
// @include http*://hentaiverse.org/
// @include http*://hentaiverse.org/?s=Character&ss=ch
// @include http://alt.hentaiverse.org/
// @include http://alt.hentaiverse.org/?s=Character&ss=ch
// @version 1.01a
// @grant none
// @author dodying
// @namespace https://github.com/dodying/
// @supportURL https://github.com/dodying//UserJs/issues
// @icon https://cdn.jsdelivr.net/gh/dodying/UserJs@master/Logo.png
// @run-at document-end
// ==/UserScript==
(function () {
/**
* [keepEqps description]
* the Equipment that you DON'T want to sell
* @type {Array}
* Eg. ['Magnificent', 'Legendary', 'Peerless']
* Eg. ['Legendary Arctic Redwood Staff of Destruction']
*/
var keepEqps = ['Superior', 'Exquisite', 'Magnificent', 'Legendary', 'Peerless']
/**
* [func description]
* here put in what you want to do after sell the eqps
* the default is the page reload.
*/
var func = function () {
window.location.href = window.location.href
}
if (!gE('#navbar')) return
var regexp = new RegExp(keepEqps.join('|'))
var soldEqps = window.localStorage.soldEqps || []
var sellEids = []
post('?s=Bazaar&ss=es', function (data) {
post(gE('#mainpane>script[src]', data).src, function (data1) {
var json = JSON.parse(data1.match(/{.*}/)[0])
for (var i in json) {
if (soldEqps.indexOf(i) === -1 && !regexp.test(json[i].t)) sellEids.push(i)
}
if (sellEids.length === 0) return
window.localStorage.soldEqps = soldEqps.concat(sellEids)
post('?s=Bazaar&ss=es', function () {
func()
}, 'storetoken=' + gE('input[name="storetoken"]', data).value + '&select_group=item_pane&select_eids=' + encodeURIComponent(sellEids.join()))
}, null, 'text')
})
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 post (href, func, parm, type) { // 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 = type || 'document'
xhr.onerror = function () {
xhr = null
post(href, func, parm, type)
}
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)
}
})()