-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
134 lines (100 loc) · 3.12 KB
/
script.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
///////////////////////////
// STREAMELEMENTS FIELDS //
///////////////////////////
let googleFont = "Open Sans";
let customFont = "";
/////////////////
// GLOBAL VARS //
/////////////////
let animationSpeed = 1.0;
let tl = gsap.timeline();
//////////////////////
// HELPER FUNCTIONS //
//////////////////////
function IsNullOrWhitespace(str) {
return /^\s*$/.test(str);
}
///////////////////////////
// STREAMELEMENTS EVENTS //
///////////////////////////
var urlParams;
var fieldData = null;
var dayFormat = "";
var clockFormat = "hh:mm A";
window.addEventListener('onWidgetLoad', function (obj) {
var fieldData = obj.detail.fieldData;
console.log(`[STREAMER-CLOCK] WIDGET LOAD. VERSION ${fieldData.previewModeLabel}.`);
// https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript
/*(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]);
})();*/
var outputDay = document.getElementById("outputDay");
var output = document.getElementById("output");
//if (urlParams["style"]) output.setAttribute("style", urlParams["style"]);
//if (urlParams["bodyStyle"]) document.body.setAttribute("style", urlParams["bodyStyle"]);
//if (urlParams["format"] == null) urlParams["format"] = "hh:mm A"; //Default format: Hours:Minutes and AM/PM
console.log(`[STREAMER-CLOCK] Set to ${fieldData.clockMode} Format.`);
switch(fieldData.dayFormat)
{
case "1":
dayFormat = "YY";
break;
case "2":
dayFormat = "YYYY";
break;
case "3":
dayFormat = "DD/MM";
break;
case "4":
dayFormat = "DD/MM/YY";
break;
case "5":
dayFormat = "DD/MM/YYYY";
break;
case "6":
dayFormat = "dddd DD/MM/YY";
break;
case "7":
dayFormat = "dddd DD/MM/YYYY";
break;
default:
case "0":
clockFormat = "";
break;
}
switch(fieldData.clockMode)
{
case "24":
clockFormat = "HH:mm";
break;
default:
case "12":
clockFormat = "hh:mm A";
break;
}
console.log("DayFormat(b):", dayFormat);
if(!IsNullOrWhitespace(fieldData.dayFormatCustom))
{
dayFormat = fieldData.dayFormatCustom;
}
console.log("DayFormat(a):", dayFormat);
//refreshValues();
});
var c;
setInterval(
c = function() {
//let format = (!IsNullOrWhitespace(dayFormat)) ? `${dayFormat} ${clockFormat}` : `${clockFormat}`;
if(!IsNullOrWhitespace(dayFormat))
{
outputDay.innerText = moment().format(dayFormat);
}
output.innerText = moment().format(`${clockFormat}`);
}, 1000);
c();