-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_text.js
45 lines (39 loc) · 1.72 KB
/
get_text.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
document.addEventListener('mousedown', (e) => {
if (e.button === 1) {
const t = e.target;
const p = t.parentElement;
// trying to find a link, won't always work and could cause 2 tabs to be opened, i think?
if (t.tagName === 'A' || t.hasAttribute('data-link') || t.hasAttribute('href') || t.getAttribute('role') === 'link'
|| p.tagName === 'A' || p.hasAttribute('data-link') || p.hasAttribute('href') || p.getAttribute('role') === 'link') {
return;
}
const selectedText = window.getSelection().toString().trim();
if (selectedText) {
chrome.runtime.sendMessage({
text: selectedText,
ctrlKey: e.ctrlKey
});
}
}
});
// document.addEventListener('mousedown', (e) => {
// console.log("in preventdefault listner: " + e);
// if (e.button === 1 && window.getSelection().toString().trim()) {
// chrome.storage.sync.get({'preventAutoscroll': false}, function(data) {
// console.log("in preventdefault block: " + data.preventAutoscroll);
// if (!data.preventAutoscroll) return;
// const t = e.target;
// const p = t.parentElement;
// // if (t.tagName === 'A' || t.hasAttribute('data-link') || t.hasAttribute('href') || t.getAttribute('role') === 'link'
// // || p.tagName === 'A' || p.hasAttribute('data-link') || p.hasAttribute('href') || p.getAttribute('role') === 'link') {
// // const url = t.href || p.href;
// // chrome.tabs.query({active: true, currentWindow: true}, (tabs) => {
// // const activeTab = tabs[0];
// // chrome.tabs.create({url: url, index: activeTab.index + 1, active: false});
// // });
// // }
// e.preventDefault();
// e.stopPropagation();
// });
// }
// });