Created
October 29, 2011 01:09
-
-
Save cowboy/1323950 to your computer and use it in GitHub Desktop.
EA Battlelog BF3 misc hacks
This file contains 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
/* 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 in " + 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!"); | |
}()); |
This file contains 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== | |
// @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); |
This file contains 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
// 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"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fantastic!