Skip to content
This repository has been archived by the owner on Nov 12, 2022. It is now read-only.

Commit

Permalink
chrome: add avatars js call, pass avatars, display as loud & crazy mode!
Browse files Browse the repository at this point in the history
  • Loading branch information
gleuch committed Oct 20, 2011
1 parent d5862db commit d1f3b5a
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 14 deletions.
8 changes: 6 additions & 2 deletions chrome/css/protest/occupy.css
@@ -1,6 +1,10 @@
#occupyinternet_plaza {position: fixed !important; right: 0 !important; bottom: 0 !important; padding: 12px !important; margin: 0 !important;;}
#occupyinternet_plaza_area {position: relative !important; padding-right: 54px !important; text-align: right !important;}
#occupyinternet_plaza .occupyinternet_protester {display: inline-block !important; width: 16px !important; height: 16px !important; color: #fff !important; background: transparent !important; margin: 6px !important;}

#occupyinternet_plaza .occupyinternet_protester_peaceful {width: 16px !important; height: 16px !important; margin: 2px !important;}
#occupyinternet_plaza .occupyinternet_protester_loud {width: 24px !important; height: 24px !important; margin: 6px !important; background: #ff0 !important;}
#occupyinternet_plaza #occupyinternet_logo {position: absolute !important; bottom: 4px !important; right: 0 !important; display: inline-block !important; width: 48px !important; height: 48px !important;}

#occupyinternet_plaza.occupyinternet_is_loud {left: 0 !important;}
#occupyinternet_plaza .occupyinternet_protester_loud {position: absolute !important; width: auto !important; height: auto !important; margin: 6px !important; background: transparent !important;}

#occupyinternet_plaza #occupyinternet_logo {position: absolute !important; bottom: 4px !important; right: 0 !important; display: inline-block !important; width: 48px !important; height: 48px !important; z-index: 1000;}
17 changes: 16 additions & 1 deletion chrome/js/api.js
Expand Up @@ -10,11 +10,26 @@
*/


OccupyInternet.API = {

avatars : function(opts) {
var defaults = {success : function(msg) {eval('OccupyInternet.API._avatars('+ msg +');');}, error : function(a, b, c) {alert('e')}, data : {}},
requires = {url : localStorage.avatars_url, type : 'GET', dataType : 'text'}; // should be json, widget part is nightmare to make true json

if (!opts) opts = {};
opts = jQuery.extend({}, defaults, opts, requires);

jQuery.ajax(opts);
},

_avatars : function(msg) {
OccupyInternet.avatars = msg;
},

update : function(opts) {
var defaults = {success : function() {}, error : function() {}, data : {}},
requires = {url : localStorage.post_url, type : 'PUT', dataType : 'json'};
requires = {url : localStorage.post_url, type : 'POST', dataType : 'json'};

if (!opts) opts = {};
opts = jQuery.extend({}, defaults, opts, requires);
Expand Down
13 changes: 10 additions & 3 deletions chrome/js/init.js
Expand Up @@ -22,6 +22,9 @@ var OccupyInternet = {
OccupyInternet.ContextMenu.init();
OccupyInternet.Windows.init();
OccupyInternet.Tabs.init();

OccupyInternet.API.avatars();
setInterval(OccupyInternet.API.avatars, 900000); // 15min
},

settings : function() {
Expand All @@ -30,12 +33,16 @@ var OccupyInternet = {

if (OccupyInternet.dev_mode) {
localStorage.app_url = 'http://localhost:4567';
localStorage.api_url = 'http://localhost:4568';
} else {
localStorage.app_url = 'http://api.occupyinter.net';
localStorage.app_url = 'http://occupyinter.net';
localStorage.api_url = 'http://api.occupyinter.net';
}

localStorage.post_url = localStorage.app_url +'/count.json';
localStorage.get_url = localStorage.app_url + '/site.json';

localStorage.avatars_url = localStorage.app_url +'/avatars.json';
localStorage.post_url = localStorage.api_url +'/join_protest.json';
localStorage.get_url = localStorage.api_url + '/site.json';
},

enabled : function() {return (localStorage.mode != 'quiet');},
Expand Down
4 changes: 2 additions & 2 deletions chrome/js/protest.js
Expand Up @@ -50,7 +50,7 @@ OccupyInternet.Protest = {
OccupyInternet.Tabs.tabs[tab.id].injected = true;

var count = OccupyInternet.Tabs.tabs[tab.id].visits,
code = "OccupyInternetPage.count = "+ count +";OccupyInternetPage.fetched = true; OccupyInternetPage.mode = '"+ OccupyInternet.mode() +"';";
code = "OccupyInternetPage.count = "+ count +";OccupyInternetPage.avatars = "+ jQuery.toJSON(OccupyInternet.avatars) +";OccupyInternetPage.fetched = true; OccupyInternetPage.mode = '"+ OccupyInternet.mode() +"';";

// Additional customizations
if (!!OccupyInternet.dev_mode) code += "OccupyInternetPage.dev_mode = true;";
Expand All @@ -64,7 +64,7 @@ OccupyInternet.Protest = {
},

update_mode : function(tabid) {
var code = "if (typeof(OccupyInternetPage) != 'undefined') {OccupyInternetPage.mode = '"+ OccupyInternet.mode() +"'; OccupyInternetPage.switch_mode();}";
var code = "if (typeof(OccupyInternetPage) != 'undefined') {OccupyInternetPage.avatars = "+ jQuery.toJSON(OccupyInternet.avatars) +";OccupyInternetPage.mode = '"+ OccupyInternet.mode() +"'; OccupyInternetPage.switch_mode();}";
chrome.tabs.executeScript(parseInt(tabid), {code:code}, function() {});
},

Expand Down
26 changes: 20 additions & 6 deletions chrome/js/protest/occupy.js
Expand Up @@ -3,6 +3,7 @@ try {$.noConflict();} catch(e) {} // Play nice!

if (typeof(OccupyInternetPage) == 'undefined') {
var OccupyInternetPage = {
avatars : [],
count : 0,
mode : 'quiet',
dev_mode : false,
Expand All @@ -13,7 +14,7 @@ if (typeof(OccupyInternetPage) == 'undefined') {
get_url : 'http://api.occupyinter.net/site.json'
};

jQuery('.occupyinternet').remove();
jQuery('.occupyinternet, #occupy-widget').remove();
}


Expand Down Expand Up @@ -52,9 +53,15 @@ jQuery.extend(true, OccupyInternetPage, {
OccupyInternetPage.gathered = true;

OccupyInternetPage._add_logo();
var count = OccupyInternetPage.count;
if (OccupyInternetPage.mode == 'loud') {
jQuery('#occupyinternet_plaza').addClass('occupyinternet_is_loud');
count = (OccupyInternetPage.avatars.length < 10 ? OccupyInternetPage.avatars.length : 10);
OccupyInternetPage.avatars.sort(function(){ return 0.5 - Math.random() });
}

for (var i=0; i<OccupyInternetPage.count; i++) {
OccupyInternetPage._add_protester();
for (var i=0; i<count; i++) {
OccupyInternetPage._add_protester(i);
}
}
},
Expand All @@ -67,13 +74,14 @@ jQuery.extend(true, OccupyInternetPage, {
jQuery('#occupyinternet_logo').attr('title', 'OccupyInter.net - '+ OccupyInternetPage.phrase());
},

_add_protester : function() {
_add_protester : function(i) {
if (OccupyInternetPage.mode == 'peaceful') {
setTimeout(function() {
jQuery('#occupyinternet_plaza_area').append(OccupyInternetPage.html.peaceful_protester.replace(/\?rnd/, '?'+Math.floor(Math.random()*1000)));
}, Math.floor(Math.random()*1500));
} else if (OccupyInternetPage.mode == 'loud') {
jQuery('#occupyinternet_plaza_area').append(OccupyInternetPage.html.loud_protester);
var src = OccupyInternetPage.avatars[i].avatar, b = 10, l = left = (i*150)-50, z = (100+Math.floor(Math.random()*20));
jQuery('#occupyinternet_plaza_area').append(OccupyInternetPage.html.loud_protester.replace(/(\#\{src\})/m, src).replace(/(\#\{b\})/m, b).replace(/(\#\{l\})/m, l).replace(/(\#\{z\})/m, z) );
}
},

Expand All @@ -94,8 +102,14 @@ jQuery.extend(true, OccupyInternetPage, {
var diff = (num - OccupyInternetPage.count);
OccupyInternetPage.count = num;

jQuery('#occupyinternet_plaza').removeClass('occupyinternet_is_loud');
jQuery('#occupyinternet_logo').attr('title', OccupyInternetPage.phrase());

if (OccupyInternetPage.mode == 'loud') {
jQuery('#occupyinternet_plaza').addClass('occupyinternet_is_loud');
OccupyInternetPage.avatars.sort(function(){ return 0.5 - Math.random() });
}

for (var i=0; i<Math.abs(diff); i++) {
if (diff > 0) {
OccupyInternetPage._add_protester();
Expand All @@ -122,7 +136,7 @@ jQuery.extend(true, OccupyInternetPage, {

html : {
peaceful_protester : '<span class="occupyinternet occupyinternet_protester occupyinternet_protester_peaceful"><img class="occupyinternet" src="'+ chrome.extension.getURL('images/protester16.gif') +'?rnd" title="" alt="" /></span>',
loud_protester : '<span class="occupyinternet occupyinternet_protester occupyinternet_protester_loud">!!!</span>',
loud_protester : '<img class="occupyinternet occupyinternet_protester occupyinternet_protester_loud" style="bottom: #{b}px !important; left: #{l}px !important; z-index: #{z} !important;" src="#{src}" />',
logo : '<a href="http://occupyinter.net" target="_blank" class="occupyinternet occupyinternet_logo"><img class="occupyinternet" id="occupyinternet_logo" src="'+ chrome.extension.getURL('images/net_protester48.gif') +'" title="OccupyInter.net" alt="" /></a>',
liberty_plaza : '<div id="occupyinternet_plaza" class="occupyinternet"><div class="occupyinternet" id="occupyinternet_plaza_area"></div></div>',
police : '',
Expand Down

0 comments on commit d1f3b5a

Please sign in to comment.