AmazonBookmarklet - アマゾンの商品ページからアソシエイトリンクを作るブックマークレット
コード
format
は'md'
または'text'
で設定しておきます。- もちろんユーザは自分の
tag
を設定してください。さもないと結城のアソシエイトリンクになります。
javascript:(function(){
const format = 'md';
const asin = location.href.match(/\/dp\/([A-Z0-9]{10})/i)?.[1];
if (!asin) return alert("ERROR: ASIN is not found.");
const tag = 'hyuki-22';
const title = document.title.replace(/\s*\|.*$/, '').trim();
const url = `https://www.amazon.co.jp/dp/${asin}/?tag=${tag}`;
let text = '?';
if (format == 'md') {
text = `- [${title}](${url})`;
} else {
text = `◆${title}\n${url}\n`;
}
navigator.clipboard.writeText(text).then(() => {
const div = document.createElement("div");
div.textContent = `${title}`;
div.style.position = "fixed";
div.style.top = "20px";
div.style.left = "50%";
div.style.transform = "translateX(-50%)";
div.style.background = "#0d6efd";
div.style.color = "white";
div.style.fontSize = "1.5em";
div.style.lineHeight = "1.5";
div.style.padding = "1em 2em";
div.style.borderRadius = "6px";
div.style.zIndex = 9999;
document.body.appendChild(div);
setTimeout(() => div.remove(), 5000);
}).catch(err => {
alert("ERROR: Fail to copy: " + err);
});
})();
(2025年6月3日)