Skip to content

Instantly share code, notes, and snippets.

@keldian
Last active May 6, 2025 08:25
Show Gist options
  • Save keldian/14015613dd60960bfd483f649dc2639b to your computer and use it in GitHub Desktop.
Save keldian/14015613dd60960bfd483f649dc2639b to your computer and use it in GitHub Desktop.
MinMaxClose Button (SVG Version) Firefox User Script
// ==UserScript==
// @name MinMaxClose Button
// @author xiaoxiaoflood
// @include main
// @shutdown UC.MinMaxCloseButton.destroy();
// @onlyonce
// ==/UserScript==
UC.MinMaxCloseButton = {
init: function () {
_uc.sss.loadAndRegisterSheet(this.STYLE, _uc.sss.USER_SHEET);
const { CustomizableUI } = window;
CustomizableUI.createWidget({
id: 'minMaxClose-button',
type: 'custom',
defaultArea: CustomizableUI.AREA_NAVBAR,
onBuild: function (doc) {
let btn = _uc.createElement(doc, 'toolbarbutton', {
id: 'minMaxClose-button',
class: 'toolbarbutton-1 chromeclass-toolbar-additional',
label: 'Window Button',
tooltiptext: 'Left-Click: Minimize\nMiddle-Click: Maximize/Restore to fixed position\nShift + Middle-Click: Maximize/Restore to previous position\nRight-Click: Exit',
oncontextmenu: 'return false',
onclick: 'UC.MinMaxCloseButton.BrowserManipulateCombine(event)'
});
return btn;
}
});
},
BrowserManipulateCombine: function (e) {
let win = e.view;
switch (e.button) {
case 0:
win.minimize();
break;
case 1:
let max = win.document.getElementById('main-window').getAttribute('sizemode') == 'maximized' ? true : false;
if ((!e.shiftKey && max) ||
(e.shiftKey && !max && !(win.screenX === -5 && win.screenY === 0 && win.innerWidth === 1992 && win.innerHeight === 1056))) {
win.resizeTo(1975, 1052);
win.moveTo(-5, 0);
} else if (max && e.shiftKey) {
win.restore();
} else {
win.maximize();
}
break;
case 2:
win.BrowserCommands.tryToCloseWindow();
}
},
STYLE: Services.io.newURI('data:text/css;charset=UTF-8,' + encodeURIComponent(`
@-moz-document url('${_uc.BROWSERCHROME}') {
#minMaxClose-button {
list-style-image: url('data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 964 964">
<path fill="context-fill" d="M 20 77.500 L 20 135 164.500 135 L 309 135 309 77.500 L 309 20 164.500 20 L 20 20 20 77.500 M 366 193 L 366 251 510.500 251 L 655 251 655 366.500 L 655 482 684 482 L 713 482 713 308.500 L 713 135 539.500 135 L 366 135 366 193 M 251 482 L 251 655 424 655 L 597 655 597 684 L 597 713 626 713 L 655 713 655 742 L 655 771 684 771 L 713 771 713 799.500 L 713 828 684 828 L 655 828 655 857 L 655 886 626 886 L 597 886 597 915 L 597 944 655 944 L 713 944 713 915 L 713 886 770.500 886 L 828 886 828 915 L 828 944 886 944 L 944 944 944 915 L 944 886 915 886 L 886 886 886 857 L 886 828 857 828 L 828 828 828 799.500 L 828 771 857 771 L 886 771 886 742 L 886 713 915 713 L 944 713 944 684 L 944 655 886 655 L 828 655 828 684 L 828 713 770.500 713 L 713 713 713 684 L 713 655 655 655 L 597 655 597 482 L 597 309 424 309 L 251 309 251 482 M 309 510.500 L 309 597 424.500 597 L 540 597 540 510.500 L 540 424 424.500 424 L 309 424 309 510.500"/>
</svg>
`)}');
-moz-context-properties: fill;
fill: var(--toolbarbutton-icon-fill, var(--toolbar-color));
}
}
`)),
destroy: function () {
Services.wm.getMostRecentBrowserWindow().CustomizableUI.destroyWidget('minMaxClose-button');
_uc.sss.unregisterSheet(this.STYLE, _uc.sss.USER_SHEET);
delete UC.MinMaxCloseButton;
}
}
UC.MinMaxCloseButton.init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment