SHIFT Redeemer

在 https://shift.gearboxsoftware.com/rewards 页面一键兑换所有平台及版本,基于kabpy的脚本(https://keylol.com/t993469-1-1)由ChatGPT改造,enjoy it!~ A script that help you to redeem all platform and versions with one click on https://shift.gearboxsoftware.com/rewards for the same SHIFT code. Mainly generated by ChatGPT based on the script by kabpy (https://keylol.com/t993469-1-1), with a few adjustment by myself. Enjoy it!~

// ==UserScript==
// @name         SHIFT Redeemer
// @name:zh   SHIFT Redeemer
// @namespace    http://tampermonkey.net/
// @version      1.0.3
// @description 在 https://shift.gearboxsoftware.com/rewards 页面一键兑换所有平台及版本,基于kabpy的脚本(https://keylol.com/t993469-1-1)由ChatGPT改造,enjoy it!~  A script that help you to redeem all platform and versions with one click on https://shift.gearboxsoftware.com/rewards for the same SHIFT code. Mainly generated by ChatGPT based on the script by kabpy (https://keylol.com/t993469-1-1), with a few adjustment by myself. Enjoy it!~
// @description:en     A script that help you to redeem all platform and versions with one click on https://shift.gearboxsoftware.com/rewards for the same SHIFT code. Mainly generated by ChatGPT based on the script by kabpy (https://keylol.com/t993469-1-1), with a few adjustment by myself. Enjoy it!~ 
// @description:zh     在https://shift.gearboxsoftware.com/rewards页面一键兑换所有平台及版本,基于kabpy的脚本(https://keylol.com/t993469-1-1)由ChatGPT改造,enjoy it!~ 
// @author       JACKIEXIA
// @match        https://shift.gearboxsoftware.com/rewards*
// @grant        none
// @license     GNU GPLv3
// ==/UserScript==

(function() {
    'use strict';

    function oneClickRedeem() {
        // 弹出输入框让你输入兑换码
        var newCode = prompt("请输入兑换码:");
        if (!newCode) {
            alert("兑换码不能为空!");
            return;
        }

        // 获取所有兑换表单
        var forms = document.querySelectorAll("form.new_archway_code_redemption");
        if (!forms.length) {
            alert("没有找到兑换表单!");
            return;
        }

        // 逐个处理每个表单
        forms.forEach(function(form, index) {
            // 找到表单中用于传递兑换码的隐藏输入框
            var codeInput = form.querySelector('input[name="archway_code_redemption[code]"]');
            if (codeInput) {
                codeInput.value = newCode;
            } else {
                console.warn("未找到兑换码输入框,跳过该表单", form);
                return;
            }

            // 延时提交,防止同时提交请求导致问题(可根据实际情况调整延时毫秒数)
            setTimeout(function() {
                // 这里模拟点击提交按钮(点击后页面可能刷新或进行异步处理)
                var submitBtn = form.querySelector('input[type="submit"].redeem_button');
                if (submitBtn) {
                    submitBtn.click();
                } else {
                    // 如果没有找到提交按钮,则直接调用表单提交方法
                    form.submit();
                }
            }, index * 500); // 每个表单间隔 500 毫秒提交
        });
    }

    // 添加一个页面上的按钮,点击触发兑换
    function addRedeemButton() {
        const container = document.createElement('div');
        container.style.position = 'fixed';
        container.style.bottom = '20px';
        container.style.right = '20px';
        container.style.zIndex = 9999;

        const btn = document.createElement('button');
        btn.textContent = '一键兑换所有平台';
        btn.style.padding = '10px 15px';
        btn.style.fontSize = '16px';
        btn.style.backgroundColor = '#0078d7';
        btn.style.color = '#fff';
        btn.style.border = 'none';
        btn.style.borderRadius = '5px';
        btn.style.cursor = 'pointer';
        btn.style.boxShadow = '0 2px 6px rgba(0,0,0,0.2)';

        btn.onclick = oneClickRedeem;

        container.appendChild(btn);
        document.body.appendChild(container);
    }

    // 等待页面加载完成后添加按钮
    window.addEventListener('load', () => {
        addRedeemButton();
    });

})();