-
Notifications
You must be signed in to change notification settings - Fork 2
/
background.html
111 lines (100 loc) · 2.52 KB
/
background.html
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<!DOCTYPE html>
<html>
<embed type="application/x-vnd-haptics" id="pluginobj"
width="0" height="0" />
<script>
// Settings.
settings = {
get version() {
return localStorage['version'];
},
set version(val) {
localStorage['version'] = val;
},
get debug() {
var key = localStorage['debug'];
return (typeof key == 'undefined') ? false : key === 'true';
},
set debug(val) {
localStorage['debug'] = val;
plugin.debug = val;
},
get opt_out() {
var key = localStorage['opt_out'];
return (typeof key == 'undefined') ? true : key === 'true';
},
set opt_out(val) {
localStorage['opt_out'] = val;
},
};
// Plugin.
plugin = document.getElementById('pluginobj');
/**
* Get the version number from the manifest.
*
* @returns {string} The current version number.
*/
function getVersion() {
var version = 'NaN';
var xhr = new XMLHttpRequest();
xhr.open('GET', chrome.extension.getURL('manifest.json'), false);
xhr.send(null);
var manifest = JSON.parse(xhr.responseText);
return manifest.version;
}
/**
* Open a singleton page, which means, if a page already exists, it
* just selects it.
*
* @param url The page which it will navigate to.
*/
function openSingletonPage(url) {
chrome.windows.getCurrent(function(win) {
chrome.tabs.getAllInWindow(win.id, function(tabs) {
for (var i = 0; i < tabs.length; i++) {
if (tabs[i].url.indexOf(url) == 0) {
chrome.tabs.update(tabs[i].id, {selected: true});
return;
}
}
chrome.tabs.create({url: url});
});
});
}
/**
* Hook for installation.
*/
function onInstall() {
}
/**
* Hook for updates.
*/
function onUpdate() {
// Do not send updates if the user is opt'd out!
if (!settings.opt_out) {
// chrome.tabs.create({url: 'updates.html'});
}
}
/**
* Initialization routine.
*/
function init() {
// Check if the version has changed. In case we want to do something in the
// future.
var currVersion = getVersion();
var prevVersion = settings.version
if (currVersion != prevVersion) {
// Update the version incase we want to do something in future.
settings.version = currVersion;
// Check if we just installed this extension.
if (typeof prevVersion == 'undefined') {
onInstall();
} else {
onUpdate();
}
}
// Sets the debugger according to the settings.
plugin.debug = settings.debug;
}
init();</script>
</html>