There are 2 previous versions of this script.
// ==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 w35l3y@brasnet.org
// @copyright 2009, w35l3y (http://gm.wesley.eti.br/includes/neopets)
// @license GNU GPL
// @homepage http://gm.wesley.eti.br/includes/neopets
// @version 1.0.0.3
// @include http://www.neopets.com/*
// @require http://userscripts.org/scripts/source/54389.user.js
// @require http://userscripts.org/scripts/source/54987.user.js
// @require http://userscripts.org/scripts/source/56489.user.js
// @require http://userscripts.org/scripts/source/56528.user.js
// ==/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/>.
**************************************************************************/
//-------------------------------//
//GM_setValue("qnty", 1);
//GM_setValue("pin", "0000");
//-------------------------------//
// Queued call
function EventListener(obj)
{
obj.element.addEventListener(obj.event, function(e)
{
var sel;
if (obj.trigger(e) && (sel = window.getSelection()).rangeCount)
{
for ( var ai = sel.rangeCount ; ai-- ; )
{
var range = sel.getRangeAt(ai);
if (range.toString().length)
{
var current = new Date().valueOf();
var next = parseInt(GM_getValue("nextAccess", "0"), 10);
var time = Math.max(0, next - current);
GM_setValue("nextAccess", obj.time() + (time ? next : current) + "");
var params = obj.parameters(range) || [];
params.unshift(obj.function, time);
setTimeout.apply(this, params);
}
}
}
}, false);
}
EventListener({
"element" : window,
"event" : "keyup",
"trigger" : function(e)
{
return e.altKey && e.keyCode == GM_getValue("keyCode", 83); // Alt + S
},
"time" : function(){return 500 + Math.ceil(500 * Math.random());},
"function" : SDB.list,
"parameters" : function(range)
{
return [{
"name" : range.toString(),
"onsuccess" : function(params)
{
var found = false;
var items = [];
var dqnty = GM_getValue("qnty", 0);
var dpin;
for each (var item in params.list)
{
items.push(item.Name);
if (item.Name == params.range.toString())
{
found = true;
var qnty = dqnty || parseInt(prompt("[Quick SDB Checker]\n\nHow many items do you want to remove?", 1), 10);
if (qnty)
{
setTimeout(SDB.remove, 1000 * !!dqnty, {
"pin" : params.response.xml.evaluate("id('pin_field')", params.response.xml, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null) && (GM_getValue("pin", "") || dpin || (dpin = prompt("[Quick SDB Checker]\n\nType in your Pin Number"))) || "",
"name" : item.Name,
"items" : [[item.Id, Math.abs(qnty) || 1]],
"onsuccess" : function(params)
{
if (params.error)
{
alert("[Quick SDB Checker]\n\n" + (params.message && params.message.textContent.replace(/^\s+|\s+$/g, "") || "Unexpected error"));
}
else
{
for each (var i in params.list)
{
if (i.Name == params.item.Name)
{
if (i.Quantity >= params.item.Quantity)
alert("[Quick SDB Checker]\n\nYou only have " + i.Quantity + " of that item");
break;
}
}
}
},
"parameters" : {"item" : item}
});
}
break;
}
}
if (!found)
{
alert("[Quick SDB Checker]\n\n"+(params.message && params.message.textContent.replace(/^\s+|\s+$/g, "") || "List of items found:\n- "+items.join("\n- ")));
}
},
"parameters" : {"range":range}
}];
}
});