Skip to content

Commit

Permalink
Updating to v0.3.4: Com center online friends are always shown by def…
Browse files Browse the repository at this point in the history
…ault, while offline friends are always hidden by default.
  • Loading branch information
cowboy committed Feb 27, 2012
1 parent 14ff7a0 commit 2282972
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 61 deletions.
2 changes: 1 addition & 1 deletion LICENSE-MIT
@@ -1,4 +1,4 @@
Copyright (c) 2011 "Cowboy" Ben Alman Copyright (c) 2012 "Cowboy" Ben Alman


Permission is hereby granted, free of charge, to any person Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation obtaining a copy of this software and associated documentation
Expand Down
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -105,7 +105,11 @@ Bugfix: When the server list is refreshed or sorted, the first server is now bot
v0.3.3 v0.3.3
Com center online friends now default to shown, while offline friends default to hidden. Com center online friends now default to shown, while offline friends default to hidden.


2/26/2011
v0.3.4
Com center online friends are always shown by default, while offline friends are always hidden by default.

## License ## License
Copyright (c) 2011 "Cowboy" Ben Alman Copyright (c) 2012 "Cowboy" Ben Alman
Licensed under the MIT license. Licensed under the MIT license.
<http://benalman.com/about/license/> <http://benalman.com/about/license/>
2 changes: 1 addition & 1 deletion dev/battlelog-hacks-dev.user.js
Expand Up @@ -5,7 +5,7 @@


/* Battlelog Hacks /* Battlelog Hacks
* http://benalman.com/ * http://benalman.com/
* Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT */ * Copyright (c) 2012 "Cowboy" Ben Alman; Licensed MIT */


var elem = document.createElement("script"); var elem = document.createElement("script");
elem.src = "http://localhost:8000/"; elem.src = "http://localhost:8000/";
Expand Down
2 changes: 1 addition & 1 deletion dev/src/bh-ajaxnavigation-scrolltop.js
@@ -1,6 +1,6 @@
/* Battlelog Hacks /* Battlelog Hacks
* http://benalman.com/ * http://benalman.com/
* Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT */ * Copyright (c) 2012 "Cowboy" Ben Alman; Licensed MIT */


cowboy.register("Suppress scrollTop on serverlist refresh"); cowboy.register("Suppress scrollTop on serverlist refresh");


Expand Down
30 changes: 8 additions & 22 deletions dev/src/bh-comcenter-friends.js
@@ -1,44 +1,30 @@
/* Battlelog Hacks /* Battlelog Hacks
* http://benalman.com/ * http://benalman.com/
* Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT */ * Copyright (c) 2012 "Cowboy" Ben Alman; Licensed MIT */


cowboy.register("Remember Com center friends list state"); cowboy.register("Initialize Com center friends list state");


(function() { (function() {
// The comcenter.updateLocalStorage method seems to be called whenever the
// online and offline friends lists are opened or closed.
cowboy.hooker.hook(comcenter, "updateLocalStorage", {
post: function() {
// Get the current com center friends list state.
var state = $S("comcenter-surface-friends").getState();
// Store state for later use.
localStorage.setItem("cb_show_friends_online", state.showingOnline);
localStorage.setItem("cb_show_friends_offline", state.showingOffline);
}
});

// Get the current Battlelog com center friends list state object. // Get the current Battlelog com center friends list state object.
var state = $S("comcenter-surface-friends").getState(); var state = $S("comcenter-surface-friends").getState();


// Fix state, logging if it actually needed to be fixed.. // Fix state, logging if it actually needed to be fixed..
function fix(mode, s) { function fix(mode, s) {
// Update the Battlelog state object showingOnline/showingOffline prop. // Update the Battlelog state object showingOnline/showingOffline prop.
state["showing" + mode[0].toUpperCase() + mode.slice(1)] = s; state["showing" + mode] = s;
// If the currently displayed state doesn't reflect the expected state... // If the currently displayed state doesn't reflect the expected state...
mode = mode.toLowerCase();
if (Boolean($(".comcenter-friend-" + mode + ":visible").length) !== s) { if (Boolean($(".comcenter-friend-" + mode + ":visible").length) !== s) {
// Log to the console.
cowboy.log("Com center " + mode + " friends list should have been " +
(s ? "visible" : "hidden") + " but wasn't, fixing.");
// Actually hide or show the friends list in the DOM. // Actually hide or show the friends list in the DOM.
$("#comcenter-" + mode + "-separator").toggleClass("showing-" + mode, s); $("#comcenter-" + mode + "-separator").toggleClass("showing-" + mode, s);
$(".comcenter-friend-" + mode).toggleClass("comcenter-friend-hidden", !s); $(".comcenter-friend-" + mode).toggleClass("comcenter-friend-hidden", !s);
} }
} }


// Fix both online and offline state. Online defaults to shown, while offline // Instead of attempting to store and restore state, always start with Online
// defaults to hidden. // friends opened and Offline friends closed. It's just easier that way.
fix("online", localStorage.getItem("cb_show_friends_online") !== "false"); fix("Online", true);
fix("offline", localStorage.getItem("cb_show_friends_offline") === "true"); fix("Offline", false);


// Force Battlelog to update its internal state objects. // Force Battlelog to update its internal state objects.
comcenter.updateLocalStorage(); comcenter.updateLocalStorage();
Expand Down
2 changes: 1 addition & 1 deletion dev/src/bh-launcher-retry.js
@@ -1,6 +1,6 @@
/* Battlelog Hacks /* Battlelog Hacks
* http://benalman.com/ * http://benalman.com/
* Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT */ * Copyright (c) 2012 "Cowboy" Ben Alman; Licensed MIT */


cowboy.register("Auto-retry join server"); cowboy.register("Auto-retry join server");


Expand Down
2 changes: 1 addition & 1 deletion dev/src/bh-serverguidesort-select.js
@@ -1,6 +1,6 @@
/* Battlelog Hacks /* Battlelog Hacks
* http://benalman.com/ * http://benalman.com/
* Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT */ * Copyright (c) 2012 "Cowboy" Ben Alman; Licensed MIT */


cowboy.register("Auto-select first server"); cowboy.register("Auto-select first server");


Expand Down
4 changes: 2 additions & 2 deletions dev/src/intro.js
@@ -1,10 +1,10 @@
/* Battlelog Hacks /* Battlelog Hacks
* http://benalman.com/ * http://benalman.com/
* Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT */ * Copyright (c) 2012 "Cowboy" Ben Alman; Licensed MIT */


// Global namespace. // Global namespace.
window.cowboy = { window.cowboy = {
version: "0.3.3", version: "0.3.4",
registry: [], registry: [],
register: function(name) { register: function(name) {
cowboy.registry.push(name); cowboy.registry.push(name);
Expand Down
2 changes: 1 addition & 1 deletion dev/src/log.js
@@ -1,6 +1,6 @@
/* Battlelog Hacks /* Battlelog Hacks
* http://benalman.com/ * http://benalman.com/
* Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT */ * Copyright (c) 2012 "Cowboy" Ben Alman; Licensed MIT */


// ========================================================================== // ==========================================================================
// Logging // Logging
Expand Down
2 changes: 1 addition & 1 deletion dev/src/outro.js
@@ -1,5 +1,5 @@
/* Battlelog Hacks /* Battlelog Hacks
* http://benalman.com/ * http://benalman.com/
* Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT */ * Copyright (c) 2012 "Cowboy" Ben Alman; Licensed MIT */


cowboy.loaded(); cowboy.loaded();
40 changes: 12 additions & 28 deletions dist/battlelog-hacks.js
@@ -1,10 +1,10 @@
/* Battlelog Hacks /* Battlelog Hacks
* http://benalman.com/ * http://benalman.com/
* Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT */ * Copyright (c) 2012 "Cowboy" Ben Alman; Licensed MIT */


// Global namespace. // Global namespace.
window.cowboy = { window.cowboy = {
version: "0.3.3", version: "0.3.4",
registry: [], registry: [],
register: function(name) { register: function(name) {
cowboy.registry.push(name); cowboy.registry.push(name);
Expand All @@ -18,13 +18,11 @@ window.cowboy = {
// Hooker. // Hooker.
var exports = cowboy.hooker = {}; var exports = cowboy.hooker = {};


/* JavaScript Hooker - v0.2.2 - 11/5/2011 /*! JavaScript Hooker - v0.2.3 - 1/22/2012
* http://github.com/cowboy/javascript-hooker * http://github.com/cowboy/javascript-hooker
* Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT, GPL */ * Copyright (c) 2012 "Cowboy" Ben Alman; Licensed MIT */


(function(exports) { (function(exports) {
// Since undefined can be overwritten, an internal reference is kept.
var undef;
// Get an array from an array-like object with slice.call(arrayLikeObject). // Get an array from an array-like object with slice.call(arrayLikeObject).
var slice = [].slice; var slice = [].slice;
// Get an "[object [[Class]]]" string with toString.call(value). // Get an "[object [[Class]]]" string with toString.call(value).
Expand Down Expand Up @@ -394,43 +392,29 @@ cowboy.register("Auto-select first server");
} }
}()); }());


cowboy.register("Remember Com center friends list state"); cowboy.register("Initialize Com center friends list state");


(function() { (function() {
// The comcenter.updateLocalStorage method seems to be called whenever the
// online and offline friends lists are opened or closed.
cowboy.hooker.hook(comcenter, "updateLocalStorage", {
post: function() {
// Get the current com center friends list state.
var state = $S("comcenter-surface-friends").getState();
// Store state for later use.
localStorage.setItem("cb_show_friends_online", state.showingOnline);
localStorage.setItem("cb_show_friends_offline", state.showingOffline);
}
});

// Get the current Battlelog com center friends list state object. // Get the current Battlelog com center friends list state object.
var state = $S("comcenter-surface-friends").getState(); var state = $S("comcenter-surface-friends").getState();


// Fix state, logging if it actually needed to be fixed.. // Fix state, logging if it actually needed to be fixed..
function fix(mode, s) { function fix(mode, s) {
// Update the Battlelog state object showingOnline/showingOffline prop. // Update the Battlelog state object showingOnline/showingOffline prop.
state["showing" + mode[0].toUpperCase() + mode.slice(1)] = s; state["showing" + mode] = s;
// If the currently displayed state doesn't reflect the expected state... // If the currently displayed state doesn't reflect the expected state...
mode = mode.toLowerCase();
if (Boolean($(".comcenter-friend-" + mode + ":visible").length) !== s) { if (Boolean($(".comcenter-friend-" + mode + ":visible").length) !== s) {
// Log to the console.
cowboy.log("Com center " + mode + " friends list should have been " +
(s ? "visible" : "hidden") + " but wasn't, fixing.");
// Actually hide or show the friends list in the DOM. // Actually hide or show the friends list in the DOM.
$("#comcenter-" + mode + "-separator").toggleClass("showing-" + mode, s); $("#comcenter-" + mode + "-separator").toggleClass("showing-" + mode, s);
$(".comcenter-friend-" + mode).toggleClass("comcenter-friend-hidden", !s); $(".comcenter-friend-" + mode).toggleClass("comcenter-friend-hidden", !s);
} }
} }


// Fix both online and offline state. Online defaults to shown, while offline // Instead of attempting to store and restore state, always start with Online
// defaults to hidden. // friends opened and Offline friends closed. It's just easier that way.
fix("online", localStorage.getItem("cb_show_friends_online") !== "false"); fix("Online", true);
fix("offline", localStorage.getItem("cb_show_friends_offline") === "true"); fix("Offline", false);


// Force Battlelog to update its internal state objects. // Force Battlelog to update its internal state objects.
comcenter.updateLocalStorage(); comcenter.updateLocalStorage();
Expand Down
2 changes: 1 addition & 1 deletion dist/battlelog-hacks.user.js
Expand Up @@ -5,7 +5,7 @@


/* Battlelog Hacks /* Battlelog Hacks
* http://benalman.com/ * http://benalman.com/
* Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT */ * Copyright (c) 2012 "Cowboy" Ben Alman; Licensed MIT */


var elem = document.createElement("script"); var elem = document.createElement("script");
elem.src = "https://raw.github.com/cowboy/battlelog-hacks/master/dist/battlelog-hacks.js"; elem.src = "https://raw.github.com/cowboy/battlelog-hacks/master/dist/battlelog-hacks.js";
Expand Down

0 comments on commit 2282972

Please sign in to comment.