Toranoana: no reload

Do not redirect after action.

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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         Toranoana: no reload
// @namespace    http://darkfader.net/
// @version      0.3
// @description  Do not redirect after action.
// @author       Rafael Vuijk
// @match        https://ec.toranoana.shop/ec/app/mypage/favorite_list/*
// @match        https://ec.toranoana.shop/ec/app/cart/cart/*
// @grant        unsafeWindow
// ==/UserScript==

HTMLElement.prototype.remove = function() { this.parentNode.removeChild(this); return this; }

function onReady() {
    const _controlAjaxSuccess = unsafeWindow.controlAjaxSuccess;
    unsafeWindow.controlAjaxSuccess = function(data, successFunction, messageType, messageAdd, formId) {
        if (formId !== undefined && formId != null) {
            console.log("controlAjaxSuccess", data, successFunction, messageType, messageAdd, formId);
            let action = document.getElementById(formId).querySelector("input[name='actionId']").value;
            console.log(data, action);
            if (action == "delete") {
                data.nextUrl = null; // don't go anywhere (and parse transactiontoken from result)
            }
            _controlAjaxSuccess(data, successFunction, messageType, messageAdd, formId);
            if (action == "delete") {
                document.getElementById(formId).remove();
            }
        } else {
            _controlAjaxSuccess(data, successFunction, messageType, messageAdd, formId);
        }
    }
}

// start the onReady...
if (document.readyState !== "loading") {
    setTimeout(onReady, 0);
} else {
    document.addEventListener("DOMContentLoaded", onReady);
}