-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
54 lines (51 loc) · 1.9 KB
/
background.js
File metadata and controls
54 lines (51 loc) · 1.9 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
chrome.runtime.onInstalled.addListener(function(details){
// when installed request user_id and store.
if (details.reason=="install"){
fetch('https://vit-captcha-solver.herokuapp.com/api/', {
// fetch('https://http://127.0.0.1:5000/api/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({'function':'createID'}),
})
.then(response => response.json())
.then(data => {
console.log(data)
chrome.storage.sync.set({uid:data.newId, isBought:0, freeLeft:5}, function(){
console.log('New uid set '+data.newId)
})
})
.catch((err) => {
console.log(err)
});
// when updated check for bought status
} else if (details.reason=="update"){
chrome.storage.sync.get(['freeLeft', 'uid'], function (result) {
fetch('https://vit-captcha-solver.herokuapp.com/api/', {
// fetch('https://http://127.0.0.1:5000/api/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({'function':'checkBought', 'uid':result.uid}),
})
.then(response => response.json())
.then(data => {
console.log(data)
if (data.ans) {
chrome.storage.sync.set({isBought:1}, function(){
console.log('Uid '+result.uid+' Bought');
})
} else {
chrome.storage.sync.set({isBought:0}, function(){
console.log('Uid '+result.uid+' not Bought');
})
}
})
.catch((err) => {
console.log(err)
});
});
}
});