Ebi's bookmarklet

Amazonのリンクを短縮

Installation

amzn-lnk ←Please drag & drop this button to bookmark bar
or copy & paste code below

Description

Amazonのリンクを短縮します。

参考

https://github.com/yug1224/pretty-amazon-url

Source code

shorten-amazon.js
function getId() {
  const url = location.href;
  const m = url.match(
    /https:\/\/www\.amazon\.co\.jp\/.*dp\/([0-9A-Z]{10})\/?/
  );
  if (m) return m[1];

  const m2 = url.match(
    /https:\/\/www\.amazon\.co\.jp\/.*product\/([0-9A-Z]{10})\/?/
  );
  if (m2) return m2[1];
  return null;
}

const p = getId();
if (!p) {
  window.alert("Amazonの商品ページではありません");
  return;
}

history.replaceState(null, "", `https://www.amazon.co.jp/dp/${p}/`);

Minified source code

javascript:!function(){const t=function(){const t=location.href,n=t.match(/https:\/\/www\.amazon\.co\.jp\/.*dp\/([0-9A-Z]{10})\/?/);if(n)return n[1];const o=t.match(/https:\/\/www\.amazon\.co\.jp\/.*product\/([0-9A-Z]{10})\/?/);return o?o[1]:null}();t?history.replaceState(null,"",`https://www.amazon.co.jp/dp/${t}/`):window.alert("Amazonの商品ページではありません")}();
Edit this page