CustomJSforFx icon indicating copy to clipboard operation
CustomJSforFx copied to clipboard

[JavaScript] General JavaScript talk and custom userChrome.js scripts

Open Aris-t2 opened this issue 8 years ago • 231 comments

Lets discuss everything related to JavaScript here instead of opening new threads for questions or request.

Custom scripts https://github.com/Aris-t2/CustomJSforFx/tree/master/scripts

Other custom script collections - by ardiman - by Endor8

Aris-t2 avatar Oct 05 '18 16:10 Aris-t2

@Aris-t2 Could you please help with adding custom icon for any custom Toolbar button createdby UserChromeJS (method2). What need to be changed in path to the file list-style-image: url("chrome://browser/skin/connection-secure.svg")

if for example external(new) SVG is located inside "image" folder from CustomCSSforFx?

UPD. maybe also you can advice how to achieve the same for the extension toolbar button... It typically uses the following properties for the icon

элемент {
    --webextension-menupanel-image: url("moz-extension://af7534e5-4987-4fe3-92e5-b36f6728ef88/icons/32-tab-undo.png");
    --webextension-menupanel-image-light: url("moz-extension://af7534e5-4987-4fe3-92e5-b36f6728ef88/icons/32-tab-undo.png");
    --webextension-menupanel-image-dark: url("moz-extension://af7534e5-4987-4fe3-92e5-b36f6728ef88/icons/32-tab-undo.png");
    --webextension-menupanel-image-2x: url("moz-extension://af7534e5-4987-4fe3-92e5-b36f6728ef88/icons/48-tab-undo.png");
    --webextension-menupanel-image-2x-light: url("moz-extension://af7534e5-4987-4fe3-92e5-b36f6728ef88/icons/48-tab-undo.png");
    --webextension-menupanel-image-2x-dark: url("moz-extension://af7534e5-4987-4fe3-92e5-b36f6728ef88/icons/48-tab-undo.png");
    --webextension-toolbar-image: url("moz-extension://af7534e5-4987-4fe3-92e5-b36f6728ef88/icons/16-tab-undo.png");
    --webextension-toolbar-image-light: url("moz-extension://af7534e5-4987-4fe3-92e5-b36f6728ef88/icons/16-tab-undo.png");
    --webextension-toolbar-image-dark: url("moz-extension://af7534e5-4987-4fe3-92e5-b36f6728ef88/icons/16-tab-undo.png");
    --webextension-toolbar-image-2x: url("moz-extension://af7534e5-4987-4fe3-92e5-b36f6728ef88/icons/32-tab-undo.png");
    --webextension-toolbar-image-2x-light: url("moz-extension://af7534e5-4987-4fe3-92e5-b36f6728ef88/icons/32-tab-undo.png");
    --webextension-toolbar-image-2x-dark: url("moz-extension://af7534e5-4987-4fe3-92e5-b36f6728ef88/icons/32-tab-undo.png");
}

Acid-Crash avatar Oct 05 '18 20:10 Acid-Crash

@Acid-Crash You to use an absolute paths, if you want to set a local icon for a button inside a JS file. list-style-image: url("file:///DRIVELETTER:/path/to/image/file.png") !important; My Portable Firefox for this case looks like this list-style-image: url("file:///G:/FirefoxPortable_JS_method2/Data/profile/chrome/image/padlock_modern.png") !important;

I'm not sure why we can not use icons from other add-ons/WEs. Probably they are no accessible from custom css or other add-ons/WEs.

Aris-t2 avatar Oct 05 '18 21:10 Aris-t2

@Aris-t2 hmm, absolute path has its flaws. I did notice that in ./css/buttons/appbutton_on_navbar_icon_white.css You've defined the path with the following list-style-image: url("../../image/appbutton-inv.svg") !important;

From my understanding it says that I need to move 2 steps back/up into file structure (from the folder where rule is defined), then go to image folder and find appbutton-inv.svg I was able to redefine some icons following this logic and they are working fine, but I struggle with that JS button

I thought that similar can be done for password_manager_button.uc.js icon The issue it that I can't seem to understand what is my starting point in file structure

Acid-Crash avatar Oct 05 '18 22:10 Acid-Crash

Unfortunately the path does not work like this inside the JS script, but it will inside userChrome.css though.

Example: chrome/image/padlock_modern.png chrome/userChrome/... (here are the scripts) chrome/userChrome.css chrome/userChrome.js

This code will work inside userChrome.css.

#pw_manager_button .toolbarbutton-icon {
  list-style-image: url("./image/padlock_modern.png") !important;
}

Aris-t2 avatar Oct 06 '18 07:10 Aris-t2

@Aris-t2 thx for the clarification. BTW I've noticed that undo_closetab_button.uc.js looses its icon (didn't change it) when placed inside Overflow menu. Maybe you know why this is happening?

ofmenu

Acid-Crash avatar Oct 07 '18 14:10 Acid-Crash

That icon seems to be something very special ;-) It requires width and height values within palette and overflow menu.

I just uploaded a new version of the script. https://github.com/Aris-t2/CustomJSforFx/blob/master/scripts/undo_closetab_button.uc.js

Aris-t2 avatar Oct 07 '18 16:10 Aris-t2

@Aris-t2, Ahh, my eye failed me((( Been staring at that icons svg and didn't notice that it lacks width="16" height="16" thx again

Acid-Crash avatar Oct 07 '18 16:10 Acid-Crash

The other buttons (like restart buttons) and svgs do not require width and height to be set, so I haven't thought about adding it to this one.

Aris-t2 avatar Oct 07 '18 17:10 Aris-t2

@Aris-t2 I've used another solution to fix troublesome icons. Not sure if it fill be suitable for everyone, still maybe someone will be interested. Load about:config?filter=svg.context-properties.content.enabled and set it to true (this will enable accepting fill and fill-opacity for local SVGs). Details are here MDN

  1. Save locally troublesome icon.
  2. Add missing SVG properties (just use another icon as a template). So far I've seen missing width="16" height="16" and fill-opacity="context-fill-opacity"
  3. Reassign icon via userChrome.css as it was mentioned in this tread
#pw_manager_button .toolbarbutton-icon {
  list-style-image: url('image/CustomIcon_Padlock.svg') !important;
}

BTW list-style-image: can be used for changing icons for the majority of extensions

Acid-Crash avatar Oct 07 '18 21:10 Acid-Crash

Ping: User Aborix in Re: userChrome.js Scripte für den Fuchs (Diskussion) (Camp Firefox; German) pointed out, that gBrowser.addTab(<URI>) does not work anymore in Fx 63 and has to be replaced by either gBrowser.addWebTab(<URI>) or gBrowser.addTrustedTab(<URI>) depending on <URI>. At least downloads_button.uc.js is affected by this.

Speravir avatar Oct 25 '18 17:10 Speravir

Thanks for the note.

I'm using this code to add a new tab since a while now: gBrowser.addTab('about:downloads', {triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal()});. It basically is the old one with some nonsense after the uri I copy&pasted from internal Firefox code. It works fine even in Fx65.

Aris-t2 avatar Oct 25 '18 19:10 Aris-t2

Strange … ( I cannot judge this, but we both know that Aborix usually is not uttering nonsense.)

Speravir avatar Oct 26 '18 18:10 Speravir

You misunderstood me. I meant {triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal()} is new nonsense Mozilla now requires for the old(?) addTab function within Firefox code. I just reused it, because I was not aware of gBrowser.addWebTab(<URI>) or gBrowser.addTrustedTab(<URI>) by that time.

For about:downloads gBrowser.addTrustedTab works fine.

Aris-t2 avatar Oct 26 '18 19:10 Aris-t2

Maybe we should have written this in German … ;-)

Speravir avatar Oct 28 '18 18:10 Speravir

Good evening.I am using v.60esr.I ..think I have put all files in the right places but it doesnt seem to work.Does it work with 60esr? I have placed the scripts in C:\Users\username\AppData\Roaming\Mozilla\Firefox\Profiles\prof_name\chrome\userChrome , is it right? The syntax I use in userChrome.js is userChrome.import("/userChrome/restart_button.uc.js", "UChrm"); is it right?

Crybal avatar Nov 02 '18 19:11 Crybal

Have you cleared the script cache? https://github.com/Aris-t2/CustomJSforFx#scriptstartup-cache-must-be-deleted-after-every-change

Which method are you using and have you also tried the other one?

Aris-t2 avatar Nov 02 '18 20:11 Aris-t2

I am using method 2 which is supposed to clear it automatically.Did I put the files in the right places? I ve not tried the other one

Crybal avatar Nov 02 '18 21:11 Crybal

OK.I did it works ok.I really thank you.By the way...the double click that opens a new tab,could it be done even on any tab? I mean except on an empty space on the tabs bar.

Crybal avatar Nov 02 '18 21:11 Crybal

1

Yes, edit the file "tabstoolbar_doubleclick_opennewtab.uc.js" and remove the line && e.target.localName != "tab". Don't forget to clear the script cache afterwards. The easiest way to do this is using my restart button/menuitem script and middle-clicking on button/menuitem to restart the browser.

Aris-t2 avatar Nov 03 '18 09:11 Aris-t2

Done,thanks.This is more useful for me

Crybal avatar Nov 03 '18 21:11 Crybal