CLASSのお知らせの本文を取得する
CLASSのお知らせの見出しの<a>タグのidから、CLASSのお知らせの本文を取得する関数
CLASSのお知らせを既読にする処理も行う
参考:CLASSのお知らせページのDOM構造
dependency
CLASSでページ遷移するscript
BlobをData URIに変換する
code:script.js
import {postToCLASS} from '../CLASSでページ遷移するscript/scrapbox.js';
import {BlobToURI} from '../BlobをData_URIに変換する/script.js';
export async function parse(id) {
const {responseText: html} = await fetchCLASS(/up/faces/up/po/pPoa0202A.jsp?fieldId=${id});
const dom = new DOMParser().parseFromString(html, 'text/html');
const title = dom.getElementById('form1:htmlTitle').textContent.trim();
const sender = dom.getElementById('form1:htmlFrom').textContent.trim();
// なぜか<br>が消えてしまうので、innerHTMLを使っている
const lines = dom.getElementById('form1:htmlMain').innerHTML.trim().split(/\n|<br>/);
const filenames = [...(dom.getElementById('form1:htmlFileTable')
?.getElementsByTagName?.('tr') ?? [])]
.flatMap((_, index) => {
// textContentだと途中で省略されてしまうので、titleから取得する
const name = dom.getElementById(form1:htmlFileTable:${index}:labelFileName)?.title;
return name ? {name, id: index,} : [];
});
// file dataを取得する
const comSunFacesVIEW = dom.getElementById('com.sun.faces.VIEW').value;
const files = [];
for (const {name, id} of filenames) {
const url = await BlobToURI(await download(id, comSunFacesVIEW));
/*
const a = document.createElement('a');
a.href = url;
a.download = name;
document.body.append(a);
a.click();
a.remove();
*/
files.push({name, dataURI: url});
}
await fetchCLASS('/up/faces/ajax/up/co/RemoveSessionAjax?target=null&windowName=Poa00201A&pcClass=com.jast.gakuen.up.po.PPoa0202A'); // 既読にする
return {title, sender, lines, files};
}
fileをdownloadする
既読にする前のみ取得可能
content-dispositionにファイル名がISO-2022-JP形式で入っている
decodeがクソめんどいtakker.icon
ISO-2022-JP�f�R�[�h
code:script.js
async function download(id, comSunFacesVIEW) {
const params = new URLSearchParams();
params.append(form1:htmlFileTable:${id}:downLoadButton.x, 0);
params.append(form1:htmlFileTable:${id}:downLoadButton.y, 0);
params.append('com.sun.faces.VIEW', comSunFacesVIEW);
params.append('form1', 'form1');
const {response} = await fetchCLASS('/up/faces/up/po/pPoa0202A.jsp', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': params.toString().length,
},
type: 'blob',
body: params.toString(),
});
return response;
}
#2021-04-05 21:16:00
#2021-03-21 01:54:21
#2021-02-24 13:57:18