aboutsummaryrefslogtreecommitdiff
path: root/chrome/js/browserOverlay.js
blob: 81d19f2b1cbe16754c14330c03b583f5a5e973d8 (plain)
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
Components.utils.import("chrome://redirector/content/js/redirectorprefs.js");
Components.utils.import("chrome://redirector/content/js/redirector.js");

var RedirectorOverlay = {
	strings		: null,
	prefs		: null,

	onLoad : function(event) {
		this.strings = document.getElementById("redirector-strings");
		this.prefs = new RedirectorPrefs();
		this.changedPrefs(this.prefs);
		this.prefs.addListener(this);
		document.addEventListener('keypress', function(event) {
			if ((event.charCode == 114) && event.altKey) { //alt+r
				RedirectorOverlay.toggleEnabled();
			}
		}, true);
	},

	onUnload : function(event) {
		this.prefs.dispose();
		Redirector.debug("Finished cleanup");
	},

	changedPrefs : function(prefs) {
		this.refreshUI();
	},

	refreshUI: function() {
		let button = document.getElementById("redirector-button");
		let item = document.getElementById("redirector-enabled-item");
		if (this.prefs.enabled) {
			button.removeAttribute('disabled');
			item.setAttribute('checked', true);
		} else {
			button.setAttribute('disabled', 'yes');
			item.setAttribute('checked', false);
		}
	},

	toggleEnabled: function(event) {
		this.prefs.enabled = !this.prefs.enabled;
		this.refreshUI();
	},

	openSettings : function() {
		gBrowser.selectedTab = gBrowser.addTab("chrome://redirector/content/redirector.html");
	},

	updateTooltip: function(event) {
		AddonManager.getAddonByID("url-rewriter@papush", (addon) => {
			let label = event.target.getElementsByClassName("redirector-tooltip-version")[0];
			label.setAttribute("value", "URL Rewriter " + addon.version);
		});
	}
};

window.addEventListener("load", function(event) { RedirectorOverlay.onLoad(event); }, false);
window.addEventListener("unload", function(event) { RedirectorOverlay.onUnload(event); }, false);