Search your inventory!
目前為
// ==UserScript==
// @name Pete's Eternity Tower Search
// @icon https://www.eternitytower.net/favicon.png
// @namespace http://mean.cloud/
// @version 1.09
// @description Search your inventory!
// @match http*://*.eternitytower.net/*
// @copyright 2017-2018, MeanCloud
// @run-at document-end
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_deleteValue
// ==/UserScript==
function addJQuery(callback)
{
var script = document.createElement("script");
script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js");
script.addEventListener('load', function()
{
var script = document.createElement("script");
script.textContent = "window.jQ=jQuery.noConflict(true);(" + callback.toString() + ")();";
document.body.appendChild(script);
}, false);
document.body.appendChild(script);
}
function startup()
{
document.CookieSet("PETE_AutoCollect", jQ("#PETSItemText").is(":checked"));
document.PETSearch_main();
}
document.PETSearch_CompareTwoWords = function(word1, word2)
{
try
{
if (word1 > word2) return 1;
if (word1 < word2) return -1;
}
catch (err) { }
return 0;
};
document.PETSearch_NeedResort = true;
document.PETSearch_GetMetaWord = function(word, item)
{
try
{
word = word.toString().trim().toLowerCase();
item = item.toString().trim().toLowerCase();
if (word === "fragment") return "magic";
if (word === "shard") return "magic";
if (word === "crystal") return "magic";
if (word === "jade") return "jewel";
if (word === "lazuli") return "jewel";
if (word === "ruby") return "jewel";
if (word === "sapphire") return "jewel";
if (word === "tanzanite") return "jewel";
if (word === "emerald") return "jewel";
if (word === "dagger") return "gear_weapon_phys";
if (word === "rapiers") return "gear_weapon_phys";
if (word === "knife") return "gear_weapon_phys";
if (word === "battleaxe") return "gear_weapon_phys";
if (word === "sword") return "gear_weapon_phys";
if (word === "spear") return "gear_weapon_phys";
if (word === "scimitar") return "gear_weapon_phys";
if (word === "tentacle") return "gear_weapon_phys";
if (item.indexOf("bone kings axe") !== -1) return "gear_weapon_phys";
if (item.indexOf("bisons axe") !== -1) return "gear_weapon_phys";
if (item.indexOf("battle axe") !== -1) return "gear_weapon_phys";
if (word === "shadow") return "gear_weapon_phys";
if (word === "smoke") return "gear_weapon_phys";
if (word === "staff") return "gear_weapon_mag";
if (word === "trident") return "gear_weapon_mag";
if (word === "wand") return "gear_weapon_mag";
if (word === "helmet") return "gear_phys_head";
if (word === "heart") return "gear_phys_chest";
if (word === "chestplate") return "gear_phys_chest";
if (item.indexOf("snake skin") !== -1) return "gear_phys_chest";
if (word === "platelegs") return "gear_phys_leg";
if (word === "shield") return "gear_phys_offhand";
if (item.indexOf("phoenix hat") !== -1) return "gear_mag_head";
if (item.indexOf("druidic hat") !== -1) return "gear_heal_head";
if (item.indexOf("wizard hat") !== -1) return "gear_mag_head";
if (item.indexOf("druidic shirt") !== -1) return "gear_heal_chest";
if (item.indexOf("wizard shirt") !== -1) return "gear_mag_chest";
if (item.indexOf("druidic pants") !== -1) return "gear_heal_leg";
if (item.indexOf("wizard shorts") !== -1) return "gear_mag_leg";
if (item.indexOf("mining") !== -1) return "mining";
if (item.indexOf(" pickaxe") !== -1) return "mining";
if (item.indexOf(" idol") !== -1) return "mining";
if (item.indexOf("pigment") !== -1) return "pigment";
if (item.indexOf("seed") !== -1) return "farm_seed";
if (item.indexOf("lettuce") !== -1) return "food";
if (item.indexOf("lemon") !== -1) return "food"; // includes 'lemonade'
if (item.indexOf("fruit") !== -1) return "food"; // grapefruit, dragonfruit, rockmelon
if (item.indexOf("apple") !== -1) return "food"; // includes 'pineapple'
if (item.indexOf("pear") !== -1) return "food";
if (item.indexOf("melon") !== -1) return "food"; // watermelon
if (item.indexOf("potato") !== -1) return "food"; // includes 'sweet potato'
if (item.indexOf("carrot") !== -1) return "food";
if (item.indexOf("acai") !== -1) return "food";
if (item.indexOf("orange") !== -1) return "food"; // to avoid conflict with wizard gear, this logic comes late
if (item.indexOf("banana") !== -1) return "food";
if (item.indexOf("honey") !== -1) return "food";
if (item.indexOf("rubia") !== -1) return "farm_herb";
if (item.indexOf("basil") !== -1) return "farm_herb";
if (item.indexOf("pink rose") !== -1) return "farm_herb";
if (item.indexOf("endive") !== -1) return "farm_herb";
if (item.indexOf("juniper") !== -1) return "farm_herb";
if (item.indexOf("agrimony") !== -1) return "farm_herb";
if (item.indexOf("chili") !== -1) return "farm_herb";
if (item.indexOf("celery") !== -1) return "farm_herb";
if (item.indexOf("feverfew") !== -1) return "farm_herb";
if (item.indexOf("catnip") !== -1) return "farm_herb";
if (item.indexOf("nasturtium") !== -1) return "farm_herb";
if (item.indexOf("lavender") !== -1) return "farm_herb";
if (item.indexOf("catnip") !== -1) return "farm_herb";
if (item.indexOf("sorrell") !== -1) return "farm_herb";
if (item.indexOf("chives") !== -1) return "farm_herb";
if (item == "marigold") return "farm_money";
if (item == "blue rose") return "farm_money";
if (item == "chrysanthemum ") return "farm_money";
if (item == "hydrangea") return "farm_money";
if (item == "poppy") return "farm_money";
if (item == "zinnia") return "farm_money";
if (item == "bamboo") return "farm_other";
if (item == "kenaf") return "farm_other";
if (item.indexOf("_log") !== -1) return "wood";
if (item.indexOf("tome") !== -1) return "tome";
if (item.indexOf("codex") !== -1) return "tome";
if (item.indexOf(" lv. 1") !== -1) return "tome";
if (item.indexOf(" lv. 2") !== -1) return "tome";
if (item.indexOf(" lv. 3") !== -1) return "tome";
if (item.indexOf(" lv. 4") !== -1) return "tome";
if (item.indexOf(" lv. 5") !== -1) return "tome";
if (word === "affliction") return "tome";
if (word === "lightning_speed") return "tome";
if (item == "stone") return "ore_basic";
if (item == "coal") return "ore_basic";
if (item == "copper") return "ore_raw01";
if (item == "tin") return "ore_raw02";
if (item == "bronze") return "ore_raw03";
if (item == "iron") return "ore_raw04";
if (item == "silver") return "ore_raw05";
if (item == "gold") return "ore_raw06";
if (item == "carbon") return "ore_raw07";
if (item == "steel") return "ore_raw08";
if (item == "platinum") return "ore_raw09";
if (item == "titanium") return "ore_raw10";
if (item == "tungsten") return "ore_raw11";
if (item == "obsidian") return "ore_raw12";
if (item == "cobalt") return "ore_raw13";
if (item == "mithril") return "ore_raw14";
if (item == "adamantium") return "ore_raw15";
if (item == "orichalcum") return "ore_raw16";
if (item == "meteorite") return "ore_raw17";
if (item == "fairy steel") return "ore_raw18";
if (item == "elven steel") return "ore_raw19";
if (item == "copper bar") return "ore_refined01";
if (item == "tin bar") return "ore_refined02";
if (item == "bronze bar") return "ore_refined03";
if (item == "iron bar") return "ore_refined04";
if (item == "silver bar") return "ore_refined05";
if (item == "gold bar") return "ore_refined06";
if (item == "carbon bar") return "ore_refined07";
if (item == "steel bar") return "ore_refined08";
if (item == "platinum bar") return "ore_refined09";
if (item == "titanium bar") return "ore_refined10";
if (item == "tungsten bar") return "ore_refined11";
if (item == "obsidian bar") return "ore_refined12";
if (item == "cobalt bar") return "ore_refined13";
if (item == "mithril bar") return "ore_refined14";
if (item == "adamantium bar") return "ore_refined15";
if (item == "orichalcum bar") return "ore_refined16";
if (item == "meteorite bar") return "ore_refined17";
if (item == "fairy steel bar") return "ore_refined18";
if (item == "elven steel bar") return "ore_refined19";
}
catch (err) { }
return "";
};
document.PETSearch_Resort = function()
{
document.PETSearch_NeedResort = false;
var itemContainer = jQ(jQ("div.item-icon-container").get(0)).parent();
var items = itemContainer.find("div.item-icon-container");
items.sort(function(a,b)
{
var sTextThisItem_a;
var sTextThisItem_b;
try
{
sTextThisItem_a = ""; try { sTextThisItem_a = document.ChopperBlank(a._tippy.popper.innerHTML, "popover-title text-capitalize\">", "</h3>").trim(); } catch (err) { }
sTextThisItem_b = ""; try { sTextThisItem_b = document.ChopperBlank(b._tippy.popper.innerHTML, "popover-title text-capitalize\">", "</h3>").trim(); } catch (err) { }
if (sTextThisItem_a.length === 0) try { sTextThisItem_a = jQ(a).find("img").attr("src").toLowerCase().replace(".svg", "").replace(".png", "").replace("/icons/", ""); } catch (err) { }
if (sTextThisItem_b.length === 0) try { sTextThisItem_a = jQ(b).find("img").attr("src").toLowerCase().replace(".svg", "").replace(".png", "").replace("/icons/", ""); } catch (err) { }
//console.log(a._tippy);
if (sTextThisItem_a.indexOf("(E)") !== -1) sTextThisItem_a = document.ChopperBlank(sTextThisItem_a, "", "(E)").trim();
if (sTextThisItem_b.indexOf("(E)") !== -1) sTextThisItem_b = document.ChopperBlank(sTextThisItem_b, "", "(E)").trim();
//console.log("a: " + sTextThisItem_a);
//console.log("b: " + sTextThisItem_b);
if (sTextThisItem_a.indexOf(" ") !== -1)
{
sLastWord_a = sTextThisItem_a.split(" ").splice(-1).toString().trim().toLowerCase();
sRest_a = document.ChopperBlank(sTextThisItem_a, "", " " + sLastWord_a);
}
else
{
sLastWord_a = sTextThisItem_a.toString().trim().toLowerCase();
sRest_a = "";
}
if (sTextThisItem_b.indexOf(" ") !== -1)
{
sLastWord_b = sTextThisItem_b.split(" ").splice(-1).toString().trim().toLowerCase();
sRest_b = document.ChopperBlank(sTextThisItem_b, "", " " + sLastWord_b);
}
else
{
sLastWord_b = sTextThisItem_b.toString().trim().toLowerCase();
sRest_b = "";
}
if (sLastWord_a === "") sLastWord_a = "zzzzz";
if (sLastWord_b === "") sLastWord_b = "zzzzz";
sQual_a = 0; try { sQual_a = parseInt(document.ChopperBlank(jQ(a).find("div.item-quality").text(), "", "%")); } catch (err) { }
sQual_b = 0; try { sQual_b = parseInt(document.ChopperBlank(jQ(b).find("div.item-quality").text(), "", "%")); } catch (err) { }
// meta words (more grouping!)
sMetaWord_a = document.PETSearch_GetMetaWord(sLastWord_a, sTextThisItem_a);
sMetaWord_b = document.PETSearch_GetMetaWord(sLastWord_b, sTextThisItem_b);
//if ((sLastWord_a === "") || (sLastWord_b === ""))
// console.log("Item '" + sRest_a + "' '" + sLastWord_a + "' ('" + sMetaWord_a + "') vs '" + sRest_b + "' '" + sLastWord_b + "' ('" + sMetaWord_b + "')");
if ((sMetaWord_a !== "") && (sMetaWord_b === "")) return -1;
if ((sMetaWord_a === "") && (sMetaWord_b !== "")) return 1;
if ((sMetaWord_a !== "") && (sMetaWord_b !== ""))
{
ret = document.PETSearch_CompareTwoWords(sMetaWord_a, sMetaWord_b);
if (ret !== 0)
return ret;
if (sMetaWord_a === "pigment") return document.PETSearch_CompareTwoWords(sTextThisItem_a, sTextThisItem_b);
if (sMetaWord_a === "tome") return document.PETSearch_CompareTwoWords(sTextThisItem_a, sTextThisItem_b);
}
ret = document.PETSearch_CompareTwoWords(sLastWord_a, sLastWord_b);
if (ret !== 0)
return ret;
if ((sRest_a !== "") && (sRest_b !== ""))
{
ret = document.PETSearch_CompareTwoWords(sRest_a, sRest_b);
if (ret !== 0)
return ret;
}
// descending order on quality
if ((sQual_a + sQual_b) > 0)
{
if (sQual_a > sQual_b) return -1;
if (sQual_a < sQual_b) return 1;
}
return document.PETSearch_CompareTwoWords(sTextThisItem_a, sTextThisItem_b);
}
catch (err) { console.log("Error: " + err); }
if (sTextThisItem_a === undefined) return 1;
if (sTextThisItem_b === undefined) return -1;
return 0;
});
items.detach().appendTo(itemContainer);
/* items.each(function()
{
console.log(document.ChopperBlank(this._tippy.popper.innerHTML, "popover-title text-capitalize\">", "</h3>").trim());
}); */
document.PETSearch_sort_scheduled = false;
//alert("Sorted!");
};
document.PETSearch_sort_scheduled = false;
document.PETSearch_main = function()
{
if (window.location.href.indexOf("/crafting") !== -1)
{
var oJQ_Options;
try
{
oJQ_Options = jQ("div#PETSOptionsEl").get(0);
if (oJQ_Options === undefined)
{
jQ("div.flex-grow h2:first-of-type").after("<div id=\"PETSOptionsEl\"><small class=\"mx-2\">" +
"Search: <input type=\"text\" id=\"PETSSearchEl\" style=\"width: 200px;\" placeholder=\"search/filter by typing here\" value=\"" + (document.CookieGet("PETSearch_Text") || "") + "\" /> " +
"<label for=\"PETSItemText\">item labels</label> <input type=\"checkbox\" id=\"PETSItemText\"" + ((document.CookieGet("PETSearch_Labels")) ? " CHECKED" : "") + "> " +
"<label for=\"PETSAutoExpand\">auto-expand</label> <input type=\"checkbox\" id=\"PETSAutoExpand\"" + ((document.CookieGet("PETSearch_AutoExpand")) ? " CHECKED" : "") + "> " +
"<input type=\"button\" value=\"Sort\" onClick=\"javascript:document.PETSearch_Resort();\">" +
"</small><br /><br /></div>");
jQ("#PETSSearchEl").focus();
try
{
jQ("#PETSSearchEl").get(0).selectionStart = 10000;
jQ("#PETSSearchEl").get(0).selectionEnd = 10000;
}
catch (errSel) { }
}
else
{
document.CookieSet("PETSearch_Text", jQ("#PETSSearchEl") .val());
document.CookieSet("PETSearch_Labels", jQ("#PETSItemText") .is(":checked"));
document.CookieSet("PETSearch_AutoExpand", jQ("#PETSAutoExpand").is(":checked"));
}
}
catch (err) { console.log(err); }
if ( jQ("#PETSAutoExpand").is(":checked")) jQ("div.show-all-items").click();
if (!jQ("#PETSItemText").is(":checked")) jQ(".PETS_SearchTag").remove();
if (document.PETSearch_sort_scheduled === false)
{
if (jQ("div.item-icon-container").length === 7)
document.PETSearch_NeedResort = true;
if ((jQ("div.item-icon-container").length > 7) && (document.PETSearch_NeedResort))
{
document.PETSearch_sort_scheduled = true;
setTimeout(document.PETSearch_Resort, 500);
}
}
jQ("div.item-icon-container").each(function()
{
try
{
if (jQ(this).attr("data-id").length != 17) return;
var sTextToSearch = jQ("#PETSSearchEl").val().trim().toLowerCase();
var sTextThisItem = jQ(this).find("img").attr("src").toLowerCase().replace(".svg", "").replace(".png", "").replace("/icons/", "");
if (jQ("#PETSItemText").is(":checked"))
{
jQ(this).css("height", "74px");
if (jQ(this).find(".PETS_SearchTag").length === 0)
jQ(this).append("<div class=\"PETS_SearchTag\" style=\"position: absolute; bottom: 10px; right: 3px; font-size: 10px; max-width: 54px; text-overflow: hidden; display: inline-block; white-space: nowrap; overflow: hidden;\">" + sTextThisItem + "</div>");
}
else
jQ(this).css("height", "64px");
while (sTextToSearch.indexOf(" ") !== -1) sTextToSearch = sTextToSearch.replace(" ", "");
while (sTextThisItem.indexOf(" ") !== -1) sTextThisItem = sTextThisItem.replace(" ", "");
if ((sTextToSearch.length > 0) && (sTextThisItem.indexOf(sTextToSearch) === -1))
jQ(this).hide();
else
jQ(this).show();
}
catch (err) { }
});
jQ("div.recipe-container").each(function()
{
try
{
var sTextToSearch = jQ("#PETSSearchEl").val().trim().toLowerCase();
var sTextThisRecipe = jQ(this).find("div div span.text-capitalize").text().trim().toLowerCase();
while (sTextToSearch. indexOf(" ") !== -1) sTextToSearch = sTextToSearch. replace(" ", "");
while (sTextThisRecipe.indexOf(" ") !== -1) sTextThisRecipe = sTextThisRecipe.replace(" ", "");
if ((sTextToSearch.length > 0) && (sTextThisRecipe.indexOf(sTextToSearch) === -1))
jQ(this).hide();
else
jQ(this).show();
}
catch (err) { }
});
}
else
{
jQ("div#PETSOptionsEl").remove();
document.PETSearch_NeedResort = true;
}
setTimeout(document.PETSearch_main, 1000);
};
if (!String.prototype.endsWith) {
String.prototype.endsWith = function(search, this_len) {
if (this_len === undefined || this_len > this.length) {
this_len = this.length;
}
return this.substring(this_len - search.length, this_len) === search;
};
}
document.CookieSet = function(name, value, days = 1000)
{
/*
var expires;
if (days)
{
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toGMTString();
}
else
expires = "";
document.cookie = encodeURIComponent(name) + "=" + encodeURIComponent(value) + expires + "; path=/";
*/
GM_setValue(name, value);
};
document.CookieGet = function(name, defVal = null)
{
try
{
/*
var nameEQ = encodeURIComponent(name) + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++)
{
var c = ca[i];
while (c.charAt(0) === ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) === 0) return decodeURIComponent(c.substring(nameEQ.length, c.length));
}
*/
return GM_getValue(name, defVal);
}
catch (err) { }
return null;
};
document.CookieDelete = function(name)
{
//document.CookieSet(name, "", -1);
GM_deleteValue(name);
};
addJQuery(startup);