Greasy Fork

Greasy Fork is available in English.

Amazon.co.jpの商品ページに各種リンク追加

Amazon.co.jpの商品ページに固定URL、サクラチェッカー、keepaなどのリンクを追加します

目前为 2022-03-05 提交的版本,查看 最新版本

// ==UserScript==
// @name         Amazon.co.jpの商品ページに各種リンク追加
// @namespace    https://www.amazon.co.jp/dp/
// @version      1.1
// @description  Amazon.co.jpの商品ページに固定URL、サクラチェッカー、keepaなどのリンクを追加します
// @include      https://www.amazon.co.jp/dp/*
// @include      https://www.amazon.co.jp/*/dp/*
// @include      https://www.amazon.co.jp/gp/product/*
// @license      MIT
// @author       nanashi <[email protected]>
// ==/UserScript==

(() => {
    "use strict";

    let asin = null;
    let element_asin = document.getElementById("ASIN");
    if(element_asin){
        let t = String(element_asin.getAttribute("value")).match(/[0-9A-Za-z]{10}/);
        if(t) asin = t[0];
    }
    if(!asin){
        let t = location.href.match(/\/(dp|gp\/product)\/([0-9A-Za-z]{10})/);
        if(t) asin = t[2];
    }
    if(!asin) return;

    let element_tell_a_friend = document.getElementById("tell-a-friend");
    if(!element_tell_a_friend) element_tell_a_friend = document.getElementById("tellAFriendBylineBox_feature_div");
    if(!element_tell_a_friend) return;

    const div_outer = document.createElement("div");

    const div_fix = document.createElement("div");
    const a_fix = document.createElement("a");
    a_fix.setAttribute("href", "https://www.amazon.co.jp/dp/" + asin + "/");
    a_fix.textContent = "固定URL";
    div_fix.appendChild(a_fix);
    div_outer.appendChild(div_fix);

    const div_sakura = document.createElement("div");
    const a_sakura = document.createElement("a");
    a_sakura.setAttribute("href", "https://sakura-checker.jp/search/" + asin + "/");
    a_sakura.setAttribute("target", "_blank");
    a_sakura.textContent = "サクラチェッカーで検索";
    div_sakura.appendChild(a_sakura);
    div_outer.appendChild(div_sakura);

    const div_keepa = document.createElement("div");
    const a_keepa = document.createElement("a");
    a_keepa.setAttribute("href", "https://keepa.com/#!product/5-" + asin);
    a_keepa.setAttribute("target", "_blank");
    a_keepa.textContent = "keepaで検索";
    div_keepa.appendChild(a_keepa);
    div_outer.appendChild(div_keepa);

    element_tell_a_friend.parentNode.insertBefore(div_outer, element_tell_a_friend.nextElementSibling);
})();