This repository has been archived by the owner on Jun 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.html
104 lines (86 loc) · 2.41 KB
/
main.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
<html>
<script src="stats_begin.js"></script>
<script src="TopicData.js"></script>
<script src="Options.js"></script>
<script>
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {
switch(request.type) {
case 'get':
var value = localStorage[request.topicId];
var response = TopicData.fromString(value);
sendResponse(response);
break;
case 'set':
var topicData = TopicData.fromObject(request);
if(topicData.lastReadMsg == 0 && !topicData.ignored) {
delete localStorage[request.topicId];
} else {
topicData.timestamp = Date.now();
localStorage[request.topicId] = topicData.toString();
}
sendResponse({});
break;
case 'get_options':
var options = Options.get(sendResponse);
break;
case 'set_options':
/* NÃO IMPLEMENTADO! */
break;
}
});
Options.get(function(options) {
getManifest(function(manifest) {
stats.setVersion(manifest.version);
stats.loaded();
var lastUsedVersion = options.lastUsedVersion;
if(lastUsedVersion != manifest.version) {
if(compareVersions(lastUsedVersion, "2.0.0") < 0) {
// Mostra instruções quando uma nova versão é instalada
openInstructions();
}
options.lastUsedVersion = manifest.version;
Options.set(options);
stats.install(manifest.version, lastUsedVersion);
}
});
});
function getManifest(handler) {
var req = new XMLHttpRequest();
req.onreadystatechange = function() {
if(req.readyState == 4) {
var manifest = JSON.parse(req.responseText);
handler(manifest);
}
};
req.open("GET", "/manifest.json", true);
req.send();
}
function openInstructions() {
chrome.tabs.create({ 'url' : '/background/options.html#instructions' });
stats.instructionsOpened();
}
function compareVersions(v1, v2) {
if(!v1) {
v1 = "0";
}
v1 = v1.split(".");
v2 = v2.split(".");
var len = Math.max(v1.length, v2.length);
while(v1.length < len) { v1.push(0); }
while(v2.length < len) { v2.push(0); }
for(var i = 0; i < len; i++) {
var n1 = parseInt(v1[i]);
var n2 = parseInt(v2[i]);
if(n1 > n2) {
return +1;
} else if(n1 < n2) {
return -1;
}
}
// Versões iguais
return 0;
}
</script>
<script src="stats_end.js"></script>
</html>