-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
51 lines (49 loc) · 1.68 KB
/
main.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
var pattern = "[-] "
window.document.onkeydown = function(event) {
if (event.altKey) {
switch (event.key) {
case 'Enter':
case 'y':
case '1':
highlight('yellow');
break;
case 'r':
highlight('red');
break;
case 'b':
highlight('royalblue');
break;
case 'g':
highlight('lime');
break;
case '0':
// 情報を隠す
highlight('#000', '#000');
break;
case 'w':
let b = document.getElementsByTagName('body');
// 編集可能かわかりにくかったので、titleで判別するようにした。
if (b[0].isContentEditable) {
document.title = document.title.substr(4);
b[0].setAttribute('contentEditable', false);
} else {
document.title = pattern + document.title;
b[0].setAttribute('contentEditable', true);
}
break;
}
}
}
function highlight(bC, tC) {
let selection = window.getSelection();
let range = selection.getRangeAt(0);
let newNode = document.createElement('span');
if (tC === undefined) {
newNode.setAttribute('style', 'background-color:' + bC + ';');
} else {
newNode.setAttribute('style', 'background-color:' + bC + ';color: ' + tC + ';');
}
newNode.innerHTML = selection.toString();
range.deleteContents();
range.insertNode(newNode);
}