MediaWiki:LootStatistics.js

// var current_tibia_version = '8.6'; var lootparser_template1_max_tibia_version = '8.54'; var lootparser_tibia_versions = ['8.4', '8.5', '8.54', '8.6']; var lootparser_tibia_versions_text = ['8.4', '8.5', '8.54 to 8.57', '8.6']; /* Code used for Loot_Statistics */

var ajax_load_bar = new Image; ajax_load_bar.src = "http://images3.wikia.nocookie.net/tibia/en/images/d/de/Ajax_Load_Bar.gif";

function gebi(id) { return document.getElementById(id) || false; } function hebi(id) { gebi(id).style.display = 'none'; } function sebi(id, b) { gebi(id).style.display = (b ? 'block' : 'inline'); } function shebi(id, bt, a, b) { var d = gebi(id).style.display; gebi(id).style.display = (d == 'none' ? 'inline' : 'none'); if (typeof bt != 'undefined') { bt.value = (d == 'none' ? b : a); } } hebi('lootparser_loot'); hebi('lootparser_add');

function trim(str) { str = str.replace(/^\s\s*/, ''); var ws = /\s/, i = str.length; while (ws.test(str.charAt(--i))){} return str.slice(0, i + 1); } function stripslashes(str) { return (str+).replace(/\\(.?)/g, function (s, n1) {   switch (n1) {      case '\\': return '\\';      case : return '';      default: return n1;    }  }); } function is_numeric(v) { v = parseFloat(v); return (typeof v === 'number' && !isNaN(v)); } function ucwords(str) { str = (str+'').replace(/^(.)|\s(.)|-(.)/g, function ($1) { return $1.toUpperCase; }); return str.replace(' Of The ', ' of the ').replace(' Of A ', ' of a ').replace(' Of An ', ' of an ').replace(' Of ', ' of ').replace(' The ', ' the '); } function array_sort(inputArr, numeric, by_key, reverse, sub_key) { var tmp_arr={}, valArr=[], keyArr=[], keys=[], sorter, i, k, populateArr = []; if (typeof numeric == 'undefined') { numeric = false;} if (typeof by_key == 'undefined') { by_key = false;} if (typeof reverse == 'undefined') { reverse = false;} if (typeof sub_key == 'undefined') { sub_key = '';} if (numeric) { sorter = function(a, b) { return (reverse ? b - a : a - b); }; } else { sorter = function(a, b) { var x = a, y = b, tmp; if (!is_numeric(a) && !is_numeric(b)) { tmp = function(a,b){a=a.search(/[a-z]/);b=b.search(/[a-z]/);if((a!==0 && b!==0)||a==b){return 0;}if(a===0){return -1;}if(b===0){return 1;}}(x, y); if (tmp !== 0) { return tmp*(reverse?-1:1); } if (a.search(/a[n]? /i) === 0) { a = a.substr(a.indexOf(" ")+1); } if (b.search(/a[n]? /i) === 0) { b = b.substr(b.indexOf(" ")+1); } if (a == b) { return 0; } if (a > b) { return (reverse ? -1 : 1); } return (reverse ? 1 : -1); }     else { a = parseFloat(a) || 0; b = parseFloat(b) || 0; return (reverse ? b - a : a - b); } }; }  if (by_key) { /*Make a list of key names*/ for (k in inputArr) { if (inputArr.hasOwnProperty(k)) { keys.push(k); } } keys.sort(sorter); /*Rebuild array with sorted key names*/ for (i = 0; i < keys.length; i++) { k = keys[i]; tmp_arr[k] = inputArr[k]; } for (i in tmp_arr) { if (tmp_arr.hasOwnProperty(i)) { populateArr[i] = tmp_arr[i]; } } } else { var bubbleSort = function(keyArr, inputArr, sub_key) { var i, j, tempValue, tempKeyVal, ret; for (i = inputArr.length-2; i >= 0; i--) { for (j = 0; j <= i; j++) { ret = (sub_key == '') ? sorter(inputArr[j+1], inputArr[j]) : sorter(inputArr[j+1][sub_key], inputArr[j][sub_key]); if (ret < 0) { tempValue = inputArr[j]; inputArr[j] = inputArr[j+1]; inputArr[j+1] = tempValue; tempKeyVal = keyArr[j]; keyArr[j] = keyArr[j+1]; keyArr[j+1] = tempKeyVal; }       }      }    }; /*Get key and value*/ for (k in inputArr) { if (inputArr.hasOwnProperty(k)) { valArr.push(inputArr[k]); keyArr.push(k); } } /*Sort our new temporary arrays*/ try { bubbleSort(keyArr, valArr, sub_key); } catch (e) { return false; } /*Repopulate the old array*/ for (i = 0; i < valArr.length; i++) { populateArr[keyArr[i]] = valArr[i]; } } return populateArr; }

var lootparser_s_words = {'*Knife':'Knives', '*Piece of *':'Pieces of ', '*Bunch of *':'Bunches of '};/*Exceptions*/

function lootparser_to_plural(t) { var x; for (x in lootparser_s_words) { if (lootparser_s_words.hasOwnProperty(x)) { if ((new RegExp('^'+x.replace(/\*/g,'.*?')+'$')).test(t)) { return t.replace(x.replace(/\*/g, ''), lootparser_s_words[x]); } } } if (typeof lootparser_s_words[t.substr(1+t.lastIndexOf(' '))] != 'undefined') { return t.substr(0,1+t.lastIndexOf(' ')) + lootparser_s_words[t.substr(1+t.lastIndexOf(' '))]; } var lastletter = t.substr(-1); if (lastletter == 's' || lastletter == 'h' || (lastletter == 'o' && t.match(/.*[^aeiou]o$/i))) { t += 'es'; } else if (lastletter == 'y') { t = t.substr(0, t.length-1)+'ies'; } else { t += 's'; } return t; }

var lootparser_creature_special_names = {'Arkhothep':'Arkhothep (Creature)', 'Armenius':'Armenius (Creature)', 'Avalanche':'Avalanche (Creature)', 'Gamemaster':'Gamemaster (Creature)', 'Hacker':'Hacker (Creature)', 'Pythius the Rotten':'Pythius the Rotten (Creature)', 'Slime':'Slime (Creature)', 'Thief':'Thief (Creature)', 'Yalahari':'Yalahari (Creature)'}; function lootparser_pagename(t, us) { if (typeof us == 'undefined') { us = false; } if (typeof lootparser_creature_special_names[t] != 'undefined') { t = lootparser_creature_special_names[t]; } return (us ? t.replace(/ /g,"_") : t); }

var lootparser_p_words = {'Cookies':'Cookie', '*Pieces of *':'Piece of ', '*Bunches of *':'Bunch of '};/*Exceptions*/ var lootparser_p_ends = {'she':'sh', 'ie':'y', 've':'fe', 'oe':'o', 'ze':'z'};/*Exceptions of endings (after removing the last 's')*/ function lootparser_to_singular(t) { var x; for (x in lootparser_p_words) { if (lootparser_p_words.hasOwnProperty(x)) { if ((new RegExp('^'+x.replace(/\*/g,'.*?')+'$')).test(t)) { return t.replace(x.replace(/\*/g, ''), lootparser_p_words[x]); } } } var lastletter = t.slice(t.length - 1); if (lastletter == "s") { t = t.slice(0, t.length - 1);/*remove the s*/ lastletter = t.slice(t.length - 3);/*check last 3 letters*/ if (typeof lootparser_p_ends[lastletter] != 'undefined') { t = t.slice(0, t.length - 3) + lootparser_p_ends[lastletter]; } lastletter = t.slice(t.length - 2);/*check last 2 letters*/ if (typeof lootparser_p_ends[lastletter] != 'undefined') { t = t.slice(0, t.length - 2) + lootparser_p_ends[lastletter]; } } return t; }

/* a is item name in singular, b is item max count */ function lootparser_wiki_links(a, b) { a = stripslashes(a); if (a == 'Empty') { return 'Empty'; } if (b < 2) { return +a+; } var ap = lootparser_to_plural(a); if (ap.substr(0, a.length) == a) { return +a++ap.substr(a.length); } else { return +ap+; } }

function lootparser_array_to_wiki2(inp) { var r, x, tmp; /*Sort*/ inp = array_sort(inp, false, true); tmp = {'version':inp.version,'kills':inp.kills,'name':inp.name}; /*Excluding named parameters from sort*/ delete inp.version; delete inp.kills; delete inp.name; if (typeof inp.Empty != 'undefined') { tmp.Empty = inp.Empty; delete inp.Empty; } /*Making 'Empty' the first one*/ //inp = array_sort(inp, false, true); inp = array_sort(inp, true, false, true, 'times'); for (x in inp) { if (inp.hasOwnProperty(x)) { tmp[x] = inp[x]; } } inp = tmp;

r = '{'+'{Loot2\r\n|version='+inp.version+'\r\n|kills='+inp.kills+'\r\n|name='+inp.name+'\r\n'; for (x in inp) { if (inp.hasOwnProperty(x)) { if (typeof inp[x] == 'object') { r += '|'; //r += lootparser_wiki_links(x, inp[x].max); //Using singular and no links for now: r += x+   ', times:'+inp[x].times+ (inp[x].min > 0 ? (', amount:'+(inp[x].min == inp[x].max ? inp[x].min : inp[x].min+'-'+inp[x].max)+) : )+ (inp[x].total > 0 ? ', total:'+inp[x].total : '')+'\r\n'; } } } r += '}'+'}\r\n'; return r; }

function lootparser_array_to_wiki1(inp) { var r, x, tmp, av_gold = 0; /*Sort*/ inp = array_sort(inp, false, true); tmp = {'version':inp.version,'kills':inp.kills,'name':inp.name}; /*Excluding named parameters from sort*/ delete inp.version; delete inp.kills; delete inp.name; if (typeof inp.Empty != 'undefined') { tmp.Empty = inp.Empty; delete inp.Empty; } /*Making 'Empty' the first one*/ //inp = array_sort(inp, false, true); inp = array_sort(inp, true, false, true, 'total'); for (x in inp) { if (inp.hasOwnProperty(x)) { tmp[x] = inp[x]; } } inp = tmp;

r = '{'+'{Loot\r\n|version='+inp.version+'\r\n|kills='+inp.kills+'\r\n|name='+inp.name+'\r\n'; for (x in inp) { if (inp.hasOwnProperty(x)) { if (typeof inp[x] == 'object') { if (x.substr(0, 9) == 'Gold Coin') { av_gold = Math.round((inp[x].total/inp.kills)*100)/100; } r += '|'+ lootparser_wiki_links(x, 1)+ ', '+   inp[x].total+ '\r\n'; } } } r += '}'+'}\r\n'+ ' Average gold: '+av_gold; return r; }

var newdiv; function lootparser_loot_process { /*execution time counter */ var starttime = new Date; starttime = starttime.getTime;

/*Cleaning DOM*/ var rdel, i = 0, results = gebi('lootparser_loot_results'); while ((rdel = gebi('lootparser_loot_results'+i))) { results.removeChild(rdel); i++; } results.innerHTML = ""; gebi('lootparser_loot_totallines').innerHTML = ""; gebi('lootparser_loot_totaltime').innerHTML = ""; /* monsters[x] = y x = monster name y = amount of x killed */ /* loot_exp[x][y] = z x = monster name y = item name z = item count Holds all items seperate */ /* loot_tem[x][y][prop] = z x = monster name y = item name prop = min, max, total, times z = prop value Holds items statistics for template*/ var monsters = {}, loot_exp = {}, loot_tem = {}, loot_tmp = {};/*temp loot info for template*/

/*lets analyse the data*/ var lootparser_use_version = gebi('lootparser_use_version').value; var use_loot2 = (lootparser_use_version > lootparser_template1_max_tibia_version); var data = trim(gebi('lootparser_loot_log').value).split("\n"); var totallines = data.length; gebi('lootparser_loot_totallines').innerHTML = "Analysing "+totallines+" lines...";

var x, line, loot, monster; var y, itemlooted, amount; for (x in data) { if (data.hasOwnProperty(x)) { line = data[x].indexOf("Loot of"); if (line === -1) { continue; } line = data[x].substr(line + 8); loot = trim(line.substr(line.indexOf(":") + 1)); monster = trim(line.slice(0, line.indexOf(":"))); if (typeof monsters[monster] == 'undefined') { monsters[monster] = 0; loot_tem[monster] = {}; loot_exp[monster] = {}; } monsters[monster]++;

loot_tmp = {}; loot = loot.split(","); for (y in loot) { if (loot.hasOwnProperty(y)) { itemlooted = ucwords(trim(loot[y])); /*the name of the looted item, capitalised*/ /*loot_exp*/ if (typeof loot_exp[monster][itemlooted] == 'undefined') { loot_exp[monster][itemlooted] = 0; } loot_exp[monster][itemlooted]++; /*loot_tem*/ amount = parseInt(itemlooted.match(/^a[n]? /i) ? 1 : (itemlooted.match(/^\d+ /i) ? itemlooted.match(/^\d+ /i) : 0), 10); itemlooted = itemlooted.substr((amount > 0) ? itemlooted.indexOf(' ') + 1 : 0); itemlooted = (amount > 1) ? lootparser_to_singular(itemlooted) : itemlooted; if (!use_loot2) { if (amount === 0) { amount = 1; } if (itemlooted == 'Nothing') { itemlooted = 'Empty'; } }     if (typeof loot_tmp[itemlooted] == 'undefined') { loot_tmp[itemlooted] = 0; } loot_tmp[itemlooted] += amount; } }   for (y in loot_tmp) { if (loot_tmp.hasOwnProperty(y)) {/*loot_tem*/ if (use_loot2) { if (y == 'Nothing') { y = 'Empty'; } } if (typeof loot_tem[monster][y] == 'undefined') { loot_tem[monster][y] = {}; } if (typeof loot_tem[monster][y].total == 'undefined') { loot_tem[monster][y].total = 0; } loot_tem[monster][y].total += loot_tmp[y]; if (use_loot2) { if (typeof loot_tem[monster][y].times == 'undefined') { loot_tem[monster][y].times = 0; } loot_tem[monster][y].times++; if (typeof loot_tem[monster][y].min == 'undefined' || loot_tmp[y] < loot_tem[monster][y].min) { loot_tem[monster][y].min = loot_tmp[y]; }       if (typeof loot_tem[monster][y].max == 'undefined' || loot_tmp[y] > loot_tem[monster][y].max) { loot_tem[monster][y].max = loot_tmp[y]; }     }    } }  } }

var id_inc = 0; /*Sort*/ monsters = array_sort(monsters, false, true); for (x in loot_exp) { if (loot_exp.hasOwnProperty(x)) { loot_exp[x] = array_sort(loot_exp[x], false, true); } }

var killed = false; for (x in loot_tem) { if (loot_tem.hasOwnProperty(x)) { killed = true; break; } } if (!killed) { results.innerHTML = "No monsters killed!"; } else { newdiv = document.createElement('div'); newdiv.setAttribute('id', 'lootparser_loot_results'+id_inc); newdiv.style.position = 'relative'; id_inc++; var in_tmp = ''; i = 0; for (x in monsters) { if (monsters.hasOwnProperty(x)) {/*Contents*/ if ((i / 15) == Math.floor(i / 15)) { if (i !== 0) { in_tmp += ' '; } in_tmp += '

";   in_tmp = '

';     newdiv.innerHTML = out_exp + out_tem; results.appendChild(newdiv); id_inc++; } } } /*execution time counter */ var endtime = new Date; endtime = endtime.getTime; var totaltime = Math.round((endtime - starttime)*1000); gebi('lootparser_loot_totaltime').innerHTML = "Calculation made in "+(totaltime/1000000)+" seconds"; }

/* Returns [, , ] textold can be an input from a wiki textarea textnew should be generated by lootparser_loot_process Gives alert and returns false on failure*/ function lootparser_add(textold, textnew, wysiwygtag) { var errors = ['Wrong data in New Statistics', 'Wrong data in Old Statistics', 'Names of creatures doesn\'t match', 'names/kills/version is missing'];

if (typeof wysiwygtag == 'undefined') { wysiwygtag = true; } var textoldo = textold; /*original old text*/ textnew = textnew.slice(textnew.search('{'+'{'), textnew.search('}'+'}')+2);/*Take only the Template part*/ use_loot2 = (textnew.match(/\{\{Loot[2]{0,1}/).join('').indexOf('2') >= 0); /*Determine version of loot data on "new"*/ textnew = textnew.slice(textnew.search(/\|/)+1, textnew.search('}'));/*Take only the parameters*/ var textnewa = textnew.split(/[\s]{1,2}\|/);/*make it an array*/ var textoldao = {}, textnewao = {}, x, tmp; for (x in textnewa) { if (textnewa.hasOwnProperty(x)) {/*parse values into an associative array*/ if (textnewa[x].search('=') != -1) { tmp = textnewa[x].split('='); tmp[0] = trim(tmp[0]); if (tmp[0] == 'version') { textnewao.version = trim(tmp[1]); } else if (tmp[0] == 'kills') { textnewao.kills = parseInt(trim(tmp[1]), 10); } else if (tmp[0] == 'name') { textnewao.name = ucwords(trim(tmp[1])); } continue; }   else if (textnewa[x].search(',') == -1) { alert(errors[0]+'(1)'); return false; }

textnewa[x] = trim((textnewa[x].substr(0,1) == '|') ? textnewa[x].substr(1) : textnewa[x]);

tmp = (use_loot2 ?         textnewa[x].match(/(.*?), ?(?:times:(\d*),? ?)(?:amount:(\d*)-?(\d*))?,? ?(?:total:(\d*))?/) :         textnewa[x].match(/(.*?), ?(?:(\d*))?/)    ); if (tmp === null || typeof tmp[1] == 'undefined' || typeof tmp[2] == 'undefined' || tmp[1] ==  || tmp[2] == ) { alert(errors[0]+'(2)'); return false; } tmp[1] = tmp[1].split('[').join().split(']',1).join().split('|',1).join(''); tmp[2] = parseInt(tmp[2], 10); textnewao[tmp[1]] = {}; if (use_loot2) { tmp[3] = (typeof tmp[3] == 'undefined' || tmp[3] == '') ? 0 : parseInt(tmp[3], 10); tmp[4] = (typeof tmp[4] == 'undefined' || tmp[4] == '') ? tmp[3] : parseInt(tmp[4], 10); tmp[5] = (typeof tmp[5] == 'undefined' || tmp[5] == '') ? 0 : parseInt(tmp[5], 10); textnewao[tmp[1]].times = tmp[2]; textnewao[tmp[1]].min = tmp[3]; textnewao[tmp[1]].max = tmp[4]; }   textnewao[tmp[1]].total = (use_loot2 ? tmp[5] : tmp[2]); } } /*Looking for matching version number on textold & textnew*/ var matches, matches_len = 0, vo, vn, textold_match = false; matches = (use_loot2 ?            textold.match(/\{\{Loot2\s*?\|[\s]{0,1}version=[\s\S]*?[\s]{0,3}?\|[\s\S]*?\}\}(?:[\s\S]{0,20}Average [\[]{0,2}gold[\]]{0,2}:[\s]{0,3}[\d\.]*[\s]?[\w]{0,6}|[\s\S]*?)/gi) :            textold.match(/\{\{Loot\s*?\|[\s]{0,1}version=[\s\S]*?[\s]{0,3}?\|[\s\S]*?\}\}(?:[\s\S]{0,20}Average [\[]{0,2}gold[\]]{0,2}:[\s]{0,3}[\d\.]*[\s]?[\w]{0,6}|[\s\S]*?)/gi)  ); for (x in matches) { if (matches.hasOwnProperty(x)) { matches_len++; } } if (typeof textnewao.version != 'undefined' && matches_len > 0) { for (x in matches) { if (matches.hasOwnProperty(x)) { vo = matches[x].match(/[\s\S]*version=([\s\S]*?)[\s]{0,3}?\|[\s\S]*/i)[1]; vn = textnew.match(/[\s\S]*version=([\s\S]*?)[\s]{0,3}?\|[\s\S]*/i)[1]; if (vo == vn) { textold_match = matches[x]; break; }   } }  }  if (textold_match === false) { textoldao = textnewao; }/*will insert the new loot at beginning of page*/ else { /*will add the new loot to an existing one*/ textold = textold_match; textold = textold.slice(textold.search('{'+'{'), textold.search('}'+'}')+2);/*Take only the Template part*/ textold = textold.slice(textold.search(/\|/)+1, textold.search('}'));/*Take only the parameters*/ var textolda = textold.split(/[\s]{1,2}\|/); var xmax = textolda.length; for (x = 0;x < xmax; x++) { if (textolda[x].search('=') != -1) { tmp = textolda[x].split('='); tmp[0] = trim(tmp[0]); if (tmp[0] == 'version') { textolda.version = trim(tmp[1]); } else if (tmp[0] == 'kills') { textoldao.kills = parseInt(trim(tmp[1]), 10); } else if (tmp[0] == 'name') { textoldao.name = ucwords(trim(tmp[1])); if (textnewao.name != textoldao.name) { alert(errors[2]+'(1)'); return false; } }       continue; }     else if (textolda[x].search(',') == -1) { alert(errors[1]+'(1)'); return false; }

textolda[x] = trim((textolda[x].substr(0,1) == '|') ? textolda[x].substr(1) : textolda[x]); tmp = (use_loot2 ?           textolda[x].match(/(.*?), ?times:(\d*),? ?(?:amount:(\d*)-?(\d*))?,? ?(?:total:(\d*))?/) :           textolda[x].match(/(.*?), ?(?:(\d*))?/)      ); if (tmp === null || typeof tmp[1] == 'undefined' || typeof tmp[2] == 'undefined' || tmp[1] ==  || tmp[2] == ) { alert(errors[1]+'(2)'); return false; } tmp[1] = tmp[1].split('[').join().split(']',1).join().split('|',1).join(''); tmp[2] = parseInt(tmp[2], 10); textoldao[tmp[1]] = {}; if (use_loot2) { tmp[3] = (typeof tmp[3] == 'undefined' || tmp[3] == '') ? 0 : parseInt(tmp[3], 10); tmp[4] = (typeof tmp[4] == 'undefined' || tmp[4] == '') ? tmp[3] : parseInt(tmp[4], 10); tmp[5] = (typeof tmp[5] == 'undefined' || tmp[5] == '') ? 0 : parseInt(tmp[5], 10); textoldao[tmp[1]].times = tmp[2]; textoldao[tmp[1]].min = tmp[3]; textoldao[tmp[1]].max = tmp[4]; }     textoldao[tmp[1]].total = (use_loot2 ? tmp[5] : tmp[2]); }   for (x in textnewao) { if (textnewao.hasOwnProperty(x)) {/*Sum both loots*/ if (typeof textoldao[x] == 'undefined') { textoldao[x] = textnewao[x]; } else if (x == 'kills') { textoldao[x] += textnewao[x]; } else if (x != 'version' && x != 'name') { if (use_loot2) { textoldao[x].min = (textoldao[x].min === 0) ? 0 : Math.min(textoldao[x].min, textnewao[x].min); textoldao[x].max = (textoldao[x].max === 0) ? 0 : Math.max(textoldao[x].max, textnewao[x].max); textoldao[x].times = textoldao[x].times + textnewao[x].times; }       textoldao[x].total = textoldao[x].total + textnewao[x].total; }   } }

} /*Generating wiki markup*/ if (!('name' in textoldao) || !('kills' in textoldao) || !('version' in textoldao)) { alert(errors[3]+'(2)'); return false; } var out = (use_loot2 ? lootparser_array_to_wiki2(textoldao) : lootparser_array_to_wiki1(textoldao)); var res = (!textold_match ? out+'\r\n\r\n\r\n'+textoldo : textoldo.replace(textold_match, out+'\r\n\r\n\r\n')); res = (wysiwygtag ? '__NOWYSIWYG__\r\n\r\n' : ) + res.replace(/__NOWYSIWYG__/g, ); while (res.search('\r\n\n') != -1) { res = res.replace('\r\n\n', '\r\n\r\n'); } while (res.search('__NOWYSIWYG__\r\n\r\n\r\n') != -1) { res = res.replace('__NOWYSIWYG__\r\n\r\n\r\n', '__NOWYSIWYG__\r\n\r\n'); } while (res.search('\r\n\r\n\r\n\r\n') != -1) { res = res.replace('\r\n\r\n\r\n\r\n', '\r\n\r\n\r\n'); } while (res.search('\r\r\r') != -1) { res = res.replace('\r\r\r', '\r\r'); } while (res.search('\n\n\n') != -1) { res = res.replace('\n\n\n', '\n\n'); } while (res.search('&a'+'mp;') != -1) { res = res.replace('&a'+'mp;', '&'); } while (res.search('&l'+'t;') != -1) { res = res.replace('&l'+'t;', '<'); } while (res.search('&g'+'t;') != -1) { res = res.replace('&g'+'t;', '>'); } while (res.search('') != -1) { res = res.replace('', ''); } return [res, textnewao.kills, textnewao.version]; }

function set_opacity(id, op) { if ((id = gebi(id))) { id.style.opacity = op / 100; id.style.filter = 'alpha(opacity='+op+')'; } }

function upload_to_wikia_end(id, msg, duration) { if (typeof duration == 'undefined') { duration = 4; } var i, timer = 0; for (i=80; i>=1; i--) { setTimeout("set_opacity('"+id+"',"+i+")", timer * duration); timer++; } setTimeout("hebi('"+id+"')", (timer * duration)+10); if (typeof msg != 'undefined') { setTimeout("alert('"+msg+"')", (timer * duration)+20); } }

function upload_to_wikia(div_id) { gebi('lootparser_loot_combined_b'+div_id).disabled = true; hebi('lootparser_loot_combined_b'+div_id); hebi('lootparser_loot_combined_t'+div_id); var divtodo = gebi('lootparser_loot_combined'+div_id); /*Function to add data to each monster page*/ var lootparser_ajax_add = function (newtext, monster, wpp) { var lootparser_loot_t; if (typeof (lootparser_loot_t = getXmlHttpRequestObject) == 'boolean') { return; } lootparser_loot_t.onreadystatechange = function { if (lootparser_loot_t.readyState != 4) { return; } upload_to_wikia_end('lootparser_loot_block'+div_id, (lootparser_loot_t.status == 200) ?        'You added current loot view to the statistics page for '+monster.replace(/_/g,' ') :         'Problems found while uploading loot, you may need to check the loot statistics page for '+monster.replace(/_/g,' ')      );/*fade out*/ var i = 1, x;     while ((x = gebi('lootparser_loot_combined_b'+i))) { if (x.value == 'Upload') { x.disabled = false; } i++; } };   var bound2 = '--u9NhcWCckcbMykvMxYdPSR'; var bound = '--'+bound2; var params = '\r\n'+ bound+'\r\n'+'Content-Disposition: form-data; name="wpCategorySelectWikitext"\r\n\r\n'+'[]'+'\r\n'+ bound+'\r\n'+'Content-Disposition: form-data; name="wpCategorySelectSourceType"\r\n\r\n'+'json'+'\r\n'+ bound+'\r\n'+'Content-Disposition: form-data; name="wpLogin"\r\n\r\n'+'\r\n'+ bound+'\r\n'+'Content-Disposition: form-data; name="wpSection"\r\n\r\n'+'\r\n'+ bound+'\r\n'+'Content-Disposition: form-data; name="wpStarttime"\r\n\r\n'+wpp.wpStarttime+'\r\n'+ bound+'\r\n'+'Content-Disposition: form-data; name="wpEdittime"\r\n\r\n'+wpp.wpEdittime+'\r\n'+ bound+'\r\n'+'Content-Disposition: form-data; name="wpScrolltop"\r\n\r\n'+'0'+'\r\n'+ bound+'\r\n'+'Content-Disposition: form-data; name="wpAutoSummary"\r\n\r\n'+wpp.wpAutoSummary+'\r\n'+ bound+'\r\n'+'Content-Disposition: form-data; name="wpTextbox1"\r\n\r\n'+newtext+'\r\n'+ bound+'\r\n'+'Content-Disposition: form-data; name="csWikitext"\r\n\r\n'+'\r\n'+ bound+'\r\n'+'Content-Disposition: form-data; name="wpSummary"\r\n\r\n'+wpp.wpSummary+'\r\n'+ bound+'\r\n'+'Content-Disposition: form-data; name="wpMinoredit"\r\n\r\n'+'1'+'\r\n'+ bound+'\r\n'+'Content-Disposition: form-data; name="wpSave"\r\n\r\n'+'Save page'+'\r\n'+ bound+'\r\n'+'Content-Disposition: form-data; name="wpEditToken"\r\n\r\n'+wpp.wpEditToken+'\r\n'+ bound+'\r\n'+'Content-Disposition: form-data; name="antispam"\r\n\r\n'+wpp.antispam+'\r\n'+ bound+'--'; lootparser_loot_t.open("POST", '/index.php?title=Loot_Statistics:'+lootparser_pagename(monster, true)+'&action=submit'); lootparser_loot_t.setRequestHeader("Content-length", params.length); lootparser_loot_t.setRequestHeader("Content-Type", 'multipart/form-data; boundary='+bound2); lootparser_loot_t.send(params); };

/*Function to check data to be added to each monster page*/ var lootparser_ajax_addcheck = function(newtext, monster, div_id) { var lootparser_loot_t; if (typeof (lootparser_loot_t = getXmlHttpRequestObject) == 'boolean') { return; }

var x, i = 1, timer = 0, b_id = 'lootparser_loot_block'+div_id; /*Disabling buttons, overlay div*/ while ((x = gebi('lootparser_loot_combined_b'+i))) { x.disabled = true; i++; } newdiv = document.createElement('div'); newdiv.setAttribute('id', b_id); newdiv.style.display = 'none'; newdiv.style.position = 'absolute'; newdiv.style.top = '0px'; newdiv.style.left = '0px'; newdiv.style.width = '100%'; newdiv.style.height = '100%'; newdiv.style.backgroundColor = '#666666'; newdiv.style.textAlign = 'center'; newdiv.innerHTML = 'Uploading

 ';   gebi('lootparser_loot_results'+div_id).appendChild(newdiv); set_opacity(b_id, 0); sebi(b_id, true);/*fade in*/ for (i=1; i<=80; i++) { setTimeout("set_opacity('"+b_id+"',"+i+")", timer * 5); timer++; }

lootparser_loot_t.onreadystatechange = function { if (lootparser_loot_t.readyState != 4) { return; } var text, i, x;     var oldtext = (text = lootparser_loot_t.responseText); if ((oldtext = oldtext.match(/([\s\S]*?)<\/textarea>/i)) === null) { alert('There was a problem trying to get current statistics for '+monster); upload_to_wikia_end('lootparser_loot_block'+div_id);/*fade out*/ i = 1; while ((x = gebi('lootparser_loot_combined_b'+i))) { if (x.value == 'Upload') { x.disabled = false; } i++; } return false; }     oldtext = trim(oldtext[1]);/*oldtext = wikia textarea contents*/ newtext = newtext.slice(newtext.search('{'+'{'), newtext.search('}'+'}')+2);/*Take only the Template part*/ if ((newtext = lootparser_add(oldtext, newtext)) === false) { upload_to_wikia_end('lootparser_loot_block'+div_id);/*fade out*/ i = 1; while ((x = gebi('lootparser_loot_combined_b'+i))) { if (x.value == 'Upload') { x.disabled = false; } i++; } return; }     var matches, wpp = {'wpStarttime':, 'wpEdittime':, 'wpAutoSummary':, 'wpEditToken':, 'antispam':''}; for (x in wpp) {/*Extra data for wikia edits*/ if (wpp.hasOwnProperty(x)) { matches = text.match(new RegExp(']*name=["\']'+x+'["\'][^>]*)>', 'i')); wpp[x] = matches[1].match(/value=["']([\s\S]*?)["']/i)[1] || ''; }     }      wpp.wpSummary = newtext[1]+' kills added with tibia wikia loot parser ('+newtext[2]+')'; lootparser_ajax_add(newtext[0], monster, wpp); };   lootparser_loot_t.open('GET', '/index.php?title=Loot_Statistics:'+lootparser_pagename(monster, true)+'&action=edit'); lootparser_loot_t.send(null); }; var mdata, wdata; wdata = divtodo.value; if ((mdata = wdata.match(/\{\{[\s\S]*?name=([\s\S]*?)\|[\s\S]*?\}\}/i)) === null) { alert('There was a problem trying to get statistics from page(2)'); return; } mdata = ucwords(trim(mdata[1])).replace(/ /g,"_"); lootparser_ajax_addcheck(wdata, mdata, div_id); }

function lootparser_add_process { /* start execution time counter */ var starttime = new Date; starttime = starttime.getTime; /* end execution time counter */ var tmp = lootparser_add(gebi('lootparser_add_log1').value, gebi('lootparser_add_log2').value)[0]; gebi('lootparser_add_results').value = (!tmp ? '' : tmp); /* start execution time counter */ var endtime = new Date; endtime = endtime.getTime; var totaltime = Math.round((endtime - starttime)*1000); gebi('lootparser_add_totaltime').innerHTML = "Calculation made in "+(totaltime/1000000)+" seconds"; /* end execution time counter */ }

function lootparser_add_init { var tmp; newdiv = document.createElement('div'); newdiv.setAttribute('id', 'lootparser_add_main1'); newdiv.setAttribute('style', 'display: none;'); newdiv.innerHTML = ' Loot Merger '+ 'This one is provided in case you need to merge/sort some statistics. '+ 'To merge statistics, copy the "old" statistics in the left box, then copy the ones that need to be added to it into the right one. '+ 'To sort statistics, just left "old" statistics blank and paste the statistics to sort on the right. '+ 'Note that only 1 statistics table will be processed on "New statistics" field. '+ '

'+ ' '+  ' '+  ' '+ ''; gebi('lootparser_add').appendChild(newdiv);

newdiv = document.createElement('div'); newdiv.setAttribute('id', 'lootparser_add_main2'); newdiv.setAttribute('style', 'display: none;'); newdiv.innerHTML = ''+ '

'+ ' '+  '

'+ ' '; tmp = gebi('lootparser_add'); tmp.appendChild(newdiv); tmp.style.fontSize = '100%'; tmp.style.border = '1px solid #bfcfcf'; tmp.style.color = '#000000'; tmp.style.backgroundColor = '#f9fcff'; tmp.style.padding = '5px 10px 5px 10px'; tmp.style.marginBottom = '10px'; sebi('lootparser_add_main1'); }

function lootparser_go_back_to_form { hebi('lootparser_loot_main2'); sebi('lootparser_loot_main1'); gebi('lootparser_loot_log').value = ''; var i, v = gebi('lootparser_use_version'); for (i in v.options) { if (v.hasOwnProperty(i)) { if (v[i].value == current_tibia_version) { v.options[i].selected = true; break; } } }

}

function lootparser_loot_init { var tmp, x; newdiv = document.createElement('div'); newdiv.setAttribute('id', 'lootparser_loot_main1'); newdiv.setAttribute('style', 'display: none;'); tmp = ' Log Analyzer/Uploader '+ 'This page will analyse your Server Log file and will then give you an overview of the monsters killed, and their loot. '+ 'If yu are logged in to wikia it will give you the option to upload statistics. '+ 'All this is to make your life easier, you do not have to manually count or edit anything. '+ '

'+ 'Copy the Server Log in this box: '+ ' '+ '

'+ ' ';  newdiv.innerHTML = tmp; gebi('lootparser_loot').appendChild(newdiv);

newdiv = document.createElement('div'); newdiv.setAttribute('id', 'lootparser_loot_main2'); newdiv.setAttribute('style', 'display: none;'); newdiv.innerHTML = '<input type="button" value="Go back to the form" onclick="lootparser_go_back_to_form;">'+ '

'+ '<div id="lootparser_loot_totallines"> '+ '<div id="lootparser_loot_results"> '+ ' '+ '<div id="lootparser_loot_totaltime"> '; tmp = gebi('lootparser_loot'); tmp.appendChild(newdiv); tmp.style.fontSize= '100%'; tmp.style.border= '1px solid #bfcfcf'; tmp.style.color = '#000000'; tmp.style.backgroundColor = '#f9fcff'; tmp.style.padding = '5px 10px 5px 10px'; tmp.style.marginBottom='10px'; sebi('lootparser_loot_main1'); } /* End of Code used for Loot_Statistics */

/*Hide bar and show loot parser */ lootparser_add_init; hebi('lootparser_add_img'); sebi('lootparser_add', true); hebi('lootparser_add_main2'); sebi('lootparser_add_main1');/* Fix for IE*/ lootparser_loot_init; hebi('lootparser_loot_img'); sebi('lootparser_loot', true); hebi('lootparser_loot_main2'); sebi('lootparser_loot_main1');/* Fix for IE*/ //