// ==UserScript==
// @name Tykinruoka's Missing Discoveries Script
// @namespace http://gm.taistelumarsu.org/
// @description Shows missing recipes
// @include http://www*.kingdomofloathing.com/craft.php?mode=discoveries*
// @include http://kingdomofloathing.com/craft.php?mode=discoveries*
// @include https://www*.kingdomofloathing.com/craft.php?mode=discoveries*
// @include https://kingdomofloathing.com/craft.php?mode=discoveries*
// @author Tykinruoka
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_xmlhttpRequest
// @version 1.0.2
// ==/UserScript==
//
//jQuery-related part
var GM_JQ = document.createElement('script');
GM_JQ.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js';
GM_JQ.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(GM_JQ);
function GM_wait() {
if(typeof unsafeWindow.jQuery == 'undefined') {
window.setTimeout(GM_wait,100);
} else {
$ = unsafeWindow.jQuery; findMehItems(false);
}
}
//end of jQuery
function get(url, cb, mode) {
GM_xmlhttpRequest({
method: "GET",
url: url,
onload: function(xhr) { cb(mode, xhr.responseText, true); }
});
}
//define recipes
var recipes = [];
var totalModeRecipes = 0;
function getRecipes(mode) {
update = false;
if (GM_getValue("kol_nextupdate_" + mode) == undefined) {
update = true;
} else {
var now = new Date();
var nextupdate = new Date();
nextupdate = Date.parse(GM_getValue("kol_nextupdate_" + mode));
if (now > nextupdate) {
update = true;
}
}
if (GM_getValue("kol_" + mode) == undefined) {
update = true;
}
if (update) {
harvestData(mode);
} else {
setData(mode, GM_getValue("kol_" + mode), false);
}
}
function setData(mode, data, saveGM) {
arr = data.split(';');
recipes[mode] = arr;
if (saveGM) {
GM_setValue("kol_" + mode,data);
var upDate=new Date();
upDate.setDate(upDate.getDate()+5);
GM_setValue("kol_nextupdate_" + mode,upDate.toString());
}
}
function harvestData(mode) {
get("http://gm.taistelumarsu.org/get" + mode + ".php", setData, mode);
}
function found(mode,item) {
newarr = [];
for (i = 0; i < recipes[mode].length; i++) {
if (recipes[mode][i].toLowerCase() != item.toLowerCase()) {
newarr[newarr.length] = recipes[mode][i];
}
}
recipes[mode] = newarr;
}
getRecipes("meatpaste");
getRecipes("food");
getRecipes("smith");
getRecipes("booze");
getRecipes("jewelry");
getRecipes("misc");
function findMehItems() {
mode = false;
$("table").each( function() {
if ($(this).attr("id")) {
//only tables with ID's are interesting
if (!mode) {
tableid = $(this).attr("id");
if (tableid.indexOf('table_combine') != -1) {
mode = "meatpaste";
}
if (tableid.indexOf('table_cook') != -1) {
mode = "food";
}
if (tableid.indexOf('table_smith') != -1) {
mode = "smith";
}
if (tableid.indexOf('table_cocktail') != -1) {
mode = "booze";
}
if (tableid.indexOf('table_jewelry') != -1) {
mode = "jewelry";
}
if (tableid.indexOf('table_multi') != -1) {
mode = "misc";
}
}
if (typeof(recipes[mode]) == "undefined") {
setTimeout(findMehItems,100);
return false;
}
if (totalModeRecipes == 0) {
totalModeRecipes = recipes[mode].length;
}
$(this).find("b").each( function() {
item = $(this).html();
found(mode,item);
});
last_table = this;
}
});
if (typeof(recipes[mode]) == "undefined") {
return false;
}
$(last_table).after('