-
Notifications
You must be signed in to change notification settings - Fork 10
/
popup.js
executable file
·98 lines (94 loc) · 2.91 KB
/
popup.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
function chrome_() {
try {
chrome !== undefined && browser !== undefined;
return browser;
} catch (e) {
console.log(e.message);
return chrome;
}
}
document.addEventListener("DOMContentLoaded", function () {
var pause = document.getElementById("pause");
var resume = document.getElementById("resume");
var signin = document.getElementById("signin");
var signout = document.getElementById("signout");
var loginContainer = document.getElementById("loginContainer");
var logoutContainer = document.getElementById("logoutContainer");
chrome_().storage.local.get(["pause"], function (data) {
if (data.pause) {
pause.style.display = "none";
resume.style.display = "visible";
} else {
pause.style.display = "visible";
resume.style.display = "none";
}
});
chrome_().storage.local.get(["token"], function (data) {
if (data.token) {
loginContainer.style.display = "none";
logoutContainer.style.display = "visible";
} else {
loginContainer.style.display = "visible";
logoutContainer.style.display = "none";
}
});
pause.addEventListener("click", function () {
chrome_().storage.local.set({ pause: true }, function () {
chrome_().notifications.create("Paused", {
type: "basic",
iconUrl: "logo.png",
title: "Paused",
message: "ExVTOP has been paused, you'll not receive updates.",
});
window.close();
});
});
document.querySelector(".github").addEventListener("click", () => {
chrome.tabs.create({
url: "https://github.com/sudonims/vtop-da-deadline",
});
window.close();
return false;
});
resume.addEventListener("click", function () {
chrome_().storage.local.set({ pause: false }, function () {
chrome_().notifications.create("Resumed", {
type: "basic",
iconUrl: "logo.png",
title: "Resumed",
message: "ExVTOP has been resumed. Enjoy!",
});
window.close();
});
});
signin.addEventListener("click", function () {
console.log(chrome_().identity.getRedirectURL());
window.close();
chrome_().runtime.sendMessage({ message: "login" }, function (response) {
if (response === "success") {
}
});
});
signout.addEventListener("click", function () {
chrome_().storage.local.get(["token"], async function (token) {
console.log(token.token);
await fetch("https://oauth2.googleapis.com/revoke?token=" + token.token, {
method: "POST",
body: "",
headers: {
"Content-type": "application/x-www-form-urlencoded",
},
})
.then((res) => res)
.then((data) => {
console.log(data);
chrome_().notifications.create("Sign Out", {
type: "basic",
iconUrl: "logo.png",
title: "Signed Out",
message: "Signed Out from Google",
});
});
});
});
});