-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeyboard Shortcuts addition
115 lines (96 loc) · 3.21 KB
/
Keyboard Shortcuts addition
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// ==UserScript==
// @name Bunpro Anki Mode
// @namespace ezhmd
// @version 1.10
// @description Anki mode for Bunpro
// @author Ezzat Chamudi
// @match https://bunpro.jp/study*
// @match https://www.bunpro.jp/cram*
// @match http://www.bunpro.jp/cram*
// @match http://bunpro.jp/study*
// @match https://www.bunpro.jp/study*
// @match http://www.bunpro.jp/study*
// @grant none
// @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
// ==/UserScript==
document.getElementById("study-answer-input").disabled = true;
(function() {
'use strict';
var css = `
.anki-show {
background-color: #000099;
}
.anki-yes {
background-color: #009900;
}
.anki-no {
background-color: #990000;
}
.anki-button {
display: inline-block;
font-size: 0.8125em;
color: #FFFFFF;
cursor: pointer;
padding: 10px;
width: 30%;
max-width: 130px;
}
.review-padding-bottom {
text-align: center;
display: inline-flex;
width: 100%;
justify-content: center;
}
`;
$(`<style>${css}</style>
<span class="anki-button anki-no" onclick='answerShow();'>Don't Know</span>
<span class="anki-button anki-show" onclick='answerShow();'>Show Answer</span>
<span class="anki-button anki-yes" onclick='answerCorrect();'>Know</span>`)
.appendTo(".review-padding-bottom");
// Reveals answer but doesn't commit
$(".anki-show").click(function() {
$("#show-answer").click();
$("#study-answer-input").val($(".study-area-input").first().text());
});
// Reveals answer, and commits the answer as correct
$(".anki-yes").click(function() {
$("#show-answer").click();
$("#study-answer-input").val($(".study-area-input").first().text());
$("#submit-study-answer").click();
});
// Inserts "I don't know", as well as commits this as a wrong answer
$(".anki-no").click(function() {
$("#study-answer-input").val("しれない");
$("#submit-study-answer").click();
});
// *IMPORTANT*
// Keyboard shortcut actions
// Modify these by changing the case numbers to match the desired keys.
// To identify the case numbers, you can identify them easily here: https://css-tricks.com/snippets/javascript/javascript-keycodes/
$(window).keydown(function(e) {
switch (e.keyCode) {
// Reveals answer but doesn't commit
case 50: // 2 On the Keyboard
case 98: // 2 On the Numpad
e.preventDefault();
$("#show-answer").click();
$("#study-answer-input").val($(".study-area-input").first().text());
return;
// Reveals answer, and commits the answer as correct
case 51: // 3 on the Upperrow
case 99: // 3 on numpad
e.preventDefault(); // avoid browser scrolling due to pressed key
$("#show-answer").click();
$("#study-answer-input").val($(".study-area-input").first().text());
$("#submit-study-answer").click();
return;
// Inserts "I don't know", as well as commits this as a wrong answer
case 49: // 1 On the Upperrow
case 97: // 1 On the Numpad
e.preventDefault();
$("#study-answer-input").val("しれない");
$("#submit-study-answer").click();
return;
}
});
})();