This repository was archived by the owner on Feb 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathbackground.js
More file actions
60 lines (58 loc) · 1.9 KB
/
background.js
File metadata and controls
60 lines (58 loc) · 1.9 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
48
49
50
51
52
53
54
55
56
57
58
59
60
// Add an event listener for the browser action icon click event
browser.browserAction.onClicked.addListener(() => {
// Get credentials from storage
browser.storage.local.get("credentials").then((results) => {
for (let i = 0; i < results.credentials.length; i++) {
// Open a new tab for each credential
new_tab(results.credentials[i].email, results.credentials[i].password);
}
console.log("credentials: ", results);
console.log("credentials.length: ", results.credentials.length);
});
});
browser.tabs.onRemoved.addListener((tabID) => {
// Delete the container with the tabID as the name OpenAI (tabID)
browser.contextualIdentities.query({}).then((containers) => {
containers.forEach((container) => {
if (container.name == "OpenAI (" + tabID + ")") {
browser.contextualIdentities.remove(container.cookieStoreId);
}
});
});
});
function new_tab(email, password) {
// Create a new container with tabID
browser.contextualIdentities
.create({
name: "OpenAI (tmp)",
color: "blue",
icon: "circle",
})
.then((container) => {
// Save email and password to container's cookies
browser.cookies.set({
url: "https://auth0.openai.com",
name: "email",
value: email,
storeId: container.cookieStoreId,
});
browser.cookies.set({
url: "https://auth0.openai.com",
name: "password",
value: password,
storeId: container.cookieStoreId,
});
// Create a new tab in the container with the tabID and URL
browser.tabs
.create({
cookieStoreId: container.cookieStoreId,
url: "https://chat.openai.com",
})
.then((tabID) => {
// Add the tabID to the container
browser.contextualIdentities.update(container.cookieStoreId, {
name: "OpenAI (" + tabID.id + ")",
});
});
});
}