Greasy Fork

Amazon 商品画面にサクラチェッカー用リンクを作成

Amazonの商品画面(の購入ボタンの下あたり)にサクラチェッカー用リンクを作成

当前为 2019-08-30 提交的版本,查看 最新版本

// ==UserScript==
// @name         Amazon 商品画面にサクラチェッカー用リンクを作成
// @namespace    unkomoreta
// @version      0.2
// @description  Amazonの商品画面(の購入ボタンの下あたり)にサクラチェッカー用リンクを作成
// @author       nikukoppun
// @match        https://www.amazon.co.jp/*
// @require      https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    jQuery.noConflict();

    (function($) {

        if (0 < $("#dp").length) {
            setCheckerButton();

            let observer = new MutationObserver(function (MutationRecords, MutationObserver) {
                setCheckerButton();
            });
            observer.observe($("#desktop_buybox").get(0), {
                childList: true
            });

            function setCheckerButton() {
                let asin = "";
                if (0 < $("#ASIN").length) {
                    asin = $("#ASIN").val();
                }

                let styleHtml = "\
                    <style>\
                        .sakurachecker a {\
                            display: inline-block;\
                            border: 1px solid gray;\
                            padding: 0.5rem;\
                            background-color: gold;\
                            margin-bottom: 2ex;\
                            width: 100%;\
                            color: crimson;\
                            font-weight: bold;\
                            text-align: center;\
                        }\
                    </style>"
                let buttonHtml = "";

                if (asin != "") {
                    let targetURL = "https://sakura-checker.jp/search/" + asin + "/";
                    buttonHtml = "\
                        <div class='sakurachecker'>\
                            <a href='@url@' target='_blank'>サクラチェッカーで確認</a>\
                        </div>";
                    buttonHtml = buttonHtml.replace("@url@", targetURL);
                } else {
                    buttonHtml = "\
                        <div class='sakurachecker'>\
                            <a href='#' onclick='return false;'>ASIN見つからず</a>\
                        </div>";
                }

                if (0 < $("#rcx-subscribe-submit-button-announce").length) {
                    $("#rcx-subscribe-submit-button-announce").closest("div.a-section").after(styleHtml + buttonHtml);
                } else if (0 < $("#buyNow").length) {
                    $("#buyNow").closest("#buyNow_feature_div").after(styleHtml + buttonHtml);
                } else if (0 < $("#add-to-cart-button").length) {
                    $("#add-to-cart-button").closest("div.a-button-stack").after(styleHtml + buttonHtml);
                } else if (0 < $("#outOfStock").length) {
                    $("#outOfStock .a-box-inner:first").prepend(styleHtml + buttonHtml);
                }
            }
        }

    })(jQuery);

})();