-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
73 lines (70 loc) · 2.34 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
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
document.getElementById('copy-tab')?.addEventListener('click', (e) => {
flashAndClosePopup(e.currentTarget);
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
copy(getWindowsPlainText(tabs), getWindowsRichText(tabs));
});
});
document.getElementById('copy-all-tabs')?.addEventListener('click', (e) => {
flashAndClosePopup(e.currentTarget);
chrome.tabs.query({}, function (tabs) {
tabs = filterTabs(tabs);
copy(getWindowsPlainText(tabs), getWindowsRichText(tabs));
});
});
document
.getElementById('copy-and-close-tab')
?.addEventListener('click', (e) => {
flashAndClosePopup(e.currentTarget);
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
copy(getWindowsPlainText(tabs), getWindowsRichText(tabs));
closeTabs(tabs);
});
});
document
.getElementById('copy-and-close-all-tabs')
?.addEventListener('click', (e) => {
flashAndClosePopup(e.currentTarget);
chrome.tabs.query({}, function (tabs) {
tabs = filterTabs(tabs);
copy(getWindowsPlainText(tabs), getWindowsRichText(tabs));
closeTabs(tabs);
});
});
document
.getElementById('download-tabs-as-txt')
?.addEventListener('click', (e) => {
flashAndClosePopup(e.currentTarget);
chrome.tabs.query({}, function (tabs) {
tabs = filterTabs(tabs);
download(getWindowsPlainTextWithoutDashes(tabs), 'text/plain', 'txt');
});
});
document
.getElementById('download-tabs-as-md')
?.addEventListener('click', (e) => {
flashAndClosePopup(e.currentTarget);
chrome.tabs.query({}, function (tabs) {
tabs = filterTabs(tabs);
download(getWindowsMarkdown(tabs), 'text/plain', 'md');
});
});
document
.getElementById('download-tabs-as-html')
?.addEventListener('click', (e) => {
flashAndClosePopup(e.currentTarget);
chrome.tabs.query({}, function (tabs) {
tabs = filterTabs(tabs);
download(getWindowsRichText(tabs), 'text/html', 'html');
});
});
const isMac = /(Mac_PowerPC)|(Macintosh)/;
Array.from(document.querySelectorAll('.shortcut')).map((el) => {
if (!isMac.test(navigator.userAgent)) return;
if (!(el instanceof HTMLElement)) return;
el.innerText = el.innerText
.replace(/Shift/gu, '\u21e7')
.replace(/Alt/gu, '\u2325')
.replace(/\+/g, '')
// Shift goes first
.replace(/(.+)\u21e7/gu, '\u21e7$1');
});