Add Keepa Links

Amazon商品ページにKeepaの価格履歴のリンクを追加

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Add Keepa Links
// @namespace    http://tampermonkey.net/
// @version      0.1.1
// @description  Amazon商品ページにKeepaの価格履歴のリンクを追加
// @author       himuro_majika
// @match        https://www.amazon.co.jp/*dp/*
// @match        https://www.amazon.co.jp/*gp/*
// @icon         https://www.google.com/s2/favicons?domain=keepa.com
// @grant        none
// ==/UserScript==

(function() {
  'use strict';

  init();
  function init() {
    insertButton();
  }
  function getProduct() {
    const url = location.href;
    const patternList = [
      /dp\/([^/?]+)/,
      /\/gp\/product\/([^/?]+)/
    ];
    let product = null;
    patternList.forEach(pattern => {
      const match = url.match(pattern);
      if (match) {
        product = match[1];
        return;
      }
    });
    return product;
  }
  function getTargetElement() {
      return document.getElementById("buybox");
  }
  function createKeepaLinkButton() {
    const button = document.createElement("div");
    const a = document.createElement("a");
    const keepaUrl = "https://keepa.com/#!search/5-";
    a.setAttribute("target", "_blank");
    a.innerText = "📉Keepaで価格を確認する.";
    a.addEventListener("click", (e) => {
      e.target.setAttribute("href", keepaUrl + getProduct());
    })
    button.appendChild(a);
    return button;
  }
  function insertButton() {
    const tEle = getTargetElement();
    tEle.parentNode.parentNode.appendChild(createKeepaLinkButton());
  }
})();