public
Last active

EA Battlelog BF3 misc hacks

  • Download Gist
battlelog-bf3-misc.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
/* EA Battlelog BF3 misc hacks
* http://benalman.com/
* Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT, GPL */
 
// What does it do?
//
// * Auto-retries server join so you don't have to spam the button.
// (close the Game Manager error popup to cancel the auto-join)
//
// What might it do in the future?
//
// * Remember server browser sorting preference.
// * Prevent the server browser from jumping to the top on refresh.
// * Possibly other stuff related to server browsing / joining.
//
// Notes
//
// * This is a work in progress.
// * This is tested only in Chrome 14.
// * It works for me.
 
(function() {
var join, id;
 
// Create an element to contain auto-retry status text.
var retryStatus = $("<span/>");
 
// Override existing "join" methods.
["joinMpServer", "joinMpFriend"].forEach(function(method) {
var orig = launcher[method];
launcher[method] = function() {
// Stop auto-retrying.
unretry();
// An easily-re-callable "join" function with arguments already applied.
join = orig.apply.bind(orig, this, arguments);
// Attempt to join and return result.
return join();
};
});
 
// Override existing error handler method.
var _triggerEvent = launcher._triggerEvent;
launcher._triggerEvent = function(type, details) {
// Call original function.
var result = _triggerEvent.apply(this, arguments);
// Auto-retry only on errors.
if (type === "error.generic") {
console.log("Starting auto-retry countdown.", details);
// Start countdown
retry();
}
return result;
};
 
// Start auto-retrying.
function retry() {
// Stop any currently executing auto-retry loop.
unretry(true);
 
// 10-seconds seems like a good number.
var count = 10;
 
// Attach status element to the DOM.
retryStatus.appendTo(".gamemanager-launchstate-gameready");
function update() {
// Update status text.
retryStatus.html(" (Auto-retry&nbsp;in&nbsp;" + count + ")");
// If counter has reached 0, stop auto-retrying and join.
if (count-- === 0) {
console.log("Retrying now.");
unretry(true);
join();
}
}
// Start counter.
update();
id = setInterval(update, 1000);
}
// Stop auto-retrying.
function unretry(silent) {
if (!id) { return; }
console.log("Stopping auto-retry.");
// Actually stop the auto-retry.
clearInterval(id);
id = null;
// Detach the status element from the DOM and empty it.
retryStatus.detach().empty();
}
 
// If use clicks "Close" button in "Could not join..." dialog, stop
// auto-retrying.
$(document).delegate("#gamemanager-state-close", "click", unretry);
 
console.log("Loaded EA Battlelog BF3 misc hacks.");
 
gamemanager.showLoaderError("A new version of Battlelog Hacks has been released. Visit http://gul.ly/d5m to upgrade!");
}());
battlelog.user.js
JavaScript
1 2 3 4 5 6 7
// ==UserScript==
// @match http://battlelog.battlefield.com/bf3/*
// ==/UserScript==
 
var elem = document.createElement("script");
elem.src = "https://raw.github.com/gist/1323950/battlelog-bf3-misc.js";
document.body.appendChild(elem);
debug.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// A little debugging help.
 
function inspect(context, prop) {
var obj = context[prop];
Object.keys(obj).filter(function(key) {
return typeof obj[key] === "function";
}).forEach(function(key) {
var name = prop + "." + key;
var orig = obj[key];
console.log("inspecting: " + name);
obj[key] = function() {
console.log.apply(console, [name].concat([].slice.call(arguments)));
return orig.apply(this, arguments);
};
});
}
 
inspect(window, "launcher");

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.