(function () {
	var prefs = Services.prefs, enabled;
	if (prefs.prefHasUserValue('userChromeJS.floating_scrollbar.enabled')) {
		enabled = prefs.getBoolPref('userChromeJS.floating_scrollbar.enabled')
	} else {
		prefs.setBoolPref('userChromeJS.floating_scrollbar.enabled', true);
		enabled = true;
	}

	var css = `/*AGENT_SHEET*/
	@namespace url(http: //www.mozilla.org/keymaster/gatekeeper/there.is.only.xul);

/* шрифт Tooltip, +фикс чёрного фона в Arch-Linux */
	tooltiptext, tooltip { -moz-appearance: none !important;
	background: #f8f8e0 !important; color: #004 !important; margin: 0 0 20px -30px; !important; border-radius: 4px/4px !important; border: 1px solid black; padding: 5px; !important; font-weight: 600 !important; line-height: 1.2 !important;
	/* font-weight: 460; font-family: "Fira Sans" !important; */
	}

/* Скроллбар полупрозрачный */
	scrollbarbutton {display: none!important;}
	scrollbar, scrollcorner {-moz-appearance: none !important; background: none !important; padding: 0 !important; border: 0 !important; margin: 0 !important;}
	scrollbar thumb, textbox scrollbar thumb { border: none !important; -moz-appearance: none !important;
		opacity: .3 !important; border-radius: 3px !important;
		min-height: 30px !important; min-width: 30px !important;
	background-image: -moz-linear-gradient(90deg, #444 0%, #999 5%, #444 50%, #999 95%, #444 100%) !important;
	}
	scrollbar:hover thumb, scrollbar:hover scrollbarbutton {opacity: .5 !important; background: #a48800 !important;}
	scrollbar[orient="vertical"] { min-width: 8px !important; max-width: 8px !important;}
	scrollbar[orient="horizontal"] { max-height: 9px !important;}
	html>scrollbar {position: relative !important; z-index: 99999999 !important;}
	html>scrollbar[orient="vertical"]:hover { margin-left: -12px !important;}
	html>scrollbar[orient="vertical"]:not(:hover) { margin-left: -8px !important;}
`;
	var sss = Cc['@mozilla.org/content/style-sheet-service;1'].getService(Ci.nsIStyleSheetService);
	var uri = makeURI('data:text/css;charset=UTF=8,' + encodeURIComponent(css));

	var p = document.getElementById('devToolsSeparator');
	var m = document.createElement('menuitem');
	m.setAttribute('label', "Scrollbar AutoHide");
	m.setAttribute('type', 'checkbox');
	m.setAttribute('autocheck', 'false');
	m.setAttribute('checked', enabled);
	p.parentNode.insertBefore(m, p);
	m.addEventListener('command', command, false);

	if (enabled) {
		sss.loadAndRegisterSheet(uri, sss.AGENT_SHEET);
	}
	function command() {
		if (sss.sheetRegistered(uri, sss.AGENT_SHEET)) {
			prefs.setBoolPref('userChromeJS.floating_scrollbar.enabled', false);
			sss.unregisterSheet(uri, sss.AGENT_SHEET);
			m.setAttribute('checked', false);
		} else {
			prefs.setBoolPref('userChromeJS.floating_scrollbar.enabled', true);
			sss.loadAndRegisterSheet(uri, sss.AGENT_SHEET);
			m.setAttribute('checked', true);
		}
		let root = document.documentElement;
		let display = root.style.display;
		root.style.display = 'none';
		window.getComputedStyle(root).display; // Flush
		root.style.display = display;
	}

})();