AmazonBot

Five demands, not one less

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         AmazonBot
// @namespace    fufuying@lihkg
// @version      1
// @description  Five demands, not one less
// @author       fufuying@lihkg
// @match        https://www.amazon.co.jp/*
// @grant        none
// ==/UserScript==

function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}

function getSeller() {
    try {
        return document.getElementById('merchant-info').getElementsByTagName('a')[0].text
    } catch (e) {
        return null
    }
}

(async function () {
    'use strict';
    
    const password = 'your password';
    const refresh_interval = 2000;
    const product_codes = ['B07573632C', 'B016DCAOOA', 'B07MJKHYDC', 'B07571223K', 'B07T3MNKKW', 'B07T5V4TCV', 'B0015R1BL4', 'B00FX4EBS0']

    const current_url = location.href;

    if (current_url.match('/signin*') !== null) {
        document.getElementById('ap_password').value = password;
        document.getElementById('signInSubmit').click();
    } else if (current_url.match('/product*')) {
        let seller = getSeller();
        let product_id = document.getElementById('ASIN').value
        // When out of stock
        console.log(product_codes.includes(product_id))
        if (product_codes.includes(product_id)) {
            while (seller !== 'Amazon.co.jp') {
                await sleep(refresh_interval)
                location.reload()
                seller = getSeller();
            }
            // When in stock
            document.getElementById('buy-now-button').click()
        }
    } else if (current_url.match('/buy/payselect/handlers/*')) {
        document.getElementsByName('ppw-widgetEvent:SetPaymentPlanSelectContinueEvent')[0].click()
    } else if (current_url.match('/gp/buy/spc/handlers/*')) {
        document.getElementsByName('placeYourOrder1')[0].click()
    }

})()