Advertisement
Jademalo

Dotabuff

Jul 12th, 2013
624
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.88 KB | None | 0 0
  1. // ==UserScript==
  2. // @name DOTABUFF
  3. // @namespace projects.scripts.dotabuff
  4. // @description Adds link to steam profile, unplayed heroes and more.
  5. // @updateURL https?://userscripts.org/scripts/source/145318.meta.js
  6. // @include http*://dotabuff.com*
  7. // @version 1.5.19
  8. // ==/UserScript==
  9. /*
  10. Can:
  11. * add steam link to profile
  12. * add numbers to heroes (disabled by default)
  13. * add not yet played heroes
  14. * add number of games untill all heroes 4 games
  15. * change highlight for performance on heroes grid page
  16.  
  17. changes:
  18. 1.5.19: fixed lack of jquery, and chrome stuff
  19. 1.4.19: added elder titan
  20. 1.4.18: added skywrath
  21. 1.4.17: added bristleback, changed unplayed to 4 since thats how dota2 counts now
  22. 1.4.16: added tusk
  23. 1.4.15: fixed http/s issues
  24. 1.4.13: added troll
  25. 1.4.12: added medusa, fixed magnus/anti-mage
  26. 1.4.11: bugfix
  27. 1.4.10: added timbersaw
  28. 1.4.9 : added slark and number of games untill all 5 (so you would get performance bar in profile)
  29. 1.4.8 : added cent
  30. 1.4.7 : added magnataur
  31. 1.4.6 : added meepo
  32. 1.4.5 : addnumbers activated on dotabuff.com/heroes
  33. 1.4 : added not yet played
  34. */
  35.  
  36.  
  37. /// jquery fix
  38.  
  39. function addJQuery(callback) {
  40. var script = document.createElement("script");
  41. script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js");
  42. script.addEventListener('load', function() {
  43. var script = document.createElement("script");
  44. script.textContent = "window.jQ=jQuery.noConflict(true);(" + callback.toString() + ")();";
  45. document.body.appendChild(script);
  46. }, false);
  47. document.body.appendChild(script);
  48. }
  49.  
  50. // main
  51.  
  52. function callback() {
  53. var currentURL = (document.location+'');
  54.  
  55. console.log("a?")
  56. //enabled features
  57.  
  58. if (currentURL .match(/https?:\/\/dotabuff\.com\/players\/[0-9]*/))
  59. {
  60. addSteamLink();
  61. }
  62. if (currentURL .match(/https?:\/\/dotabuff\.com\/players\/[0-9]*\/heroes/)) {
  63. addNumbers();
  64. notPlayedHeroes();
  65. }
  66. if (currentURL .match(/https?:\/\/dotabuff\.com\/heroes\/.?/)) {
  67. addNumbers();
  68. }
  69. if (currentURL .match(/https?:\/\/dotabuff\.com\/heroes/)) {
  70. changeHeroes();
  71. }
  72.  
  73.  
  74.  
  75. ///////// STEAM ID
  76.  
  77. function toSteamID(account)
  78. {
  79. return '7656119' + (7960265728+(account*1)).toString() ;
  80. }
  81.  
  82. function addSteamLink()
  83. {
  84.  
  85. var accountid = location.pathname.split('/')[2];
  86. var a = 'http://steamcommunity.com/profiles/'+toSteamID(accountid)+ '/';
  87. var s = 'http://store.steampowered.com/favicon.ico';
  88. var style = 'display: inline-block; padding-left: 5px;';
  89.  
  90. var d = '<div style="'+style+'"> <a href="'+a+'" target="_blank"> <img src="'+s+'"></a></div>';
  91.  
  92. $('.content-header-title').children().first().append(d);
  93. }
  94.  
  95.  
  96. ///////// HERO NUMBER (for easy counting)
  97.  
  98. function addNumbers()
  99. {
  100. var i = 1;
  101. $('.cell-icon').parent().prepend(function(a,b){ return '<td>' + i++ +'</td>';} );
  102. $('th').parent().prepend('<td style="width: 25px" ></th>');
  103. }
  104.  
  105. ///////// UNPLAYED HEROES
  106.  
  107. function notPlayedHeroes()
  108. {
  109. var unplayed = 'alchemist ancient-apparition anti-mage axe bane batrider beastmaster bloodseeker bounty-hunter brewmaster bristleback broodmother centaur-warrunner chaos-knight chen clinkz clockwerk crystal-maiden dark-seer dazzle death-prophet disruptor doom-bringer dragon-knight drow-ranger earthshaker elder-titan enchantress enigma faceless-void gyrocopter huskar invoker jakiro juggernaut keeper-of-the-light kunkka leshrac lich lifestealer lina lion lone-druid luna lycanthrope magnus medusa meepo mirana morphling naga-siren natures-prophet necrolyte night-stalker nyx-assassin ogre-magi omniknight outworld-destroyer phantom-assassin phantom-lancer puck pudge pugna queen-of-pain razor riki rubick sand-king shadow-demon shadow-fiend shadow-shaman silencer skeleton-king skywrath-mage slardar slark sniper spectre spirit-breaker storm-spirit sven templar-assassin tidehunter timbersaw tinker tiny treant-protector troll-warlord tusk undying ursa vengeful-spirit venomancer viper visage warlock weaver windrunner wisp witch-doctor zeus ';
  110.  
  111.  
  112. $('.hero-link').each( function(i,a)
  113. {
  114. name = a.href.split('/')[4]+' ';
  115.  
  116. unplayed= unplayed.replace(name,'');
  117. });
  118. //console.log(unplayed);
  119.  
  120. var s='';
  121. notempty = unplayed.split(' ').filter(function(a){return a!=""});
  122. amount = notempty.length;
  123. notempty = notempty.join(', ');
  124.  
  125. if ( amount >0)
  126. {
  127. unplayed = notempty.replace(/-/g,' ');
  128. unplayed = unplayed.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
  129.  
  130. s = '<div>Not played yet heroes: ' +unplayed + '</div>';
  131. }
  132.  
  133. { // this part adds number of games until You got visible perf. bar for each hero
  134.  
  135. var more = 0;
  136. $('.hero-link').each(function(a,b){
  137. v = $(this).parent().next()[0].textContent ;
  138.  
  139. more += Math.max(0, 4-(v*1)); // for number of games under 5
  140. });
  141. more += amount*4;
  142. if (more>0)
  143. s+='<div> Matches before all heroes played 4 times: '+more+'</div>';
  144. }
  145.  
  146. $('#page-content').append(s);
  147.  
  148. }
  149.  
  150.  
  151.  
  152.  
  153.  
  154. //////// TRANSPARENT PNG
  155. // semi transparent png is faster then css "opacity: 0.2;"
  156. // move very fast on dotabuff.com/heroes page to see difference
  157. // (highlighting speed)
  158.  
  159. function addCss(cssString) {
  160. var head = document.
  161. getElementsByTagName('head')[0];
  162. var newCss = document.createElement('style');
  163. newCss.type = "text/css";
  164. newCss.innerHTML = cssString;
  165. head.appendChild(newCss);
  166. }
  167.  
  168. function changeHeroes()
  169. {
  170. // non opacity version
  171. addCss (
  172. '.tile-container .decorative-backdrop { opacity: 1.0 ; '
  173. +'background: url("http://i.imgur.com/q7iK0.png") repeat scroll 0 0 transparent; }'
  174. );
  175. }
  176.  
  177. }
  178.  
  179.  
  180. addJQuery(callback);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement