Advertisement
Guest User

Homepage and wins 1.2

a guest
Jan 14th, 2015
603
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.24 KB | None | 0 0
  1. // ==UserScript==
  2. // @name TagPro Homepage And Wins Needed
  3. // @version 1.2
  4. // @description Improve Homepage and show needed wins
  5. // @include http://tagpro-*.koalabeast.com/
  6. // @include http://tagpro-*.koalabeast.com/games*
  7. // @include http://*.jukejuice.com/
  8. // @include http://*.jukejuice.com/games*
  9. // @include http://*.newcompte.fr/
  10. // @include http://*.newcompte.fr/games*
  11. // @author defense_bot, ballparts, ben, despair
  12. // @grant none
  13.  
  14. // ==/UserScript==
  15.  
  16. // - - - SETTINGS - - - //
  17.  
  18. // Show degree and wins till next degree
  19. var showWinsUntil = true;
  20.  
  21. // Show win-rate
  22. var showWinRate = false;
  23.  
  24. // Show daily stats - sets winrate to false
  25. var showDailyStats = true;
  26.  
  27. // Change text of main page
  28. var changeMainMenu = true;
  29.  
  30. // Show current server stats
  31. var showServerStats = true;
  32.  
  33. // - CUSTOMIZE TEXT - // {?} <- use to place number
  34. var playText = ["Play Now", "{?} Online"],
  35. profileText = ["Profile", "Settings"],
  36. logonText = ["Log On", "Track Stats"],
  37. groupText = ["Groups", "- {?} -"],
  38. leaderText = ["Leaders", "Rank Points"],
  39. replayText = ["Replays", "Watch Yourself"],
  40. mapsText = ["Maps", "Map Info"];
  41.  
  42. // - END OF SETTINGS - //
  43.  
  44. if(showDailyStats){showWinRate = false;}
  45.  
  46. var pageLoc = (location.href.indexOf("games/find") == -1) ? "home" : "find";
  47. var parentSlot;
  48.  
  49. // Gets a list of all the links on the page //
  50. anchor = document.getElementsByTagName("a");
  51. var playID = findID("Play Now");
  52.  
  53. cacheProfile();
  54. findParentSlot();
  55. if(showDailyStats){addDailyStats();}
  56. if(showWinRate){addWinRate();}
  57. if(showWinsUntil){addWinsUntil();}
  58. if(pageLoc == "home" && changeMainMenu){
  59. changeHome();
  60. updatePlayerCount();
  61. }else if(pageLoc == "find" && showServerStats){
  62. serverButton = createButton();
  63. getStats(serverButton);
  64. }
  65.  
  66. function cacheProfile(){
  67. url = $('a[href^="/profile"]').attr('href');
  68. if(url !== undefined){
  69. var n = url.lastIndexOf('/');
  70. var profileNum = url.substring(n + 1);
  71. profilePage = String('/profile/'+profileNum);
  72. localStorage.setItem('profilePage',profilePage);
  73. }
  74. }
  75.  
  76. function findParentSlot(){
  77. if(pageLoc == "home"){
  78. parentSlot = (playID === 1) ? $('article > div.tiny') : $('article > h1');
  79. }else{
  80. parentSlot = $('article > div.section.smaller');
  81. }
  82. }
  83.  
  84. function addWinsUntil(){
  85. parentSlot.after( "<center><h3><p id='winsneeded'></p></h3></center>" );
  86. $( "#winsneeded" ).load(localStorage.getItem('profilePage') + ' article > h3 > div', function(){
  87. $('h3').css({'margin':'10px'});
  88. $('#winsneeded > div:last-child').css({'font-size':'50%'});
  89. });
  90. }
  91.  
  92. function addWinRate(){
  93. parentSlot.after('<h4><center><span id="winp"><span id="inner"></span></span></center></h4>');
  94. element = $('<center><span id="created"></span></center>');
  95. $(winp).append(element);
  96. $( element ).load(localStorage.getItem('profilePage') + ' td:eq(6)', function(){
  97. text = $('td').text();
  98. text = text.substring(0, 3);
  99. if(text != "100"){text = text.substring(0, 2);}
  100. text = "Daily Win : " + text + "%";
  101. $('#inner').append(text);
  102. $('center > td').remove();
  103. $('h4').css({'margin':'10px'});
  104. });
  105. }
  106.  
  107. function addDailyStats(){
  108. parentSlot.after( "<h4><table class='board'><tbody id='header1'></h4>" );
  109. $('h4').css({'margin':'10px'});
  110. $('#header1').after( "<tbody id='dailyStats'>" );
  111. $.get(localStorage.getItem('profilePage'), function(data) {
  112. var timePos = data.indexOf("<td class=\"duration\">") + 21,
  113. timeText = data.substring(timePos, timePos+10);
  114. timeText = timeText.substring(0, timeText.indexOf("<"));
  115. data = data.replace(" class=\"duration\">" + timeText, ">"+formatTime(timeText));
  116. $( "#header1" ).html($(data).find('tr:eq(0)'));
  117. $( "#dailyStats" ).html($(data).find('tr:eq(1)'));
  118. });
  119. }
  120.  
  121. function formatTime(text){
  122. var h, m, s;
  123. var num = Number(text);
  124. h = Math.floor(num/3600);
  125. m = Math.floor(num/60) - h*60;
  126. s = num - h*3600 - m*60;
  127. return addZero(h) +":"+ addZero(m) +":"+ addZero(s);
  128. }
  129.  
  130. function addZero(input){
  131. return (input < 10) ? "0"+input : ""+input;
  132. }
  133.  
  134. // configure buttons
  135. function setText(button, main, small, replace){
  136. var msg = main + "<span>" + small + "</span>";
  137. if(replace !== undefined){
  138. msg = msg.replace("{?}", replace);
  139. }
  140. anchor[button].innerHTML = msg;
  141. }
  142.  
  143. function changeHome(){
  144. setText(playID, playText[0], playText[1], "?");
  145. if(anchor[playID+1].innerHTML.indexOf("Profile") != -1){
  146. setText(playID+1, profileText[0], profileText[1]);
  147. }else{
  148. setText(playID+1, logonText[0], logonText[1]);
  149. }
  150. var startPos = anchor[playID+2].innerHTML.indexOf(":") + 1,
  151. endPos = anchor[playID+2].innerHTML.indexOf("<"),
  152. groupCount = anchor[playID+2].innerHTML.substring(startPos, endPos);
  153. setText(playID+2, groupText[0], groupText[1], groupCount);
  154. setText(playID+3, leaderText[0], leaderText[1]);
  155. // mod buttons after //
  156. var replayID, mapsID;
  157. replayID = findID("Replays");
  158. if(replayID !== undefined){
  159. setText(replayID, replayText[0], replayText[1]);
  160. }
  161. setTimeout(function(){
  162. mapsID = findID("Maps");
  163. if(mapsID !== undefined){
  164. setText(mapsID, mapsText[0], mapsText[1]);
  165. }
  166. },250);
  167. }
  168.  
  169. function findID(match){
  170. var i;
  171. for(i=0; i<anchor.length; i++){
  172. if(anchor[i].innerHTML.indexOf(match) != -1){
  173. return i;
  174. }
  175. }
  176. }
  177.  
  178. function updatePlayerCount(){
  179. var ServerURL = location.href + "stats?callback";
  180. $.ajax({
  181. timeout:1e3, dataType:"json",
  182. url:ServerURL,
  183. success:function(i){
  184. setText(playID, playText[0], playText[1], i.players);
  185. },
  186. });
  187. }
  188.  
  189. function findInputSpot() {
  190. SS = $('div.smaller.section');
  191. for (var i = 0; i < SS.length; i ++) {
  192. textcontent = SS[i].innerText || SS[i].textContent
  193. if (textcontent == 'Or Switch Server:') {
  194. return SS[i];
  195. }
  196. }
  197. return false;
  198. }
  199.  
  200. function getStats(e) {
  201. n=(new Date).getTime();
  202. var wattt = e.attr("href")+"stats?callback=?";
  203. $.ajax({timeout:1e3,dataType:"json",url:wattt,success:function(i){
  204. i.ping=(new Date).getTime()-n,e.attr("data-ping",i.ping).find(".stats").text("Ping: "+
  205. i.ping+", Players: "+i.players+(i.playerCapacity?"/"+i.playerCapacity:""))
  206. },error:function(){
  207. e.find(".stats").text("error getting stats.")
  208. }})
  209. }
  210.  
  211. function capitaliseFirstLetter(string){
  212. return string.charAt(0).toUpperCase() + string.slice(1);
  213. }
  214.  
  215. function createButton() {
  216. var serverURL = tagpro.serverHost + "/";
  217. var serverName = serverURL.replace('.koalabeast.com/','').replace('tagpro-','')
  218. if(location.href.indexOf("tangent") != -1){serverName = "tangent";}
  219. else if(location.href.indexOf("newcompte") != -1){serverName = "newcompte";}
  220. inputSpot = $(findInputSpot());
  221. inputSpot.before('<center><a id=currentServer href=http://'+serverURL+
  222. ' class="button">'+capitaliseFirstLetter(serverName)+'<span class="stats">');
  223. return($('#currentServer'));
  224. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement