-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservice_worker.js
More file actions
35 lines (26 loc) · 1019 Bytes
/
service_worker.js
File metadata and controls
35 lines (26 loc) · 1019 Bytes
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
chrome.webNavigation.onBeforeNavigate.addListener((details) => {
// Only act on the main frame navigation (not iframes)
if (details.frameId !== 0) {
return;
}
const url = new URL(details.url);
const hostname = url.hostname;
const googleDomainRegex = /^(drive|mail|sheets|docs|photos|chat|meet)\.google\.com$|^gmail\.com$/
if (googleDomainRegex.test(hostname)) {
if (url.pathname === "/" && url.search === "") {
let continueUrl;
if (hostname === "gmail.com") {
continueUrl = "https://mail.google.com/";
} else {
continueUrl = `https://${hostname}/`;
}
const chooserUrl = `https://accounts.google.com/AccountChooser?continue=${encodeURIComponent(continueUrl)}`;
chrome.tabs.update(details.tabId, { url: chooserUrl });
}
}
}, {
url: [
{ hostSuffix: "google.com" },
{ hostSuffix: "gmail.com" }
]
});