MozillaZine

[Ext] userChrome.js

Announce and Discuss the Latest Theme and Extension Releases.
dougeeebear

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

Post Posted June 3rd, 2006, 7:26 am

Diorser,
test.uc.js is a file I use to test new userChrome.js scripts.

Correction needed:

Last line, add one more ")" before the ";"

JNewbry

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

Post Posted June 3rd, 2006, 7:28 am

Code: Select all
/*  This script will add "Hello, World!" menuitem before
    the "Open Link in New Window" menuitem on Context Menu    */

(function() {
  var newItem = document.createElement("menuitem");
  newItem.setAttribute("label", "Hello, World!");
  newItem.setAttribute("oncommand", "alert('Hello, World!');");
  var openLink = document.getElementById("context-openlink");
  openLink.parentNode.insertBefore(newItem, openLink);
})();


*Corrected - Thanks zeniko!

If you have the <a href="data:text/javascript,%2F*%20%3A%3A%3A%3A%3A%3A%3A%3A%20Sub-Script%20Loader%20%3A%3A%3A%3A%3A%3A%3A%3A%3A%3A%3A%3A%3A%3A%3A%20*%2F%0A%0A%2F%2F%20automatically%20includes%20all%20files%20ending%20in%20.uc.js%20from%20the%20profile's%20chrome%20folder%0A%0A(function()%20%7B%0A%09var%20chromeDir%20%3D%20Components.classes%5B%22%40mozilla.org%2Ffile%2Fdirectory_service%3B1%22%5D.getService(Components.interfaces.nsIProperties).get(%22UChrm%22%2C%20Components.interfaces.nsILocalFile)%3B%0A%09var%20files%20%3D%20chromeDir.directoryEntries.QueryInterface(Components.interfaces.nsISimpleEnumerator)%3B%0A%09%0A%09while%20(files.hasMoreElements())%0A%09%7B%0A%09%09var%20file%20%3D%20files.getNext().QueryInterface(Components.interfaces.nsIFile)%3B%0A%09%09if%20(%2F%5C.uc%5C.js%24%2Fi.test(file.leafName))%0A%09%09%7B%0A%09%09%09setTimeout(function(aFile)%20%7B%0A%09%09%09%09Components.classes%5B%22%40mozilla.org%2Fmoz%2Fjssubscript-loader%3B1%22%5D.getService(Components.interfaces.mozIJSSubScriptLoader).loadSubScript(Components.classes%5B%22%40mozilla.org%2Fnetwork%2Fio-service%3B1%22%5D.getService(Components.interfaces.nsIIOService).getProtocolHandler(%22file%22).QueryInterface(Components.interfaces.nsIFileProtocolHandler).getURLSpecFromFile(aFile))%3B%0A%09%09%09%7D%2C%200%2C%20file)%3B%0A%09%09%7D%0A%09%7D%0A%7D)()%3B%0A">Sub-Script Loader</a> in userChrome.js..... it will recognize all files ending in .uc.js
Last edited by JNewbry on June 3rd, 2006, 8:59 am, edited 2 times in total.
<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>

Diorser

User avatar
 
Posts: 960
Joined: June 22nd, 2005, 6:57 am

Post Posted June 3rd, 2006, 7:38 am

Ha, I have edited my previous post before reading this !
Yes, now it works fine. But no JS error was reported with the code directly in userchrome.js ....

ps: I am not a JS specialist at all !!!!!! (I just copy/paste and trust proposed codes ! :oops: )

old zeniko
 
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post Posted June 3rd, 2006, 7:52 am

If you use the "anonymous function" idiom to hide variables from the global scope, make sure that it looks as follows:
Code: Select all
(function() {
   // this code won't pollute the global scope
})();

This creates an anonymous function and executes it in place (the parentheses surrounding the function are needed to prevent a syntax error and the parentheses at the end actually execute it).

Diorser

User avatar
 
Posts: 960
Joined: June 22nd, 2005, 6:57 am

Post Posted June 3rd, 2006, 12:52 pm

userChrome.js again..... I don't see any effect with this one....
  • <a href="data:application/x-javascript;charset=utf-8;base64,Ly9UaGlzIHNjcmlwdCB3aWxsIGFkZCAiSGVsbG8sIFdvcmxkISIgYnV0dG9uIG9uIHRoZSB0b29sYmFyDQoNCihmdW5jdGlvbigpIHsNCiAgdmFyIG5ld0J1dHRvbiA9IGRvY3VtZW50LmNyZWF0ZUVsZW1lbnQoInRvb2xiYXJidXR0b24iKTsNCiAgbmV3QnV0dG9uLnNldEF0dHJpYnV0ZSgibGFiZWwiLCAiSGVsbG8sIFdvcmxkISIpOw0KICBuZXdCdXR0b24uc2V0QXR0cmlidXRlKCJvbmNvbW1hbmQiLCAiYWxlcnQoJ0hlbGxvLCBXb3JsZCEnKTsiKTsNCiAgbmV3QnV0dG9uLnN0eWxlLmxpc3RTdHlsZUltYWdlID0gInVybChkYXRhOmltYWdlL3BuZztiYXNlNjQsaVZCT1J3MEtHZ29BQUFBTlNVaEVVZ0FBQUJBQUFBQVFBUU1BQUFBbFBXMGlBQUFBRlhSRldIUkRjbVZoZEdsdmJpQlVhVzFsQUFmV0F4c1NLU1VONmlBZUFBQUFCM1JKVFVVSDFnTWJFaTA0MzRGcXN3QUFBQWx3U0ZsekFBQU9kQUFBRG5RQmF5U3oxZ0FBQUFaUVRGUkZBQUFBJTJGJTJGJTJGJTJGcGRtZjNRQUFBQ1ZKUkVGVWVOcGolMkJQJTJCZkFZS21uV0lvMndsQ2swNUJSYjcxTTN5WXolMkZCdFA0Z0JVd1lBaGNVYldjdWhlVDhBQUFBQVNVVk9SSzVDWUlJJTNEKSI7DQogIG5ld0J1dHRvbi5zdHlsZS5wYWRkaW5nID0gIjAiOw0KDQogIHZhciBob21lQnV0dG9uID0gZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoImhvbWUtYnV0dG9uIik7IC8vSG9tZSBidXR0b24NCiAgaG9tZUJ1dHRvbi5wYXJlbnROb2RlLmluc2VydEJlZm9yZShuZXdCdXR0b24sIGhvbWVCdXR0b24ubmV4dFNpYmxpbmcpOyAvL2FkZHMgdGhlIG5ldyBidXR0b24gb24gdGhlIHJpZ2h0IG9mIEhvbWUgYnV0dG9uDQoNCn0pKCk7DQoNCg%3D%3D">Adds a toolbarbutton</a>
.... final parenthetical looks ok this time ! Something wrong ? Do I miss something ?

old zeniko
 
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post Posted June 3rd, 2006, 11:59 pm

Adding the toolbar button works for me. Make sure that the script is actually run (try placing an <code>alert("it runs");</code> inside and/or outside the function) and that you get no errors in the JavaScript console (having set javascript.options.showInConsole to true).

Diorser

User avatar
 
Posts: 960
Joined: June 22nd, 2005, 6:57 am

Post Posted June 4th, 2006, 1:29 am

I get:
    Error: homeButton has no properties
    Source File: file:///D:/Applis/Mozilla/FFProf/chrome/ToolbarButoon.uc.js
    Line: 13
line 13 for me is:
Code: Select all
homeButton.parentNode.insertBefore(newButton, homeButton.nextSibling);
And following line is the last one with })();

Well, my conclusion is that without learning JavaScript, difficult to go far by just copying proposed codes found on a forum !

KidReefer

User avatar
 
Posts: 141
Joined: May 7th, 2006, 6:10 am
Location: Earth...mainly

Post Posted June 4th, 2006, 1:39 am

JNewbry wrote:You might find this helpful... download this <a href="http://webdesigns.ms11.net/ChromeFiles.zip">ZIP</a> file & study the file structure a little while.
Diorser: Check this out. These work. Helped me. Props to JNewbry, Thanks alot man, it really helped.


Peace

Diorser

User avatar
 
Posts: 960
Joined: June 22nd, 2005, 6:57 am

Post Posted June 4th, 2006, 2:00 am

Thanks for your help, and will investigate.
However, if I am even blocked with the toolbar button test script, I must say my ambition suddenly becomes much more limited than my first enthusiasm !

old zeniko
 
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post Posted June 4th, 2006, 2:02 am

Diorser wrote:Error: homeButton has no properties

Make sure that the "Home" button is actually visible on one of your toolbars, otherwise the snippet obviously won't work.

Diorser

User avatar
 
Posts: 960
Joined: June 22nd, 2005, 6:57 am

Post Posted June 4th, 2006, 2:11 am

Yes Home button is visible, but still absolutely no effect.

My home is set to "about:blank", and is still the same by using your files ....

"NoScript" extension problem / about:config tweak ?
Don't know, but less obvious than expected.

ps: other js files work fine, except this toolbar button.

(currently using Fx 1.5.0.4)

KidReefer

User avatar
 
Posts: 141
Joined: May 7th, 2006, 6:10 am
Location: Earth...mainly

Post Posted June 4th, 2006, 2:18 am

did you see this

dougeeebear wrote:I found out if there is a coding mistake anywhere within userChrome.js, none of the scripts work (meaning the script with the mistake plus all other scripts).
You have to physically go and find the file and edit it and correct your mistake before anything will work again.
I guess that means don't make any mistakes.


Got any other scripts?

Diorser

User avatar
 
Posts: 960
Joined: June 22nd, 2005, 6:57 am

Post Posted June 4th, 2006, 2:23 am

I just unzipped the files you proposed in my chrome dir and nothing else.
No other scripts (deleted / cleaned / checked).

Probably a mismatch with a script embedded in an extension.
KDE4.3 RC

KidReefer

User avatar
 
Posts: 141
Joined: May 7th, 2006, 6:10 am
Location: Earth...mainly

Post Posted June 4th, 2006, 2:32 am

Do you have sub script loader ( avalible on the first
post ) in your userChrome.js file? You need it to load "uc.js" scripts.

Diorser

User avatar
 
Posts: 960
Joined: June 22nd, 2005, 6:57 am

Post Posted June 4th, 2006, 2:37 am

Now solved !!!!
I used your zip files, but thought the Button test scripts was in the UCJSFiles dir !!! But not .... Just added and now works fine.
But, did not identify what went wrong with exactly the same test script few hours before.

Ok, I am now going to take a breath !

Many thanks for your precious help !

Return to Extension/Theme Releases


Who is online

Users browsing this forum: No registered users and 4 guests