This repository has been archived by the owner on Jul 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
menu.js
66 lines (54 loc) · 1.95 KB
/
menu.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
(function(){
var metaKey;
updateMetaKey();
chrome.storage.onChanged.addListener(function(changes, areaName){
if(areaName == "sync"){
updateMetaKey();
}
})
document.addEventListener("click", function(event){
if((event.altKey && metaKey == "Alt")
|| (event.ctrlKey && metaKey == "Ctrl")
|| (event.shiftKey && metaKey == "Shift")) {
copyCommand(event.target);
event.preventDefault();
}
}, false);
function updateMetaKey(){
chrome.storage.sync.get({
metaKey: 'Alt',
}, function(items) {
metaKey = items.metaKey;
});
};
function copyCommand(clickedElement){
var text = getText(clickedElement.firstChild, "\r\n");
copy(text.trim());
var rect = clickedElement.getBoundingClientRect();
var frame = document.createElement("div");
frame.style.position = "absolute";
frame.style.top = (rect.top + window.scrollY) + "px";
frame.style.left = (rect.left + window.scrollX) + "px";
frame.style.width = (rect.width - 4) + "px";
frame.style.height = (rect.height - 4) + "px";
frame.style.border = "solid 2px gold";
frame.style.borderRadius = "5px";
frame.style.zIndex = "99999";
frame.style.pointerEvents = "none";
document.body.appendChild(frame);
$(frame).fadeIn(300, "swing").delay(500).fadeOut(500, "swing");
// console.log(text.trim());
}
function copy(text){
var textArea = document.createElement("textarea");
textArea.style.cssText = "position: absolute; left: -100%;";
try{
document.body.appendChild(textArea);
textArea.value = text;
textArea.select();
document.execCommand("copy");
}finally{
document.body.removeChild(textArea);
}
}
})();