forked from taicki/omnibox-timer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ui.js
148 lines (125 loc) · 4.42 KB
/
ui.js
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
$(function () {
buildPage();
chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
console.log(message);
if (message.action == "refreshPage") buildPage();
});
});
function showSaveMessage() {
$("#flash").show();
$("#flash").html("Option Saved");
setTimeout(function () {
$("#flash").fadeOut("slow");
}, 1000);
}
function buildPage() {
// Fetch manifest.json
let extVer = null;
fetch('manifest.json')
.then(response => response.json())
.then(data => {
// Access the properties in the manifest.json file
console.log('Version:', data.version);
extVer = data.version;
// You can do more with other properties as needed
$('#version').text("Ver " + extVer);
})
.catch(error => console.error('Error fetching manifest.json:', error));
chrome.storage.local.get({
timers: [],
idCounter: 0,
soundType: "tts",
notitype: "chromenoti",
historySuggestionType: "time"
}, function (object) {
$("#timers > tbody:last tr.record").remove();
for (var i = 0; i < Math.min(object.timers.length, 10); i++) {
console.log(object.timers);
var timer = object.timers[i];
$("#timers > tbody:last")
.append("<tr class='record'>"
+ "<td>" + timer.desc + "</td>"
+ "<td>" + moment(timer.currentTime).calendar() + "</td>"
+ "<td>" + moment(timer.notificationTime).calendar() + " (" + moment(timer.notificationTime).fromNow() + ")</td>"
+ "<td toid='" + timer.tid + "' class='remove-button " + timer.status + "'> " + timer.status + "</td>"
+ "</tr>");
$('tr').last().addClass(timer.status);
if (timer.status == 'ongoing') {
$(".remove-button").last().text("Ongoing");
} else if (timer.status == 'done') {
$(".remove-button").last().text("Done");
} else if (timer.status == 'snoozed') {
$(".remove-button").last().text("Snoozed");
} else if (timer.status == 'reached') {
$(".remove-button").last().text("Reached");
} else if (timer.status == 'cancelled') {
$(".remove-button").last().text("Cancelled");
}
}
$('.remove-button').click(function () {
// if ($(this).parent().hasClass('ongoing') == false) return;
if (confirm("To Cancel Timer? ")) {
var curi = parseInt($(this).attr('toid'));
console.log(curi)
chrome.runtime.sendMessage({ action: 'clearTimeOut', dat: curi });
}
});
$('#clear-button').off('click');
$('#clear-button').on('click', function () {
if (confirm("Sure to stop all timers?"))
chrome.runtime.sendMessage({ action: 'clearAllTimer' });
});
// $("#stats").html("<li># of timers you created: " + object.idCounter + "</li>");
if (object.notitype == "windownoti") {
$("input#windownoti").attr("checked", true);
} else if (object.notitype == "chromenoti") {
$("input#chromenoti").attr("checked", true);
} else {
$("input#chromenoti").attr("checked", true);
}
$("input#windownoti").change(function () {
chrome.storage.local.set({ notitype: "windownoti" });
showSaveMessage();
});
$("input#chromenoti").change(function () {
chrome.storage.local.set({ notitype: "chromenoti" });
showSaveMessage();
});
if (object.soundType == "tts") {
$("input#tts").attr("checked", true);
} else if (object.soundType == "mute") {
$("input#mute").attr("checked", true);
} else {
$("input#bell").attr("checked", true);
}
$("input#tts").change(function () {
chrome.storage.local.set({ soundType: "tts" });
showSaveMessage();
});
$("input#mute").change(function () {
chrome.storage.local.set({ soundType: "mute" });
showSaveMessage();
});
$("input#bell").change(function () {
chrome.storage.local.set({ soundType: "bell" });
showSaveMessage();
});
if (object.historySuggestionType === "time") {
$("input#time").attr("checked", true);
} else {
$("input#count").attr("checked", true);
}
$("input#time").change(function () {
chrome.storage.local.set({ historySuggestionType: "time" });
showSaveMessage();
});
$("input#count").change(function () {
chrome.storage.local.set({ historySuggestionType: "count" });
showSaveMessage();
});
});
//Other refinement
$('h2').click(function () {
$(this).nextUntil('h2').toggle();
});
}