// ==UserScript== // @name WoTStatScript - ForumsExtendedStat // @version 1.0 // @description Adds some usable fields for forum.worldoftanks // @author Orrie // @contributor seriych // @namespace http://forum.worldoftanks.eu/index.php?/topic/263423- // @icon http://dl.dropboxusercontent.com/u/12497046/wot/projects/statscript/img/icon.png // @include /^http://forum\.worldoftanks\.(eu|com|ru|asia|kr)/\S+/topic// // @include /^http://forum\.worldoftanks\.(eu|com|ru|asia|kr)/\S+\?showtopic/ // @include /^http://forum.worldoftanks\.(eu|com|ru|asia|kr)/index\.php\?app=members&module=messaging§ion=view&do=showConversation&topicID=\d+/ // @grant GM_xmlhttpRequest // @license MIT License // @downloadURL none // ==/UserScript== (function () { // data uri var uri = { icon_arrow:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPwAAAAJCAMAAAAhKrH/AAAAV1BMVEUAAAD///+TKCf9AQmTLiX9AQmTMir9AQmTLif9AQmTMSz9AQmTMir9AQmTMyn9AQmTMirvGgKTMirsIAGTMirwGQOTMiqTMirsIAGaNDGgNzfqJwDrJABtE0DNAAAAGnRSTlMAABERIiIzM0REVVVmZnd3iIqZmrvDzN3g7thzQuwAAACHSURBVHja5dVLDsIwDEXRCySlP0IMoXXs7H+dDBASA1bQ3B0cPclm2Fe2wrfTQeO3qwqqAKWek80HxfO/l1/EBRgtU2tf+KkJ7TO9hdVSV3jU42f6ZClY6Qt/d4n+BGol29jTwQN1pE2QbA610BVefImuwL7xsNAXXhVpEYY8kNfO/rwsyA3ekEsOT2YDLE8AAAAASUVORK5CYII=" }; // style contents var style = elem("style", "wotstatscript", "", "text/css"), styleText = [ ".author_info {z-index: 1;}", ".user_details > br {display: none;}", ".basic_info {margin: 0 0 4px;}", ".post_count.margin-bottom {margin: 0 0 5px;}", ".battles_count {display: none;}", ".i-xvm-lang {vertical-align: text-top;}", ".t-table-stats {margin: 5px 0; width: auto;}", ".t-table-stats td {padding: 0 5px 0 0; line-height: 16px;}", ".t-table-stats td:last-of-type {font-weight: bold;}", //".t-tables-links {margin: 5px 0; width: 106px;}", ".t-tables-links {background: #EDEDED; border: 1px solid #d5d5d5; border-radius: 3px; box-shadow: 0 2px 2px rgba(0, 0, 0, 0.1), 0 0 3px 3px rgba(255, 255, 255, 0.2); display: inline-block; margin: 5px 0 5px -3px; overflow: hidden; padding: 3px 3px 0; text-overflow: ellipsis; white-space: nowrap; width: 90px;}", ".t-tables-links:hover {border-color: #7D7D7D; width: 180px;}", ".t-tables-links tbody {display: table; width: 180px;}", ".t-tables-links td {padding: 0 0 2px; font-weight: bold;}", ".t-tables-links td a { background: url("+uri.icon_arrow+") no-repeat scroll 0 2px rgba(0, 0, 0, 0); padding: 0 0 0 10px; vertical-align: middle;}", ".t-tables-links td a:hover {background: url("+uri.icon_arrow+") no-repeat scroll -244px 2px rgba(0, 0, 0, 0);}", ".t-tables-links tr:last-of-type td {}", ".realm_kr .t-tables-links {width: 108px;}", ".realm_kr .t-tables-links:hover {width: 215px;}", ".realm_kr .t-tables-links tbody {width: 215px;}" ]; for (var css=0; css-1) { postObj.num[index][postObj.num[index].length] = t; } else { postObj.ids[users] = id; postObj.num[users] = []; postObj.num[users][0] = t; } } } // request and retrieve statistics from API if (!!users) { wg.api.i = "http://api.worldoftanks."+wg.srv+"/wot/account/info/?application_id="+wg.api[wg.srv]+"&account_id="+postObj.ids.join(','); wg.api.v = "http://api.worldoftanks."+wg.srv+"/wot/account/tanks/?application_id="+wg.api[wg.srv]+"&account_id="+postObj.ids.join(','); reqHnd(wg.api.i, apiInfoHnd); } // processing information from player API -> links and stats function apiInfoHnd(resp) { console.log("apiInfoHnd:", resp); for (var a in resp.data) { if (resp.data.hasOwnProperty(a)) { // store stats var id = resp.data[a].account_id; s[id].u = { name: resp.data[a].nickname, id: resp.data[a].account_id, cid: resp.data[a].clan_id, bat: resp.data[a].statistics.all.battles, win: resp.data[a].statistics.all.wins/resp.data[a].statistics.all.battles, dmg: resp.data[a].statistics.all.damage_dealt/resp.data[a].statistics.all.battles, frag: resp.data[a].statistics.all.frags/resp.data[a].statistics.all.battles, spot: resp.data[a].statistics.all.spotted/resp.data[a].statistics.all.battles, def: resp.data[a].statistics.all.dropped_capture_points/resp.data[a].statistics.all.battles, wgr: resp.data[a].global_rating, lng: resp.data[a].client_language }; // start creating html var iPost = postObj.ids.indexOf(a), userStats = [ ""+loc.f01+""+colStat((s[id].u.bat > 0)?s[id].u.win*100:0,"wr",2,"%")+"", ""+loc.f02+""+colStat(s[id].u.bat,"bat",0,"")+"", ""+loc.f03+""+colStat(s[id].u.wgr,"pr",0,"")+"", ""+loc.f04+"----" ], userLinks = [ [ ["Player Profile"], [srv.ws, "WoTstats"] ], [ [srv.wl, "WoTLabs"], [srv.cs, "WoT-CS"] ], [ [srv.nm, "Noobmeter"], [srv.wr, "WoTReplays"] ], [ [srv.wn, "Wot-news"], (wg.srv=="ru") ? [srv.wr, "WoTS.com.ua"] : [srv.wlife, "WoT-Life"] ] ]; // modify existing html if (iPost >- 1) { for (var i=0; i"), flag = elem("img", "i-xvm-lang", "", "", "https://bytebucket.org/seriych/worldoftanksforumextendedstat.user.js/raw/tip/data/img/lang/"+s[id].u.lng+".png"); flag.title = s[id].u.lng.toUpperCase()+" "+loc.f00; for (var sr=0; sr WN8 function apiVehHnd(resp) { console.log("apiVehHnd:", resp); for (var p in resp.data) { if (resp.data.hasOwnProperty(p)) { var iPost = postObj.ids.indexOf(p), rWin, rDmg, rFrag, rSpot, rDef; if (s[p].u.bat > 0) { for (var v in resp.data[p]) { if (resp.data[p].hasOwnProperty(v)) { var vehStat = statObj[resp.data[p][v].tank_id], vehBats = resp.data[p][v].statistics.battles; s[p].v.frag += vehStat.frag*vehBats; s[p].v.dmg += vehStat.dmg *vehBats; s[p].v.spot += vehStat.spot*vehBats; s[p].v.def += vehStat.def *vehBats; s[p].v.win += vehStat.win *vehBats; } } rWin = Math.max( ((s[p].u.bat /(s[p].v.win /s[p].u.bat)-0.71)/(1-0.71) ),0); rDmg = Math.max( ((s[p].u.dmg /(s[p].v.dmg /s[p].u.bat)-0.22)/(1-0.22) ),0); rFrag = Math.max(Math.min(rDmg+0.2,((s[p].u.frag/(s[p].v.frag/s[p].u.bat)-0.12)/(1-0.12))),0); rSpot = Math.max(Math.min(rDmg+0.1,((s[p].u.spot/(s[p].v.spot/s[p].u.bat)-0.38)/(1-0.38))),0); rDef = Math.max(Math.min(rDmg+0.1,((s[p].u.def /(s[p].v.def /s[p].u.bat)-0.10)/(1-0.10))),0); s[p].wn8 = colStat(980*rDmg + 210*rDmg*rFrag + 155*rFrag*rSpot + 75*rDef*rFrag + 145*Math.min(1.8,rWin),"wn8",0); } else { s[p].wn8 = colStat(0,"wn8",0); } if (iPost >- 1) { for (var i=0; i= 1000) { output = input.toFixed(dec).toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1"+wg.sym); } for (var c in colArr) { if (colArr.hasOwnProperty(c)) { if (input >= colArr[c][colArr.id[type]]) { color = colArr[c][0]; break; } } } return ""+output+""; } // quick creation of element function elem(tag, name, html, type, src) { var element = document.createElement(tag); if (name) {element.className = name;} if (html) {element.innerHTML = html;} if (type) {element.type = type;} if (src) {element.src = src;} return element; } }());