Made the button be automatically added the first time the extension is loaded.
[taboo.git] / chrome / taboo / content / overlay.js
blobea8c15858c396acaa03c41b503d42fe1edabe218
1 var npDebug = true;
2 var log = null;
3 var $ = function(x) { return document.getElementById(x); }
4 var tboPrefs = null;
6 function Taboo() {
7 const CC = Components.classes;
8 const CI = Components.interfaces;
9 const SVC = CC['@oy/taboo;1'].getService(CI.oyITaboo);
11 this.onclick = function(event) {
12 if (event.shiftKey) {
13 this.show();
15 else {
16 SVC.save(null);
19 this.show = function() {
20 openUILinkIn('chrome://taboo/content/start.xul', 'tab');
23 tboInstallInToolbar();
26 var taboo;
28 function taboo_init() {
29 if (npDebug) {
30 if (typeof(console)=="undefined") {
31 var t = Components.classes['@mozilla.org/consoleservice;1'].getService(Components.interfaces.nsIConsoleService)
32 log = function(x) { t.logStringMessage(x); }
34 else {
35 log = console.log;
38 else {
39 log = function(x) {};
41 tboPrefs = Cc['@mozilla.org/preferences-service;1'].getService(Ci.nsIPrefBranch);
42 taboo = new Taboo();
45 window.addEventListener("load", taboo_init, true);
47 // Check whether we installed the toolbar button already and install if not
48 function tboInstallInToolbar() {
49 // Make sure not to run this twice
50 if (!tboPrefs.getPrefType("extensions.taboo.setup")) {
51 if (!document.getElementById("taboo-toolbarbutton")) {
52 var insertBeforeBtn = "urlbar-container";
53 var toolbar = document.getElementById("nav-bar");
54 if (!toolbar) {
55 insertBeforeBtn = "button-junk";
56 toolbar = document.getElementById("mail-bar");
58 if (toolbar && "insertItem" in toolbar) {
59 var insertBefore = $(insertBeforeBtn);
60 log(insertBefore);
61 if (insertBefore && insertBefore.parentNode != toolbar)
62 insertBefore = null;
64 toolbar.insertItem("taboo-toolbarbutton", insertBefore, null, false);
66 toolbar.setAttribute("currentset", toolbar.currentSet);
67 document.persist(toolbar.id, "currentset");
70 tboPrefs.setBoolPref("extensions.taboo.setup", true);