-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeedback.js
More file actions
54 lines (46 loc) · 1.89 KB
/
feedback.js
File metadata and controls
54 lines (46 loc) · 1.89 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
console.log("Running feedback.js");
chrome.storage.sync.get(optionNames, (items) => {
if (items["show_submission_text_length"]) showSubmissionTextLength();
if (items["adjacent_feedback_button"]) duplicateFeedbackButton();
emphasizeLateSubmission();
addDatalistForScore();
});
function showSubmissionTextLength() {
const submissionText = document.getElementById("submissionText");
if (submissionText) {
const length = submissionText.textContent.length;
submissionText.insertAdjacentText("afterend", `(${length}文字)`);
}
}
function duplicateFeedbackButton() {
const buttons = document.querySelectorAll(".feedback-transition-btn");
const nextButtons = Array.from(buttons).filter(b => b.textContent.includes("次"));
const errMessage = document.getElementById("errmsg_score");
if (errMessage) {
const target = errMessage.parentElement;
nextButtons.forEach(button => {
const clone = button.cloneNode(true);
target.insertBefore(clone, errMessage);
});
}
}
function emphasizeLateSubmission() {
const spans = document.querySelectorAll("span");
spans.forEach(span => {
if (span.textContent.includes("期限後提出")) {
span.classList.add("strong-warning");
}
});
}
function addDatalistForScore() {
const maxScore = document.querySelector('input[name="report.maxScore"]').value;
const inputField = document.querySelector('input[name="score"]');
const datalist = document.createElement('datalist');
datalist.id = 'score-candidates';
const option = document.createElement('option');
option.value = maxScore;
option.textContent = `${maxScore}点(満点)`;
datalist.appendChild(option);
inputField.parentNode.insertBefore(datalist, inputField.nextSibling);
inputField.setAttribute('list', 'score-candidates');
}