amazon command

Amazonの商品検索画面で、Amazon.jpから販売される商品のみが検索結果に表示されるようになるボタンを追加します。

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Advertisement:

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

Advertisement:

// ==UserScript==
// @name         amazon command
// @namespace    amazon command
// @version      0.2
// @description  Amazonの商品検索画面で、Amazon.jpから販売される商品のみが検索結果に表示されるようになるボタンを追加します。
// @author       meguru
// @include      https://www.amazon.co.jp/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const createButton = (label, cmd) => {
        const button = document.createElement('button');
        if (!button) { console.log('failed create ${label}') };
        button.innerHTML = label;
        button.onclick = () => {
            window.location.href += cmd;
        };
        return button;
    }

    const refArea = document.getElementById('s-refinements');
    if (!refArea) {
        console.log('not find refArea');
        return;
    };

    const fromAmazonJpButton = createButton('from amazon.jp', '&emi=AN1VRQENFRJN5');
    let res = refArea.parentNode.insertBefore(fromAmazonJpButton, refArea);
    if (!res) {
        console.log('failed add button');
        return;
    };

    const offButton = createButton('50% off', '&pct-off=50-');
    res = refArea.parentNode.insertBefore(offButton, refArea);
    if (!res) {
        console.log('failed add button');
        return;
    };

})();