とらのあなから書誌情報を取得するUserScript
Scrapboxで同人誌を整理する実験で同人誌の情報を手入力するのが面倒になって作ったUserScript
もともと「とらのまき」という名前だったが、DISC:書誌情報を取得するユーザースクリプトの一部になった
最終的にこうなる
https://gyazo.com/f156fc506cc663ff54131b2abba03c53
つみのこし
✅情報があったりなかったりするのに対応できる仕組み
✅複数のメインキャラに対応
⬜イベント名をうまく切り取る
めんどそう…基素.icon
使い方(Chrome)
tampermonkeyを入れる
http://www.tampermonkey.net/
https://chrome.google.com/webstore/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo?hl=ja
スクリプトを追加ボタンを押す
https://gyazo.com/32c4b070cc20559ceb81613c781fc7c6
こうなるので、本ページ下部にあるスクリプトをコピペする
https://gyazo.com/70b8f28de03946a4f650c4c7b97efbe1
保存
https://gyazo.com/d90a465f1ea396f5169652226d99fd85
とらのあなのサイトに行くとこんな感じで出る
https://gyazo.com/f156fc506cc663ff54131b2abba03c53
code: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.rows2.cells1.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.cells0.innerText === leftHeaderStr)
if (filtered.length > 0) {
// assumed that the contents of left column are not duplicated.
return filtered0.cells1.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
複数名のメインキャラに対応
複数のジャンルに対応
メインキャラがいない場合に対応