-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontent-script.js
More file actions
43 lines (37 loc) · 1.24 KB
/
content-script.js
File metadata and controls
43 lines (37 loc) · 1.24 KB
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
browser.storage.sync.get(['enableSSM']).then(res => {
if (!res.enableSSM) return;
$(document).ready(function(){
$("span.sentence").hover(function(){
$(this).css("text-decoration", "underline #6b7 solid 3px");
$(this).css("text-decoration-skip-ink", "none");
},
function(){
$(this).css("text-decoration", "");
});
});
$('p').each(function() {
$(this).html($(this).text()
.split(/(?<=[\.\?!] )/)
.map(v => {return ' <span class=sentence>'+v.trimRight()+'</span> '}));
});
$('span.sentence').click(obj => {
let selection = window.getSelection();
selection.modify('extend','backward','word');
let a = selection.toString();
selection.modify('extend','forward','word');
while (selection.toString().slice(-1) == "-") {
selection.modify('extend','forward','word');
}
let b = selection.toString();
selection.modify('move','forward','character');
word = (a + b).replace(/[.,\/#!$%\^&\*;:{}=\_…`~()]/g, "");
console.log(word);
console.log(obj)
copyobj = {
"sentence": obj.target.textContent.trim(),
"word": word.trim()
};
console.log(copyobj)
navigator.clipboard.writeText(JSON.stringify(copyobj));
});
});