Table of Contents
Code of Anti-Paranoia Firefox Extension
Project site - This here is the code section.
How to get to the source
- Save the extension somewhere.
- Rename it to the extension
.zip. - Unzip it in a directory.
- Go into the directory
chrome. - Unzip
antiparanoia.jar - in
content\antiparanoia\, look at the fileantiparanoiaOverlay.js
How to repack the source
... after doing something with the code ...
- Update the changes into the zip
chrome/antiparanoia.jar(drag’n’drop should be enough) - Update the changes into the zip
chrome/anti-paranoia-0.3-fx.xpi.zip(drag’n’drop should be enough) - Rename it to the extension
.xpi - Drag it into Firefox.
The Files
This is quite the Hello world-extension
antiparanoiaOverlay.js
function dontPanic() {
var icon = "chrome://antiparanoia/skin/antiparanoiam.png";
var url = null;
var title = "Don't Panic";
var texts = new Array(6);
texts[0] = "Stay calm.";
texts[1] = "Everything is good.";
texts[2] = "No one is against you.";
texts[3] = "The world is a good place.";
texts[4] = "Nobody is watching you.";
texts[5] = "Everything will be much better soon.";
texts[6] = "It isn't your fault.";
var text = texts[ Math.round(Math.random()*(texts.length-1)) ];
var preferences = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
var mybranch = preferences.getDefaultBranch("antiparanoia.");
var timeMinimal = mybranch.getIntPref("minimaltime");
var timeRandomMax = mybranch.getIntPref("randommax");
if(timeMinimal<60000) timeMinimal = 60000;
if(timeRandomMax<0) timeMinimal = 0;
var timeoutTilNext = Math.round(Math.random()*timeRandomMax) + timeMinimal;
var alerts = Components.classes["@mozilla.org/alerts-service;1"].getService(Components.interfaces.nsIAlertsService);
alerts.showAlertNotification(icon, title, text, false, null, null);
setTimeout("dontPanic()",timeoutTilNext);
}
- As you can see, It it is very easy to add texts: just add a
texts[6] = .... - You can also see, how the randomness is made.
- And you can see, how the popup is made (i saw this it at forecastfox).
- At the end of the function, it recalls itself.