-
Notifications
You must be signed in to change notification settings - Fork 22
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
Comments
Not sure, what exactly causes this to fail, but I'm looking into to. Current status: |
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 |
Did some testing based on the above code. Sometimes it refuses to work on any window, sometimes it works on more then 5 windows. (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);
}()); |
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);
|
I'm not sure it's right to close it |
Let leave this open for now. The original script works fine on Nightly (113) without intervals and timeouts on as many windows I open. |
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. |
document.getElementById("unified-extensions-area") returns null when you open a new window.
The text was updated successfully, but these errors were encountered: