const got = require('got')
const liveapi = "" // Deploy your own Endpoint from https://runkit.com/neverbehave/5ec9f6c9db17df001a1a4e8c
const api = "https://sentinel.majorleaguegaming.com/api/v1/viewers/owl"
const interval = 60000 // 1min
const liveinterval = 3000000 // 5mins
let shouldRun = false
const accountId = "" // login and access "https://www.blizzard.com/zh-tw/user", filled in the userId field
const template = `{"accountId":"${accountId}"}`
const options = {
method: "POST",
headers: {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:76.0) Gecko/20100101 Firefox/76.0",
"Accept": "application/json",
"Accept-Language": "zh-CN,en-US;q=0.7,en;q=0.3",
"Referer": "https://overwatchleague.com/en-us/",
"Content-Type": "application/json",
"Origin": "https://overwatchleague.com" ,
"Connection": "keep-alive",
"TE": "Trailers"
},
body: template
}
const run = async () => {
let result = await got(liveapi).catch(e => console.log(e))
return JSON.parse(result.body).result.player
}
const cal = async () => {
run().then(res => {
console.log(res)
shouldRun = res
})
}
const main = () => shouldRun && got(api, options).then(res => console.log(res.body))
cal().then(() => {
main()
setInterval(main, interval);
}) // trigger the first run after page identification
const liveTask = setInterval(cal, liveinterval);