-
Notifications
You must be signed in to change notification settings - Fork 20
/
popup.js
41 lines (38 loc) · 1.26 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
document.addEventListener("DOMContentLoaded", function () {
const googleSignInButton = document.getElementById("googleSignInButton");
function checkAuth() {
chrome.storage.sync.get(["apiKey", "access_token"], function (data) {
if (data.apiKey || data.access_token) {
// User is logged in, close the popup and open the sidebar
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {action: "toggleSidebar"});
window.close();
});
}
});
}
if (googleSignInButton) {
googleSignInButton.addEventListener("click", function () {
chrome.storage.sync.set({ userId: "chrome-extension-user" });
chrome.storage.sync.get(["userLoggedIn"], function (data) {
if (data.userLoggedIn) {
chrome.tabs.create(
{ url: "https://app.mem0.ai/extension" },
function (tab) {
window.close();
}
);
} else {
chrome.tabs.create(
{ url: "https://app.mem0.ai/login?source=chrome-extension" },
function (tab) {
window.close();
}
);
}
});
});
}
// Check auth status when popup opens
checkAuth();
});