-
Notifications
You must be signed in to change notification settings - Fork 0
/
xbox-stock-checker.js
46 lines (42 loc) · 1.53 KB
/
xbox-stock-checker.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
let xbox = (function() {
const yeah = new Audio('https://instantrimshot.com/audio/csi.mp3')
const regex = /(aria\-label\=\")?\>?add to cart\"?\<?/i
function get(url, callback) {
let xhr = new XMLHttpRequest()
xhr.open('GET', url, true)
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
callback(xhr.response)
}
}
xhr.send()
}
function check() {
get(window.location.href, response => {
if (regex.test(response)) {
console.warn(new Date().toLocaleTimeString() + ' | IN STOCK')
yeah.play()
}
setTimeout(check, 1000)
})
}
let start = new Date()
setTimeout(check)
console.info(
`%cXbox Stock Checker%c is running in the background.
Do not close this tab.
Call %cxbox.runtime()%c to view elapsed time.`,
'background-color:#107c10;','','background-color:#33c;',''
)
return {
runtime: function() {
let now = new Date()
let diff = now - start
let days = Math.floor(diff / 86400000)
let hours = Math.floor((diff -= days * 86400000) / 3600000)
let minutes = Math.floor((diff -= hours * 3600000) / 60000)
let seconds = Math.floor((diff -= minutes * 60000) / 1000)
return `${days>0?days+' days, ':''}${hours>0?hours+' hours, ':''}${minutes>0?minutes+' minutes, ':''}${seconds+' seconds'}`
}
}
})()