-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathbackground.js
More file actions
47 lines (42 loc) · 1.23 KB
/
Copy pathbackground.js
File metadata and controls
47 lines (42 loc) · 1.23 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
function handleMessage(request) {
if (
request &&
request.closeWebPage === true &&
request.isSuccess === true
) {
/* Set username */
chrome.storage.local.set(
{ leethub_username: request.username },
() => {
window.localStorage.leethub_username = request.username;
},
);
/* Set token */
chrome.storage.local.set({ leethub_token: request.token }, () => {
window.localStorage[request.KEY ?? 'leethub_token'] =
request.token;
});
/* Close pipe */
chrome.storage.local.set({ pipe_leethub: false }, () => {
console.log('Closed pipe.');
});
chrome.tabs.getSelected(null, function (tab) {
chrome.tabs.remove(tab.id);
});
/* Go to onboarding for UX */
const urlOnboarding = chrome.runtime.getURL('welcome.html');
chrome.tabs.create({ url: urlOnboarding, active: true }); // creates new tab
} else if (
request &&
request.closeWebPage === true &&
request.isSuccess === true
) {
alert(
'Something went wrong while trying to authenticate your profile!',
);
chrome.tabs.getSelected(null, function (tab) {
chrome.tabs.remove(tab.id);
});
}
}
chrome.runtime.onMessage.addListener(handleMessage);