ISBNや出版社の情報も取り込むブックマークレット
/rashitamemo/ISBNや出版社の情報も取り込むブックマークレット
code:script.js
javascript:(function(){
var p = document.getElementById("productTitle");//書籍のタイトルの処理
if (!p) var p = document.getElementById("ebooksProductTitle");
var title = window.prompt('Scrap "Amazon" to your scrapbox.', p.innerText.trim());
if (!title) return;
title = '『'+ title +'』';
var asin = document.getElementById('ASIN');//ASIN番号の処理
if(asin){
var a = 'ISBN:' + asin.value;
}else{
var asin = document.getElementsByName('ASIN.0')0,a = 'ASIN:' + asin.value;
}
var detail = document.getElementById('detailBullets_feature_div');//出版社と出版年月の処理
if (!detail) {
var subdoc = document.getElementById("product-description-iframe").contentWindow.document;
var detail = subdoc.getElementById("productDetailsTable");
}
var detailtext = detail.innerText;
var pubdata = detailtext.match(/(出版社 : .+) (\(.+\))/);//1出版社:シーアンドアール研究所,2(2018/7/27)
if (pubdata){
pubdata1 = pubdata1.replace(/: /,':[');//出版社名をリンクにしないならこの2行は削除する
pubdata1 = (pubdata1.match(/;/)?pubdata1.replace(/;/,'];'):pubdata1.trim() + ']');
//pubdata2 = pubdata2 + ' ';//リンクなし
//pubdata2 = pubdata2.replace(/\((\d+)\//, '($1/') + ' ';//年をリンクに
pubdata2 = pubdata2.replace(/\((\d+\/\d+)\//, '($1/') + ' ';//年月をリンクに
}else{
var pubdata = '','','';
}
//内容紹介の処理
//bookDescription_feature_div
const isbookDesc = document.getElementById("bookDescription_feature_div")
if(isbookDesc){
if (isbookDesc.innerText == ""){
const eDiv = document.getElementById("editorialReviews_feature_div")
if (eDiv) d1 = eDiv.innerText.replace(/\n/g,"\n>")
}else{
var d1 = isbookDesc.innerText.replace(/\n/g,"\n>").replace("続きを読む","")
}
}else{
const probookDesc = document.getElementById("productDescription_feature_div")
if (probookDesc){
var decsdocP = document.getElementsByClassName("pInfoTabCExpander-content");
var decsdoc = decsdocP0;
var d1 = decsdoc.innerText.replace(/\n/g,"\n>")
}
}
//書影の処理
var image=document.getElementById("landingImage");
if (!image) var image = document.getElementById("ebooksImgBlkFront");
var imageurl = image.getAttribute("src");
//著者情報の処理
var pub = [];
var c = document.getElementsByClassName('author');
for (g = 0; g < c.length ;g++){
var at = cg.innerText.replace(/\r?\n/g, '').replace(/,/,'');
var pu = at.match(/\(.+\)/);
var ct = at.replace(/\(.+\)/,'').replace(/ /g,'');
pub.push(pu + ' + ct.trim() + '');
}
var lines=''+imageurl+' '+window.location.href+'\n' + pub.join(' ') + '\n' + pubdata1 + pubdata2 + a + '\n>' + d1 + '\n#書籍名\n';//ページへの書き込み内容。ここで順番を変えれば作成されるページの内容も変わります。
var body = encodeURIComponent(lines);
window.open('https://scrapbox.io/kijisaba-project/'+encodeURIComponent(title.trim())+'?body='+body)
})();
コードが長い場合はコードブロックからjsを読み込むことが出来るらしい
/rashitamemo/ScrapboxのコードブロックからJavaScriptを読み込むようにする
code:script.js
javascript:(function(d,s){s=d.createElement('script');s.src='https://scrapbox.io/api/code/kijisaba-project/ISBN%E3%82%84%E5%87%BA%E7%89%88%E7%A4%BE%E3%81%AE%E6%83%85%E5%A0%B1%E3%82%82%E5%8F%96%E3%82%8A%E8%BE%BC%E3%82%80%E3%83%96%E3%83%83%E3%82%AF%E3%83%9E%E3%83%BC%E3%82%AF%E3%83%AC%E3%83%83%E3%83%88/script.js';d.body.appendChild(s);})(document)
script.jsがあるページへのパスを書いて読み込ませていると思っている
#UserScript #scrapbox
public.icon