AmazonからブックマークでConsenseへ

最近、Helpfeel Consense ( 旧Scrapbox )にハマっています。
Helpfeel Consenseはブラウザのメモアプリです。



僕はこのサービスを使った読書管理を始めたのですが、
より使いやすくするためにブックマークレットを作成したので紹介します。



今回行うのは、これから登録したいページをamazonのサイトで探し、
そのサイトでブックマークレットを動かすことで著作情報がConsenseに自動で登録されるものです。


僕はコーディングの知識がまったくないので、プログラムの部分は丸々chatGPT4oに作成してもらいました。以下が実際に動作するJavaScriptです。


javascript:(function() {
  function extractProductInfo() {
    const productTitleElement = document.querySelector('#productTitle');
    const productTitle = productTitleElement ? productTitleElement.textContent.trim() : '';
    const productImageElement = document.querySelector('#imgTagWrapperId img');
    const productImageURL = productImageElement ? productImageElement.src : '';
    const authorInfoElement = document.querySelector('.author .a-link-normal');
    const authorInfo = authorInfoElement ? authorInfoElement.textContent.trim() : '';
    return { title: productTitle, imageURL: productImageURL, author: authorInfo };
  }
  function sendToScrapbox(productInfo) {
    const lines = `[${productInfo.title}]\nAuthor: ${productInfo.author}\n[${productInfo.imageURL}]`;
    var body = encodeURIComponent(lines.trim());
    window.open('https://scrapbox.io/xxxxxxxxxx/' + encodeURIComponent(productInfo.title.trim()) + '?body=' + body);
  }
  const productInfo = extractProductInfo();
  sendToScrapbox(productInfo);
})();

コードの中の”https://scrapbox.io/xxxxxxxxxx”  は自身のHelpfeel ConsenseのURLに変えてください。これをChromeのブックマークに保存してあげると、amazon.comのページで作動します。


このブックマークレットを動かすと、そのサイトのhtmlからタイトル、著者名、本の表紙のURLを抽出します。
そして情報をテキストに整理し、Consenseの新規ページに書き込まれます。
紙版、kindle版どちらにも対応しています。



以下が実際に動作してる様子です。

amazonの登録したいページでブックマークレットをクリックする

するとすぐに、別ウィンドウでConsenseが開き、

Consenseでタイトル、著者名、表紙写真が表示される



現在、著者の経歴なども追加できるように調整中です。記録用だけでなく、読みたい本リストの作成などにも利用できると思います。


最後に今回参考にさせていただいたサイトを載せておきます。


この記事が気に入ったらサポートをしてみませんか?