forked from QasimWani/LeetHub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
33 lines (28 loc) · 1.12 KB
/
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
26
27
28
29
30
31
32
33
function handleMessage(request) {
if ( request && request.closeWebPage === true && request.isSuccess === true ) {
/* Set username */
chrome.storage.local.set({ leethub_username: request.username });
/* Set token */
chrome.storage.local.set({ leethub_token: request.token });
/* Close pipe */
chrome.storage.local.set({ pipe_leethub: false }, () => {
console.log('Closed pipe.');
});
chrome.tabs.query({ active: true, lastFocusedWindow: true }, function(tabs) {
var tab = tabs[0];
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 === false ) {
alert(
'Something went wrong while trying to authenticate your profile!',
);
chrome.tabs.query({ active: true, lastFocusedWindow: true }, function(tabs) {
var tab = tabs[0];
chrome.tabs.remove(tab.id)
});
}
}
chrome.runtime.onMessage.addListener(handleMessage);