This repository has been archived by the owner on Dec 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextrack.gs
123 lines (113 loc) · 5.54 KB
/
extrack.gs
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
116
117
118
119
120
121
122
123
// 1Mc8BthYthXx6CoIz90-JiSzSafVnT6U3t0z_W3hLTAX5ek4w0G_EIrNw
function extrack(event) {
//アップデート確認
const versionUpdate = SpreadsheetApp.openById("1UcRDr9Nt9B6XY7MEydLLrCiyEagPrIK5_vG1YamuNwg").getRange("A" + (VERSION + 1)).getValue();
let preaseUpdate = "";
if (versionUpdate) {
preaseUpdate = "\n" +
'★<a href="https://github.com/tsukasa0220/MoodleCalender">最新のバージョンがあります!!</a>\n';
}
const eventArr = parse1(event, 'data-type="event"', 'class="card-link"');
const id = parse1(event, 'data-event-id="', '"');
let title = parse1(event, '<h3 class="name d-inline-block">', '</h3>');
const due = parse1(event, '<a href="https://kadai-moodle.kagawa-u.ac.jp/calendar/view.php?view=day&time=', '">');
let subject = parse1(event, '<div class="col-11"><a href="https://kadai-moodle.kagawa-u.ac.jp/course/view.php?id=', '</a></div>');
let url = parse1(event, '<div class="card-footer text-right bg-transparent">\n ', '" class="card-link">');
let description = [''];
for (let i = 0; i < eventArr.length; i++) {
if (eventArr[i].includes('<div class="description-content col-11">')) {
description[i] = parse2(eventArr[i], '<div class="description-content col-11">', '</div>');
} else {
description[i] = 'お知らせはありません';
}
}
let lors = [""];
const content = [""];
const color = [];
const subjectTitle = [""];
for (let i = 0; i < id.length; i++) {
//取得したurlを利用して、includesで分類(提出、出席、小テスト等)とurlを作成
lors[i] = '期限';
if (url[i].includes("assign")) { //課題
color[i] = 11;
url[i] = url[i] + '" class="card-link">提出物をアップロードする</a>';
subjectTitle[i] = "課題:" + subject[i].slice(6);
} else if (url[i].includes("attendance")) { //出席
color[i] = 2;
url[i] = url[i] + '" class="card-link">出席登録を行う</a>';
subjectTitle[i] = "出席:" + subject[i].slice(6);
if (subject[i].includes(description[i])) {
title[i] = description[i];
} else {
title[i] = subject[i].slice(6);
}
} else if (url[i].includes("quiz")) { //小テスト
color[i] = 5;
url[i] = url[i] + '" class="card-link">小テストを受験する</a>';
subjectTitle[i] = "小テスト:" + subject[i].slice(6);
if (title[i].includes("開始")) {lors[i] = "開始"}
} else if (url[i].includes("questionnaire")) { //アンケート
color[i] = 8;
url[i] = url[i] + '" class="card-link">アンケートに回答する</a>';
subjectTitle[i] = "アンケート:" + subject[i].slice(6);
} else { //その他(amsplayer,chatなど)
color[i] = 7;
url[i] = url[i] + '" class="card-link">活動に移動する</a>'
subjectTitle[i] = "活動:" + subject[i].slice(6);
}
//時間割名にURLを付与
subject[i] = '<a href="https://kadai-moodle.kagawa-u.ac.jp/course/view.php?id=' + subject[i] + '</a>';
//本文を1つに統合
content[i] = conbibe(title[i], url[i], subject[i], description[i], due[i], lors[i], preaseUpdate);
}
return [id, subjectTitle, content, due, color];
}
//文字列をパースする
function parse1(html, start, end) {
return Parser.data(html).from(start).to(end).iterate();
}
function parse2(html, start, end) {
return Parser.data(html).from(start).to(end).build();
}
//時間を{yyyy年mm月dd日(day of week)hh時mm分ss秒}に変換
function timeChange(dateObj){
let text = '';
let aryWeek = ['日', '月', '火', '水', '木', '金', '土'];
text = dateObj.getFullYear() + '年' + //年の取得
(dateObj.getMonth() + 1) + '月' + //月の取得 ※0~11で取得になるため+1
dateObj.getDate() + '日' + //日付の取得
'(' + aryWeek[dateObj.getDay()] + ')' + //曜日の取得 0~6で取得になるため事前に配列で設定
dateObj.getHours() + '時' + //時間の取得
dateObj.getMinutes() + '分' /*+ //分の取得
dateObj.getSeconds() + '秒'*/; //秒の取得(未使用)
return text;
}
function conbibe(title, url, subject, description, due, lors, update) {
return "====================\n" +
"Moodleカレンダー ver. " + VERSION + "\n" +
"====================\n" +
update +
"\n" +
"★" + url + "\n" +
"\n" +
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" +
"\n" +
"■" + lors + ":" + timeChange(new Date(due * 1000)).slice(5) + "\n" +
"\n" +
"■時間割名:" + subject + "\n" +
"\n" +
"■概要" + "\n" +
"\n" +
title + "\n" +
"\n" +
"■本文" + "\n" +
"\n" +
description + "\n" +
"\n" +
"■更新日時:" + timeChange(new Date()) + "\n" +
"\n" +
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" +
"\n" +
"万一、このシステムによって利用者の不手際が発生しても一切保証を負えませんのでご了承ください。\n" +
'詳細については<a href="https://github.com/tsukasa0220/MoodleCalender">こちら</a>から'
}