Steam Redeem Sub

Steam激活Sub

目前為 2019-08-13 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Steam Redeem Sub
// @namespace    Steam Redeem Sub
// @version      0.2
// @description  Steam激活Sub
// @author       HCLonely
// @include      /https?:\/\/store\.steampowered\.com\/account\/licenses\/(\?sub\=[\w\W]{0,})?/
// @include      *://steamdb.info/freepackages*
// @grant        GM_registerMenuCommand
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    const url=window.location.href;

    //steamdb.info
    if(/https?:\/\/steamdb\.info\/freepackages\//.test(url)){//点击自动跳转到激活页面
        let activateConsole = function(e) {
            document.execCommand("Copy");
            let jsText = window.getSelection().toString().trim() || e.target.value;
            if (/\(function\(\)[\w\W]{0,}let freePackages \=[\w\W]{0,}\}\(\)\)\;/.test(jsText)) {
                let freePackages=jsText.match(/[\d]{2,},[\s]\/\/ \[REMOVE\]/g).join("-").match(/[\d]{2,},/g).join("");
                window.open("https://store.steampowered.com/account/licenses/?sub=" + freePackages,"_self");
            }
        };
        let fp=setInterval(()=>{
            if(document.getElementById("freepackages")){
                document.getElementById("freepackages").innerHTML=`<button>激活SUB</button>`+document.getElementById("freepackages").innerHTML;
                document.getElementById("freepackages").onclick=activateConsole;
                clearInterval(fp);
            }
        },1000);
        //GM_registerMenuCommand
    }else{
        function redeemSub(e){
            let subText=e||document.getElementById("gameSub").value;
            if(subText){
                let ownedPackages = {};
                jQuery( '.account_table a' ).each( function( i, el ){
                    let match = el.href.match( /javascript:RemoveFreeLicense\( ([0-9]+), '/ );
                    if( match !== null ){
                        ownedPackages[ +match[ 1 ] ] = true;
                    }
                } );
                let freePackages =subText.match(/[\d]{2,}/g);
                let i = 0,
                    loaded = 0,
                    packae = 0,
                    total = freePackages.length,
                    modal = ShowBlockingWaitDialog( 'Executing…',
                                                   'Please wait until all requests finish. Ignore all the errors, let it finish.' );
                for( ; i < total; i++ ){
                    packae = freePackages[ i ];
                    if( ownedPackages[ packae ] ){
                        loaded++;
                        continue;
                    }
                    jQuery.post(
                        '//store.steampowered.com/checkout/addfreelicense',
                        {
                            action: 'add_to_cart',
                            sessionid: g_sessionID,
                            subid: packae
                        }
                    ).always( function( )
                             {
                        loaded++;
                        modal.Dismiss();
                        if( loaded >= total )
                        {
                            window.open("https://store.steampowered.com/account/licenses/","_self");
                        }
                        else
                        {
                            modal = ShowBlockingWaitDialog( 'Executing…',
                                                           'Loaded <b>' + loaded + '</b>/' + total + '.' );
                        }
                    }
                            );
                }
            }
        }
        function cc(){
            jQuery.ajax({
                url:"//store.steampowered.com/cart/",
                type:"get",
                success:function(data){
                    if(data.match(/id\=\"usercountrycurrency_trigger\"[\w\W]*?\>[w\W]*?\<\/a/gim)){
                        let c=data.match(/id\=\"usercountrycurrency_trigger\"[\w\W]*?\>[w\W]*?\<\/a/gim)[0].replace(/id\=\"usercountrycurrency_trigger\"[\w\W]*?\>|\<\/a/g,"");
                        let thisC=data.match(/id\=\"usercountrycurrency\"[\w\W]*?value=\".*?\"/gim)[0].match(/value=\".*?\"/gim)[0].replace(/value=\"|\"/g,"");
                        let div=data.match(/\<div class=\"currency_change_options\"\>[\w\W]*?\<p/gim)[0].replace(/[\s]*?\<p/gim,"")+"</div>";
                        jQuery("body").append(`<div id="ccDiv" style="position:fixed;margin:auto;z-index: 1000;width:629px;height:228px;top:20px;bottom:20px;left:20px;right:20px;background-color:#232b34"><div class="newmodal_header_border"><div class="newmodal_header"><div class="newmodal_close"></div><div id="nowCountry" class="ellipsis" data-country="${thisC}" style="font-size:20px;">转换商店和钱包&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;当前国家/地区:${c}</div></div></div><div style="padding:20px">${div}</div></div>`);
                        jQuery(".currency_change_option").click(function(){
                            changeCountry(jQuery(this).attr("data-country"));
                        });
                        jQuery(".newmodal_close").click(function(){
                            jQuery("#ccDiv").remove();
                        });
                    }else{
                        alert("需要挂相应地区的梯子!");
                    }
                },
                error:()=>{
                    alert("获取当前国家/地区失败!");
                }
            });
        }
        function changeCountry(country){
            jQuery.ajax({
                url:"//store.steampowered.com/account/setcountry",
                type:"post",
                data:{
                    sessionid:document.cookie.match(/sessionid\=.*?\;/gim)[0].replace(/sessionid\=|\;/g,""),
                    "cc":country
                },
                complete:function(data){
                    jQuery.ajax({
                        url:"//store.steampowered.com/cart/",
                        type:"get",
                        success:function(data){
                            let c=data.match(/id\=\"usercountrycurrency_trigger\"[\w\W]*?\>[w\W]*?\<\/a/gim)[0].replace(/id\=\"usercountrycurrency_trigger\"[\w\W]*?\>|\<\/a/g,"");
                            let thisC=data.match(/id\=\"usercountrycurrency\"[\w\W]*?value=\".*?\"/gim)[0].match(/value=\".*?\"/gim)[0].replace(/value=\"|\"/g,"");
                            let div=data.match(/\<div class=\"currency_change_options\"\>[\w\W]*?\<p/gim)[0].replace(/[\s]*?\<p/gim,"")+"</div>";
                            jQuery("#ccDiv").html(`<div class="newmodal_header_border"><div class="newmodal_header"><div class="newmodal_close"></div><div id="nowCountry" class="ellipsis" data-country="${thisC}" style="font-size:20px;">转换商店和钱包&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;当前国家/地区:${c}</div></div></div><div style="padding:20px">${div}</div>`);
                            jQuery(".currency_change_option").click(function(){
                                changeCountry(jQuery(this).attr("data-country"));
                            });
                            jQuery(".newmodal_close").click(function(){
                                jQuery("#ccDiv").remove();
                            });
                            if(thisC===country){
                                alert("更换成功!");
                            }else{
                                alert("更换失败!");
                            }
                        },
                        error:()=>{
                            alert("获取当前国家/地区失败!");
                        }
                    });
                }
            });
        }
        jQuery('.pageheader').parent().append('<div style="float: left;";>' +
                                              '<textarea class="registerkey_input_box_text" rows="1"' + 'name="product_key"' +
                                              ' id="gameSub" placeholder="输入SUB,多个SUB之间用英文逗号连接"' + 'value=""' + 'color:#fff;' +
                                              ' style="margin: 3px 0px 0px; width: 400px; height: 15px;background-color:#102634; padding: 6px 18px 6px 18px; font-weight:bold; color:#fff;"></textarea>' +
                                              ' &nbsp ' + '</div>' + '<a tabindex="300" class="btnv6_blue_hoverfade btn_medium"' +
                                              ' style="width: 95px; height: 30px;"' +
                                              ' id="buttonSUB"><span>激活SUB</span></a>'+ '<a tabindex="300" class="btnv6_blue_hoverfade btn_medium"' +
                                              ' style="width: 125px; height: 30px;"' +
                                              ' id="changeCountry"><span>更改国家/地区</span></a>');
        jQuery('#buttonSUB').click(redeemSub);
        jQuery('#changeCountry').click(cc);
        if (url.includes("sub=")){
            setTimeout(()=>{redeemSub(url)},2000);
        }
    }
})();