授業情報ページ作成bookmarklet
2021-04-14 19:10:35 随分前に使わなくなった
/icons/hr.icon
授業情報ページ作成bookmarklet
実装
相違点
基本情報をテーブルにする
いくつか情報を削る
code:bookmarklet.js
code:script.js
javascript: (() => {
const isCLASSsyllabus = /\w*class\.admin\.tus\.ac\.jp\/up\/faces\/up\/km/.test(document.URL);
if (!isCLASSsyllabus) return;
// 記事本文を含んだHTML Elementsを取得
const p = document.getElementsByClassName('gyoTable')0; if(!p.innerText) return;
const dom = document.createElement('div');
dom.appendChild(p.cloneNode(true));
let rows = dom.getElementsByTagName('tr')
const hankaku2Zenkaku = str => str.replace(/A-Za-z0-9/g, s => String.fromCharCode(s.charCodeAt(0) - 0xFEE0)); // tableの要素を抽出するためのhelper lambda式
const cell = (row, col) => rowsrow.cellscol.innerText.trim(); const multiLine = (row, col) => rowsrow.cellscol.innerHTML.trim().replace(/[\\\n・]|&(?:nbsp|amp);/g, '').split('<br>').map(text => ${hankaku2Zenkaku(text)}); // 科目名称
const title = cell(1, 1);
let lines = [
'table:basic information',
Course title\t${cell(1, 1)},
' Instructor\t'
+ cell(5, 1).replace(/\s/g, '').split(',').map(name => [${name}]).join(' '),
Course number\t${cell(1, 3)},
Schedule\t${cell(8, 1)} ${cell(11, 1)},
Course credit\t${cell(17, 1)},
' Department\t'
+ cell(14, 1).split(/\s/).reduce((categories, category) => ${categories} ${category}),
Grade\t${cell(17, 3)},
Course category\t${cell(18, 1)},
Course form\t${cell(18, 3)},
'',
'Descriptions',
...multiLine(20, 1),
'',
'Objectives',
...multiLine(21, 1),
'',
'Outcomes',
...multiLine(22, 1),
'',
'Course notes prerequisites',
...multiLine(23, 1),
'',
'Preparation and review',
...multiLine(31, 1),
'',
'Performance grading policy',
...multiLine(32, 1),
'',
'Materials'
];
const printIf = (subtitle, text) => {
if (text == '-') return;
lines.push( ${subtitle});
if (/○|〇/.test(text)) return;
lines.push( ${text});
};
printIf('Textbooks/Readings', cell(34, 1));
printIf('Course material', cell(35, 1));
printIf('Educational software', cell(41, 1));
// 桁合わせ用lambda式
const zero = n => String(n).padStart(2, '0');
const today = (d => ${d.getFullYear()}-${zero(d.getMonth() + 1)}-${zero(d.getDate())})(new Date());
lines = [...lines,
'',
'Class plan',
...multiLine(37, 1),
'',
'Syllabus',
[Syllabus | ${cell(2, 1)}],
'',
Added on [${today}], // スクラップした日付
];
const e = t => encodeURIComponent(t);
const ng = text => text.trim().replace(/[\\\n]/g, ' '); window.open(${site}/${e(ng(title))}?body=${e(lines.join('\n'))});
})();