-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy path61435.user.js
270 lines (246 loc) · 8.1 KB
/
61435.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
// ==UserScript==
// @name Neopets : Quick SDB Checker
// @namespace http://gm.wesley.eti.br/neopets
// @description Enables Alt+S to quickly check whether the selected text is in SDB and asks to remove it
// @author w35l3y
// @email [email protected]
// @copyright 2013+, w35l3y (http://gm.wesley.eti.br/includes/neopets)
// @license GNU GPL
// @homepage http://gm.wesley.eti.br/includes/neopets
// @version 3.1.1
// @include http://www.neopets.com/*
// @grant GM_log
// @grant GM_addStyle
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_deleteValue
// @grant GM_xmlhttpRequest
// @grant GM_getResourceText
// @icon http://gm.wesley.eti.br/icon.php?desc=61435
// @resource winConfigCss ../../includes/Includes_WinConfig/resources/default.css
// @resource winConfigQuickSDBCheckerCss resources/default.css
// @require ../../includes/Includes_XPath/63808.user.js
// @require ../../includes/Includes_HttpRequest/56489.user.js
// @require ../../includes/Includes_Neopets_Safety_Deposit_Box/56528.user.js
// @require ../../includes/Includes_WinConfig/163374.user.js
// @history 3.1.1 Added missing @icon
// @history 3.1.0 Added Includes Checker (due to the recent problems with userscripts.org)
// @history 3.0.0 Added WinConfig Settings
// @history 2.0.0.0 Updated @require#54987
// @noframes
// ==/UserScript==
/**************************************************************************
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
(function (window) {
'use strict';
/*jslint indent: 4, maxerr: 50, browser: true, vars: true, nomen: true, plusplus: true, regexp: true, newcap: true */
GM_addStyle(GM_getResourceText("winConfigQuickSDBCheckerCss"));
function execute(obj) {
var sel;
if ((sel = window.getSelection()).rangeCount) {
var ai = sel.rangeCount;
while (ai--) {
var range = sel.getRangeAt(ai);
if (range.toString().length) {
var current = new Date().valueOf(),
next = parseInt(GM_getValue("nextAccess", "0"), 10),
time = Math.max(0, next - current),
params = obj.parameters(range) || [];
GM_setValue("nextAccess", String(obj.time() + (time ? next : current)));
params.unshift(obj.callback, time);
window.setTimeout.apply(null, params);
}
}
}
}
WinConfig.init({
title : "Quick SDB Checker : Settings",
type : WinConfig.WindowType.CUSTOM,
size : ["340px", 0],
default : {
executeHotKey : {
keys : 0x1
},
group : {
pin : "",
qnty : 0,
interval : {
min : 500,
rnd : 500
}
}
},
fields : [{
name : "settingsHotKey",
label : "Settings HotKey",
key : "hotkey",
callback : function (event, win) {
win.open();
}
}, {
name : "executeHotKey",
label : "Search HotKey",
key : "hotkey",
callback : function (event, win) {
var config = win.get("group");
execute({
"time" : function () {
return config.interval.min + Math.ceil(config.interval.rnd * Math.random());
},
"callback" : SDB.list,
"parameters" : function (range) {
return [{
"name" : range.toString(),
"onsuccess" : function (params) {
var found = false,
items = [],
dqnty = config.qnty,
dpin,
executeQnty = function (qnty, item) {
var executePin = function (pin) {
window.setTimeout(SDB.remove, 1000 * !!dqnty, {
"pin" : pin,
"name" : item.Name,
"items" : [[item.Id, Math.abs(qnty) || 1]],
"onsuccess" : function (params) {
if (params.error) {
WinConfig.init({
title : "Quick SDB Checker : Error",
type : WinConfig.WindowType.ERROR,
description : "<br />" + ((params.message && params.message.textContent.trim()) || "Unexpected error")
});
} else {
var ai = 0,
at = params.list.length;
while (ai < at) {
var i = params.list[ai++];
if (i.Name === params.item.Name) {
if (i.Quantity >= params.item.Quantity) {
WinConfig.init({
title : "Quick SDB Checker : Error",
type : WinConfig.WindowType.ERROR,
description : "<br />You only have " + i.Quantity + " of that item."
});
}
break;
}
}
}
},
"parameters" : {
"item" : item
}
});
},
tPin = "";
if (!xpath("id('pin_field')", params.response.xml) || (tPin = (config.pin || dpin))) {
executePin(tPin);
} else {
WinConfig.init({
title : "Quick SDB Checker : Pin number",
type : WinConfig.WindowType.PROMPT,
description : "<br />Type in your Pin number:",
load : function (result) {
if (result.text) {
executePin(dpin = result.text);
}
}
});
}
},
ai = 0,
at = params.list.length;
while (ai < at) {
var item = params.list[ai++];
items.push(item.Name);
if (item.Name === params.range.toString()) {
found = true;
if (dqnty) {
executeQnty(dqnty, item);
} else {
WinConfig.init({
title : "Quick SDB Checker : Quantity",
type : WinConfig.WindowType.PROMPT,
description : "<br />How many items do you want to remove?<br />(Max = " + item.Quantity + ")",
default : {
text : 1
},
load : function (result) {
var qnty = parseInt(result.text, 10);
if (qnty) {
executeQnty(qnty, item);
}
}
});
}
break;
}
}
if (!found) {
WinConfig.init({
title : "Quick SDB Checker : Warning",
type : WinConfig.WindowType.WARNING,
description : "<br />" + ((params.message && params.message.textContent.replace(/^\s+|\s+$/g, "")) || "<b>List of items found:</b><br />- " + items.join("<br />- "))
});
}
},
"parameters" : {
"range" : range
}
}];
}
});
}
}, {
name : "group",
type : WinConfig.FieldType.GROUP,
fields : [{
name : "pin",
label : "Pin number",
type : WinConfig.FieldType.PASSWORD,
help : true,
description : "Leave it blank whether you want to be prompted on demand."
}, {
name : "qnty",
label : "Quantity",
format : WinConfig.FieldFormat.NUMBER,
help : true,
description : "Leave it blank whether you want to be prompted on demand."
}]
}, {
name : "group",
nogroup : true,
type : WinConfig.FieldType.GROUP,
fields : [{
name : "interval",
label : "Interval",
type : WinConfig.FieldType.GROUP,
fields : [{
name : "min",
label : "Minimum",
format : WinConfig.FieldFormat.NUMBER,
description : "The minimum value of time between searches.<br /><sup><i>Time in miliseconds</i></sup>",
empty : 0,
help : true
}, {
name : "rnd",
label : "Random",
format : WinConfig.FieldFormat.NUMBER,
description : "The random value of time between searches.<br />This value is multiplied by random value between 0-1 and added to the minimum value.<br /><sup><i>Time in miliseconds</i></sup>",
empty : 0,
help : true
}]
}]
}]
});
}(this));