Last active
November 2, 2023 05:02
-
-
Save htakeuchi/c912ab5e0c50583aa3543ab37d75aa74 to your computer and use it in GitHub Desktop.
Amazonの書誌情報をTextwellの追記するブックマークレット
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript: (() => { | |
const dest_path = 'notes'; //ファイルを格納するパス | |
const amazon_id = 'namaraiicom-22'; // アフィリエイトID | |
let p = document.getElementById("productTitle"); //書籍のタイトルの処理 | |
p = p ? p : document.getElementById("ebooksProductTitle"); | |
const title = p.innerText.trim(); | |
let asin = document.getElementById('ASIN'); //ASIN番号の処理 | |
const a = asin ? asin.value : document.getElementsByName('ASIN.0')[0].value; | |
const url = `https://www.amazon.co.jp/exec/obidos/ASIN/${a}/${amazon_id}/`; | |
const link = `[${title}](${url})`; | |
let image = document.getElementById("imgTagWrapperId"); //書影の処理 | |
image = image ? image : document.getElementById("ebooksImgBlkFront"); | |
const imageurl = image.querySelector("img").getAttribute("src"); | |
const c = document.getElementsByClassName('author'); | |
const pub = []; | |
const ct_list = []; // ctの各要素を保存する配列を新たに定義 | |
for (let g = 0; g < c.length; g++) { | |
const at = c[g].innerText.replace(/\r?\n/g, '').replace(/,/,''); | |
const pu = at.match(/\(.+\)/); | |
const ct = at.replace(/\(.+\)/,'').replace(/ /g,''); | |
ct_list.push(ct); // ctを配列に追加 | |
pub.push(`${pu} [[${ct}]]`); | |
} | |
const author = pub.join(' '); | |
let h1title = `『${title}』`; | |
h1title = h1title.replace(/[\\/:*?"<>|.]/g, char => ({ | |
':': ':', '\\': '\', '/': '/', '?': '?', | |
'*': '*', '"': '”', '<': '<', '>': '>', | |
'|': '|', '.': '.' | |
}[char])); | |
const mdimage = `[![|100](${imageurl})](${url})`; | |
// 登録情報欄を取得 | |
let detail = document.getElementById('detailBullets_feature_div'); | |
if (!detail) { | |
const subdoc = document.getElementById("product-description-iframe").contentWindow.document; | |
detail = subdoc.getElementById("detailBullets_feature_div"); | |
} | |
const detailtext = detail.innerText; | |
const pubdata = detailtext.split(/\n/); | |
pubdata[2] = pubdata[2]?.slice(10); // 出版社 | |
const date = new Date().toLocaleDateString('sv-SE'); | |
const lines = `---%0D%0Atitle: "${h1title}"%0D%0Adate%3A%20${date}%0D%0Aupdated%3A%20${date}%0D%0Andl%3A%0D%0Atags%3A%20読書メモ%0D%0Adraft%3A%20true%0D%0A---%0D%0A${mdimage}%0D%0A-%20${link}%0D%0A-%20${author}%0d%0A-%20${pubdata[2]}%0D%0A%0D%0A%23%23 関連・思い出した本 %0d%0A%23%23 読書メモ%0d%0A`; | |
const app = `textwell:///add?text=${lines}`; | |
window.open(app); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment