Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
EA Battlelog BF3 misc hacks
/* 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!");
}());
// ==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);
// 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");
@cowboy
Owner

This has been replaced with a much newer, better version.

@brandond

Fantastic!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.