// ==UserScript==
// @name Tykinruoka's Display Case Script
// @namespace http://trashf.taistelumarsu.org
// @description Compares between your inventory and your display case
// @include http://*.kingdomofloathing.com/managecollection.php
// @grant none
// @version 0.1
// ==/UserScript==
/*
Version history:
v0.01 Alpha version
- slow, looped through the display case every time
- browser stopped responding
v0.01 Beta version
- works pretty nice I think :)
- some ideas not yet implemented
v0.01 Initial release
- no longer pops up the question, just prints all kind of stuff without asking any questions
- added checkbox for hiding the information
v0.02
- fixed a bug occuring when case was empty
- fixed a calculations bug
- changed visibility -> display, which is much wiser when the list is long
- automatically inserts next 10 items to boxes
v0.03
- fixed to work with Firefox 4
v0.1
- major optimization by switching to (key in array) instead of for-looping
TODO:
- Check for script updates.
Feel free to develop further.
Questions? Feedback? Want to develop this PoS further? Please, contact Tykinruoka (#875019) a.k.a. TrashF @ QuakeNET, IRCnet & netgamers.
*/
//get all selects with name "whichitem1"
var selects = document.getElementsByName("whichitem1");
//first one of them is user inventory
var invselect = selects[0];
//and the second one is user's display case (if there is no 2nd select, case is empty)
var dispselect = false;
var dispitems = [];
if (selects.length > 1) {
dispselect = selects[1];
}
if (dispselect != false) {
//collect all display case item's item-id's here
for (i = 0; i < dispselect.options.length; i++) {
dispitems[dispselect.options[i].value] = true;
}
}
//then write something to output
var msg = "";
msg += "Unique items in inventory: " + parseInt(invselect.options.length-1) + "
";
if (dispselect != false) {
msg += "Unique items in display case: " + dispselect.options.length + "
";
} else {
msg += "Unique items in display case: 0
";
}
var notfound = 0;
function handleMissing(num) {
addboxes = 1;
if (num > 10) {
num = 10;
}
while (addboxes <= num) {
if (addboxes > 1) {
addDiv = document.getElementById('inv_item' + addboxes);
if (addDiv.wrappedJSObject)
addDiv = addDiv.wrappedJSObject;
addDiv.innerHTML = 'Put: ';
addedSelect = document.getElementsByName('whichitem' + addboxes)[0];
if (addedSelect.wrappedJSObject)
addedSelect = addedSelect.wrappedJSObject;
for (i = 0; i < invselect.options.length; i++) {
newOption = document.createElement('option');
newOption.text = invselect.options[i].text;
newOption.value = invselect.options[i].value;
try {
addedSelect.add(newOption, null);
} catch (ex) {
addedSelect.add(newOption);
}
}
}
addboxes++;
}
notFoundLi = document.getElementsByClassName('tykinruoka-notfound');
for (i = 0; i < notFoundLi.length; i++) {
if (i > 10) break;
howmany = 'howmany' + (parseInt(i)+1);
document.getElementsByName(howmany)[0].value = '1';
whichitem = 'whichitem' + (parseInt(i)+1);
document.getElementsByName(whichitem)[0].value = notFoundLi[i].title;
}
}
for (i = 0; i < invselect.options.length; i++) {
if (invselect.options[i].value != "") {
//looping through user inventory
var found_in_disp = false;
if (invselect.options[i].value > 0 && invselect.options[i].value != "") {
var compare = parseInt(invselect.options[i].value);
found_in_disp = (compare in dispitems);
if (!found_in_disp) {
if (notfound == 0) {
msg += "Items in inventory that aren't in display case (TOTALNUM):