-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
71 lines (62 loc) · 2.4 KB
/
script.js
File metadata and controls
71 lines (62 loc) · 2.4 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
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
const TOOLTIP_VALUES = ["📋 CLICK to copy comment<br /><br />❌ (CTRL-CLICK to remove)", "📋 COPIED!", "❌ REMOVED!"];
const FLASH_TIME = 500;
function flash_tooltip(which) {
var tooltipSpan = document.getElementById('tooltip-span');
tooltipSpan.innerHTML = TOOLTIP_VALUES[which];
tooltipSpan.classList.add('yellow');
setTimeout(function() {
tooltipSpan.innerHTML = TOOLTIP_VALUES[0];
tooltipSpan.classList.remove('yellow');
}, FLASH_TIME
);
}
function copyText(e) {
if (e.ctrlKey) {
flash_tooltip(2);
setTimeout(function () { e.target.remove(); }, FLASH_TIME);
return;
}
navigator.clipboard.writeText(e.target.innerHTML);
flash_tooltip(1);
}
function addComment()
{
var comment_editor = document.getElementById("comment-editor");
if (!comment_editor.value) {
alert("Please type a comment");
return;
}
var new_comment = document.createElement("div");
new_comment.className = "comment-box clickable dotted wrapped";
new_comment.appendChild(document.createTextNode(comment_editor.value));
new_comment.addEventListener("click", copyText);
new_comment.addEventListener("contextmenu", function(e) {
e.preventDefault();
copyText({'target': this, ctrlKey: true});
});
document.getElementById("comment-container").appendChild(new_comment);
comment_editor.value = "";
}
window.onload = function() {
var addCommentBtn = document.querySelector("#add-comment");
addCommentBtn.addEventListener('click', addComment);
var comment_editor = document.getElementById("comment-editor");
comment_editor.focus();
comment_editor.addEventListener('blur', function(e) {
comment_editor.focus();
});
comment_editor.addEventListener('keydown', function(e) {
if (e.ctrlKey && (e.keyCode === 13 || e.keyCode === 10)) {
addCommentBtn.click();
}
});
document.querySelector("#clear-comments").addEventListener('click', function() {
location.reload();
});
var tooltipSpan = document.getElementById('tooltip-span');
tooltipSpan.innerHTML = TOOLTIP_VALUES[0];
window.onmousemove = function (e) {
tooltipSpan.style.left = (e.pageX + 15) + 'px';
tooltipSpan.style.top = (e.pageY + 15) + 'px';
};
};