-
Notifications
You must be signed in to change notification settings - Fork 3
/
sidebar_switch.uc.js
executable file
·85 lines (66 loc) · 2.84 KB
/
sidebar_switch.uc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* Firefox userChrome script
* Add a slim switch on left of main content to toggle Firefox's native sidebar
* Tested on Firefox 128
* Author: garywill (https://garywill.github.io)
*/
// ==UserScript==
// @include main
// ==/UserScript==
console.log("sidebar_switch.js");
(() => {
const bbrowser = document.getElementById("browser");
if ( bbrowser && document.getElementById("main-window") && document.getElementById("TabsToolbar") && document.getElementById("urlbar-container") )
{
var switcher_c = document.createElement("vbox"); // TODO XULElement
var switcher = document.createElement("vbox");
switcher.id = "sidebar_switcher";
switcher_c.id = "sidebar_switcher_c";
switcher.tooltipText = "Click to toggle sidebar"
switcher_c.appendChild(switcher);
bbrowser.insertBefore(switcher_c, bbrowser.childNodes[0]);
switcher.addEventListener('click', async function(){
await SidebarController.toggle();
});
Components.utils.import("resource:///modules/CustomizableUI.jsm");
const Services = globalThis.Services || ChromeUtils.import("resource://gre/modules/Services.jsm").Services;
const sss = Components.classes["@mozilla.org/content/style-sheet-service;1"].getService(Components.interfaces.nsIStyleSheetService);
const css_ucjs = Services.io.newURI( "data:text/css;charset=utf-8," + encodeURIComponent(`
#sidebar_switcher_c
{
position: relative;
display: block;
z-index: 99999;
}
#sidebar_switcher
{
opacity: 0.2;
width: 6px;
min-width:6px;
max-width:6px;
height: 100%;
position: absolute;
background-color:blue;
}
#sidebar_switcher:hover
{
opacity: 0.3;
}
`), null, null );
sss.loadAndRegisterSheet(css_ucjs, sss.USER_SHEET);
const nav_tb = document.getElementById("navigator-toolbox");
var tabsbar_fullscr_observer = new MutationObserver(function(){
if(nav_tb.getAttribute("inFullscreen")) // fullscreen
{
if(document.fullscreen) // video fullscreen
{
switcher_c.style.display = "none"; // hide
}
}
else // not fullscreen
{
switcher_c.style.display = "block";
}
});
tabsbar_fullscr_observer.observe(nav_tb,{attributes:true});
}
})();