Last active
September 25, 2017 21:20
-
-
Save vatho/d3720201f66cc64ada7c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Fix Dota builds page | |
// @namespace https://gist.github.com/parnakra/d3720201f66cc64ada7c | |
// @version 7.00 | |
// @updateURL https://gist.github.com/parnakra/d3720201f66cc64ada7c/raw/ | |
// @downloadURL https://gist.github.com/parnakra/d3720201f66cc64ada7c/raw/ | |
// @description Fixes various issues on the Dota 2 builds page | |
// @author Parnakra | |
// @match http://tampermonkey.net/index.php?version=3.11&ext=dhdg&updated=true#features | |
// @grant none | |
// @include http*://www.dota2.com/workshop/builds/edit* | |
// ==/UserScript== | |
(function(){ | |
window.setAbilityData = function setAbilityData(abilityData) { | |
if(!abilityData) { | |
$.ajax({ | |
type:'GET', | |
cache: true, | |
url:"http://www.dota2.com/jsfeed/abilitydata?l=english", | |
dataType:'json', | |
async: false, | |
success: function(itemJSON) { | |
setAbilityData(itemJSON.abilitydata); | |
}, | |
failure: function() { | |
// alert("Unable to get data from Dota.com!"); | |
} | |
}); | |
return; | |
} | |
g_GuideBuilder.abilities.data = abilityData; | |
g_GuideBuilder.abilities.data["attribute_bonus"] = new Array(); | |
} | |
window.hidePromptMessageBox=function() { | |
// Restore tooltips to activity | |
window.g_bTooltipsActive = true; | |
$('#promptTooltip').remove(); | |
showBlackoutCurtain(false); | |
}; | |
window.hideTooltipEditBox=function(){ | |
window.g_bTooltipsActive=true; | |
$('#editTooltip').remove(); | |
}; | |
function addCss(cssCode) { | |
var styleElement=document.createElement("style"); | |
styleElement.type="text/css"; | |
if(styleElement.styleSheet){ | |
styleElement.styleSheet.cssText=cssCode; | |
}else{ | |
styleElement.appendChild(document.createTextNode(cssCode)); | |
} | |
document.getElementsByTagName("head")[0].appendChild(styleElement); | |
} | |
addCss("#editTooltip, #promptTooltip { display: block !important;}"); | |
function fixBeastmasterUlt() { | |
console.log("fixing beastmaster ult"); | |
var primalRoarSkillRow = $("div[abilityName^='beastmaster_primal_roar']"); | |
primalRoarSkillRow.attr('abilityMaxlevel', '3'); | |
primalRoarSkillRow.attr('abilityType', 'ULTIMATE'); | |
primalRoarSkillRow.attr('class', 'skillBlock'); | |
primalRoarSkillRow.appendTo('#skillBuildContent'); | |
primalRoarSkillRow.removeAttr('style'); | |
var toReplace = "s1"; | |
var replaceWith = "s" + ($('.skillRow').length + 1); | |
var newSkillRow = $('.skillRow').first().clone(); | |
newSkillRow.find("td").each(function(index, el) { | |
el.id = el.id.replace(toReplace, replaceWith); | |
$(el).attr('class', 'skillBox skillUnset skillAvailable'); | |
}); | |
newSkillRow.appendTo(primalRoarSkillRow); | |
$("div[abilityName^='attribute_bonus']").appendTo('#skillBuildContent'); | |
$('.unusedSkills').appendTo('#skillBuildContent'); | |
$('#skillBuildContent .skillTable').off('mouseup', '.skillBox'); | |
} | |
window.attemptPageLoad = function() { | |
var doLoad = false; | |
if (g_abilityDataLoaded && g_heroDataLoaded && g_itemDataLoaded && g_itemLocationLoaded) { | |
doLoad = true; | |
} | |
if(!doLoad) { return; } | |
initItemTooltips( g_itemTooltips ); | |
initAbilityTooltips( g_abilityTooltips ); | |
// Init our edit elements | |
initItemBuildPanel( g_items ); | |
if(g_hero === 38) { fixBeastmasterUlt(); } // fix beastmaster ult | |
initSkillBuildElements( NUM_ROWS ); | |
addTooltipHinting( true ); | |
setupTooltipInsertion(); | |
highlightTooltipItems(); | |
// Hide our spinners | |
$('#itemSpinner').hide(); | |
$("#loadingText").hide(); | |
showBlackoutCurtain( false ); | |
} | |
window.populateItems = function(initData) { | |
addUpgradeableItems(); | |
// Default parameter | |
initData = typeof initData !== 'undefined' ? initData : null; | |
// Fade the loading spinner out | |
$("#itemLoadingIcon").fadeOut( 500, function() { $(this).remove(); } ); | |
// First, create columns that items should be sorted into | |
var numKeys = 1; | |
for ( var key in g_GuideBuilder.items.locations ) { | |
if ( !g_GuideBuilder.items.locations.hasOwnProperty(key) ) | |
continue; | |
// Create a new column to place these items into | |
var newColumn = $("<div id=col_"+key+" class='shopColumn'></div>"); | |
// Look up our category image in our column map | |
if ( SHOP_COLUMN_MAP.hasOwnProperty( key ) ) { | |
var imageName = 'http://cdn.dota2.com/apps/dota2/images//heropedia/' + SHOP_COLUMN_MAP[key]; | |
$("<div class='columnImage'></div>") | |
.css( "background-image", "url("+imageName+")" ) | |
.attr( "title", key.toUpperCase() ) | |
.appendTo( newColumn ); | |
} | |
// Now, add each item into the column in turn | |
for ( var i = 0; i < g_GuideBuilder.items.locations[key].length; i++ ) { | |
var itemData = g_GuideBuilder.items.data[g_GuideBuilder.items.locations[key][i]]; | |
var elementCode = "<div class='itemImage draggableSource shrink'></div>"; | |
imageName = 'http://cdn.dota2.com/apps/dota2/images//items/' + itemData.img; | |
var newElement = $(elementCode); | |
newElement | |
.data({ itemData: itemData, key: g_GuideBuilder.items.locations[key][i] } ) | |
.css({ "background-image": "url("+imageName+")", | |
"filter": "progid:DXImageTransform.Microsoft.AlphaImageLoader( src='"+imageName+"', sizingMethod='scale')" } ) // IE FIX! | |
.appendTo( newColumn ) | |
.addClass( "itemIconWithTooltip" ) | |
.attr( "itemname", g_GuideBuilder.items.locations[key][i] ) | |
.removeAttr( 'title' ); | |
makeDraggableSource( newElement ); | |
} | |
// Finally, place it into the DOM | |
// $(newColumn).insertBefore( "#itemLoadingIcon" );/*.hide().delay( numKeys++*25 ).fadeIn( 500 );*/ | |
$(newColumn).appendTo( '#palettePanel' ); | |
} | |
// Finally, load our build items if we have it | |
if ( initData != null ) { | |
loadGuide( initData ); | |
} | |
} | |
function addUpgradeableItems() { | |
// dagon | |
let itemName = 'dagon', | |
itemIndex = g_GuideBuilder.items.locations.caster.indexOf(itemName); | |
for(let i=2; i<=5; i++) { | |
g_GuideBuilder.items.locations.caster.splice(itemIndex+1, 0, itemName + '_' + i); | |
itemIndex++; | |
} | |
// necronomicon | |
itemName = 'necronomicon'; | |
itemIndex = g_GuideBuilder.items.locations.caster.indexOf(itemName); | |
for(let i=2; i<=3; i++) { | |
g_GuideBuilder.items.locations.caster.splice(itemIndex+1, 0, itemName + '_' + i); | |
itemIndex++; | |
} | |
// bots | |
itemName = 'travel_boots'; | |
itemIndex = g_GuideBuilder.items.locations.common.indexOf(itemName); | |
for(let i=2; i<=2; i++) { | |
g_GuideBuilder.items.locations.common.splice(itemIndex+1, 0, itemName + '_' + i); | |
itemIndex++; | |
} | |
// diffusal | |
itemName = 'diffusal_blade'; | |
itemIndex = g_GuideBuilder.items.locations.artifacts.indexOf(itemName); | |
for(let i=2; i<=2; i++) { | |
g_GuideBuilder.items.locations.artifacts.splice(itemIndex+1, 0, itemName + '_' + i); | |
itemIndex++; | |
} | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment