-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent_clock.js
More file actions
137 lines (113 loc) · 3.28 KB
/
event_clock.js
File metadata and controls
137 lines (113 loc) · 3.28 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/**
* XSplit script for adding a time display suitable for live events.
* It features both a clock and a day counter: "HH:MM:SS<br>Day N"
*/
'use strict';
/**
* @name ShowSeconds
* @label Clock seconds
* @type boolean
* @description Show clock seconds
*/
var ShowSeconds = true;
/**
* @name TextBefore
* @label Text Before
* @type text
* @description Text that will go before the timer
*/
var TextBefore = "";
/**
* @name TextAfter
* @label Text After
* @type text
* @description Text that will go after the timer
*/
var TextAfter = "";
/**
* @name DateReference
* @label Event start date
* @type date
* @description Date of the first day, format MM/DD/YYYY
*/
var DateReference = "9/20/2015";
/**
* @name DayString
* @label Day text
* @type text
* @description Day count text, %N will be replaced by the day number
*/
var DayString = "<br>Dag %N";
/*Do not modify anything below*/
var isPaused = false;
var UPDATEINTERVAL = 500; //0.5 seconds
function getDays(){
var refParts = DateReference.split("/");
var ref = new Date(refParts[2] + "," + refParts[0] + "," + refParts[1]);
var now = Date.now();
var delta = now - ref;
var days = Math.floor(delta / (1000 * 3600 * 24));
if ( days >= 0 ){
return DayString.replace(/%N/, days + 1);
} else {
return '';
}
}
function getClock(){
var currentTime = new Date();
var currentHours = currentTime.getHours();
var currentMinutes = currentTime.getMinutes();
var currentSeconds = currentTime.getSeconds();
/* zeropad */
currentHours = ( currentHours < 10 ? '0' : '' ) + currentHours;
currentMinutes = ( currentMinutes < 10 ? '0' : '' ) + currentMinutes;
currentSeconds = ( currentSeconds < 10 ? '0' : '' ) + currentSeconds;
if ( ShowSeconds ){
return currentHours + ':' + currentMinutes + ':' + currentSeconds;
} else {
return currentHours + ':' + currentMinutes;
}
}
function updateText(){
var clock = getClock();
var days = getDays();
SetText(TextBefore + clock + days + TextAfter, 'Event Clock');
smlTitleTimeouts = setTimeout(function() { updateText(); }, UPDATEINTERVAL);
}
var isPreview = false, isThumbnail = false;
var isPreviewID;
if (window.external.GetLocalProperty){
isPreviewID = window.external.GetLocalPropertyAsync("prop:viewid");
isThumbnail = window.external.GetGlobalProperty("preview_editor_opened") === 0;
}
function OnSceneLoad(){
if (window.external.GetLocalProperty){
isPreview = false;
isThumbnail = false;
}
}
var secondsElapsed = 0;
var startPause, endPause;
var browserConfigID;
window.OnAsyncCallback = function(async_id, result){
result = decodeURIComponent(result);
if (async_id == isPreviewID){
isPreview = result == 1;
} else if (async_id == browserConfigID){
var config = JSON.parse(result);
config.isPaused = isPaused.toString();
window.external.SetLocalPropertyAsync("prop:BrowserConfiguration", JSON.stringify(config));
}
};
function HandlePostMessage(event){
if (event.data == "OnSceneLoad"){
OnSceneLoad();
} else if (event.data == "TogglePause"){
TogglePause();
}
}
if (smlTitleTimeouts && smlTitleTimeouts !== null){
clearTimeout(smlTitleTimeouts);
}
window.addEventListener('message', HandlePostMessage, false);
updateText();