forked from zchr/zoomies
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
108 lines (93 loc) · 2.56 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
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (changeInfo.status != "complete" || !tab.active) {
return;
}
async function execute() {
function isAroundPage() {
return isMatch("around", "around.co", ["Continue in Browser"]);
}
function isAsanaPage() {
return isMatch("asana", "asana.com", ["Opening link in Asana"]);
}
function isAWSPage() {
return isMatch("aws", "awsapps.com", ["You may now close this browser"]);
}
function isFigmaPage() {
return isMatch("figma", "figma.com", ["Open here instead"]);
}
function isLinearPage() {
return isMatch("linear", "linear.app", [
"The link was opened in the Linear app",
]);
}
function isMiroPage() {
return isMatch("miro", "miro.com/app/board/", null);
}
function isNotionPage() {
return isMatch("notion", "notion.so", ["Redirecting to your Notion app"]);
}
function isTeamsPage() {
return isMatch("teams", "teams.live.com", ["Open your Teams app"]);
}
function isZoomPage() {
return isMatch("zoom", "zoom.us", [
"Your meeting has been launched",
"on the dialog shown by your browser",
]);
}
async function isMatch(name, origin, searches) {
const regex = new RegExp(`https://([a-z]*\\.)?${origin}`, "g");
const isSiteActive = (await chrome.storage.local.get("sites")).sites[
name
];
return (
isSiteActive &&
window.location.href.match(regex) &&
(searches == null ||
searches.find((search) =>
window.find(
search,
/* aCaseSensitive */ false,
/* aBackwards */ false,
/* aWrapAround */ true
)
))
);
}
const checks = [
isAroundPage,
isAsanaPage,
isAWSPage,
isFigmaPage,
isLinearPage,
isMiroPage,
isNotionPage,
isTeamsPage,
isZoomPage,
];
for (let i = 0; i < checks.length; i++) {
if (await checks[i]()) {
return true;
}
}
return false;
}
chrome.scripting
.executeScript({
target: { tabId, allFrames: true },
func: execute,
})
.then((response) => {
const { result } = response[0];
if (result) {
setTimeout(() => {
chrome.tabs.remove(tabId);
chrome.storage.local
.get("tally")
.then(({ tally }) =>
chrome.storage.local.set({ tally: (tally || 0) + 1 })
);
}, 1000);
}
});
});