![]() Shoutbox (View Full Shoutbox)
|
||||
Click Refresh to load shouts. |
||||
|
[Greasemonkey] Tibia.com improvements
|
|
02-08-2010, 05:20 PM
(This post was last modified: 02-09-2010 08:19 PM by Ian. Edit Reason: Added syntax highlighting)
Post: #1
|
|||
|
|||
|
[Greasemonkey] Tibia.com improvements
Hello, I've written two scripts that provide some extra information on tibia.com. I recognize they may not be beautifully written and I encourage you to post here or private message me with any comments, questions and of course corrections.
1. Shows online time and vocation of online players in guild profile- it looks quite like this. select JavaScript
// ==UserScript== // @name Tibia guild online // @description Shows online guild members // @author Goodfellow // @include http://*tibia.com/community/?subtopic=guilds* // ==/UserScript== var gameWorld = document.body.innerHTML.match(/The guild was founded on [A-Z][^\s]+ on [A-Z][^&]+ \d\d \d\d\d\d\./); gameWorld = String(gameWorld).replace('The guild was founded on ', ''); gameWorld = String(gameWorld).replace(/ on [A-Z][^&]+ \d\d \d\d\d\d\./, ''); function fixGuild() { try { GM_log(gameWorld); if (typeof gameWorld == 'undefined' || gameWorld == 'null') return; GM_xmlhttpRequest({ method: 'GET', url: 'http://www.tibia.com/community/?subtopic=whoisonline&world=' + gameWorld, onload: function(responseDetails) { if (responseDetails.status != 200) return; //code 200- connection successful, 404- page not found var onlineList = responseDetails.responseText; var nicks = document.evaluate('//table[@cellspacing="1"][@cellpadding="4"][1]/tbody/tr/td/a', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); var guildMemList = document.evaluate('//table[@cellspacing="1"][@cellpadding="4"][1]/tbody/tr/td', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); var y=0, x, name, level, vocation, len, pos, totalPlayers = 0, sdShoters = 0, sdPower= 0; for (var i=5; i<(guildMemList.snapshotLength-1); i+=3) { x = onlineList.indexOf('>' + to_html(nicks.snapshotItem(i-5-y*2).textContent) + '<'); if (x != -1) { name = to_html(nicks.snapshotItem(i-5-y*2).textContent); totalPlayers++; pos = onlineList.indexOf('<', x+name.length+24) len = pos-(x+name.length+24); level = onlineList.substr(x+name.length+24, len); len = onlineList.indexOf('<', pos+11)-(pos+19); vocation = onlineList.substr(pos+19, len); if ((vocation == 'Master Sorcerer' || vocation == 'Elder Druid') && parseInt(level) > 80) {sdShoters++; sdPower +=150;} guildMemList.snapshotItem(i).style.border = "2px solid #00FF00"; guildMemList.snapshotItem(i+1).textContent = level; guildMemList.snapshotItem(i-1).textContent = vocation; } else { guildMemList.snapshotItem(i+1).textContent = ''; guildMemList.snapshotItem(i-1).textContent = ''; } y++; } if (totalPlayers > 0) guildMemList.snapshotItem(0).innerHTML += '<b> ' + totalPlayers + ' online, ' + sdShoters + ' mages (approx. ' + sdPower + ' of sd damage)</b>'; guildMemList.snapshotItem(1).innerHTML = '<b>Vocation</b>'; guildMemList.snapshotItem(3).innerHTML = '<b>Level</b>'; } }) } catch(e) {} }; function to_html (str) { str = str.replace(/\s/g, ' '); return str; }; fixGuild(); 2. Formats player profile just like this (direct links to house, online times taken from pskonejott.com and experiance gains from tibia-stats.com. select JavaScript
// ==UserScript== // @name Tibia fix profiles // @description links to houses, adds online time (taken from pskonejott.com) and experience gains (<a href="http://tibia-stats.com/)" target="_blank">http://tibia-stats.com/)</a> // @author Goodfellow // @include http://*tibia.com/community/?subtopic=characters* // ==/UserScript== var plName = document.evaluate('//table[@cellspacing="1"][@cellpadding="4"][1]/tbody/tr[2]/td[2]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; var hasHouse = 0; var elmHouse = document.evaluate('//table[@cellspacing="1"][@cellpadding="4"][1]/tbody/tr[8]/td[1]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; if (elmHouse.textContent == 'House:') { //handling marriages hasHouse = 1; elmHouse = document.evaluate('//table[@cellspacing="1"][@cellpadding="4"][1]/tbody/tr[8]/td[2]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; } else if (document.evaluate('//table[@cellspacing="1"][@cellpadding="4"][1]/tbody/tr[9]/td[1]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.textContent == 'House:') { hasHouse = 1; elmHouse = document.evaluate('//table[@cellspacing="1"][@cellpadding="4"][1]/tbody/tr[9]/td[2]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; } var plWorld = document.evaluate('//table[@cellspacing="1"][@cellpadding="4"][1]/tbody/tr[6]/td[2]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; var plHouse = String(elmHouse.textContent).replace(/ \([^)].+/, ''); var plCity = String(elmHouse.textContent).replace(/.*\(/, ''); plCity = plCity.replace(/\).*/, ''); //GM_log('World = ' + plWorld.textContent + ' House = ' + plHouse + ' City = ' + plCity); function fixOnlineTime() { try { if (typeof plName == 'undefined' || plName == 'null') return; //exit if character does not exist GM_xmlhttpRequest({ method: 'GET', url: 'http://www.pskonejott.com/otc_display.php?character=' + encodeURI(plName.textContent), onload: function(responseDetails) { if (responseDetails.status != 200) return; //code 200- connection successful, 404- page not found var pskProfile = responseDetails.responseText; if (pskProfile.indexOf(plName.textContent + ' has no Online Time Counter entry!') != -1) return; //exit if pskonejott has no info to show var onTimes = pskProfile.match(/\d+h<BR>\d+m<\/TD><TD class="r">\d+h<BR>\d+m<\/TD><TD class="r_grn">/); var weekON = String(onTimes).replace('<\/TD><TD class="r_grn">', ''); weekON = weekON.replace(/\d+h<BR>\d+m<\/TD><TD class="r">/, ''); weekON = weekON.replace('<BR>', ' '); //online this week var monthON = String(onTimes).replace(/<\/TD><TD class="r">\d+h<BR>\d+m<\/TD><TD class="r_grn">/, ''); monthON = monthON.replace('<BR>', ' '); //online this month //GM_log('weekly = ' + weekON + ' monthly = ' +monthON); //creating table var elmlastTable = document.evaluate('//table[@cellspacing="1"][@cellpadding="4"][last()]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; var elmOnlineTable = document.createElement('table'); elmOnlineTable.width = "100%"; elmOnlineTable.cellSpacing = "1"; elmOnlineTable.cellPadding = "4"; elmOnlineTable.border= "0"; elmlastTable.parentNode.insertBefore(elmOnlineTable, elmlastTable.nextSibling); elmOnlineTable.innerHTML += '<TR BGCOLOR=#505050><TD COLSPAN=4 CLASS=white><B>Online time</B></TD></TR><TR BGCOLOR=#F1E0C6><TD WIDTH=20%>Last week:</TD><TD WIDTH=80%>' + weekON + '<TR BGCOLOR=#D4C0A1><TD>This month:</TD><TD>' + monthON +'</TD></TR>'; }}) } catch(e) {} }; function linkToHouse(world, houseName, city) { try { if (hasHouse == 0) return; GM_xmlhttpRequest({ method: 'POST', url: 'http://www.tibia.com/community/?subtopic=houses&world=' + world, headers:{'Content-type':'application/x-www-form-urlencoded'}, data:encodeURI('town=' + city), onload: function(responseDetails) { if (responseDetails.status != 200) return; var check = responseDetails.responseText.indexOf(to_html(houseName)); if(check == -1) return; var start = responseDetails.responseText.indexOf('houseid VALUE=', check); var end = responseDetails.responseText.indexOf('>', start); var houseID = responseDetails.responseText.substr(start+14, end-start-14); if (isNaN(houseID)) return; //GM_log(houseID); var elmlastTable = document.evaluate('//table[@cellspacing="1"][@cellpadding="4"][last()]/tbody/tr[1]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; elmlastTable.innerHTML += '<FORM METHOD="POST" NAME="houseForm" Action ="http://www.tibia.com/community/?subtopic=houses&page=view"><INPUT TYPE="HIDDEN" NAME="world" VALUE="' + plWorld.textContent + '"><INPUT TYPE="HIDDEN" NAME="houseid" VALUE="' +houseID + '"></FORM></td></tr></tbody></table>'; elmHouse.innerHTML = '<a href="#" o<strong></strong>nClick="document.houseForm.submit();">' + elmHouse.textContent; }}) } catch(e) {} }; function addOnlineTime(name) { try { GM_xmlhttpRequest({ method: 'GET', url: 'http://tibia-stats.com/index.php?akcja=777&player=' + name, onload: function(responseDetails) { if (responseDetails.status != 200) return; //code 200- connection successful, 404- page not found var statsProfile = responseDetails.responseText; var expDaily, expWeekly; if (statsProfile.indexOf('Such character does not exists in our database <img src="http://www.tpforums.org/forum/images/smilies/sad.gif" style="vertical-align: middle;" border="0" alt="Sad" title="Sad" />') != -1) { return; //exit if character profile does not exist } else if (statsProfile.indexOf('Shows daily experience growth') != -1) { var start = statsProfile.indexOf('Shows daily experience growth') + 78; var end = statsProfile.indexOf('</td>', start); expDaily = statsProfile.substr(start, end-start); start = statsProfile.indexOf('Shows weekly experience growth', end) + 80; end = statsProfile.indexOf('</td>', start); expWeekly = statsProfile.substr(start, end-start); } else return; //creating table var elmlastTable = document.evaluate('//table[@cellspacing="1"][@cellpadding="4"][last()]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; var elmOnlineTable = document.createElement('table'); elmOnlineTable.width = "100%"; elmOnlineTable.cellSpacing = "1"; elmOnlineTable.cellPadding = "4"; elmOnlineTable.border= "0"; elmlastTable.parentNode.insertBefore(elmOnlineTable, elmlastTable.nextSibling); elmOnlineTable.innerHTML += '<TR BGCOLOR=#505050><TD COLSPAN=4 CLASS=white><B>Experience gains:</B></TD></TR><TR BGCOLOR=#F1E0C6><TD WIDTH=20%>Today:</TD><TD WIDTH=80%>' + expDaily + '<TR BGCOLOR=#D4C0A1><TD>Last week:</TD><TD>' + expWeekly +'</TD></TR>'; }}) } catch(e) {} }; function to_html (str) { str = str.replace(/\s/g, ' '); return str; }; if (typeof plWorld != 'undefined' && typeof plHouse != 'undefined' && typeof plCity != 'undefined' && plWorld.textContent != 'null' && plHouse != 'null' && plCity != 'null') linkToHouse(plWorld.textContent, plHouse, plCity); fixOnlineTime(); if (typeof plName != 'undefined' && plName.textContent != 'null') addOnlineTime(plName.textContent); In case you wonder: Greasemonkey is a Firefox extension which allows you to execute your own javascripts on sites you do not own. Beauty of this addon is that it allows you to do things regular javascript cannot (access any site on the web for instance). |
|||
|
02-08-2010, 07:52 PM
Post: #2
|
|||
|
|||
|
RE: [Greasemonkey] Tibia.com improvements
Awesome, thanks
|
|||
|
02-09-2010, 08:20 PM
(This post was last modified: 02-09-2010 08:21 PM by Ian. Edit Reason: )
Post: #3
|
|||
|
|||
|
RE: [Greasemonkey] Tibia.com improvements
Awesome scripts. Did you post these at http://userscripts.org yet?
TibiaAPI, SharpOT |
|||
|
02-09-2010, 09:49 PM
(This post was last modified: 02-09-2010 09:50 PM by DarkstaR. Edit Reason: )
Post: #4
|
|||
|
|||
|
RE: [Greasemonkey] Tibia.com improvements
I tried the char page one. Online time works but houses didnt.
I did some tests, it always stops after the line if(check == -1) return; in function linkToHouse() |
|||
|
02-24-2010, 09:54 AM
(This post was last modified: 02-24-2010 11:00 AM by Goodfellow. Edit Reason: )
Post: #5
|
|||
|
|||
|
RE: [Greasemonkey] Tibia.com improvements
Nope, I haven't posted it on userscripts yet.
@DarkstaR That's weird. I used it past month and didn't notice anything like that. Can you give me an example of character it fails on? P.S I am sorry for late reply |
|||
|
« Next Oldest | Next Newest »
|

![[-]](images/mint/collapse.gif)




