This repository has been archived by the owner on Feb 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.html
85 lines (67 loc) · 2.38 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
<html>
<script src="jquery.js"></script>
<script src="cache.js"></script>
<script src="underscore.js"></script>
<script src="wandermind.js"></script>
<script>
var colors = {"work": [192, 0, 0, 255], "break": [0, 192, 0, 255]}
var finishedSound = new Audio("ring.mp3");
/* blocking */
function block(tab) {
if (currentState.mode != "break" &&
blacklist.isBlocked(tab.url) &&
!_.any(currentState.tags, function(tag) { return whitelist.isAllowed(tag, tab.url) }) ) {
chrome.tabs.executeScript(tab.id, {file: "overlay.js"})
}
}
function blockAll() {
chrome.windows.getAll({populate:true}, function (windows) {
_.each(windows, function (window) {
_.each(window.tabs, function (tab) {
block(tab)
})
})
})
}
/* Modes: pause, work, break */
var currentState, interval
function change() {
if (currentState.mode == "pause") {
blockAll()
clearInterval(interval) // just in case
chrome.browserAction.setBadgeText({text: ''})
chrome.browserAction.setIcon({path: "icons/pause.png"})
chrome.browserAction.setPopup({popup: "popup.html"})
} else {
var timeRemaining = currentState.duration * 60
chrome.browserAction.setBadgeBackgroundColor({color: colors[currentState.mode]})
chrome.browserAction.setBadgeText({text: formatDuration(timeRemaining)})
chrome.browserAction.setIcon({path: "icons/" + currentState.mode + ".png"})
chrome.browserAction.setPopup({popup: "popup_cancel.html"})
function tick() {
timeRemaining--
chrome.browserAction.setBadgeText({text: formatDuration(timeRemaining)})
if (timeRemaining <= 0) {
notification = webkitNotifications.createNotification(
"icons/" + currentState.mode + ".png",
"Time's up!",
"Bring more work on!"
)
notification.show()
finishedSound.play()
_.each(currentState.tags, function (tag) {
tagCounter.increment(tag)
})
mode.pause()
}
}
interval = window.setInterval(tick, 1000)
return interval
}
}
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
block(tab)
})
mode.pause()
</script>
</html>