// ==UserScript==
// @name DOTABUFF
// @namespace projects.scripts.dotabuff
// @description Adds link to steam profile, unplayed heroes and more.
// @updateURL https?://userscripts.org/scripts/source/145318.meta.js
// @include http*://dotabuff.com*
// @version 1.5.19
// ==/UserScript==
/*
Can:
* add steam link to profile
* add numbers to heroes (disabled by default)
* add not yet played heroes
* add number of games untill all heroes 4 games
* change highlight for performance on heroes grid page
changes:
1.5.19: fixed lack of jquery, and chrome stuff
1.4.19: added elder titan
1.4.18: added skywrath
1.4.17: added bristleback, changed unplayed to 4 since thats how dota2 counts now
1.4.16: added tusk
1.4.15: fixed http/s issues
1.4.13: added troll
1.4.12: added medusa, fixed magnus/anti-mage
1.4.11: bugfix
1.4.10: added timbersaw
1.4.9 : added slark and number of games untill all 5 (so you would get performance bar in profile)
1.4.8 : added cent
1.4.7 : added magnataur
1.4.6 : added meepo
1.4.5 : addnumbers activated on dotabuff.com/heroes
1.4 : added not yet played
*/
/// jquery fix
function addJQuery(callback) {
var script = document.createElement("script");
script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js");
script.addEventListener('load', function() {
var script = document.createElement("script");
script.textContent = "window.jQ=jQuery.noConflict(true);(" + callback.toString() + ")();";
document.body.appendChild(script);
}, false);
document.body.appendChild(script);
}
// main
function callback() {
var currentURL = (document.location+'');
console.log("a?")
//enabled features
if (currentURL .match(/https?:\/\/dotabuff\.com\/players\/[0-9]*/))
{
addSteamLink();
}
if (currentURL .match(/https?:\/\/dotabuff\.com\/players\/[0-9]*\/heroes/)) {
addNumbers();
notPlayedHeroes();
}
if (currentURL .match(/https?:\/\/dotabuff\.com\/heroes\/.?/)) {
addNumbers();
}
if (currentURL .match(/https?:\/\/dotabuff\.com\/heroes/)) {
changeHeroes();
}
///////// STEAM ID
function toSteamID(account)
{
return '7656119' + (7960265728+(account*1)).toString() ;
}
function addSteamLink()
{
var accountid = location.pathname.split('/')[2];
var a = 'http://steamcommunity.com/profiles/'+toSteamID(accountid)+ '/';
var s = 'http://store.steampowered.com/favicon.ico';
var style = 'display: inline-block; padding-left: 5px;';
var d = '

';
$('.content-header-title').children().first().append(d);
}
///////// HERO NUMBER (for easy counting)
function addNumbers()
{
var i = 1;
$('.cell-icon').parent().prepend(function(a,b){ return '' + i++ +' | ';} );
$('th').parent().prepend('');
}
///////// UNPLAYED HEROES
function notPlayedHeroes()
{
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 ';
$('.hero-link').each( function(i,a)
{
name = a.href.split('/')[4]+' ';
unplayed= unplayed.replace(name,'');
});
//console.log(unplayed);
var s='';
notempty = unplayed.split(' ').filter(function(a){return a!=""});
amount = notempty.length;
notempty = notempty.join(', ');
if ( amount >0)
{
unplayed = notempty.replace(/-/g,' ');
unplayed = unplayed.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
s = ' Not played yet heroes: ' +unplayed + ' ';
}
{ // this part adds number of games until You got visible perf. bar for each hero
var more = 0;
$('.hero-link').each(function(a,b){
v = $(this).parent().next()[0].textContent ;
more += Math.max(0, 4-(v*1)); // for number of games under 5
});
more += amount*4;
if (more>0)
s+=' Matches before all heroes played 4 times: '+more+' ';
}
$('#page-content').append(s);
}
//////// TRANSPARENT PNG
// semi transparent png is faster then css "opacity: 0.2;"
// move very fast on dotabuff.com/heroes page to see difference
// (highlighting speed)
function addCss(cssString) {
var head = document.
getElementsByTagName('head')[0];
var newCss = document.createElement('style');
newCss.type = "text/css";
newCss.innerHTML = cssString;
head.appendChild(newCss);
}
function changeHeroes()
{
// non opacity version
addCss (
'.tile-container .decorative-backdrop { opacity: 1.0 ; '
+'background: url("http://i.imgur.com/q7iK0.png") repeat scroll 0 0 transparent; }'
);
}
}
addJQuery(callback); |