-
Notifications
You must be signed in to change notification settings - Fork 0
/
course_top.js
98 lines (82 loc) · 3.6 KB
/
course_top.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
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
console.log("Running course_top.js");
chrome.storage.sync.get(optionNames, (items) => {
if(items["format_periods"]) formatPeriods();
if(items["hide_tableheaders"]) hideTableheaders();
if(items["hide_filenames"]) hideFilenames();
if(items["title_tab"]) titleTab();
// コース編集画面の場合
if(document.getElementById("course_edit")){
if(items["promote_default_actions"]) promoteDefaultActions();
}
adjustHeights();
});
///////////////////////////////////////////////////////////////////////////////
// 不要な情報を非表示にする
///////////////////////////////////////////////////////////////////////////////
function hideTableheaders() {
Array.from(document.querySelectorAll("div.bold-txt"))
.filter(e => e.innerText.includes("資料タイトル"))
.map(e => e.closest(".contents-list"))
.forEach(e => e.style.display = "none");
}
function hideFilenames() {
document.querySelectorAll("div.material-type-file-name")
.forEach(e => e.style.display = "none");
}
function adjustHeights() {
document.querySelectorAll(".block").forEach(b => {
const title = b.querySelector(".block-title");
const content = b.querySelector(".block-contents");
content.style.height = "auto";
title.style.height = content.offsetHeight + "px";
});
}
///////////////////////////////////////////////////////////////////////////////
// 表示を変更する
///////////////////////////////////////////////////////////////////////////////
function formatPeriods() {
Array.from(document.querySelectorAll("span.bold-txt"))
.filter(e => e.innerText.includes("公開期間") && !e.innerText.includes("結果"))
.map(e => e.closest(".contents-detail"))
.forEach(formatPeriod);
}
function formatPeriod(e){
const periodText = e.querySelector(".contents-input-area").textContent;
const toDate = new Date(periodText.split("~")[1].trim());
const remaining = remainingTime(toDate); // 残り時間[秒]
// 残り時間が1年以上の場合は非表示、1週間以下の場合は強調表示
if(remaining > 86400 * 365){
e.style.display = "none";
} else if(remaining < 86400 * 7){
e.classList.add("highlight-txt");
}
}
function titleTab() {
const titleElement = document.querySelector(".course-title-txt");
if (titleElement) {
const spans = titleElement.querySelectorAll("span");
document.title = spans[0].textContent + " " + spans[spans.length - 1].textContent;
}
}
function promoteDefaultActions() {
promoteDefaultActionsImpl("report", "course-edit-report-name");
promoteDefaultActionsImpl("examination", "course-edit-examination-name");
promoteDefaultActionsImpl("questionnaire", "course-edit-questionnaire-name");
promoteDefaultActionsImpl("discussion", "course-edit-forum-title");
}
function promoteDefaultActionsImpl(id, className) {
const block = document.getElementById(id);
block.querySelectorAll("div.course-result-list").forEach(l => {
const editAction = l.querySelector("a." + className);
const defaultAction = l.querySelector("li.control-list > a").cloneNode(true);
const wrapper = document.createElement("div");
editAction.classList.remove(className);
wrapper.classList.add(className);
editAction.parentNode.insertBefore(wrapper, editAction);
wrapper.appendChild(editAction);
wrapper.appendChild(defaultAction);
defaultAction.className = "";
wrapper.style.display = "flex";
wrapper.style.justifyContent = "space-between";
});
}