授業情報ページ作成bookmarklet
2021-04-14 19:10:35 随分前に使わなくなった
代わりに授業情報ページを作成するscriptを使っている
/icons/hr.icon
from 予定の組み立て 2020-09-17
授業情報ページ作成bookmarklet
CLASS.iconのシラバス情報から、授業情報ページを生成するbookmarklet
実装
CLASS-scrapを流用
相違点
基本情報をテーブルにする
いくつか情報を削る
code:bookmarklet.js
javascript:(()=>{let s=document.createElement("script");s.src='https://scrapbox.io/api/code/takker-memex/%E6%8E%88%E6%A5%AD%E6%83%85%E5%A0%B1%E3%83%9A%E3%83%BC%E3%82%B8%E4%BD%9C%E6%88%90bookmarklet/script.js';document.body.appendChild(s);})()
code:script.js
javascript: (() => {
const site = 'https://scrapbox.io/takker-memex';
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'))});
})();
#2021-04-14 19:13:50
#2020-09-17 16:13:28