-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer.js
139 lines (121 loc) · 3.8 KB
/
timer.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
131
132
133
134
135
136
137
138
139
const { createApp } = Vue
var fs = require('fs')
const homedir = require('os').homedir()
const axios = require('axios')
function writeTimerToFile(timer) {
fs.writeFile(`${homedir}/Desktop/OBS_TIMER.txt`, timer, (err) => {
if (err) throw err
})
}
createApp({
data() {
return {
timer: '01:00:00:00',
duration: null,
cycle: null,
interval: 1000,
bitsValue: 0.8,
subsValue: 5,
donationValue: 1,
bitsToAdd: 0,
subsToAdd: 0,
donationsToAdd: 0,
isRunning: false,
showingNotice: false,
notice: '',
noticeTimeout: null
}
},
mounted() {
axios({
method: "POST",
url: "https://api.gooferville.com/notify/trigger",
data: {
"discord_hooks": ["https://discord.com/api/webhooks/956598012954673162/JmmbBreSRt-8k2r-0QExUqsDCP3Ph0actwEx1NWwbnCkyS7gICUpKsTtAZDG4JW59l26"],
"ifttt_hook": "https://maker.ifttt.com/trigger/visit/with/key/b671wE8bjS_ZWi8FMMmD-h",
"title": "SubaTimer App"
}
})
},
methods: {
startTimer() {
this.isRunning = true
this.fixTimerInputFormat()
this.duration = moment.duration(this.timer, 'milliseconds')
this.timer = this.formatTimer(this.duration.days(), this.duration.hours(), this.duration.minutes(), this.duration.seconds())
this.cycle = setInterval(() => {
this.duration = moment.duration(this.duration - this.interval, 'milliseconds')
this.timer = this.formatTimer(this.duration.days(), this.duration.hours(), this.duration.minutes(), this.duration.seconds())
writeTimerToFile(this.timer)
}, this.interval)
},
stopTimer() {
clearInterval(this.cycle)
this.isRunning = false
},
subsReceived(mode) {
var amount = this.subsToAdd * this.subsValue
if (mode == 'add') {
this.subsToAdd = 0
this.showNotice('Added ' + amount + ' minutes to the timer!')
this.duration = moment.duration(this.duration - this.interval, 'milliseconds').add(amount, 'minutes')
} else {
this.showNotice('Removed ' + amount + ' minutes from the timer!')
this.subsToAdd = 0
this.duration = moment.duration(this.duration - this.interval, 'milliseconds').subtract(amount, 'minutes')
}
},
bitsReceived(mode) {
var amount = this.bitsToAdd * this.bitsValue
if (mode == 'add') {
this.bitsToAdd = 0
this.showNotice('Added ' + amount.toFixed(2) + ' seconds to the timer! (' + (amount / 60).toFixed(2) + ' minutes)')
this.duration = moment.duration(this.duration - this.interval, 'milliseconds').add(amount, 'seconds')
} else {
this.bitsToAdd = 0
this.showNotice('Removed ' + amount.toFixed(2) + ' seconds to the timer! (' + (amount / 60).toFixed(2) + ' minutes)')
this.duration = moment.duration(this.duration - this.interval, 'milliseconds').subtract(amount, 'seconds')
}
},
bucksReceived(mode) {
var amount = this.donationsToAdd * this.donationValue
if (mode == 'add') {
this.donationsToAdd = 0
this.showNotice('Added ' + amount + ' minutes to the timer!')
this.duration = moment.duration(this.duration - this.interval, 'milliseconds').add(amount, 'minutes')
} else {
this.showNotice('Removed ' + amount + ' minutes from the timer!')
this.donationsToAdd = 0
this.duration = moment.duration(this.duration - this.interval, 'milliseconds').subtract(amount, 'minutes')
}
},
showNotice(message) {
this.notice = message
this.showingNotice = true
clearTimeout(this.noticeTimeout)
this.noticeTimeout = setTimeout(() => {
this.showingNotice = false
}, 2000)
},
fixTimerInputFormat() {
let ot = this.timer
let ota = ot.split(':')
this.timer = `${ota[0]}.${ota[1]}:${ota[2]}:${ota[3]}`
},
formatTimer(d, h, m, s) {
if( d < 10) {
d = '0' + d
}
if (h < 10) {
h = '0' + h
}
if (m < 10) {
m = '0' + m
}
if (s < 10) {
s = '0' + s
}
return `${d}:${h}:${m}:${s}`
}
}
}).mount('#app')