Chunithm Exchange Helper (International ver.)

Selection Expansion Tool for Trade by Currency

// ==UserScript==
// @name		Chunithm Exchange Helper (International ver.)
// @namespace		https://m.dcinside.com/board/cnt/45945
// @version		1.0.2
// @description		Selection Expansion Tool for Trade by Currency
// @author		https://m.dcinside.com/board/cnt/45945
// @match		https://chunithm-net-eng.com/mobile/netStore/currencyExchange
// @grant			none
// ==/UserScript==

(function () {
    'use strict';

    console.log("Script Loaded");

    // 현재 보유 재화 값 가져오기
    var currentCurrencyBlock = document.querySelector('.current_currency_block span.text_b');
    var CurrentCurrency = parseInt(currentCurrencyBlock.textContent.replace(/,/g, ''), 10);

    // 모든 교환 아이템 처리
    var exchangeItems = document.querySelectorAll('div.w400.box04');
    exchangeItems.forEach(function (item, index) {

        // 필요한 요소 선택
        var costElement = Array.from(item.querySelectorAll('.text_c.text_b'))
            .find(el => el.textContent.includes('Required currency'));
        var owningElement = Array.from(item.querySelectorAll('.text_c.text_b'))
            .find(el => el.textContent.includes('Owning numbers'));

        // 아이템 가격, 소유 값 파싱
        var itemCost = parseInt(costElement.textContent.split(':')[1].replace(/,/g, '').trim(), 10);
        var owningNumbers = parseInt(owningElement.textContent.split(':')[1].replace(/,/g, '').trim(), 10);

        // 보유 포인트로 구매 가능한 최대 수량 계산
        var maxExchange = Math.floor(CurrentCurrency / itemCost);

        // 소유 수량 확인 및 최대 구매 가능한 수량 제한
        maxExchange = Math.min(maxExchange, 99 - owningNumbers);

        // 옵션 초기화
        var selectElement = item.querySelector('select');
        selectElement.innerHTML = '';

        // maxExchange 따른 옵션 생성
        if (maxExchange == 0){
            var option0 = document.createElement('option');
            option0.value = 0;
            option0.textContent = `Exchange is not available`;
            selectElement.appendChild(option0);
        }else{
            for (let i = maxExchange + 1; i >= 1; i--) {
                var option = document.createElement('option');
                if (i == maxExchange + 1){
                    option.value = 0;
                    option.textContent = `Select the number of exchanges`;
                    selectElement.appendChild(option);
                }else{
                    option.value = i;
                    option.textContent = `Buy × ${i} (Cost: ${i * itemCost} Currency)`;
                    selectElement.appendChild(option);
                }
            }
        }
    });
})();