Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug Fx release/beta] Addon buttons do not work with multiples windows (addon_buttons_in_overflow_menu.uc.js) #80

Open
sdavidg opened this issue Mar 27, 2023 · 8 comments
Labels
bug Something isn't working help wanted Extra attention is needed under investigation Looking for the issue.

Comments

@sdavidg
Copy link

sdavidg commented Mar 27, 2023

document.getElementById("unified-extensions-area") returns null when you open a new window.

@sdavidg
Copy link
Author

sdavidg commented Mar 27, 2023

@Aris-t2
Copy link
Owner

Aris-t2 commented Mar 27, 2023

Not sure, what exactly causes this to fail, but I'm looking into to.

Current status:
Nightly 113: works fine in multi-window environment
Beta 112: does not work at all
Release 111: works on first window only

@Aris-t2 Aris-t2 added bug Something isn't working help wanted Extra attention is needed under investigation Looking for the issue. labels Mar 27, 2023
@Aris-t2 Aris-t2 changed the title Addon buttons don´t work with multiples windows [Bug] Addon buttons do not work with multiples windows (addon_buttons_in_overflow_menu.uc.js) Mar 27, 2023
@sdavidg
Copy link
Author

sdavidg commented Mar 27, 2023

Beta 112 works on first window if you set a delay:

setTimeout(function/(){
	let wofl = document.getElementById("widget-overflow-fixed-list");
	let uea = document.getElementById("unified-extensions-area");
	console.log(wofl, uea);
}, 1000)

I suppose the "document" is not ready when the script is executed, but uea is null on new windows.

But if you use this code

setTimeout(function() {
	var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
				.getService(Components.interfaces.nsIWindowMediator);
	var ws = wm.getEnumerator(null);
	while(ws.hasMoreElements()) {
		let w = ws.getNext();
		let wofl = w.document.getElementById("widget-overflow-fixed-list");
		let uea = w.document.getElementById("unified-extensions-area");
		console.log("window", wofl, uea);
	}	
}, 1000);

uea is ok on first window, null on second window, but if you open a third window, is ok on first and second. uea is null on the last window

@Aris-t2
Copy link
Owner

Aris-t2 commented Mar 27, 2023

Did some testing based on the above code. Sometimes it refuses to work on any window, sometimes it works on more then 5 windows. SetInverval is a dirty function to achieve this, but it at least offers some kind of results on beta for me.

(function() {
/*
	try {
	  document.getElementById("widget-overflow-fixed-list").appendChild(document.getElementById("unified-extensions-area"));
	} catch (e) {}
*/	
setInterval(function() {
	var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
				.getService(Components.interfaces.nsIWindowMediator);
	var ws = wm.getEnumerator(null);
	while(ws.hasMoreElements()) {
		let w = ws.getNext();
		let wofl = w.document.getElementById("widget-overflow-fixed-list");
		let uea = w.document.getElementById("unified-extensions-area");
		//console.log("window", wofl, uea);
		
		try {
		  wofl.appendChild(uea);
		} catch (e) {}
	}	
}, 1000);

setInterval(function() {
	// style sheet
	Components.classes['@mozilla.org/content/style-sheet-service;1'].getService(Components.interfaces.nsIStyleSheetService).loadAndRegisterSheet(
	  Services.io.newURI('data:text/css;charset=utf-8,' + encodeURIComponent(`
		  #unified-extensions-area .unified-extensions-item-contents, 
		  #unified-extensions-area toolbarbutton + toolbarbutton.subviewbutton {
			display: none !important;
		  }
		  #unified-extensions-area toolbarbutton .toolbarbutton-text {
			display: flex !important;
		  }
		  #unified-extensions-area .toolbarbutton-icon {
			width: 16px !important;
			height: 16px !important;
		  }
		  #unified-extensions-button {
			position: absolute !important;
			right: 0 !important;
			opacity: 0 !important;
			z-index: -1000 !important;
		  }
	  `), null, null),
	  Components.classes['@mozilla.org/content/style-sheet-service;1'].getService(Components.interfaces.nsIStyleSheetService).AGENT_SHEET
	);
}, 1100);


}());

@sdavidg
Copy link
Author

sdavidg commented Mar 28, 2023

A code proposal canceling the interval

// ==UserScript==
// @name            addon_buttons_in_overflow_menu
// @author          Aris
// @version         1.0
// @homepage        https://raw.githubusercontent.com/Aris-t2/CustomJSforFx/master/scripts/addon_buttons_in_overflow_menu.uc.js
// ==/UserScript==

// 'Add-on buttons in overflow menu' script for Firefox 111+ by Aris
// At least one default toolbar button has to be inside overflow menu for it to show up on navigation toolbar.
// Pin buttons to toolbar or move buttons to overflow menu using 'right-click' context menus 'Pin to Toolbar'.
// Unified extension button gets hidden and moved to toolbars end for extension popups to appear there.

setTimeout(function() {
	
	var idInterval = setInterval(function() {
		let wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
					.getService(Components.interfaces.nsIWindowMediator);
		let ws = wm.getEnumerator(null);
		let allWinOK = true;
		while(ws.hasMoreElements()) {
			let w = ws.getNext();
			if(!w.addon_buttons_in_overflow_menu){
				let wofl = w.document.getElementById("widget-overflow-fixed-list");
				let uea = w.document.getElementById("unified-extensions-area");
				if(wofl && uea){
					wofl.appendChild(uea);
					addStyle();
					w.addon_buttons_in_overflow_menu = true;
				}
			}
			
			allWinOK = allWinOK && w.addon_buttons_in_overflow_menu;
		}
		
		if(allWinOK){
			clearInterval(idInterval);
		}
	}, 2000);

	function addStyle(){
		Components.classes['@mozilla.org/content/style-sheet-service;1'].getService(Components.interfaces.nsIStyleSheetService).loadAndRegisterSheet(
			Services.io.newURI('data:text/css;charset=utf-8,' + encodeURIComponent(`
				#unified-extensions-area .unified-extensions-item-contents, 
				#unified-extensions-area toolbarbutton + toolbarbutton.subviewbutton {
					display: none !important;
				}
				#unified-extensions-area toolbarbutton .toolbarbutton-text {
					display: flex !important;
				}
				#unified-extensions-area .toolbarbutton-icon {
					width: 16px !important;
					height: 16px !important;
				}
				#unified-extensions-button {
					position: absolute !important;
					right: 0 !important;
					opacity: 0 !important;
					z-index: -1000 !important;
				}
			`), null, null),
			Components.classes['@mozilla.org/content/style-sheet-service;1'].getService(Components.interfaces.nsIStyleSheetService).AGENT_SHEET
		);
	}
}, 1000);	

@sdavidg sdavidg closed this as completed Mar 28, 2023
@sdavidg
Copy link
Author

sdavidg commented Mar 28, 2023

I'm not sure it's right to close it

@sdavidg sdavidg reopened this Mar 28, 2023
@Aris-t2
Copy link
Owner

Aris-t2 commented Apr 3, 2023

Let leave this open for now.

The original script works fine on Nightly (113) without intervals and timeouts on as many windows I open.
We will see what happens once 113 will be on release channel.

@Aris-t2 Aris-t2 changed the title [Bug] Addon buttons do not work with multiples windows (addon_buttons_in_overflow_menu.uc.js) [Bug Fx release/beta] Addon buttons do not work with multiples windows (addon_buttons_in_overflow_menu.uc.js) Apr 3, 2023
@mzso
Copy link

mzso commented Apr 3, 2023

Well, it works. Though this way it's little different from unified menu. (It lacks some features compared to it, on the other hand it's not cluttered with disabled items.) I either have clutter of unwanted icons in the overflow menu, or on the toolbar. I can't remove unwanted ones to configure mode's repository of elements.
It thought movability was just some attribute that may be restored/forced-on toolbar buttons.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed under investigation Looking for the issue.
Projects
None yet
Development

No branches or pull requests

3 participants