Skip to content

Commit

Permalink
Get newtabicons working, which required some cleanup.
Browse files Browse the repository at this point in the history
Also, bump to version 0.4.
  • Loading branch information
bwinton committed Feb 22, 2013
1 parent 67f9cbc commit 4d93c70
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 23 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package.json.backup
.DS_Store
whimsy.xpi
whimsy.xpi
whimsy.update.rdf
17 changes: 17 additions & 0 deletions data/newtabicons-content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*jshint forin:true, noarg:true, noempty:true, eqeqeq:true, bitwise:true,
strict:true, undef:true, curly:true, browser:true, es5:true, esnext:true,
indent:2, maxerr:50, devel:true, node:true, boss:true, white:true,
globalstrict:true, nomen:false, newcap:true*/

/*global self:true, addon:true, dump:true */

"use strict";

var thumbnails = window.document.getElementsByClassName('newtab-thumbnail');
dump("\n\nBW: Got " + thumbnails.length + " thumbnails!\n");

for (var i = 0; i < thumbnails.length; ++i) {
var thumbnail = thumbnails[i];
dump(self.options[i] + "\n");
thumbnail.style.backgroundImage = 'url("' + self.options[i] + '")';
}
30 changes: 26 additions & 4 deletions lib/etherpad.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ var Request = require('sdk/request').Request;

const Etherpad = Class({
initialize: function initialize(page) {
console.log("\n\nCreating Etherpad for " + page + "!!!\n\n");
this.PLACEHOLDERS = {};
this.page = page;
},
Expand All @@ -26,9 +25,11 @@ const Etherpad = Class({
},

loadPlaceholders: function () {
var self = this;
var etherpadRequest = new Request({
url: 'https://firefox-ux.etherpad.mozilla.org/ep/pad/export/' + this.page + '/latest?format=txt',
onComplete: function (response) {

if (response.status !== 200) {
return;
}
Expand All @@ -38,13 +39,34 @@ const Etherpad = Class({
}).filter(function (x) {
return !x.startsWith('#') && (x !== '');
});
this.PLACEHOLDERS = result;
self.PLACEHOLDERS = result;
}
}).get();
},

getItem: function (id) {
return this.PLACEHOLDERS[id % this.PLACEHOLDERS.length];
getItem: function (id, values) {
if (!values) {
values = this.PLACEHOLDERS;
}
return values[id % values.length];
},

getRandomItem: function () {
var id = Math.floor(Math.random() * this.PLACEHOLDERS.length);
return this.getItem(id);
},

getRandomItems: function (n) {
var rv = [];
var values = this.PLACEHOLDERS.slice(0);

for (var i = 0; i < n; ++i) {
var id = Math.floor(Math.random() * values.length);
var item = this.getItem(id, values);
values.splice(id, 1);
rv.push(item);
}
return rv;
}

});
Expand Down
37 changes: 21 additions & 16 deletions lib/newtabicons.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,44 @@

var Etherpad = require('./etherpad').Etherpad;
var etherpad = new Etherpad('thumbnail-gifs');
var pageMod = require('sdk/page-mod');
var prefs = require('simple-prefs');
var Request = require('sdk/request').Request;
var self = require('self');
var tabs = require('tabs');
var winutils = require('window/utils');

var mod = null;
var tracker = null;

etherpad.setDefaults([
'http://25.media.tumblr.com/tumblr_ma7rqzY6zQ1qis5xyo1_400.gif'
]);

var tabActivate = function (tab) {
var window = winutils.getMostRecentBrowserWindow();
var tabOpen = function (tab) {
if (!tab) {
tab = tabs.activeTab;
}
tab.on('ready', function (tab) {
if (tab.url === 'about:newtab') {
tab.attach({
contentScriptFile: self.data.url("newtabicons-content.js"),
contentScriptOptions: etherpad.getRandomItems(9)
});
}
});
};

var run = function () {
var window = winutils.getMostRecentBrowserWindow();
window.gURLBar.placeholder = etherpad.getItem(0);
etherpad.loadPlaceholders();
if (!mod) {
mod = pageMod.PageMod({
include: 'about:newtab',
contentScript: 'document.body.innerHTML = ' +
' "<h1>Page matches ruleset</h1>";'
// contentStyle: '.newtab-thumbnail { border: 3px solid red; }'
});
}
tabs.on('open', tabOpen);
tabOpen();
};

var stop = function () {
if (mod) {
mod.destroy();
mod = null;
}
tabs.removeListener('open', tabOpen);
var window = winutils.getMostRecentBrowserWindow();
window.gURLBar.placeholder = 'Search or enter address';
};

var listener = function (prefName) {
Expand Down
1 change: 0 additions & 1 deletion lib/ponami.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ var windowUtils = require("sdk/deprecated/window-utils");
let recorder= require("micropilot").Micropilot("ponamicode").start()

var tracker = null;
var about = null;

var code = [
"0:38", "0:38", "0:40", "0:40",
Expand Down
1 change: 1 addition & 0 deletions lib/urlbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var run = function () {
window.gURLBar.placeholder = etherpad.getItem(0);
etherpad.loadPlaceholders();
tabs.on('activate', tabActivate);
tabActivate(tabs.activeTab);
};

var stop = function () {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"bugs": {},
"amd": {},
"repository": {},
"version": "0.1",
"version": "0.4",
"contributors": [],
"fullName": "whimsy",
"id": "jid1-6mUPixNFCjAgkg",
Expand Down
12 changes: 12 additions & 0 deletions volofile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ module.exports = {
v.spawn('git', ['clone', module[2], module[1]]);
}
}
},
},

deploy: {
run: function (d, v, namedArgs, appName) {
v.sequence([
['cfx', 'xpi',
'--update-link', 'https://people.mozilla.com/~bwinton/whimsy/whimsy.xpi',
'--update-url', 'https://people.mozilla.com/~bwinton/whimsy/whimsy.update.rdf'],
[v, 'copyFile', 'whimsy.xpi', '/Volumes/people.mozilla.com/public_html/whimsy/whimsy.xpi'],
[v, 'copyFile', 'whimsy.update.rdf', '/Volumes/people.mozilla.com/public_html/whimsy/whimsy.update.rdf']
], {useConsole: !namedArgs.quiet});
}
}
};

0 comments on commit 4d93c70

Please sign in to comment.