Skip to content

Instantly share code, notes, and snippets.

@andersevenrud
Last active September 11, 2015 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andersevenrud/d9f3ae140a587106f21d to your computer and use it in GitHub Desktop.
Save andersevenrud/d9f3ae140a587106f21d to your computer and use it in GitHub Desktop.
Better Battlelog Loadout
// ==UserScript==
// @name Better Battlelog Loadout
// @namespace http://andersevenrud.github.io/
// @version 0.3
// @description Improves the Loadout screen in battlelog a bit
// @match http://battlelog.battlefield.com/*
// @updateURL https://gist.github.com/andersevenrud/d9f3ae140a587106f21d/raw/bbl.user.js
// @downloadURL https://gist.github.com/andersevenrud/d9f3ae140a587106f21d/raw/bbl.user.js
// @author andersevenrud
// ==/UserScript==
/*
=== INSTALLATION ===
1: Install Greasemonkey (Firefox) or Tampermonkey (Chrome) browser extension.
2: Click the "RAW" button on this gist and it should install automatically
3: Refresh battlelog and it should now work automatically when you browse your loadout
If it does not install automatically:
1: Go to battlelog, click the browser extension icon and choose to add a new file or script
2: Copy/Paste this file
3: Refresh battlelog and it should now work automatically when you browse your loadout
=== NOTES ===
This is just something I hacked in place, but it seems to work nicely (although the stats sort of just pops in)
=== SCREENSHOTS ===
http://i.imgur.com/mqlY94L.png
=== ALSO TAKE A LOOK AT ===
* Better Battlelog Favourite Server Browser
https://gist.github.com/andersevenrud/b49950126c344261ce17
* Bring Battlelog Hooahs back!
https://gist.github.com/andersevenrud/c4cf8ec40ed25c2ef2cf
* Battlelog Server Browser Blacklist
https://gist.github.com/andersevenrud/e275e0b600578bcf6e26
* Fullscreen Battlelog Server Browser (BF4)
https://gist.github.com/andersevenrud/c684dac238b87fdc8bda
=== LINKS ===
Reddit thread: http://www.reddit.com/r/battlefield_4/comments/2ujxkt/better_battlelog_loadout_more_info_in_comments/
*/
(function() {
function renderStat(name, weap) {
$(".category-group .box-content h1 span").each(function() {
var title = $(this).html();
if ( title === name ) {
var par = $(this).parents(".box").first();
if ( par && !par.hasClass("locked") ) {
var hk = ((weap.headshots / weap.kills) * 100).toFixed(1);
if ( isNaN(hk) ) { hk = (0.0).toFixed(1); }
var acc = ((weap.shotsHit / weap.shotsFired) * 100).toFixed(1);
if ( isNaN(acc) ) { acc = (0.0).toFixed(1); }
var stars = $("<div class=\"service-star-container custom-container\"><i class=\"service-star\">" + weap.serviceStars.toString() + "</i></div>");
stars.css({
position: "absolute",
bottom: "10px",
left: "10px"
});
stars.find("i").css({
"font-size": "14px",
"font-weight": 400
});
par.find(".items-select-item-content").append(stars);
var info = $("<div class=\"custom-container\">" + weap.kills.toString() + " kills | " + acc.toString() + " %ACC | " + hk.toString() + " %HK</div>");
info.css({
position : "absolute",
left : "10px",
top : "10px",
right : "10px",
"font-size": "11px",
"font-weight": "normal",
"text-align": "center"
});
par.find(".items-select-item-content").append(info);
$(par).parents(".loadout-item-grid").first().hover(function() {
stars.hide();
info.hide();
}, function() {
stars.show();
info.show();
});
}
}
});
}
function renderWeaponStats(list) {
$("#items-select-menu .custom-container").remove();
list.forEach(function(weap) {
var name = weap.name;
if ( Surface.translations[name] ) {
renderStat(Surface.translations[name], weap);
}
});
}
function getUser() {
var tmp = window.location.href.match(/\/bf4\/(.*)\/(.*)\/(.*)\/pc/);
if ( tmp.length >= 4 ) {
return {id: tmp[3], name: tmp[2]};
}
return null;
}
var busy = false;
function initStats() {
if ( busy ) { return; }
if ( !$("#items-select-menu").children().length ) {
//console.error("CANNOT INIT STATS");
return;
}
if ( $("#items-select-menu .custom-container").length ) {
return;
}
var user = getUser();
if ( user ) {
busy = true;
$.get("/bf4/warsawWeaponsPopulateStats/" + user.id + "/1/unlocks/", function(response) {
if ( response && response.data ) {
if ( response.data.mainWeaponStats ) {
renderWeaponStats(response.data.mainWeaponStats);
}
}
busy = false;
});
}
}
setInterval(function() {
initStats();
}, 250);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment