Amazon Automation

Automations for Amazon.

Mint 2018.11.04.. Lásd a legutóbbi verzió

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        Amazon Automation
// @namespace   https://greasyfork.org/users/222319
// @version     1.4.38
// @date        2018-10-30
// @description Automations for Amazon.
// @author      Explisam <[email protected]>
// @compatible  chrome
// @compatible  firefox
// @compatible  opera
// @compatible  safari
// @license     MIT License <https://opensource.org/licenses/MIT>
// @include     *://*.amazon.co*/*
// @grant       GM_addStyle
// @run-at      document-idle
// ==/UserScript==

(function() {

    const ListContainer = document.getElementById("wl-list-collaborators");
    const CartContainer = document.getElementById('sc-active-cart');
    const SaveContainer = document.getElementById('sc-saved-cart');

    if (ListContainer) {
        ListPolymer();
    }

    if (CartContainer) {
        CartPolymer();
    }

    if (SaveContainer) {
        SavePolymer();
    }

    function polymerBuild(id, float, margin, style, action, text, host) {
        var buttonDec = document.createElement("span");
        buttonDec.className = "a-declarative";
        buttonDec.id = id;
        buttonDec.addEventListener("click", action, false);

        if (float) {
            buttonDec.style.float = float;
        }

        if (margin) {
            buttonDec.style.marginBottom = margin;
            buttonDec.style.display = "block";
        }

        var buttonPab = document.createElement("span");
        buttonPab.style.width = "100%";
        buttonPab.className = "a-button a-button-normal a-button-primary " + style;

        var buttonInn = document.createElement("span");
        buttonInn.className = "a-button-inner";

        var button = document.createElement("span");
        button.appendChild(document.createTextNode(text));
        button.className = "a-button-text";
        button.role = "button";

        buttonDec.appendChild(buttonPab);
        buttonPab.appendChild(buttonInn);
        buttonInn.appendChild(button);
        host.appendChild(buttonDec);

        return buttonDec;
    }

    function ListPolymer() {
        var checkdi = document.getElementById('amazonAutoCAd');
        var checkli = document.getElementById("g-items").querySelectorAll('[data-action=add-to-cart]');

        if (!checkdi && checkli[0]) {
            var button = polymerBuild("amazonAutoCAd", "right", undefined, "wl-info-aa_add_to_cart", AddList, "Add List to Cart", ListContainer)
            var referenceNode = ListContainer.querySelector('.aok-inline-block');
            referenceNode.parentNode.insertBefore(button, referenceNode.nextSibling);
        }
    }

    function CartPolymer() {
        var checkdi = document.getElementById('amazonAutoCDt');
        var checkli = CartContainer.querySelectorAll('*[name^="submit.delete"]');

        if (!checkdi && checkli[0]) {
            var button = polymerBuild("amazonAutoCDt", undefined, "20px", "a-row", DeleteCart, "Delete all items", CartContainer)
            var referenceNode = document.getElementById('sc-active-cart');
            referenceNode.insertBefore(button, referenceNode.firstChild);
        }
    }

    function SavePolymer() {
        var checkdi = document.getElementById('amazonAutoCSv');
        var checkli = SaveContainer.querySelectorAll('*[name^="submit.delete"]');

        if (!checkdi && checkli[0]) {
            var button = polymerBuild("amazonAutoCSv", undefined, "20px", "a-row", DeleteSave, "Delete all saved", CartContainer)
            var referenceNode = document.getElementById('sc-saved-cart');
            referenceNode.insertBefore(button, referenceNode.firstChild);
        }
    }

    function getRex(name) {
        return document.getElementById(name).getElementsByTagName('span')[0].getElementsByTagName('span')[0].getElementsByTagName('span')[0];
    }

    var ListPass;
    var ListLength;
    var ListTimer;

    function AddList(zEvent) {
        if (ListPass) {
            return;
        }

        var addObj = document.getElementById('amazonAutoCAd');
        addObj.disabled = "disabled";
        ListPass = true;

        ListLength = document.getElementById("g-items").querySelectorAll('[data-action=add-to-cart]').length;

        ListTimer = window.setInterval(function() {
            var listButtons = document.getElementById("g-items").querySelectorAll('[data-action=add-to-cart]');

            if (listButtons[0]) {
                listButtons[0].click();
                getRex('amazonAutoCAd').innerText = "Added " + (ListLength - listButtons.length + 1) + " items..";
            } else {
                getRex('amazonAutoCAd').innerText = "Added " + ListLength + " items to cart";
                window.clearInterval(ListTimer);
            }
        }, 500);
    }

    var CartPass;

    function DeleteCart(zEvent) {
        if (CartPass) {
            return;
        }

        var cartLength = CartContainer.querySelectorAll('*[name^="submit.delete"]').length;
        var cartObj = document.getElementById('amazonAutoCDt');
        cartObj.disabled = "disabled";
        CartPass = true;

        var cartTimer = window.setInterval(function() {
            var listButtons = CartContainer.querySelectorAll('*[name^="submit.delete"]');

            if (listButtons[0] && cartLength == listButtons.length) {
                listButtons[0].click();

                cartLength = listButtons.length - 1;
                getRex('amazonAutoCDt').innerText = cartLength + " items left..";
            } else if (!listButtons[0]) {
                cartObj.parentNode.removeChild(cartObj);
                window.clearInterval(cartTimer);
            }
        }, 500);
    }

    var SavePass;

    function DeleteSave(zEvent) {
        if (SavePass) {
            return;
        }

        var saveLength = SaveContainer.querySelectorAll('*[name^="submit.delete"]').length;
        var saveObj = document.getElementById('amazonAutoCSv');
        saveObj.disabled = "disabled";
        SavePass = true;

        var saveTimer = window.setInterval(function() {
            var listButtons = SaveContainer.querySelectorAll('*[name^="submit.delete"]');

            if (listButtons[0] && saveLength == listButtons.length) {
                listButtons[0].click();

                saveLength = listButtons.length - 1;
                getRex('amazonAutoCSv').innerText = saveLength + " items left..";
            } else if (!listButtons[0]) {
                saveObj.parentNode.removeChild(saveObj);
                window.clearInterval(saveTimer);
            }
        }, 500);
    }
})();