/
background.html
68 lines (61 loc) · 1.84 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
<!DOCTYPE html>
<html>
<head>
<script>
function updateIcon(state) {
chrome.browserAction.setIcon({path: 'icon_' + state + '.png'});
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.sendRequest(tab.id, {state: state});
});
}
function toggleState() {
enabled = (enabled + 1) % 2;
updateIcon(enabled);
localStorage['enabled'] = enabled;
}
var enabled = parseInt(localStorage['enabled'] || '1');
updateIcon(enabled);
chrome.browserAction.onClicked.addListener(toggleState);
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
if (request.state == 'current') {
sendResponse({state: enabled});
} else {
sendResponse({});
}
});
// http://stackoverflow.com/questions/2399389/chrome-extension-first-run
function onInstall() {
chrome.tabs.create({url: 'http://buzzgrowl.com/leaderboard#welcome'});
}
function onUpdate() {}
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;
}
var currVersion = getVersion();
var prevVersion = localStorage['version'];
if (currVersion != prevVersion) {
if (typeof prevVersion == 'undefined') {
onInstall();
} else {
onUpdate();
}
localStorage['version'] = currVersion;
}
</script>
<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-10579921-6']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = 'https://ssl.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
</html>