-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
30 lines (28 loc) · 991 Bytes
/
script.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
function setup() {
chrome.storage.local.get("token", function (obj) {
if (obj.token) {
document.querySelector("button").innerHTML = "Stack Exchange log out";
} else {
document.querySelector("button").innerHTML = "Stack Exchange log in";
}
});
}
function buttonClick() {
chrome.storage.local.get("token", function (obj) {
if (obj.token) {
chrome.extension.getBackgroundPage().getToken(chrome.extension.getBackgroundPage().logout);
} else {
chrome.extension.getBackgroundPage().login();
}
});
}
setup();
document.querySelector("button").addEventListener("click", buttonClick, false);
chrome.storage.onChanged.addListener(function(obj, namespace) {
console.log(obj);
if (obj.token.newValue) {
document.querySelector("button").innerHTML = "Stack Exchange log out";
} else {
document.querySelector("button").innerHTML = "Stack Exchange log in";
}
});