This repository was archived by the owner on Jan 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathturn-timer.js
More file actions
107 lines (89 loc) · 3.88 KB
/
Copy pathturn-timer.js
File metadata and controls
107 lines (89 loc) · 3.88 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
// GitHub: https://github.com/JamesMowery/turn-timer
// By: James Mowery
// Contact: https://app.roll20.net/users/1001679/james-mowery
var seconds = 0;
var interval = null;
var TurnTimer = TurnTimer || (function() {
'use strict';
var version = "0.0.1";
});
function countDown() {
'use strict';
seconds = seconds - 1;
if (seconds == 121) {
sendChat("GM", "<div style='height:32px; border:1px solid #CCC; \
font-weight: bold;'><img src=\
'https://cdn0.iconfinder.com/data/icons/feather/96/clock-512.png' \
width='32px' height='32px' style='float: left;'> \
<div style='float: left; height: 16px; \
vertical-align:middle; margin: 8px 0 0 10px;'>\
2 Minutes Remaining</div></div>");
}
if (seconds == 61) {
sendChat("GM", "<div style='height:32px; border:1px solid #CCC; \
font-weight: bold;'><img src=\
'https://cdn0.iconfinder.com/data/icons/feather/96/clock-512.png' \
width='32px' height='32px' style='float: left;'> \
<div style='float: left; height: 16px; \
vertical-align:middle; margin: 8px 0 0 10px;'>\
1 Minute Remaining</div></div>");
}
if (seconds == 16) {
sendChat("GM", "<div style='height:32px; border:1px solid #CCC; \
font-weight: bold;'><img src=\
'https://cdn0.iconfinder.com/data/icons/feather/96/clock-512.png' \
width='32px' height='32px' style='float: left;'> \
<div style='float: left; height: 16px; \
vertical-align:middle; margin: 8px 0 0 10px;'>\
15 Seconds Remaining!</div></div>");
}
if (seconds <= 0) {
sendChat("GM", "<div style='height:32px; border:1px solid #CCC; \
font-weight: bold;'><img src=\
'https://cdn0.iconfinder.com/data/icons/feather/96/clock-512.png' \
width='32px' height='32px' style='float: left;'> \
<div style='float: left; height: 16px; \
vertical-align:middle; margin: 8px 0 0 10px;'>\
Time\'s Up!</div></div>");
clearInterval(interval);
}
}
on("chat:message", function(msg) {
'use strict'
// When the GM types !t <number>, start a timer for <number> seconds
if(msg.type == "api" && msg.content.indexOf("!t ") !== -1) {
// Clear the previous timer if running.
clearInterval(interval);
log("Detected Typing");
// Extracts the number of seconds in the command
seconds = Number(msg.content.replace("!t ", ""));
log(seconds);
// Begin the countdown
interval = setInterval(countDown, 1000, seconds);
// Inform the players that the timer has started
sendChat("GM", "<div style='height:32px; border:1px solid #CCC; \
font-weight: bold;'><img src=\
'https://cdn0.iconfinder.com/data/icons/feather/96/clock-512.png' \
width='32px' height='32px' style='float: left;'> \
<div style='float: left; height: 16px; \
vertical-align:middle; margin: 8px 0 0 10px;'>\
Timer Started</div></div>");
}
// When the GM types !t, start a timer for a default number of seconds
else if(msg.type == "api" && msg.content.indexOf("!t") !== -1) {
clearInterval(interval); // Clear the previous timer if running.
seconds = 60; // Sets the default number of seconds
// Begins the countdown
interval = setInterval(countDown, 1000, seconds);
sendChat("GM", "<div style='height:32px; border:1px solid #CCC; \
font-weight: bold;'><img src=\
'https://cdn0.iconfinder.com/data/icons/feather/96/clock-512.png' \
width='32px' height='32px' style='float: left;'> \
<div style='float: left; height: 16px; \
vertical-align:middle; margin: 8px 0 0 10px;'>\
Timer Started - 1 Minute</div></div>");
}
});
on("ready", function() {
'use strict';
});