[Ext] userChrome.js

Announce and Discuss the Latest Theme and Extension Releases.
Locked
User avatar
aaron
Posts: 3130
Joined: November 4th, 2002, 8:49 pm
Location: Texas
Contact:

Post by aaron »

I'm trying to put both of these scripts together in my userchrome.js file but they keep conflicting one another... Either one will work or the other but not both at the same time. Could I get some advice?

Code: Select all

eval("OpenSearch = " + OpenSearch.toString().replace('window.open(defaultSearchURL, "_blank");', 'gBrowser.addTab(defaultSearchURL);'));

Code: Select all

/* :::::::: WindowHook :::::::: */
//by Zeniko http://forums.mozillazine.org/viewtopic.php?p=2169699#2169699
//allows userChrome.js to target all windows / not only the main window

function() {
  var WindowHook = {
    observe: function(aSubject, aTopic, aData) {
      if(!aSubject._WindowHook) {
        aSubject._WindowHook = this;
        aSubject.addEventListener("load", this.onLoad_window, false);
      }
    },

    onLoad_window: function() {
      this.removeEventListener("load", this._WindowHook.onLoad_window, false);
      var funcs = this._WindowHook.mFuncs[this.document.location.href] || null;
      if(funcs) {
        funcs.forEach(function(aFunc) { aFunc(this); }, this);
      }
      delete this._WindowHook;
    },

    register: function(aURL, aFunc) {
      if(!this.mFuncs) {
        this.mFuncs = {};
        Components.classes["@mozilla.org/observer-service;1"]
          .getService(Components.interfaces.nsIObserverService)
          .addObserver(this, "domwindowopened", false);
      }
      if(!this.mFuncs[aURL]) {
        this.mFuncs[aURL] = [];
      }
      this.mFuncs[aURL].push(aFunc);
    }
  };

  function moveThrobber(win, id) {
    var throbber = win.document.getElementById("throbber-box");
    throbber.style.backgroundColor = "transparent";
    throbber.style.backgroundImage = "none";

    var spring = win.document.createElement("toolbarspring");
    spring.setAttribute("flex", 1);

    var menubar = win.document.getElementById(id);
    menubar.appendChild(spring);
    menubar.appendChild(throbber);
  }

  //Mail window
  WindowHook.register("chrome://messenger/content/messenger.xul",
    function(aWindow) {
      moveThrobber(aWindow, "mailMenubar");
    }, false);

  //Composer window
  WindowHook.register("chrome://editor/content/editor.xul",
    function(aWindow) {
      moveThrobber(aWindow, "main-menubar");
    }, false);

  //Address Book window
  WindowHook.register("chrome://messenger/content/addressbook/addressbook.xul",
    function(aWindow) {
      moveThrobber(aWindow, "ab-menubar");
    }, false);

  //Mail Compose window
  WindowHook.register("chrome://messenger/content/messengercompose/messengercompose.xul",
    function(aWindow) {
      moveThrobber(aWindow, "compose-menubar");
    }, false);

  //Main window
  WindowHook.register("chrome://navigator/content/navigator.xul",
    function(aWindow) {
      moveThrobber(aWindow, "main-menubar");
    }, false);

  //Mail window
  document.getElementById("mailMenubar").appendChild(document.getElementById("throbber-box"));
})();
User avatar
aaron
Posts: 3130
Joined: November 4th, 2002, 8:49 pm
Location: Texas
Contact:

Post by aaron »

Seems that I messed something up when trying to get both snippets to work... the second bit of code no longer moves the throbber up into the menu bar for SeaMonkey... If I could get some help debugging the current code (or better, cleaner code), I would really appreciate it!
Old Greg S
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post by Old Greg S »

I just now updated to FF 1.5.0.9 and none of my scripts are working. Any ideas?

Well nevermind. I wonder how these scripts were working before without userChrome.js installed? For what ever reason, I thought Chromedit plus had userChrome.js incorp. into it's extension. A few days ago I updated Chromedit plus with all scripts working and no userChrome.js installed. Today I updated FF to 1.5.0.9 with no userChrome.js installed and scripts quit working. On a whim I just now installed userChrome.js and all scripts are now working. Now I have to ask, how were they working before?
User avatar
JNewbry
Posts: 321
Joined: April 9th, 2005, 3:56 am
Location: Dallas,TX
Contact:

Post by JNewbry »

Hey Greg... Your looking for ChromEdit Plus SE... it includes the userChrome.js extension.

http://webdesigns.ms11.net/chromeditpSE.html

I just updated it too for 1.5 - 3.0a2
<a href="http://webdesigns.ms11.net/chromeditp.html" target="_blank">ChromEdit Plus</a> | <a href="http://webdesigns.ms11.net/winstripethemes.html" target="_blank">Firefox Themes</a>
User avatar
dougeeebear
Posts: 548
Joined: September 15th, 2005, 4:17 pm

Post by dougeeebear »

Jim,
Did you see the Sub-XUL Loader that pile0nades came up with?
It makes using xul a whole lot easier.
Of course I had to modify it to use the .xul files in my userChrome-XUL folder.
User avatar
JNewbry
Posts: 321
Joined: April 9th, 2005, 3:56 am
Location: Dallas,TX
Contact:

Post by JNewbry »

dougeeebear, I'm guilty of not paying much attention to this extension lately... Shame on ME!
I'll take a look at it... IF there is still use for the userChrome.xul tab in CEP & CEP SE, I'll leave things as they are... for now.

Thanks for pointing it out!
<a href="http://webdesigns.ms11.net/chromeditp.html" target="_blank">ChromEdit Plus</a> | <a href="http://webdesigns.ms11.net/winstripethemes.html" target="_blank">Firefox Themes</a>
User avatar
dougeeebear
Posts: 548
Joined: September 15th, 2005, 4:17 pm

Post by dougeeebear »

JNewbry wrote:IF there is still use for the userChrome.xul tab in CEP & CEP SE, I'll leave things as they are... for now.
I don't see any reason you would have to remove the tab.
If userChrome.xul doesn't exist the tab won't show up anyway, right? ;)

I just figured the sub-loader script was good food for thought.
Old Greg S
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post by Old Greg S »

JNewbry wrote:Hey Greg... Your looking for ChromEdit Plus SE... it includes the userChrome.js extension.

http://webdesigns.ms11.net/chromeditpSE.html

I just updated it too for 1.5 - 3.0a2

Hi Jim,
Somethings gone wrong then because the update updated my version as non SE if that makes sense and this would explain my scripts not working. Well now wait a minute, maybe there was no update notification in Extension Manager although I think there was. I may have updated from your site but am not for sure. I made a copy of my profile before updating so I guess I could put it back and see for sure which it was. I do know this, I had to install userChrome.js to get my scripts back working.
User avatar
DynaBMan
Posts: 383
Joined: November 15th, 2003, 9:46 pm
Location: Oklahoma

Post by DynaBMan »

I have just started using userchrome.js and I have a quick question. I am using the sub loader provided by the ChromeEditSE extension and am importing two scripts. One is the clock in the title bar and the other is the fashion tabs script. I open Firefox up with just one tab, my home page. I have noticed that the script doesn't take affect until I click on a link from my home page or until I open a page in a new tab. Is this the way it should work? It really doesn't amount to any trouble and I can easily live with it, I am just curious if that is how it should work. Thanks for your help.
LJ
My best friend is my wife!!
Political Realities
User avatar
DynaBMan
Posts: 383
Joined: November 15th, 2003, 9:46 pm
Location: Oklahoma

Post by DynaBMan »

One more quick question. I am using the code listed below to put the clock in the title bar of Firefox and Thunderbird. In Firefox, the title is not replaced. In Thunderbird, all I get is the date and clock. The title is missing. Any idea what could be the problem? Thanks again for your help.

Edit: Actually, the title flashes onto the title bar when I change folders and when the program starts up and then the date and time takes it's place. This happens also if Firefox, except for the fact that the title does not disappear. The date and time is just appended to the end of the title.

Code: Select all

function doTheClock() {
  var days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
  var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
  var title = content.document.title;
  window.setTimeout("try{doTheClock()}catch(ex){}", 1000 );
  var D = new Date();
  var day = days[D.getDay()];
  var month = months[D.getMonth()];
  var year = D.getFullYear();
  var hour = D.getHours();
  var minute = (D.getMinutes() <10> 12 ? hour - 12 : hour) + ":" + minute + (hour >= 12 ? "pm" : "am");
  var timestr = " - " + date + ", " + time;
  document.title = title + timestr;
}

doTheClock();
LJ
My best friend is my wife!!
Political Realities
Old Greg S
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post by Old Greg S »

DynaBMan wrote:One more quick question. I am using the code listed below to put the clock in the title bar of Firefox and Thunderbird. In Firefox, the title is not replaced. In Thunderbird, all I get is the date and clock. The title is missing. Any idea what could be the problem? Thanks again for your help.

Edit: Actually, the title flashes onto the title bar when I change folders and when the program starts up and then the date and time takes it's place. This happens also if Firefox, except for the fact that the title does not disappear. The date and time is just appended to the end of the title.


This should append to the title

Code: Select all

 function Clock() {
  var title = content.document.title;
  var days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
  var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
    var D = new Date();
    var day = days[D.getDay()];
    var month = months[D.getMonth()];
    var year = D.getFullYear();
    var hours = D.getHours();
    var min = D.getMinutes();
    var Time = ((hours > 12) ? hours - 12 :(hours == 0) ? 12 :hours);
    Time += ((min <10>= 12) ? " PM" : " AM";
    var date = "-  " + day + ", " + month + " " + D.getDate() + ", " + year;
    var timestr = date + "   " + Time;
    document.title = title + "   " + timestr;
    setTimeout("Clock()",1000);
  }

 Clock();



This should not

Code: Select all

 function Clock() {
  var title = content.document.title;
  var days = [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
  var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
    var D = new Date();
    var day = days[D.getDay()];
    var month = months[D.getMonth()];
    var year = D.getFullYear();
    var hours = D.getHours();
    var min = D.getMinutes();
    var Time = ((hours > 12) ? hours - 12 :(hours == 0) ? 12 :hours);
    Time += ((min <10>= 12) ? " PM" : " AM";
    var date = day + ", " + month + " " + D.getDate() + ", " + year;
    var timestr = date + "   " + Time;
    document.title = timestr;
    setTimeout("Clock()",1000);
  }

 Clock();
Last edited by Old Greg S on December 26th, 2006, 6:38 am, edited 1 time in total.
old zeniko
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post by old zeniko »

DynaBMan wrote:I have noticed that the script doesn't take affect until I click on a link from my home page or until I open a page in a new tab. Is this the way it should work?

This isn't the intended behavior -- but it can happen due to the way the sub-scripts are loaded (namely with a slight delay). To fix this issue for the Fashion Tabs script, try changing the first few lines to (note the added line)

Code: Select all

      Array.forEach(getBrowser().mTabs, function(aTab) {
         aTab.linkedBrowser.addProgressListener(this);
         this.colorizeTab(aTab);
      }, this);
User avatar
DynaBMan
Posts: 383
Joined: November 15th, 2003, 9:46 pm
Location: Oklahoma

Post by DynaBMan »

Well, the fashion tab problem is fixed, but the clock still insists on hiding the title in Thunderbird. If I change the entire code to what you have above, it doesn't work at all, either in Firefox or Thunderbird. I have noticed also that the day is wrong. It says Wed instead of Tues.
LJ
My best friend is my wife!!
Political Realities
Old Greg S
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post by Old Greg S »

DynaBMan wrote:Well, the fashion tab problem is fixed, but the clock still insists on hiding the title in Thunderbird. If I change the entire code to what you have above, it doesn't work at all, either in Firefox or Thunderbird. I have noticed also that the day is wrong. It says Wed instead of Tues.


When trying your code, I noticed the day was off by one day. I changed it in the code I posted. As for T'bird, I don't use it.
pile0nades
Posts: 756
Joined: May 15th, 2005, 2:31 am

Post by pile0nades »

Code: Select all

function Clock() {
    var title = content.document.title;
    var days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
    var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
    var D = new Date();
    var day = days[D.getDay()];
    var month = months[D.getMonth()];
    var year = D.getFullYear();
    var hours = D.getHours();
    var min = D.getMinutes();
    var sec = D.getSeconds();
    var Time = ((hours > 12) ? hours - 12 :(hours == 0) ? 12 :hours);
    Time += ((min < 10) ? ":0" : ":") + min;
    Time += ((sec < 10) ? ":0" : ":") + sec;
    Time += ((hours >= 12) ? " PM" : " AM");
    var date = "*   Greg's Firefox 1.5   *   " + day + ", " + month + " " + D.getDate() + ", " + year;
    var timestr = date + "   " + Time;
    document.getElementById("statusbar-display").setAttribute("label", timestr);
    setTimeout("Clock()", 100);
  }

Clock();


Does this work?
Linkify bug numbers - test: bug 258287
Locked