-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnewtimer.js
More file actions
118 lines (107 loc) · 3.62 KB
/
newtimer.js
File metadata and controls
118 lines (107 loc) · 3.62 KB
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
const monthNames = ["JAN", "FEB", "MAR", "APR", "MAY", "JUN",
"JUL", "AUG", "SEP", "OCT", "NOV", "DEC"
];
$(function () {
var audio = new Audio('silence.mp3');
audio.play();
var tz = moment.tz.guess();
var dateObj = moment().tz(tz);
var month = dateObj.month(); //months from 1-12
var day = dateObj.date();
var year = dateObj.year();
$("#month").text(monthNames[month]);
$("#day").text(day + '.');
chrome.storage.sync.get(['mission'], function (result) {
var missionText = result.mission;
if (missionText != null) {
document.getElementById('mission').value = missionText;
}
});
chrome.storage.sync.get(['task'], function (result) {
var text = result.task;
if (text != null) {
document.getElementById('task').value = text;
}
});
chrome.storage.sync.get(['taskTimerDate'], function (result) {
var taskTimerDate = result.taskTimerDate;
var date = moment(taskTimerDate);
if (taskTimerDate != null) {
if (date > moment()) {
var $taskTimerDate = $('#taskTimerDate');
$($taskTimerDate).countdown(date.toDate());
}
}
});
chrome.storage.sync.get(['longTimerTitle'], function (result) {
var longTimerTitle = result.longTimerTitle;
if (longTimerTitle != null) {
$('#longTimerTitle').text(longTimerTitle);
}
});
chrome.storage.sync.get(['longTimerDate'], function (result) {
var longTimerDate = result.longTimerDate;
if (longTimerDate != null) {
var $date = $('#longTimerDate');
$($date).countdown(longTimerDate);
}
});
});
$("#task-form").submit(function (event) {
event.preventDefault();
var mins = $('#task-form :input[name=time]').val();
var tz = moment.tz.guess();
var d1 = moment().tz(tz);
d2 = moment(d1).add(mins, 'minutes');
var date = d2.toDate();
var dateString = date.toString()
chrome.storage.sync.set({'taskTimerDate': dateString }, () => {
if (mins != null) {
var $taskTimerDate = $('#taskTimerDate');
$($taskTimerDate).countdown(date);
}
});
})
$("#config").submit(function (event) {
event.preventDefault();
var $inputs = $('#config :input');
$inputs.each(function () {
var val = $(this).val();
var name = this.name;
chrome.storage.sync.set({ [name]: val }, () => {
if (name == 'longTimerDate') {
if (val != null) {
$longTimerDate = $('#longTimerDate');
$($longTimerDate).countdown(val);
}
}
if (name == 'longTimerTitle') {
if (val != null) {
$('#longTimerTitle').text(val);
}
}
});
});
})
$("#mission").change(function () {
var missionText = this.value;
chrome.storage.sync.set({ 'mission': missionText }, function () {
console.log('set mission to ' + missionText);
});
});
$("#task").change(function () {
var text = this.value;
chrome.storage.sync.set({ 'task': text }, function () {
console.log('set task to ' + text);
});
});
$('[data-countdown]').each(function () {
var $this = $(this), finalDate = $(this).data('countdown');
$this.countdown(finalDate, function (event) {
$this.html(event.strftime('%D d %H h %M m %S s'));
}).on('finish.countdown', function(event){
var audio = new Audio('tuturu_1.mp3');
audio.play();
$(this).html('END').parent().addClass('disabled');
});
});