/
background.js
25 lines (19 loc) · 913 Bytes
/
background.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
milestoneReached = false
setInterval(async () => {
const key = config.key
const subscriptionMilestone = config.subscriptionMilestone
const reqUrl = `https://www.googleapis.com/youtube/v3/channels?part=statistics&forUsername=PewDiePie&key=${key}`
const response = await fetch(reqUrl)
const data = await response.json()
let pewdiepieSubscriptions = parseInt(data.items[0].statistics.subscriberCount)
subscriptionsLeft = subscriptionMilestone - pewdiepieSubscriptions
if (subscriptionsLeft < 0 && subscriptionsLeft > -25000 && milestoneReached == false) {
chrome.notifications.create({
type: "basic",
iconUrl: "img/icon_128.png",
title: `Pewdiepie has reached ${subscriptionMilestone.toLocaleString('en-us')}`,
message: `Pewdiepie has reached ${subscriptionMilestone.toLocaleString('en-us')}. We have to celebrate!`
})
milestoneReached = true
}
}, 300000);