Greasy Fork

Cart - Flip

Опции для корзины

目前为 2023-07-26 提交的版本。查看 最新版本

// ==UserScript==
// @name           Cart - Flip
// @namespace      scriptomatika
// @author         mouse-karaganda
// @description    Опции для корзины
// @license        MIT
// @include        https://*flip.kz/cart*
// @require        https://greasyfork.org/scripts/379902-include-tools/code/Include%20Tools.js?version=1071128
// @version        1.0
// @grant          none
// ==/UserScript==

(function() {
    const $ = window.jQuery;
    const $$ = window.__krokodil;

    $$.renderStyle(
        '.disabledFrame { position: fixed; bottom: 0; right: 0; width: 400px; padding: 5px; border-radius: 10px 0 0 0; background-color: rgba(10, 121, 213, 0.9); }',
        '.disabledFrame iframe { width: 400px; height: 100px; }'
    );

    let disabledList;

    const body = document.body;
    let disabledFrame = $('<div class="disabledFrame" />').appendTo(body);
    let div = $('<div />').appendTo(disabledFrame);
    $('<a class="nbtn gray small m-r-10" />').appendTo(div)
        .text('К недоступному')
        .click(function(event) {
            let viewRow;
            if (disabledList && disabledList.length > 0) {
                viewRow = disabledList.eq(0);
            } else {
                viewRow = $('#module-cart .row').last();
            }
            viewRow.get(0).scrollIntoView();
        });
    $('&nbsp;&nbsp;<a class="nbtn gray small m-r-10" />').appendTo(div)
        .text('Открыть 3')
        .click(function(event) {
            let period = 1500;
            setTimeout(function() {
                let informer = window.open('', 'manual_postpone0', 'width=450,height=300,left=0,top=0');
                console.log('frame 0 == ', informer);
            }, 1);
            setTimeout(function() {
                let informer = window.open('', 'manual_postpone1', 'width=450,height=300,left=455,top=0');
                console.log('frame 1 == ', informer);
            }, period);
            setTimeout(function() {
                let informer = window.open('', 'manual_postpone2', 'width=450,height=300,left=910,top=0');
                console.log('frame 2 == ', informer);
            }, period * 2);
        });

    let postponeClass = 'add_postpone_button';
    let current = 0;

    disabledList = $('#module-cart .row')
        .filter(function(index) {
            let thisRow = $(this);
            let srok = $('label + div + div', thisRow);
            let result = srok.text().includes('Недоступен для заказа');

            if (result) {
                let div = $('<div />').appendTo(srok);
                let href = $('a[href^="/catalog?"]', thisRow).attr('href');
                let product = href.match(/\d+/)[0];
                thisRow.addClass(postponeClass);

                $('<a class="nbtn gray small" />').appendTo(div)
                    .text('Отложить')
                    .attr({
                        target: 'manual_postpone' + (current++ % 3),
                        href: '/subscribe?type=preorder&action=add&id=' + product
                    })
                    .click(function(event) {
                        setTimeout(function() {
                            div.remove();
                            thisRow.removeClass(postponeClass);
                        }, 1500);
                    });
            }
            return result;
        });
    console.log('disabledList [%o] == ', disabledList.length, disabledList);

    console.log('Cart - Flip 💬 1.0');
})();