DLSiteから書誌情報を取得するUserScript
電子書籍のみ対応
✅マニアックス対応(https://www.dlsite.com/maniax/work/=/product_id/RJ250721.htmlのようなURL)
2020/4/6対応
code:disc_DLsite.user.js
// ==UserScript==
// @name DISC_DLSite
// @version 0.1
// @description Get a bibliography from DLSite
// @author Motoso Inami
// DLSiteはbabel-polififllを利用しているので多重に読み込む必要はない
// ==/UserScript==
var inline_src = (<><![CDATA[
var results = [];
const title = document.getElementById('work_name').innerText;
const table = document.getElementById('work_maker');
// 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){
return filtered0.cells1.innerText; }else {
return null;
}
};
const outlineTable = document.getElementById('work_outline');
// optionals
// Get elements from table if string of left side is equal to "match"
// TODO: Merge to the above function
const getElemIfExistsFromOutline = (leftHeaderStr) => {
if(filtered.length > 0){
return filtered0.cells1.innerText; }else {
return null;
}
};
const url = document.location.href;
const author = getElemIfExists("著者");
const rabel = getElemIfExists("レーベル");
// 出版社名\nフォローする\n1234 -> 出版社名
const publisher = getElemIfExists("出版社名").match(/(^.*)\r?\n/)1; // YYYY年MM月DD日 -> YYYY-MM-DD
const publishedAt = new Date(getElemIfExistsFromOutline("販売日").match(/(\d{4})年(\d{2})月(\d{2})日/).slice(1).join("-"));
const year = publishedAt.getFullYear();
const month = publishedAt.getMonth() + 1;
const day = publishedAt.getDate();
results.push(title);
results.push([DLSiteで読む ${url}]);
results.push([[作家名]]:[${author}]);
results.push([[概要]]:);
results.push([[レーベル]]:[${rabel}]);
results.push([[出版社]]:[${publisher}]);
results.push([[発行年]]:[${year}]/${month}/${day});
// テキストエリアを設置して描画
let textarea = document.createElement('textarea'); textarea.id = 'textarea'; textarea.rows = 11;
let header = document.getElementById('header'); header.appendChild(textarea);
let t = document.getElementById('textarea'); t.value = results.join('\n');
]]></>).toString();
eval(c.code);