JD Helper

JD Helper Description

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         JD Helper
// @namespace    https://greasyfork.org/en/users/318347
// @version      0.3
// @description  JD Helper Description
// @author       LambertQin
// @match        https://item.jd.com/*
// @match        https://cart.jd.com/*
// @match        https://trade.jd.com/*
// @connect-src  www.jd.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    var itemMaxCount = 2;

    var executeOrDelayUntilConditionMeet = function (condition, callback, timeout) {
        if(!timeout) { timeout = 25 }
        setTimeout(function(){
            if (condition()) {
                callback();
            }else {
                executeOrDelayUntilConditionMeet(condition, callback);
            }
        }, timeout);
    }
    var AddToCart = function () {
        var init = function () {
            executeOrDelayUntilConditionMeet(
                function () {
                    return $('#InitCartUrl').length
                },
                function(){
                    var addToCartElement = $('#InitCartUrl');
                    window.location = addToCartElement.prop('href');
                }
            )
        }()
        var exec = function () {
        }
        return {
            'init': init,
            'exec': exec
        }
    }
    var AddToCart1 = function () {
        var init = function () {
            executeOrDelayUntilConditionMeet(
                function () {
                    return $('#btn-reservation').length && '抢购' === $('#btn-reservation').text()
                },
                function(){
                    var addToCartElement = $('#btn-reservation');
                    window.location = addToCartElement.prop('href');
                }
            )
        }()
        var exec = function () {
        }
        return {
            'init': init,
            'exec': exec
        }
    }
    var GoToCart = function () {
        var init = function () {
            executeOrDelayUntilConditionMeet(
                function () {
                    return $('#GotoShoppingCart').length
                },
                function(){
                    var goToCartElement = $('#GotoShoppingCart');
                    window.location = goToCartElement.prop('href');
                }
            )
        }()
        var exec = function () {
        }
        return {
            'init': init,
            'exec': exec
        }
    }

    var SubmitCart = function () {
        var init = function () {
            executeOrDelayUntilConditionMeet(
                function () {
                    return $('.common-submit-btn').length
                },
                function(){
                    var submitCartElement = $('.common-submit-btn');
                    window.location = 'https://trade.jd.com/shopping/order/getOrderInfo.action'
                }
            )
        }()
        var exec = function () {
        }
        return {
            'init': init,
            'exec': exec
        }
    }

    var SubmitOrder = function () {
        var init = function () {
            executeOrDelayUntilConditionMeet(
                function () {
                    return $('#order-submit').length
                },
                function(){
                    var submitOrderElement = $('#order-submit');
                    submitOrderElement.click();
                }
            )
        }()
        var exec = function (showNewerFirst) {
        }
        return {
            'init': init,
            'exec': exec
        }
    }
    var appInit = function () {
        switch (top.location.hostname) {
            case 'item.jd.com':
                AddToCart1();
                break;
            case 'cart.jd.com':
                if (true === top.location.pathname.startsWith('/cart_index/')) {
                    SubmitCart();
                } else {
                    GoToCart();
                }
                break;
            case 'trade.jd.com':
                if (true === top.location.pathname.startsWith('/shopping/order')) {
                    SubmitOrder();
                }
                break;
            default:
        }
    }
    setInterval(appInit, 100);
})();