とらのあなから書誌情報を取得するUserScript
最終的にこうなる
つみのこし
✅情報があったりなかったりするのに対応できる仕組み
✅複数のメインキャラに対応
⬜イベント名をうまく切り取る
めんどそう…

使い方(Chrome)
スクリプトを追加ボタンを押す
こうなるので、本ページ下部にあるスクリプトをコピペする
保存
とらのあなのサイトに行くとこんな感じで出る

toranomaki.user.js// ==UserScript==
// @name DISC_toranoana
// @namespace https://scrapbox.io/motoso
// @version 0.1.1
// @description Get a bibliography from toranoana
// @author Motoso Inami
// @require https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.18.2/babel.js
// @require https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.16.0/polyfill.js
// @match https://ec.toranoana.shop/tora/ec/item/*
// @match https://ec.toranoana.jp/tora_r/ec/item/*
// ==/UserScript==
var inline_src = (<><![CDATA[
var result = [];
const title = document.querySelector('.product-info span').innerText;
const circleName = document.querySelector('.product-info .sub-circle .sub-p').innerText;
const author = document.querySelector('.product-info .sub-name .sub-p').innerText;
const table = document.getElementsByClassName('detail4-spec')[0];
// object[イラスト集,入荷アラート, br ,鉄道, 入荷アラート] => "[イラスト集] [鉄道]"
const genre = [...table.rows[2].cells[1].querySelectorAll('span span')].map(item => item.innerText.trim()).filter(item => !['', '入荷アラートを設定'].includes(item)).map(item => `[${item}]`).join(' ')
// optionals
// Get elements from table if string of left side is equal to "match"
const getElemIfExists = (leftHeaderStr) => {
const filtered = [...table.rows].filter((row) => row.cells[0].innerText === leftHeaderStr)
if (filtered.length > 0) {
// assumed that the contents of left column are not duplicated.
return filtered[0].cells[1].innerText;
} else {
return null;
}
};
const mainCharacterElem = getElemIfExists("メインキャラ");
// main character is optional
const mainCharacter = mainCharacterElem ? mainCharacterElem.split(' ').map(item => `[${item}]`).join(' ') : '';
// "2016/08/14 コミックマーケット90(3日目)" => "コミックマーケット90(3日目)"
const eventOrNull = getElemIfExists("初出イベント");
const event = eventOrNull ? `[${eventOrNull.replace(/^\d{4}\/\d{2}\/\d{2}/, '').trim()}]` : '';
const publishedAt = new Date(getElemIfExists("発行日"));
const year = publishedAt.getFullYear();
const month = publishedAt.getMonth() + 1;
const day = publishedAt.getDate();
result.push(title);
result.push(`[[作家名]]:[${author}]`);
result.push(`[[サークル名]]:[${circleName}]`);
result.push(`[[原作]]:${genre} ${mainCharactor}`);
result.push(`[[概要]]:`);
result.push(`[[イベント]]:${event}`);
result.push(`[[発行年]]:[${year}]/${month}/${day}`);
result.push(`[[印刷所]]:`);
// Show results
let textarea = document.createElement('textarea'); textarea.id = 'textarea'; textarea.rows = 10;
let header = document.querySelector('header'); header.appendChild(textarea);
let t = document.getElementById('textarea'); t.value = result.join('\n');
]]></>).toString();
var c = Babel.transform(inline_src, { presets: [ "es2015", "es2016" ] });
eval(c.code);
更新履歴
2020/3/30 0.1.1 初出イベントが存在しない場合に動かなかったバグを修正
2020/3/15
複数名のメインキャラに対応
複数のジャンルに対応
メインキャラがいない場合に対応