-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock.html
More file actions
109 lines (103 loc) · 2.62 KB
/
clock.html
File metadata and controls
109 lines (103 loc) · 2.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
<!DOCTYPE html>
<html>
<head>
<title>OBS Timer</title>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>
</head>
<body translate="no">
<div id="output"></div>
<p id="debug"></p>
</body>
<script type="text/javascript">
//base on https://gist.github.com/sam0737/a0ee8ca253fc5c84b2aa2ac018f7b8ad
//RegEx from here
var urlParams, timer;
(function () {
var match,
pl = /\+/g, // Regex for replacing addition symbol with a space
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
query = window.location.search.substring(1);
urlParams = {};
while (match = search.exec(query))
urlParams[decode(match[1])] = decode(match[2]);
})();
//RegEx end
var output=document.getElementById("output");
function getURL(){
var URL = window.location.search.substring(1);
document.getElementById("showURL").innerHTML=URL;
}
function showClock(){
var c;
setInterval(
c = function() {
output.innerText = moment().format(urlParams["format"] || '');
}
, 500);
}
function getSetTime(){
var setTime;
if (urlParams["time"]) {
setTime=urlParams["time"];
}
else{
setTime=0;
if (urlParams["hour"]) setTime+=(Number(urlParams["hour"])*3600);
if (urlParams["min"]) setTime+=(Number(urlParams["min"])*60);
if (urlParams["sec"]) setTime+=Number(urlParams["sec"]);
}
showRegTime(setTime);
return setTime;
}
function showRegTime(time){
var setHour, setMin, setSec;
setHour=Math.floor(time/3600);
if (setHour<10) setHour="0"+setHour;
setMin=Math.floor(Math.floor(time/60)%60);
if (setMin<10) setMin="0"+setMin;
setSec=time%60;
if (setSec<10) setSec="0"+setSec;
output.innerText = setHour+":"+setMin+":"+setSec;
}
function showMessage(msg){
output.innerText = msg;
}
function countDown(time, msg){
var count;
if (time==0) return 0;
timer1 = setInterval(
count = function(){
time--;
showRegTime(time);
if (time==0) {
clearInterval(timer1);
if (msg) {
showMessage(msg);
}
}
}
,1000);
}
if (urlParams["mode"]) {
var mode = urlParams["mode"];
switch(mode){
case 'timer' :{
if (urlParams['msg']) {
countDown(getSetTime(),urlParams['msg']);
}
else countDown(getSetTime());
break;
}
default :{
showClock();
break;
}
}
}
else showClock();
if (urlParams["style"]) output.setAttribute("style", urlParams["style"]);
if (urlParams["bodyStyle"]) document.body.setAttribute("style", urlParams["bodyStyle"]);
</script>
</html>