Permalink
Browse files

Get newtabicons working, which required some cleanup.

Also, bump to version 0.4.
  • Loading branch information...
1 parent 67f9cbc commit 4d93c70a0ea3f083ac544390ecab3d8100a7a5b2 @bwinton committed Feb 22, 2013
Showing with 80 additions and 23 deletions.
  1. +2 −1 .gitignore
  2. +17 −0 data/newtabicons-content.js
  3. +26 −4 lib/etherpad.js
  4. +21 −16 lib/newtabicons.js
  5. +0 −1 lib/ponami.js
  6. +1 −0 lib/urlbar.js
  7. +1 −1 package.json
  8. +12 −0 volofile
View
@@ -1,3 +1,4 @@
package.json.backup
.DS_Store
-whimsy.xpi
+whimsy.xpi
+whimsy.update.rdf
@@ -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] + '")';
+}
View
@@ -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;
},
@@ -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;
}
@@ -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;
}
});
View
@@ -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) {
View
@@ -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",
View
@@ -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 () {
View
@@ -36,7 +36,7 @@
"bugs": {},
"amd": {},
"repository": {},
- "version": "0.1",
+ "version": "0.4",
"contributors": [],
"fullName": "whimsy",
"id": "jid1-6mUPixNFCjAgkg",
View
@@ -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.