書誌情報を取り込むブックマークレット
参考
/rashitamemo/ScrapboxのコードブロックからJavaScriptを読み込むようにする
/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 = '','','';
}
var isbookDesc = document.getElementById("bookDescription_feature_div") != null
if (isbookDesc){
var decsdocP = document.getElementById("bookDescription_feature_div");//内容紹介の処理
var decsdoc = decsdocP.firstElementChild;
if (decsdoc){
var d = decsdoc.firstElementChild;
if (d){//内容紹介が存在しているなら
var d1 = d.innerText.replace(/\n/g,'\n>');
}else{
var d1 = "";//内容紹介が空っぽの場合
}
}else{
var d1 = "";//内容紹介が空っぽの場合
}
}
var image=document.getElementById("imgBlkFront");//書影の処理
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/practicefield/'+encodeURIComponent(title.trim())+'?body='+body)
})();
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番号の処理
//<20230108 ISBNにASINが入力される問題
//if(asin){
// var a = 'ISBN:' + asin.value;
//}else{
// var asin = document.getElementsByName('ASIN.0')0,a = 'ASIN:' + asin.value;
//}
if(asin.value.match(/B.+/)){
var a = 'ASIN:' + asin.value;
}else{
var a = 'ISBN:' + asin.value;
}
//20230108>
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;
//<20230108出版社のデータ取得の正規表現見直し
//var pubdata = detailtext.match(/(出版社 : .+) (\(.+\))/);//1出版社:シーアンドアール研究所,2(2018/7/27)
var pubdata = detailtext.match(/(出版社.+: .+) (\(.+\))/);//1出版社:シーアンドアール研究所,2(2018/7/27)
if (pubdata){
//pubdata1 = pubdata1.replace(/: /,':[');//出版社名をリンクにしないならこの2行は削除する
pubdata1 = pubdata1.replace(/:./,':[');//出版社名をリンクにしないならこの2行は削除する
pubdata1 = (pubdata1.match(/;/)?pubdata1.replace(/;/,'];'):pubdata1.trim() + ']');
//pubdata2 = pubdata2 + ' ';//リンクなし
//pubdata2 = pubdata2.replace(/\((\d+)\//, '($1/') + ' ';//年をリンクに
//pubdata2 = pubdata2.replace(/\((\d+\/\d+)\//, '($1/') + ' ';//年月をリンクに
pubdata2 = pubdata2.replace(/\((\d+\/\d+)\//, '($1/') + ' \n';//年月をリンクに
//20230108>
}else{
var pubdata = '','','';
}
var isbookDesc = document.getElementById("bookDescription_feature_div") != null
if (isbookDesc){
var decsdocP = document.getElementById("bookDescription_feature_div");//内容紹介の処理
var decsdoc = decsdocP.firstElementChild;
if (decsdoc){
var d = decsdoc.firstElementChild;
if (d){//内容紹介が存在しているなら
var d1 = d.innerText.replace(/\n/g,'\n>');
}else{
var d1 = "";//内容紹介が空っぽの場合
}
}else{
var d1 = "";//内容紹介が空っぽの場合
}
}
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/practicefield/'+encodeURIComponent(title.trim())+'?body='+body)
})();
code: obsidian1.js
javascript:(function(){
var p = document.getElementById("productTitle");//書籍のタイトルの処理
if (!p) var p = document.getElementById("ebooksProductTitle");
var title = p.innerText.trim();
var asin = document.getElementById('ASIN');//ASIN番号の処理
if(asin){
var a = asin.value;
}else{
var asin = document.getElementsByName('ASIN.0')0,a = asin.value;
}
//登録情報欄を取得
var detail = document.getElementById('detailBullets_feature_div');
if (!detail) {
var subdoc = document.getElementById("product-description-iframe").contentWindow.document;
var detail = subdoc.getElementById("detailBullets_feature_div");
}
var detailtext = detail.innerText;
var pubdata = detailtext.split(/\n/);
pubdata2 = pubdata2.slice(10);//出版社
pubdata1 = pubdata1.slice(10);//出版社
//var publish = pubdata.filter(pubdata => detailtext.match(/\出版社/));
//var publisher = publish0;//出版社
var url = 'https://www.amazon.co.jp/exec/obidos/ASIN/'+a+'/room510-22/';
var link = ''+title+'('+url+')';
var image=document.getElementById("imgBlkFront");//書影の処理
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 + ']');
}
var author = pub.join(' ');
// 自分が必要なパラメータに変換
var h1title = '『'+title+'』';
if (/:|\\|\//.test(h1title)) {
h1title = h1title.replace(/:/g, ':').replace(/\\/g, '\').replace(/\//g, '/');
}
var mdimage = '%0A!|100(' +imageurl+ ')%0A';
// 表示させたい項目
var lines= '%0A'+link + mdimage + author +'%0A'+ pubdata1 + '%0A' + pubdata2 +'%0A%0A%23%23 関連・思い出した本 %0A%0A%23%23 読書メモ%0A%0A';
var lines2 = '![+ title + '(' + url + ')](' + imageurl + ')';
const obsidian = 'obsidian://advanced-uri?filepath='+h1title+ '&data='+lines;
window.open(obsidian);
})();
code: obsidian.js
javascript:(function(){
var p = document.getElementById("productTitle");//書籍のタイトルの処理
if (!p) var p = document.getElementById("ebooksProductTitle");
var title = p.innerText.trim();
var asin = document.getElementById('ASIN');//ASIN番号の処理
if(asin){
var a = asin.value;
}else{
var asin = document.getElementsByName('ASIN.0')0,a = asin.value;
}
//登録情報欄を取得
var detail = document.getElementById('detailBullets_feature_div');
if (!detail) {
var subdoc = document.getElementById("product-description-iframe").contentWindow.document;
var detail = subdoc.getElementById("detailBullets_feature_div");
}
var detailtext = detail.innerText;
var pubdata = detailtext.split(/\n/);
pubdata2 = pubdata2.slice(10);//出版社
pubdata1 = pubdata1.slice(10);//出版社
var url = 'https://www.amazon.co.jp/exec/obidos/ASIN/'+a+'/room510-22/';
var link = ''+title+'('+url+')';
var image=document.getElementById("imgTagWrapperId");//書影の処理
if (!image) var image = document.getElementById("ebooksImgBlkFront");
var imageurl = image.querySelector("img").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 + ']');
}
var author = pub.join(' ');
// 自分が必要なパラメータに変換
var h1title = '『'+title+'』';
if (/:|\\|\/|\?|"|<|>|\|\.|/.test(h1title)) {
h1title = h1title.replace(/:/g, ':')
.replace(/\\/g, '\')
.replace(/\//g, '/')
.replace(/\?/g, '?')
.replace(/"/g, '"')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/\|/g, '|')
.replace(/\./g, ' ');
}
var mdimage = '%0A!|100(' +imageurl+ ')%0A';
// 表示させたい項目
var lines= '%0A'+link + mdimage + author +'%0A'+ pubdata1 + '%0A' + pubdata2 +'%0A%0A';
var lines2 = '![+ title + '(' + url + ')](' + imageurl + ')';
const obsidian = 'obsidian://advanced-uri?filepath='+h1title+ '&data='+lines;
window.open(obsidian);
})();
code: obsidian0.js
javascript:(function(){
var p = document.getElementById("productTitle");//書籍のタイトルの処理
if (!p) var p = document.getElementById("ebooksProductTitle");
var title = p.innerText.trim();
var asin = document.getElementById('ASIN');//ASIN番号の処理
if(asin){
var a = asin.value;
}else{
var asin = document.getElementsByName('ASIN.0')0,a = asin.value;
}
//登録情報欄を取得
var detail = document.getElementById('detailBullets_feature_div');
if (!detail) {
var subdoc = document.getElementById("product-description-iframe").contentWindow.document;
var detail = subdoc.getElementById("detailBullets_feature_div");
}
var detailtext = detail.innerText;
var pubdata = detailtext.split(/\n/);
pubdata2 = pubdata2.slice(10);//出版社
pubdata1 = pubdata1.slice(10);//出版社
//var publish = pubdata.filter(pubdata => detailtext.match(/\出版社/));
//var publisher = publish0;//出版社
var url = 'https://www.amazon.co.jp/exec/obidos/ASIN/'+a+'/room510-22/';
var link = ''+title+'('+url+')';
var image=document.getElementById("imgTagWrapperId");//書影の処理
if (!image) var image = document.getElementById("ebooksImgBlkFront");
var imageurl = image.querySelector("img").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 + ']');
}
var author = pub.join(' ');
// 自分が必要なパラメータに変換
var h1title = '『'+title+'』';
if (/:|\\|\/|\?|"|<|>|\|\.|/.test(h1title)) {
h1title = h1title.replace(/:/g, ':')
.replace(/\\/g, '\')
.replace(/\//g, '/')
.replace(/\?/g, '?')
.replace(/"/g, '”')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/\|/g, '|')
.replace(/\./g, ' ');
}
var mdimage = '%0A!|100(' +imageurl+ ')%0A';
// 表示させたい項目
var lines= '%0A'+link + mdimage + author +'%0A'+ pubdata1 + '%0A' + pubdata2 +'%0A%0A%23%23 関連・思い出した本 %0A%0A%23%23 読書メモ%0A%0A';
var lines2 = '![+ title + '(' + url + ')](' + imageurl + ')';
const obsidian = 'obsidian://advanced-uri?filepath='+h1title+ '&data='+lines;
window.open(obsidian);
})();