This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
background.html
93 lines (87 loc) · 2.94 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
<html>
<head>
<script>
// ---- CHECK UPDATE ----//
var major = 2;
var minor = 2;
if (localStorage["major"] == undefined) {
localStorage["major"] = 0;
}
if (localStorage["major"] < major) {
chrome.tabs.create({url:chrome.extension.getURL("options.html#update")});
localStorage["uncheckedUpdate"] = true;
localStorage["major"] = major;
}
if (localStorage["minor"] == undefined) {
localStorage["minor"] = 0;
}
if (localStorage["minor"] < minor) {
localStorage["uncheckedUpdate"] = true;
localStorage["minor"] = minor;
}
// ---- END CHECK UPDATE ----//
//---- TALK TO ICON ----//
function checkForGcal(tabId, changeInfo, tab) {
if (localStorage["uncheckedUpdate"] == "true") {
chrome.pageAction.setIcon({tabId: tab.id, path: "img/icons/icon19_update.png"});
chrome.pageAction.setTitle({tabId: tab.id, title:"Minimalist for Google Calendar has been updated! Click to dismiss."});
} else {
chrome.pageAction.setIcon({tabId: tab.id, path: "img/icons/icon19.png"});
chrome.pageAction.setTitle({tabId: tab.id, title: "Minimalist for Google Calendar Options"});
localStorage["uncheckedUpdate"] = false;
}
var o = JSON.parse(localStorage["options"]);
if (tab.url.indexOf('google.com/calendar') > -1 && !o.mcicon) {
chrome.pageAction.show(tabId);
}
};
chrome.tabs.onUpdated.addListener(checkForGcal);
//---- END TALK TO ICON ----//
//---- TALK TO SCRIPTS ----//
var joy = true; // whether or not Minimalist for Google Calendar is activated [via icon]
chrome.extension.onRequest.addListener(function (request, sender, sendResponse) {
if (request.elements == "o" && joy) {
sendResponse({
"o": JSON.parse(localStorage["options"])
});
}
if (request.elements == "e") {
sendResponse({
"e": localStorage["easterEgg"]
});
}
if (request.action == "reload") reloadTab();
if (request.action == "toggle") joy ? joy = false : joy = true;
});
//---- END TALK TO SCRIPTS ----//
//---- HELPER METHODS ----//
function reloadTab() {
chrome.windows.getCurrent(function(win) {
var cwin = win.id;
chrome.tabs.getAllInWindow(cwin, function(tabs) {
for (var i = 0; i < tabs.length; i++) {
var t = tabs[i].url;
if (t.match('google.com/calendar')) {
var tab = tabs[i];
chrome.tabs.update(tab.id, {url: tab.url, selected: tab.selected}, null);
}
}
});
});
}
//---- END HELPER METHODS ----//
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-21124660-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
</body>
</html>