授業情報ページを作成するscript
2022-08-02 14:04:43 Deprecated
/icons/hr.icon
授業情報ページを作成するscript
授業コードを事前に調べておく必要があるので、ちょっと使いづらい
code:js
import('/api/code/takker/講義情報ページのformat/script.js')
.then(({execute}) => execute(''));
code:script.js
import {lightFormat} from '../date-fns.min.js/script.js';
import {search} from '../LETUSの検索結果を取得するscript/script.js';
const format = text => text
.replace(/\s+$/, '') // 末尾の余計な空白を消す
.replace(/^(\s*)・/, '$1 ') // ・を箇条書きに変える
.replace(/A-Za-z0-9/g, s => String.fromCharCode(s.charCodeAt(0) - 0xFEE0)) // 全角英数を半角に直す .replace(/\s?\[/g, '[') // リンク記法をescapeする
.replace(/\s?\[/g, '[')
.replace(/(\d+).\s*/g, '$1. ') // 番号付き箇条書きにする
.replace(/./g, '。') // 句読点を変換する
.replace(/,/g, '、');
export async function execute(id, year = 2021) {
const {responseText: json} = await fetchCLASS(/v1/syllabuses/${year}/${id}?format=true);
const {
title,
englishTitle,
instructors,
semester,
hours,
credits,
courseNumber,
descriptions,
objectives,
outcomes,
prerequisites,
preparationAndReview,
evaluation,
references,
plan,
} = json;
// LETUSの授業ページURLも取得する
const {url} = (await search(id)).pop();
const body = [
'table:basic information',
Course title\t${format(title)},
Schedule\t${semester} ${hours.join(' ')},
Course credits\t${credits},
Course number\t${courseNumber},
Course code\t${id},
[LETUS ${url}],
[syllabus https://tus-class-api.vercel.app/v1/${year}/${id}?format=true],
'',
'Descriptions',
...descriptions.map(text => ${format(text)}),
'',
'Objectives',
...objectives.map(text => ${format(text)}),
'',
'Outcomes',
...outcomes.map(text => ${format(text)}),
'',
'Course notes prerequisites',
...prerequisites.map(text => ${format(text)}),
'',
'Preparation and review',
...preparationAndReview.map(text => ${format(text)}),
'',
'Evaluation',
...evaluation.map(text => ${format(text)}),
'',
'Materials',
...references.map(text => ${format(text)}),
'',
'Plan',
...plan.map(text => ${format(text)}),
'',
#${lightFormat(new Date(), 'yyyy-MM-dd HH:mm:ss')},
].join('\n');
window.open(https://scrapbox.io/${scrapbox.Project.name}/${encodeURIComponent(englishTitle)}?body=${encodeURIComponent(body)});
}