Custom Mandarake

Deactivate alerts without the whole page reloading

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

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

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         Custom Mandarake
// @namespace    http://tampermonkey.net/
// @version      2024-04-10
// @description  Deactivate alerts without the whole page reloading
// @author       Doni
// @match        https://order.mandarake.co.jp/order/mypage/announceList*
// @match        https://order.mandarake.co.jp/order/mypage/favoritesList*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=mandarake.co.jp
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    addAjaxAlertToggle();
    addAjaxDeleteFavorite();
})();

function addAjaxAlertToggle() {
    var scriptElem = document.createElement('script');

    const script =
          "function changeMailStateItem(shohinIndex, status) {                                                                   " +
          "                                                                                                                      " +
          "    const form = document.getElementById('change_mail_item_form');                                                    " +
          "    form.shohinIndex.value = shohinIndex;                                                                             " +
          "    form.status.value = status;                                                                                       " +
          "                                                                                                                      " +
          "    if (!(status == 0 || status == 1)) {                                                                              " +
          "        return;                                                                                                       " +
          "    }                                                                                                                 " +
          "                                                                                                                      " +
          "   const data = new FormData(form);                                                                                   " +
          "   fetch(form.action, { method: 'POST', body: data });                                                                " +
          "                                                                                                                      " +
          "   const block = document.querySelector(\"div[data-itemidx='\" + shohinIndex + \"']\");                               " +
          "   const badge = block.querySelector(status == 1 ? '.alert_off' : '.alert_on');                                       " +
          "   badge.textContent = status == 1 ? 'Alerts Are On' : 'Alerts Are Off';                                              " +
          "   badge.classList.remove(status == 1 ? 'alert_off' : 'alert_on');                                                    " +
          "   badge.classList.add(status == 1 ? 'alert_on' : 'alert_off');                                                       " +
          "                                                                                                                      " +
          "   const actionButton = block.querySelector('.mail p:nth-child(2) a:first-child');                                    " +
          "   actionButton.textContent = status == 0 ? 'Activate Alerts' : 'Deactivate Alerts';                                  " +
          "   const actionHref = 'javascript:changeMailStateItem(\\\'' + shohinIndex + '\\\', ' + (status == 0 ? 1 : 0) + ')';   " +
          "   actionButton.href = actionHref;                                                                                    " +
          "}                                                                                                                     ";

    scriptElem.innerHTML = script;
    document.body.appendChild(scriptElem);
}

function addAjaxDeleteFavorite() {
    var scriptElem = document.createElement('script');

    const script =
          "function deleteItem(deleteIndex, target) {                                                        " +
          "                                                                                                  " +
          "    const form = document.getElementById('delete_form');                                          " +
          "    form.deleteIndex.value = deleteIndex;                                                         " +
          "    form.target.value = target;                                                                   " +
          "                                                                                                  " +
          "    const data = new FormData(form);                                                              " +
          "    fetch(form.action, { method: 'POST', body: data });                                           " +
          "                                                                                                  " +
          "    const formulaString = 'javascript:deleteItem(\\\'' + deleteIndex + '\\\', ' + target + ')';   " +
          "    const caller = document.querySelector('a[href=\"' + formulaString + '\"]');                   " +
          "    caller.parentElement.parentElement.remove();                                                  " +
          "}                                                                                                 ";

    scriptElem.innerHTML = script;
    document.body.appendChild(scriptElem);
}