MozillaZine

[Ext] userChrome.js

Announce and Discuss the Latest Theme and Extension Releases.
aaron

User avatar
 
Posts: 3130
Joined: November 4th, 2002, 8:49 pm
Location: Texas

Post Posted December 20th, 2006, 4:02 pm

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"));
})();

aaron

User avatar
 
Posts: 3130
Joined: November 4th, 2002, 8:49 pm
Location: Texas

Post Posted December 20th, 2006, 4:47 pm

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 Posted December 20th, 2006, 9:27 pm

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?

JNewbry

User avatar
 
Posts: 321
Joined: April 9th, 2005, 3:56 am
Location: Dallas,TX

Post Posted December 21st, 2006, 6:49 am

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>

dougeeebear

User avatar
 
Posts: 548
Joined: September 15th, 2005, 4:17 pm

Post Posted December 21st, 2006, 7:10 am

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.

JNewbry

User avatar
 
Posts: 321
Joined: April 9th, 2005, 3:56 am
Location: Dallas,TX

Post Posted December 21st, 2006, 7:27 am

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>

dougeeebear

User avatar
 
Posts: 548
Joined: September 15th, 2005, 4:17 pm

Post Posted December 21st, 2006, 8:51 am

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 Posted December 21st, 2006, 4:48 pm

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.

DynaBMan

User avatar
 
Posts: 383
Joined: November 15th, 2003, 9:46 pm
Location: Oklahoma

Post Posted December 25th, 2006, 7:02 pm

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

DynaBMan

User avatar
 
Posts: 383
Joined: November 15th, 2003, 9:46 pm
Location: Oklahoma

Post Posted December 25th, 2006, 7:15 pm

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 Posted December 25th, 2006, 8:15 pm

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 Posted December 25th, 2006, 11:27 pm

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);

DynaBMan

User avatar
 
Posts: 383
Joined: November 15th, 2003, 9:46 pm
Location: Oklahoma

Post Posted December 26th, 2006, 4:38 am

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 Posted December 26th, 2006, 6:36 am

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 Posted December 26th, 2006, 11:16 am

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

Return to Extension/Theme Releases


Who is online

Users browsing this forum: No registered users and 5 guests