[Ext] userChrome.js

Announce and Discuss the Latest Theme and Extension Releases.
Locked
Old Greg S
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post by Old Greg S »

pile0nades wrote:Use this as your userChrome.js file:

Code: Select all

/* :::::::: Sub-XUL/Script Loader ::::::::::::::: */

// automatically includes all files ending in .uc.xul and .uc.js from the profile's chrome folder

(function() {
  var chromeDir = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("UChrm", Components.interfaces.nsILocalFile);
  var files = chromeDir.directoryEntries.QueryInterface(Components.interfaces.nsISimpleEnumerator);
  if(files.hasMoreElements()) loadXULorJS(files);

  function loadXULorJS(files) {
    var file = files.getNext().QueryInterface(Components.interfaces.nsIFile);
    if (/(^userChrome|\.uc)\.xul$/i.test(file.leafName)) {
      document.loadOverlay(Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService).getProtocolHandler("file").QueryInterface(Components.interfaces.nsIFileProtocolHandler).getURLSpecFromFile(file), null);
    }
    else if(/\.uc\.js$/i.test(file.leafName)) {
      Components.classes["@mozilla.org/moz/jssubscript-loader;1"].getService(Components.interfaces.mozIJSSubScriptLoader).loadSubScript(Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService).getProtocolHandler("file").QueryInterface(Components.interfaces.nsIFileProtocolHandler).getURLSpecFromFile(file));
    }
    if(files.hasMoreElements()) setTimeout(loadXULorJS, 0, files);
  }
})();


I removed the top code because this sub-script loader will load a userChrome.xul file too, so with the top code, the file would have been loaded twice.


You're probably gonna kill me but using the above gives me nothing, meaning no .xul or .js that will work. I've tried on new profile, existing profile/s and my main profile without success. I'm trying to find out what it is that's causing it. I'll be the first to admit that it possibly could be my coding except for the fact that alot of the scripts/code came from users such as yourself, meaning yall know what you're doing.
pile0nades
Posts: 756
Joined: May 15th, 2005, 2:31 am

Post by pile0nades »

I've seen errors in one script cause other scripts not to work, so it might be that. Do you get any errors in the console?
Linkify bug numbers - test: bug 258287
User avatar
dougeeebear
Posts: 548
Joined: September 15th, 2005, 4:17 pm

Post by dougeeebear »

pile0nades wrote:I've seen errors in one script cause other scripts not to work

I have a "TEST.uc.js" file that I use for testing new scripts just for that reason.
When I'm sure the new script works ok, I will add it to my userChrome.js file (or some other .uc.js file).
old zeniko
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post by old zeniko »

pile0nades wrote:I've seen errors in one script cause other scripts not to work, so it might be that.

I've finally updated the <a href="data:text/javascript,/* :::::::: Sub-Script/XUL Loader ::::::::::::::: */%0A%0A// automatically includes all files ending in .uc.js and .uc.xul from the profile's chrome folder%0A%0A(function() {%0A%09var getURLSpecFromFile = Components.classes[">Sub-Script/XUL Loader</a> snippet to work for several XUL files while still loading all JS files (except those containing errors). Greg S and pile0nades, you might want to give this one a try...
max1million
Posts: 2810
Joined: November 15th, 2004, 5:03 am

Post by max1million »

Miccovin The script does what it designed for. It looks like it may be coded in the firefox.exe that auto display of Download Manager is always a window. Might be able to listen for the window to open then open a tab and close the window. A bit sloppy. Or leave window disabled and listen for start of download to open tab. Little cleaner approach in operation. But I'm not in for it, and apparently none else.
pile0nades
Posts: 756
Joined: May 15th, 2005, 2:31 am

Post by pile0nades »

zeniko wrote:
pile0nades wrote:I've seen errors in one script cause other scripts not to work, so it might be that.

I've finally updated the <a href="data:text/javascript,/* :::::::: Sub-Script/XUL Loader ::::::::::::::: */%0A%0A// automatically includes all files ending in .uc.js and .uc.xul from the profile's chrome folder%0A%0A(function() {%0A%09var getURLSpecFromFile = Components.classes[">Sub-Script/XUL Loader</a> snippet to work for several XUL files while still loading all JS files (except those containing errors). Greg S and pile0nades, you might want to give this one a try...


The code seems to be cut off:

Code: Select all

/* :::::::: Sub-Script/XUL Loader ::::::::::::::: */

// automatically includes all files ending in .uc.js and .uc.xul from the profile's chrome folder

(function() {
   var getURLSpecFromFile = Components.classes[
Linkify bug numbers - test: bug 258287
old zeniko
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post by old zeniko »

Oops, the quotation marks seem to have been unescaped when I copied the snippet from the first post. Here goes the complete snippet: <a href="data:text/javascript,/* :::::::: Sub-Script/XUL Loader ::::::::::::::: */%0A%0A// automatically includes all files ending in .uc.js and .uc.xul from the profile's chrome folder%0A%0A(function() {%0A%09var getURLSpecFromFile = Components.classes[%22@mozilla.org/network/io-service;1%22].getService(Components.interfaces.nsIIOService).getProtocolHandler(%22file%22).QueryInterface(Components.interfaces.nsIFileProtocolHandler).getURLSpecFromFile;%0A%09var chromeDir = Components.classes[%22@mozilla.org/file/directory_service;1%22].getService(Components.interfaces.nsIProperties).get(%22UChrm%22, Components.interfaces.nsILocalFile);%0A%09var files = chromeDir.directoryEntries.QueryInterface(Components.interfaces.nsISimpleEnumerator);%0A%09var xul_files = [];%0A%09%0A%09while (files.hasMoreElements())%0A%09{%0A%09%09var file = files.getNext().QueryInterface(Components.interfaces.nsIFile);%0A%09%09if (/\.uc\.js$/i.test(file.leafName))%0A%09%09{%0A%09%09%09setTimeout(function(aFile) {%0A%09%09%09%09Components.classes[%22@mozilla.org/moz/jssubscript-loader;1%22].getService(Components.interfaces.mozIJSSubScriptLoader).loadSubScript(getURLSpecFromFile(aFile));%0A%09%09%09}, 0, file);%0A%09%09}%0A%09%09else if (/(^userChrome|\.uc)\.xul$/i.test(file.leafName))%0A%09%09{%0A%09%09%09xul_files.push(file);%0A%09%09}%0A%09}%0A%09%0A%09setTimeout(function() {%0A%09%09if (xul_files.length > 0)%0A%09%09{%0A%09%09%09document.loadOverlay(getURLSpecFromFile(xul_files.shift()), null);%0A%09%09%09setTimeout(arguments.callee, 0);%0A%09%09}%0A%09}, 0);%0A})();%0A%0A">Sub-Script/XUL Loader</a>.
User avatar
dougeeebear
Posts: 548
Joined: September 15th, 2005, 4:17 pm

Post by dougeeebear »

I'm using zeniko's original uc.js sub-script loader, and pile0nades xul sub-script loader that he originally posted.
I modified both of these to append a different directory to the chrome directory.

excerpt from uc.js sub-script loader

Code: Select all

(function() {
   var chromeDir = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("UChrm", Components.interfaces.nsILocalFile);
chromeDir.append("userChrome-UCJS"); //gives access to the userChrome-UCJS folder


excerpt from xul sub-script loader

Code: Select all

(function() {
  var chromeDir = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("UChrm", Components.interfaces.nsILocalFile);
chromeDir.append("userChrome-XUL"); //gives access to the userChrome-XUL folder


That way, I have uc.js files in one sub-directory, and .xul files in another.
This helps keep the chrome directory uncluttered.
I don't know if I could do that in a single sub-script loader file.
Old Greg S
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post by Old Greg S »

zeniko wrote:Oops, the quotation marks seem to have been unescaped when I copied the snippet from the first post. Here goes the complete snippet: <a href="data:text/javascript,/* :::::::: Sub-Script/XUL Loader ::::::::::::::: */%0A%0A// automatically includes all files ending in .uc.js and .uc.xul from the profile's chrome folder%0A%0A(function() {%0A%09var getURLSpecFromFile = Components.classes[%22@mozilla.org/network/io-service;1%22].getService(Components.interfaces.nsIIOService).getProtocolHandler(%22file%22).QueryInterface(Components.interfaces.nsIFileProtocolHandler).getURLSpecFromFile;%0A%09var chromeDir = Components.classes[%22@mozilla.org/file/directory_service;1%22].getService(Components.interfaces.nsIProperties).get(%22UChrm%22, Components.interfaces.nsILocalFile);%0A%09var files = chromeDir.directoryEntries.QueryInterface(Components.interfaces.nsISimpleEnumerator);%0A%09var xul_files = [];%0A%09%0A%09while (files.hasMoreElements())%0A%09{%0A%09%09var file = files.getNext().QueryInterface(Components.interfaces.nsIFile);%0A%09%09if (/\.uc\.js$/i.test(file.leafName))%0A%09%09{%0A%09%09%09setTimeout(function(aFile) {%0A%09%09%09%09Components.classes[%22@mozilla.org/moz/jssubscript-loader;1%22].getService(Components.interfaces.mozIJSSubScriptLoader).loadSubScript(getURLSpecFromFile(aFile));%0A%09%09%09}, 0, file);%0A%09%09}%0A%09%09else if (/(^userChrome|\.uc)\.xul$/i.test(file.leafName))%0A%09%09{%0A%09%09%09xul_files.push(file);%0A%09%09}%0A%09}%0A%09%0A%09setTimeout(function() {%0A%09%09if (xul_files.length > 0)%0A%09%09{%0A%09%09%09document.loadOverlay(getURLSpecFromFile(xul_files.shift()), null);%0A%09%09%09setTimeout(arguments.callee, 0);%0A%09%09}%0A%09}, 0);%0A})();%0A%0A">Sub-Script/XUL Loader</a>.



OK, scripts are working but the xul is not fully working. I see evidence of their location be it hover, borders etc.. After adding this what else should I do? Should I rename all *.xul to *.uc.xul? Should I delete my userChrome.xul which was for me nothing more than an import for my .xul files?
Thanks
pile0nades
Posts: 756
Joined: May 15th, 2005, 2:31 am

Post by pile0nades »

Greg S wrote:Should I rename all *.xul to *.uc.xul?


Sounds like that might be it. The script will only load files ending in .uc.xul. If they end with that then it should work. Also, if all the userChrome.xul file is jut loading other xul files, delete it, because it might be loading the same files twice.
Linkify bug numbers - test: bug 258287
Miccovin
Posts: 51
Joined: February 9th, 2007, 12:44 am

Post by Miccovin »

@max1million:
hi, i hope i am understanding you. The script doesn´t want to open the downloadmanager (DM) automatically in a new tab, when a download is starting, right? I only can open the DM with the shortcut or with the extras-menu in a Tab, but a download does not open it. So in my eyes the script is absolutely useless till it can do this.
Old Greg S
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post by Old Greg S »

pile0nades wrote:
Greg S wrote:Should I rename all *.xul to *.uc.xul?


Sounds like that might be it. The script will only load files ending in .uc.xul. If they end with that then it should work. Also, if all the userChrome.xul file is jut loading other xul files, delete it, because it might be loading the same files twice.


Almost there,lol
I have a problem with one script. Console says document.getElementByID("statusclock") has no properties
I'm sure that I'm doing this wrong but the id "statusclock" is created in one of the .uc.xul files

Code: Select all

function statusClock() {
    var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
    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>= 12) ? " PM" : " AM");
    var date = day + ", " + month + " " + D.getDate() + ", " + year;
    document.getElementById("statusclock").label = date + "   " + Time;
    setTimeout("statusClock()", 1000);
}

statusClock();
User avatar
pirlouy
Posts: 232
Joined: February 11th, 2005, 6:29 am
Location: France

Post by pirlouy »

Could anyone find the right code to use so that when I close a tab, the left tab is selected (by default, the right one is selected) ?

Jochen gives me this code for Mouse Gestures:

Code: Select all

var mgToBeRemoved = getBrowser().mCurrentTab;
getBrowser().mTabBox._tabs.advanceSelectedTab(-1, true);
getBrowser().removeTab(mgToBeRemoved);

But would it be possible to have this functionality not only for mouse gesture, but each time I close a tab (middle click, menu > close tab, etc) ?

Thanks in advance...
old zeniko
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post by old zeniko »

pirlouy:

Code: Select all

eval("gBrowser.removeTab = " + gBrowser.removeTab.toString().replace("index == l - 1", "index > 0"));


Miccovin:
The problem with that request is that the Download Manager is opened from C++ and not from JavaScript which makes it pretty much impossible to intercept the call to open it in a new window. Your best bet would indeed be to use a WindowHook (copy that snippet from the first post) for redirecting it into a new tab - e.g. such as following:

Code: Select all

WindowHook.register("chrome://mozapps/content/downloads/downloads.xul", function(aWindow) {
   var browser = Components.classes["@mozilla.org/appshell/window-mediator;1"]
      .getService(Components.interfaces.nsIWindowMediator)
      .getMostRecentWindow("navigator:browser").getBrowser();
   aWindow.addEventListener("unload", function() {
      browser.selectedTab = browser.addTab("chrome://mozapps/content/downloads/downloads.xul");
   }, false);
   aWindow.close();
});
Last edited by old zeniko on February 11th, 2007, 12:43 pm, edited 1 time in total.
Miccovin
Posts: 51
Joined: February 9th, 2007, 12:44 am

Post by Miccovin »

@zeniko:
hey, thanks, that works better. But now the downloadmanager opened in a new tab is not refreshing. I have to open it once more (in a new tab) to look at the actual download-progress. How can I fix this?
Locked