-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathe-typing-Shortcuts.user.js
More file actions
52 lines (48 loc) · 1.71 KB
/
Copy pathe-typing-Shortcuts.user.js
File metadata and controls
52 lines (48 loc) · 1.71 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
// ==UserScript==
// @name e-typing Shortcuts
// @namespace https://github.com/horyu/
// @version 0.2
// @description iframeに自動フォーカス & ボタンショートカットの追加(Ctrl+Enter:スタート・もう一回、Alt+Enter:ミスだけ)
// @match https://www.e-typing.ne.jp/*
// @run-at document-end
// @grant none
// ==/UserScript==
(function () {
'use strict';
const observer = new MutationObserver(mutationObserverCallback);
observer.observe(document.body, { childList: true, subtree: true });
function mutationObserverCallback(mutations) {
try {
// continue break するためにforEachではなくfor文を使用
for (let mutation of mutations) {
let iframe = [...mutation.addedNodes].find(node => node.tagName === 'IFRAME');
if (!iframe) {
continue;
}
iframe.onload = () => {
addShortcuts(iframe.contentWindow.document);
iframe.contentWindow.focus();
};
break;
};
} catch (e) {
console.log(e);
}
}
function addShortcuts(doc) {
doc.addEventListener('keydown', (event) => {
if (event.ctrlKey && event.key === 'Enter') {
clickById('start_btn');
clickById('replay_btn');
} else if (event.altKey && event.key === 'Enter') {
clickById('miss_only_btn');
}
});
const clickById = (id) => {
const btn = doc.getElementById(id);
if (btn) {
btn.click();
}
};
}
})();