Skip to content

Instantly share code, notes, and snippets.

@htakeuchi
Created November 1, 2023 08:02
Show Gist options
  • Save htakeuchi/12c99928dea4e7697ebc021100c5f6ac to your computer and use it in GitHub Desktop.
Save htakeuchi/12c99928dea4e7697ebc021100c5f6ac to your computer and use it in GitHub Desktop.
Amazon商品の商品名と画像へのリンクをTextwellに追加するブックマークレット
javascript: (() => {
const dest_path = "notes"; //ファイルを格納するパス
const amazon_id = "namaraiicom-22"; // アフィリエイトID
let p = document.getElementById("productTitle") || document.getElementById("ebooksProductTitle"); //書籍のタイトルの処理
const title = p.innerText.trim();
const asinElement = document.getElementById('ASIN') || document.getElementsByName('ASIN.0')[0]; //ASIN番号の処理
const a = asinElement.value;
const url = `https://www.amazon.co.jp/exec/obidos/ASIN/${a}/${amazon_id}/`;
const link = `[${title}](${url})`;
const image = document.getElementById("landingImage");
const imageurl = image.getAttribute("src");
// 自分が必要なパラメータに変換
let h1title = title.replace(/[\\/:*?"<>|.]/g, char => ({
':': ':', '\\': '\', '/': '/', '?': '?',
'*': '*', '"': '”', '<': '<', '>': '>',
'|': '|', '.': '.'
}[char]));
const mdimage = `[![|100](${imageurl})](${url})`;
const lines = `${mdimage}%0D%0A%0D%0A${link}%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