Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @id hv_shop_filter_plus
- // @name HentaiVerse Shop Filter Plus
- // @version 1.1
- // @namespace
- // @author Razor320 (fix by AnimeAi)
- // @description Provides an easy way to sell and salvage multiple items at one go.
- // @include http://hentaiverse.org/?s=Bazaar&ss=es*
- // @run-at document-end
- // ==/UserScript==
- /*
- - Character level parser
- +/- Equip parser + Params breakdown + Attribute descaler
- + Checkboxes generator
- + Selector API
- + Mass Processor API
- + Batch hide/show/check/uncheck using Selector API
- + Top menu builder
- +/- Seller, salvager and unlocker using Mass Processor API
- + HV Compat text renderer
- */
- /* Settings */
- // Overrides original selection of hentaiverse, allowing to select more than 1 item. Neat, but requires browser with specific support.
- // Examples: Firefox 3.5+, Google Chrome with Tampermonkey (GC itself emulate only stub unsafeWindow - without real content).
- const USE_HOOKS = true;
- /*
- Define set of menu entries. All entries should be defined in next way:
- Array(<display name>, <filter function>[, <input function>]);
- where <filter function> is function, which has one argument (object hvEquipItem with item data) and should return true or false, based on where item should be hidden or not.
- There are also several function generators available to use:
- textFunction(String) - generates filter function that hides items, which title contain specified text
- regexpFunction(RegExp) - generates filter function that hides items, which title matches to specified regular expression
- invRegexpFunction(RegExp) - works similar way to regexpFunction, but hides all items, which title doesn't match to specified reguilar exression
- You can use any generator instead of writing manually specific filter function.
- <input function> is special function which executes when user selects entry in menu. It can perform some additional setup actions, before filter could be applied to list of items. For example, this function used to implement custom text filter in default implementation.
- */
- const MENU_ENTRIES = [
- ["Hide Shade armor", textFunction("Shade")],
- ["Hide Phase armor", textFunction("Phase")],
- ["Hide Power armor", textFunction("Power")],
- ["Hide Plate armor of Deflection", regexpFunction(/Plate.+Deflection/)],
- ["Hide Force Shields", textFunction("Force Shield")],
- ["Hide Magnificient+ items", regexpFunction(/Magnificent|Peerless|Legendary/)],
- ["Show only Battlecaster items", invRegexpFunction(/Battlecaster/)],
- ["Show only...", function(item){return !item.title.contains(storage.getCustomQuery());}, function(){
- var input = prompt("Enter custom text:", storage.getCustomQuery());
- if (input != null){
- if (input.length > 0){
- storage.setCustomQuery(input);
- storage.store();
- return true;
- }
- }
- return false;
- }]
- ];
- /*
- This structure inflated to fill "Selection" menu. Same rules applied as in MENU_ENTRIES structure.
- If you don't need this menu, just comment entire statement.
- Notice, that selection procedure, unlike filtering, is exclusive - this means previous selection would be overwritten.
- */
- const SELECT_MENU_ENTRIES = [
- ["Select all", function(item){return true;}],
- ["Select none", function(item){return false;}],
- ["Invert selection", function(item){return !item.selected}],
- ];
- /* End of settings */
- /* Internal constants */
- const CHECKBOXES_CLASS = "item_checkboxes";
- const IAB_TYPES = [
- "Strength", "Dexterity", "Agility", "Endurance", "Intelligence", "Wisdom",
- "Fire", "Cold", "Holy", "Elec", "Dark", "Wind",
- "Crushing", "Slashing", "Piercing",
- "Supportive", "Deprecating", "Elemental", "Divine", "Forbidden"
- ];
- const EQUIP_TYPES = [
- ["One-handed", "1handed"],
- ["Two-handed", "2handed"],
- ["Staff", "staff"],
- ["Shield", "shield"],
- ["Cloth", "acloth"],
- ["Light", "alight"],
- ["Heavy", "aheavy"]
- ]
- /* Regular expressions used to parse live data */
- const ITEM_SRC_REGEXP = /common\.show_popup_box\((?:.+?,){6}(.+?),(.+?),.+equips.set\((\d+),\s*(.+?)\)/;
- const IAB_REGEXP = /(\w+).+?(\d+(?:\.\d+))/
- const ITEM_TYPE_REGEXP = /(.+?)\s+Level\s+(\d+)\s+(?:(\d+)\s*\/\s*(\d+))?/;
- const ITEM_COST_REGEXP = /shops\.set_selected_item\(.+,\s*(\d+)/;
- const INTEGER_REGEXP = /\d+/;
- const CURRENT_CREDITS_REGEXP = /current_credits\s*=.+?(\d+)/;
- const SALVAGE_REGEXP = /Salvaged\s+(.+)/;
- /* Results of some checks */
- var FULL_UNSAFE = false;
- try{
- //Unfortunately (for Chrome users though xD), Google Chrome doesn't support direct access to page context from chrome.
- //Maybe at some point in future i will write event-driven layer to overcome this injustice.
- var FULL_UNSAFE = "common" in unsafeWindow;
- } catch (e){}
- const USE_MAGIC = USE_HOOKS && FULL_UNSAFE;
- if (!("contains" in String)){
- //Google chrome is missing "contains(text)" function in String object.
- String.prototype.contains = function(text){
- return this.indexOf(text) > -1;
- }
- }
- var items = [];
- var storage = new filterStorage();
- var filterMenuButton = null;
- var AUTO_UPDATE_COST = true;
- var current_credits = parseInt(USE_MAGIC ? unsafeWindow.current_credits:CURRENT_CREDITS_REGEXP.exec(document.body.innerHTML)[1]);
- main();
- /*
- Short reference:
- title: contains full item title, like 'Exquisite Plate Sabatons of Protection'
- id: contains item id (required to perform an action with it)
- key: a hexadecimal string used in HV to generate equipment description links
- (http://hentaiverse.org/pages/showequip.php?eid=<insert id here>&key=<insert key here> and it could be used on forums, for example)
- attributes: an array with item attributes, each attribute has following format:
- name: title of attribute
- value: attribute value
- type: internal attribute type (integer). Compared using IAB_TYPES array
- node: html div, which represents this item in hentaiverse shop interface. Internally used to hide and show item in list
- equipType: type of equipment, as used on server. Internally used to sort out requests, so future client mod with panel, containing all items, could be implemented with lesser work
- potencyLVL: stands for equip potency level. Not used internally, available to use in filter functions.
- potencyCurExp: stands for gained potency experience at current potency level. Also parsed just in case and internally is not used
- potencyNextExp: stands for potency experience required to gain a new level. Parsed just in case, in other script used to calculate number of ItemWorld rounds
- const: item price for selling to the equipment shop
- selected: states for selection state of item. Read all you want, change at your own risk, as there could be invalid selection indication after untidy use.
- hidden: indicates that item was hidden from list. Same precaution as with previous.
- */
- function hvEquipItem(source){
- var data = ITEM_SRC_REGEXP.exec(source.getAttribute("onmouseover"));
- data[1] = sanitize(data[1]); //This is an item title
- data[2] = sanitize(data[2]); //This is popup box data with item description
- data[4] = sanitize(data[4]); //This is an item key required to build link with item description
- this.title = data[1];
- this.id = parseInt(INTEGER_REGEXP.exec(source.id)[0]);
- this.key = data[4];
- this.attributes = [];
- this.node = source;
- // Ask browser's HTML parser for assistance in parsing equipment attributes and other information
- var e = document.createElement("div");
- e.innerHTML = data[2];
- data = e.getElementsByClassName("e9");
- for (var i = 0; i<data.length; i++){
- var m = IAB_REGEXP.exec(data[i].textContent);
- this.attributes.push({name: m[1], value: m[2], type: IABtypeof(m[1])});
- }
- data = ITEM_TYPE_REGEXP.exec(e.getElementsByClassName("e1")[0].textContent);
- console.log(data);
- this.equipType = EQUIPtypeof(data[1]);
- this.potencyLvl = data[2];
- if (data[3] != null){
- this.potencyCurExp = parseInt(data[3]);
- this.potencyNextExp = parseInt(data[4]);
- } else {
- this.potencyCurExp = 0;
- this.potencyNextExp = 0;
- }
- //Try to retrieve item cost
- data = ITEM_COST_REGEXP.exec(source.getAttribute("onclick"));
- if (data != null){
- this.cost = parseInt(data[1]);
- } else {
- this.cost = 0;
- }
- this.selected = false;
- this.hidden = false;
- function IABtypeof(name){
- for (var i = 0; i<IAB_TYPES.length; i++){
- if (name == IAB_TYPES[i]){
- return i;
- }
- }
- return -1;
- }
- function EQUIPtypeof(name){
- for (var i = 0; i<EQUIP_TYPES.length; i++){
- if (name.contains(EQUIP_TYPES[i][0])){
- return EQUIP_TYPES[i][1];
- }
- }
- return "unknown";
- }
- }
- function filterStorage(){
- var flags = localStorage.getItem("HV_ITEM_FILTER_FLAGS");
- var customFilter = localStorage.getItem("HV_ITEM_FILTER_CUSTOM_STRING");
- if (isNaN(flags)) flags = 0;
- this.store = function(){
- localStorage.setItem("HV_ITEM_FILTER_FLAGS", flags);
- localStorage.setItem("HV_ITEM_FILTER_CUSTOM_STRING", customFilter);
- };
- this.setFlag = function(flagPos){
- flags |= (1<<flagPos);
- };
- this.clearFlag = function(flagPos){
- flags &= ~(1<<flagPos);
- };
- this.isEnabled = function(flagPos){
- return (flags & (1<<flagPos)) == (1<<flagPos)
- }
- this.getCustomQuery = function(){
- return customFilter;
- }
- this.setCustomQuery = function(str){
- customFilter = str;
- }
- }
- /* Main */
- function main(){
- //Retrieve all items and store them into an array
- var iblocks = document.getElementById("item_pane").getElementsByClassName("eqdp");
- for (var i = 0; i<iblocks.length; i++){
- items.push(new hvEquipItem(iblocks[i]));
- if (!USE_MAGIC) insertCheckbox(iblocks[i]);
- }
- //Create menu
- generateMenu();
- //Make some magic!
- if (USE_MAGIC){
- mpOverrideSelector();
- }
- //Create new mass sell/salvage interface
- replaceShopSellInterface();
- //Update list
- updateListEntries();
- }
- function mpOverrideSelector(){
- unsafeWindow.common.set_text_selected = function (obj){
- obj = obj.getElementsByClassName("fd2")[0]
- if (obj != null)
- obj = obj.firstChild;
- else
- return;
- if (obj.getAttribute("hvsSelected") == "1"){
- obj.style.color = "";
- obj.setAttribute("hvsSelected", "0");
- } else {
- obj.style.color = "#0030CC";
- obj.setAttribute("hvsSelected", "1");
- }
- }
- const originalFunc = unsafeWindow.shops.set_selected_item;
- unsafeWindow.shops.set_selected_item = function (mode, iid, count, unk, title){
- if (mode == "item_pane"){
- selectorCallback(iid);
- }
- originalFunc.call(unsafeWindow.shops, mode, iid, count, unk, title);
- }
- }
- function generateMenu(){
- const panelWidth = 130;
- if (SELECT_MENU_ENTRIES != undefined){
- if (SELECT_MENU_ENTRIES.length > 0) {
- var plusWidth = 30;
- } else {
- var plusWidth = 0;
- }
- }
- var heads = document.querySelectorAll(".cfb,.cfbs");
- //Calculate width
- var fieldWidth = 0;
- for (var i = 0; i<heads.length; i++) fieldWidth += parseInt(INTEGER_REGEXP.exec(heads[i].style.width)[0]);
- var ratio = (fieldWidth-panelWidth-plusWidth)/fieldWidth;
- //Create new tab's head
- filterMenuButton = heads[(heads[0].className == "cfb" ? 0:1)].cloneNode(true);
- filterMenuButton.children[0].children[0].innerHTML = "Filter";
- filterMenuButton.setAttribute("onclick", null);
- filterMenuButton.style.width = panelWidth + "px";
- for (var i = 0; i<heads.length; i++){
- heads[i].style.width = Math.floor(parseInt(INTEGER_REGEXP.exec(heads[i].style.width)[0])*ratio) + "px";
- }
- heads[0].parentNode.insertBefore(filterMenuButton, heads[0].parentNode.firstElementChild);
- //Generate submenu
- var root = document.createElement("div");
- root.className = "cnbc";
- root.style.borderWidth = "1px";
- var template = document.getElementsByClassName("cnbs")[0].cloneNode(true);
- template.setAttribute("onclick", null);
- for (var i = 0; i<MENU_ENTRIES.length; i++){
- var entry = template.cloneNode(true);
- travelToText(entry).innerHTML = "<input type='checkbox'" + (storage.isEnabled(i) ? " checked":"") + "></input>" + MENU_ENTRIES[i][0];
- entry.setAttribute("entryID", i);
- entry.addEventListener("click", menuEntryClickCallback, false);
- root.appendChild(entry);
- }
- filterMenuButton.parentNode.insertBefore(root, filterMenuButton.nextSibling);
- root.style.top = (filterMenuButton.offsetHeight + filterMenuButton.offsetTop) + "px";
- setupMenu(filterMenuButton, root);
- //Create selection menu if required
- if (plusWidth > 0){
- var plusMenuButton = heads[(heads[0].className == "cfb" ? 0:1)].cloneNode(true);
- plusMenuButton.children[0].children[0].innerHTML = "+"
- plusMenuButton.setAttribute("onclick", null);
- plusMenuButton.style.width = plusWidth + "px";
- filterMenuButton.parentNode.insertBefore(plusMenuButton, filterMenuButton.nextElementSibling);
- root = document.createElement("div");
- root.className = "cnbc";
- root.style.borderWidth = "1px";
- for (var i = 0; i<SELECT_MENU_ENTRIES.length; i++){
- var entry = template.cloneNode(true);
- travelToText(entry).innerHTML = SELECT_MENU_ENTRIES[i][0];
- entry.setAttribute("entryID", i);
- entry.addEventListener("click", selectMenuEntryClickCallback, false);
- root.appendChild(entry);
- }
- plusMenuButton.parentNode.insertBefore(root, plusMenuButton.nextSibling);
- root.style.top = (plusMenuButton.offsetHeight + plusMenuButton.offsetTop) + "px";
- setupMenu(plusMenuButton, root);
- }
- }
- function replaceShopSellInterface(){
- var root = document.getElementById("transaction_pane");
- root.style.textAlign = "left";
- //Hide all unnecessary buttons and fields
- hideChildren(root);
- document.getElementById("sellall_pane").style.display = "none";
- var container = document.createElement("div");
- container.style.marginLeft = "120px";
- container.style.marginTop = "8px";
- var elem = document.createElement("span");
- elem.id = "sell_selected_button";
- elem.innerHTML = mktext("Sell selected", true);
- elem.addEventListener("click", sellSelectedClickCallback, false);
- setupButton(elem);
- container.appendChild(elem);
- elem = document.createElement("span");
- elem.id = "total_cost_field";
- elem.style.display = "inline-block";
- elem.style.paddingLeft = "60px";
- elem.innerHTML = mktext("0 c", true);
- container.appendChild(elem);
- root.appendChild(container);
- container = document.createElement("div");
- container.style.marginLeft = "120px";
- container.style.marginTop = "8px";
- elem = document.createElement("span");
- elem.id = "salvage_selected_button";
- elem.innerHTML = mktext("Salvage selected", true);
- elem.addEventListener("click", salvageSelectedClickCallback, false);
- setupButton(elem);
- container.appendChild(elem);
- root.appendChild(container);
- }
- /* UI listeners */
- function selectorCallback(iid){
- for (var i = 0; i<items.length; i++){
- if (items[i].id == iid){
- items[i].selected = !items[i].selected;
- console.log("Item '" + items[i].title + "' " + (items[i].selected ? "selected":"deselected"));
- if (AUTO_UPDATE_COST) updateButtonsStateAndItemsCost();
- return items[i].selected;
- }
- }
- return false;
- }
- function menuEntryClickCallback(e){
- var eid = parseInt(this.getAttribute("entryID"));
- var passed = true;
- var input = this.querySelector("input");
- if (storage.isEnabled(eid)){
- storage.clearFlag(eid);
- input.checked = false;
- } else {
- //Probe for initialization function
- if (MENU_ENTRIES[eid][2] != undefined){
- passed = MENU_ENTRIES[eid][2].call(this);
- }
- if (passed){
- storage.setFlag(eid);
- input.checked = true;
- }
- }
- if (passed){
- //Update field
- updateListEntries();
- //Store filter values
- storage.store();
- }
- e.preventDefault();
- }
- function selectMenuEntryClickCallback(e){
- var eid = parseInt(this.getAttribute("entryID"));
- var passed = true;
- if (SELECT_MENU_ENTRIES[eid][2] != undefined){
- passed = SELECT_MENU_ENTRIES[eid][2].call(this);
- }
- if (passed){
- //Select and deselect items based on filter function. Selection is exclusive
- var func = SELECT_MENU_ENTRIES[eid][1];
- //Since running cost check every time after selection changes before final selection made is pointless.
- AUTO_UPDATE_COST = false;
- for (var i = 0; i<items.length; i++){
- var state = items[i].selected;
- newstate = func(items[i]);
- if (state != newstate){
- //Switch state by issuing click event to target
- document.getElementById(items[i].id + "item_pane").click();
- }
- }
- AUTO_UPDATE_COST = true;
- updateButtonsStateAndItemsCost();
- }
- }
- function sellSelectedClickCallback(e){
- var list = getSelectedItemsList();
- var totalCreds = 0;
- if (list.length > 0){
- if(confirm("Do you want to sell all selected items to eqiupment shop?")){
- var iter = BazaarUriIterator(list, "/?s=Bazaar&ss=es", "select_mode=item_pane&select_item=$1&select_count=1");
- var pwindow = createProgressWindow();
- pwindow.children[0].innerHTML = "Selling items to shop... [0/" + list.length + "]";
- requestConveyour(iter, function(){
- var pwindow = createProgressWindow();
- var d = document.createElement("div");
- d.innerHTML = "<span style='float:right'>Total: " + totalCreds + "<span>";
- pwindow.children[0].innerHTML = "Sold " + list.length + " items to shop";
- pwindow.children[1].appendChild(d);
- pwindow.children[1].scrollTop = pwindow.children[1].scrollTopMax;
- pwindow.children[2].innerHTML = "Click here to reload current page.";
- pwindow.children[2].addEventListener("click", function(){
- document.location = document.location.href;
- }, false);
- }, function(docroot){
- var creds = parseInt(CURRENT_CREDITS_REGEXP.exec(docroot.body.innerHTML)[1]);
- var diff = creds-current_credits;
- current_credits = creds;
- totalCreds += diff;
- var d = document.createElement("div");
- d.innerHTML = iter.get().title + "<span style='float:right'>" + diff + "</span>";
- var pwindow = createProgressWindow();
- pwindow.children[0].innerHTML = "Selling items to shop... [" + iter.position() + "/" + iter.length() + "]";
- pwindow.children[1].appendChild(d);
- pwindow.children[1].scrollTop = pwindow.children[1].scrollTopMax;
- });
- }
- }
- }
- function salvageSelectedClickCallback(e){
- var list = getSelectedItemsList();
- var materials = [];
- materials.addMaterial = function(mat){
- for (var i = 0; i<this.length; i++){
- if (this[i][0] == mat){
- this[i][1]++;
- return;
- }
- }
- this.push([mat, 1]);
- };
- if (list.length > 0){
- if(confirm("Do you want to salvage all selected items?")){
- var iter = BazaarUriIterator(list, "/?s=Forge&ss=sa", "select_item=$1&select_action=salvage");
- var pwindow = createProgressWindow();
- pwindow.children[0].innerHTML = "Salvaging items... [0/" + list.length + "]";
- requestConveyour(iter, function(){
- var pwindow = createProgressWindow();
- var d = document.createElement("div");
- d.style.fontWeight = "bold";
- d.innerHTML = "Total:";
- pwindow.children[1].appendChild(d);
- for (var i = 0; i<materials.length; i++){
- d = document.createElement("div");
- d.innerHTML = materials[i][0] + "<span style='float:right'>x" + materials[i][1] + "</span>";
- pwindow.children[1].appendChild(d);
- }
- pwindow.children[0].innerHTML = "Salvaged " + list.length + " items";
- pwindow.children[1].scrollTop = pwindow.children[1].scrollTopMax;
- pwindow.children[2].innerHTML = "Click here to reload current page.";
- pwindow.children[2].addEventListener("click", function(){
- document.location = document.location.href;
- }, false);
- }, function(docroot){
- var item = docroot.getElementById("messagebox").getElementsByClassName("cmb6");
- item = SALVAGE_REGEXP.exec(item[item.length-1].textContent);
- if (item != null){
- item = item[1];
- } else {
- item = "Unknown resource";
- }
- materials.addMaterial(item);
- var d = document.createElement("div");
- d.innerHTML = iter.get().title + "<span style='float:right'>" + item + "</span>";
- var pwindow = createProgressWindow();
- pwindow.children[0].innerHTML = "Salvaging items... [" + iter.position() + "/" + iter.length() + "]";
- pwindow.children[1].appendChild(d);
- pwindow.children[1].scrollTop = pwindow.children[1].scrollTopMax;
- });
- }
- }
- }
- /* */
- function insertCheckbox(node){
- var a = document.createElement("input");
- a.type = "checkbox";
- a.className = CHECKBOXES_CLASS;
- a.style = "margin-top: 3px";
- //a.setAttribute("itemID", parseInt(INTEGER_REGEXP.exec(node.id)[0]));
- //a.addEventListener("click", _checkboxClickEventGlue, false);
- node.addEventListener("click", _checkboxClickEventGlue, false);
- node.setAttribute("itemID", parseInt(INTEGER_REGEXP.exec(node.id)[0]));
- node = travelToText(node);
- node.insertBefore(a, node.firstChild);
- }
- function updateListEntries(){
- var activeFilters = 0;
- var hiddenEntries = 0;
- for (var i = 0; i<items.length; i++) items[i].hidden = false;
- for (var i = 0; i<MENU_ENTRIES.length; i++){
- if (storage.isEnabled(i)){
- activeFilters++;
- var func = MENU_ENTRIES[i][1];
- for (var k = 0; k<items.length; k++){
- if (!items[k].hidden) items[k].hidden |= func(items[k]);
- }
- }
- }
- for (var i = 0; i<items.length; i++){
- if (items[i].hidden){
- items[i].node.parentNode.style.display = "none";
- hiddenEntries++;
- } else {
- items[i].node.parentNode.style.display = "";
- }
- }
- travelToText(filterMenuButton).innerHTML = "Filter" + (activeFilters > 0 ? ": <span style='color:red'>" + activeFilters + "</span> active":"");
- travelToText(document.getElementById("leftpane").firstElementChild).innerHTML = "Your inventory" + (hiddenEntries > 0 ? "[<span style='color:blue'>" + hiddenEntries + "</span> item(s) hidden]":"");
- updateButtonsStateAndItemsCost();
- }
- function updateButtonsStateAndItemsCost(){
- var list = getSelectedItemsList();
- var cost = 0;
- for (var i = 0; i<list.length; i++){
- cost += list[i].cost;
- }
- document.getElementById("total_cost_field").innerHTML = mktext(cost + " c", true);
- var ttype = list.length > 0 ? "b":"g";
- swtextstyle(document.getElementById("sell_selected_button"), ttype);
- swtextstyle(document.getElementById("salvage_selected_button"), ttype);
- }
- function requestConveyour(uriIterator, postExecuteCallback, progressCallback){
- const req = new XMLHttpRequest();
- req.addEventListener("load", function(){
- progressCallback(this.responseXML);
- requestConveyour(uriIterator, postExecuteCallback, progressCallback);
- }, false);
- var obj = uriIterator.next();
- if (obj.done){
- postExecuteCallback();
- } else {
- req.open("post", obj.uri, true);
- req.responseType = "document";
- req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
- req.send(obj.post);
- }
- }
- function getSelectedItemsList(){
- var newArr = [];
- for (var i = 0; i<items.length; i++){
- if (!items[i].hidden && items[i].selected){
- newArr.push(items[i]);
- }
- }
- return newArr;
- }
- function createProgressWindow(){
- var rw = document.getElementById("progress_window");
- if (rw == null){
- rw = document.createElement("div");
- rw.className = "btcp";
- rw.innerHTML = "<div class='btc' style='font-weight:bold;margin-top:10px'></div><div class='btc' style='margin-top:10px;padding:4px;overflow-x:hidden;overflow-y:scroll;background-color:rgba(0,0,0,0.08);height:80px'></div><div class='btc' style='margin-top:5px'></div>";
- rw.id = "progress_window";
- rw.style.left = (window.innerWidth-360)/2 + "px";
- rw.style.top = (window.innerHeight-150)/2 + "px";
- document.body.appendChild(rw);
- }
- return rw;
- }
- /* Glue */
- function _checkboxClickEventGlue(){
- //Used when inserting checkboxes as selection method
- this.querySelector("input").checked = selectorCallback(parseInt(this.getAttribute("itemID")));
- }
- /* Miscellanoius functions */
- function sanitize(text){
- text = text.replace(""", "\"");
- if (text.charAt(0) == "'" || text.charAt(0) == "\""){
- text = text.substring(1, text.length-1);
- }
- return text;
- }
- function travelToText(node){
- var a = node.querySelector(".fd2,.fd4");
- while (a.firstElementChild != null && a.firstElementChild == a.firstChild){
- a = a.firstElementChild;
- }
- return a;
- }
- function getOffsetTop(node){
- var acc = node.offsetTop;
- while (node.offsetParent != null){
- node = node.offsetParent;
- acc += node.offsetTop;
- }
- return acc;
- }
- function getOffsetLeft(node){
- var acc = node.offsetLeft;
- while (node.offsetParent != null){
- node = node.offsetParent;
- acc += node.offsetLeft;
- }
- return acc;
- }
- function setupMenu(button, menu){
- var id = "menu" + Math.floor(Math.random()*80000+10000);
- button.id = id + "_button";
- menu.id = id + "_panel";
- button.addEventListener("mouseover", function(){
- document.getElementById(id + "_panel").style.visibility = "visible";
- }, false);
- button.addEventListener("mouseout", function(e){
- if (e.clientY <= (getOffsetTop(this) + this.offsetHeight-5)){
- document.getElementById(id + "_panel").style.visibility = "hidden";
- }
- }, false);
- menu.addEventListener("mouseout", function(e){
- var top = getOffsetTop(this);
- var left = getOffsetLeft(this);
- if (e.clientX <= left || e.clientX >= (left + this.offsetWidth) || e.clientY <= top || e.clientY >= (top + this.offsetHeight)){
- this.style.visibility = "hidden";
- }
- }, false);
- }
- function setupButton(button){
- const reg = /f([24])l[ba]/;
- button.style.cursor = "pointer";
- button.addEventListener("mouseover", function(){
- var t = this.getElementsByTagName("div");
- for (var i = 0; i<t.length; i++){
- t[i].className = t[i].className.replace(reg, "f$1la");
- }
- }, true);
- button.addEventListener("mouseout", function(){
- var t = this.getElementsByTagName("div");
- for (var i = 0; i<t.length; i++){
- t[i].className = t[i].className.replace(reg, "f$1lb");
- }
- }, true);
- }
- function hideChildren(node){
- for (var i = 0; i<node.childNodes.length; i++){
- if (node.childNodes[i].nodeType == 1) node.childNodes[i].style.display = "none";
- }
- }
- function mktext(text, isbig){
- const TYPESET = "0123456789.,!?%+-=/\\'\":;()[]_ ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- isbig = isbig || false;
- isbig = (isbig ? "<div class='f4lb f4":"<div class='f2lb f2");
- text = text.toUpperCase();
- var out = "";
- var ccode = "A".charCodeAt(0);
- for (var i = 0; i<text.length; i++){
- var t = TYPESET.indexOf(text.charAt(i));
- out += isbig + t + "'" + (text.charAt(i+1) == " " ? " style='width:16px'":"") + "></div>";
- }
- return out;
- }
- function swtextstyle(node, target){
- var reg = /f([24])l[bag]/;
- target = "f$1l" + target;
- var t = node.getElementsByTagName("div");
- for (var i = 0; i<t.length; i++){
- t[i].className = t[i].className.replace(reg, target);
- }
- }
- //"/?s=Bazaar&ss=es" shop
- //"/?s=Bazaar&ss=fr" forge
- function BazaarUriIterator(itemList, baseUri, postTemplate){
- var index = 0;
- var obj = null;
- return {
- next: function(){
- if (index<itemList.length){
- obj = { uri: baseUri + "&filter=" + itemList[index].equipType,
- post: postTemplate.replace("$1", itemList[index].id),
- done: false };
- index++;
- return obj;
- } else {
- return {done: true};
- }
- },
- get: function(){
- return itemList[index-1];
- },
- length: function(){
- return itemList.length;
- },
- position: function(){
- return index;
- }
- }
- }
- function textFunction(text){
- return function(item){
- return item.title.contains(text);
- }
- }
- function regexpFunction(regexp){
- return function(item){
- return regexp.test(item.title);
- }
- }
- function invRegexpFunction(regexp){
- return function(item){
- return !regexp.test(item.title);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment