forked from sethcottle/tabcloser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
131 lines (121 loc) · 3.74 KB
/
options.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Copyright (C) 2023-2024 Seth Cottle
// This file is part of TabCloser.
// TabCloser is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or any later version.
// TabCloser is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Please see the
// GNU General Public License for more details.
const debug = false;
const predefinedUrlPatterns = [
{
label: ' Asana',
pattern: '^https?://app\\.asana\\.com/-/desktop_app_link\\?.*',
},
{
label: ' AWS IAM Access Auth Success',
pattern: '^https://[a-z0-9-]+\\.awsapps\\.com/start/user-consent/login-success.html',
},
{
label: ' Discord Invites',
pattern: '^https?://discord\\.com/invite/',
},
{
label: ' Figma Files',
pattern: '^https?://(?:www\.)?figma\.com/file/',
},
{
label: ' Linear',
pattern: '^https?://linear\\.app/.*\\?noRedirect=1$',
},
{
label: ' Microsoft Teams',
pattern: '^https?://teams\\.microsoft\\.com/dl/launcher/.*',
},
{
label: ' Notion',
pattern: '^https?://www\\.notion\\.so/native/.*&deepLinkOpenNewTab=true',
},
{
label: ' Slack',
pattern: '^https?://(?!(app\\.slack\\.com|slack\\.com|.*\\/(customize|account|apps)(\\/|$)|.*\\/home(\\/|$)))[a-z0-9-]+\\.slack\\.com/.*$',
},
{
label: ' Spotify',
pattern: '^https?://open\\.spotify\\.com',
},
{
label: ' VS Code Live Share',
pattern: '^https?://vscode\\.dev/liveshare',
},
{
label: ' Webex Joins',
pattern: '^https?://([a-z0-9-]+\\.)?webex\\.com/wbxmjs/joinservice',
},
{
label: ' Zoom Joins',
pattern: '^https?://([a-z0-9-]+\\.)?zoom\\.us/j/[^/]+#success$',
},
{
label: ' AWS VPN',
pattern: '^http://127.0.0.1:35001/$',
},
];
function saveOptions() {
const disabledUrls = [];
predefinedUrlPatterns.forEach(({ pattern }) => {
const checkbox = document.getElementById(pattern);
if (!checkbox.checked) {
disabledUrls.push(pattern);
}
});
chrome.storage.sync.set({ disabledUrls }, () => {
if (debug) {
console.log('Options saved. Disabled URLs:', disabledUrls);
}
});
}
function renderCheckboxes() {
chrome.storage.sync.get(['disabledUrls'], ({ disabledUrls }) => {
if (!disabledUrls) {
disabledUrls = [];
}
predefinedUrlPatterns.forEach(({ label, pattern }) => {
const isChecked = !disabledUrls.includes(pattern);
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.id = pattern;
checkbox.checked = isChecked;
checkbox.addEventListener('click', saveOptions);
const labelElement = document.createElement('label');
labelElement.htmlFor = pattern;
labelElement.appendChild(checkbox);
labelElement.appendChild(document.createTextNode(label));
document.getElementById('url-options').appendChild(labelElement);
});
});
}
function loadCheckInterval() {
chrome.storage.sync.get(['interval'], ({ interval }) => {
if (!interval) {
interval = 15;
}
const checkIntervalInput = document.getElementById('check-interval');
checkIntervalInput.value = interval;
checkIntervalInput.addEventListener('input', () => {
const newValue = parseInt(checkIntervalInput.value, 10);
if (newValue > 0) {
chrome.storage.sync.set({ interval: newValue }, () => {
if (debug) {
console.log('Check interval saved:', newValue);
}
});
}
});
});
}
document.addEventListener('DOMContentLoaded', () => {
renderCheckboxes();
loadCheckInterval();
});