Greasy Fork

Greasy Fork is available in English.

一键制作补充包(请看描述)

To dear sbeamer!

目前为 2018-12-28 提交的版本,查看 最新版本

// ==UserScript==
// @name         一键制作补充包(请看描述)
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  To dear sbeamer!
// @author       ZXR
// @email        [email protected]

// @include			*steamcommunity.com/*boostercreator*

//这里就用艹猫来做个示例
//appid   游戏名称
//385800  NEKOPARA Vol. 0
//333600  NEKOPARA Vol. 1
//420110  NEKOPARA Vol. 2
//602520  NEKOPARA Vol. 3
//899970  NEKOPARA Extra
//758230  NEKOPARA OVA

// ==/UserScript=='''''

//将所有要做补充包的游戏appid添加在这里,不在这里面将会被过滤掉
var richGameArray = ['385800','333600','420110','602520','899970','758230'];
var opitonArray = [];//过滤后的所有游戏
var availableGame = [];//当前可以做包的游戏
var steamCookie = document.cookie;
var totalGame = [];//所有游戏
var showAll = false;//是否展示全部游戏


//根据自己预设的数据,过滤掉其他所有游戏
function deletePoorGame(){
    let originSeletor = document.getElementById("booster_game_selector")
    if(originSeletor.length == 0){
        return
    };
    for(let i=originSeletor.length -1 ;i >=0 ;i--){
        totalGame.push(originSeletor.options[i])
        if(originSeletor.options[i].value && richGameArray.indexOf(originSeletor.options[i].value) >= 0 ){
           opitonArray.push(originSeletor.options[i])
           if(originSeletor.options[i].getAttribute("class") == "available"){
               availableGame.push(originSeletor.options[i])
           }
        }
    }
    totalGame.reverse();
    originSeletor.options.length=0;
    opitonArray.map((item)=>{
        originSeletor.add(item)
    })
}
//执行过滤
deletePoorGame();

//根据过滤结果展示一键制作按钮
if(availableGame.length > 0){
    $J('.booster_game_selector').before('<h4 style="margin-top: 12px; color: red;">已经过筛选</h4>')
        .after('<div><div id="create_booster" class="btnv6_blue_blue_innerfade btn_medium btn_makepack"><span id="button_name">一键制作 '+availableGame.length+' 个补充包</span></div><div id="reset" style="margin-left: 16px" class="btnv6_blue_blue_innerfade btn_medium btn_makepack"><span id="show_all_name">展示全部</span></div></div></div>');
    $J('#create_booster').click( function() {
        document.getElementById("create_booster").setAttribute("class","btnv6_blue_blue_innerfade btn_medium btn_makepack btn_disabled")
        create(0);
    });
}else{
    $J('.booster_game_selector').before('<h4 style="margin-top: 12px; color: red;">已经过筛选</h4>')
        .after('<div><div class="btnv6_blue_blue_innerfade btn_medium btn_makepack btn_disabled"><span id="button_name">全部冷却中</span></div><div id="reset" style="margin-left: 16px" class="btnv6_blue_blue_innerfade btn_medium btn_makepack"><span id="show_all_name">展示全部</span></div></div>');
}
 $J('#reset').click( function() {
        convertStatus();
    });


//提交请求
//tradability_preference值1表示可交易,3表示不可交易,实测一直传1,steam后端会自动校验,如果可交易宝珠不够自动转为不可交易
//series可能代表此游戏有多个补充包,但是我的发现几次全都是1,没见到更多的,暂定1,遇到特殊游戏再修改吧
function create(index){
    document.getElementById("button_name").innerHTML = "正在制作第 "+(index+1)+"个补充包"
    let item = availableGame[index]
    $J.ajax({
                url: 'https://steamcommunity.com/tradingcards/ajaxcreatebooster/',
                type: 'POST',
                data: {
                    sessionid: steamCookie.split('sessionid=')[1].split(';')[0],
                    appid: item.value,
                    series: 1,
                    tradability_preference: 1
                },
                crossDomain: true,
                xhrFields: {withCredentials: true}
            }).success(function (data) {
                if(showAll){
                    for(let i=0;i<totalGame.length;i++){
                        if(totalGame[i].value == item.value){
                            totalGame[i].setAttribute("class","unavailable")
                            break;
                        }
                    }
                }else{
                    for(let i=0;i<opitonArray.length;i++){
                        if(opitonArray[i].value == item.value){
                            opitonArray[i].setAttribute("class","unavailable")
                            break;
                        }
                    }
                }
                if(index+1 < availableGame.length){
                    //默认500毫秒后进行下一次制作,不建议太快
                    setTimeout(function(){
                        create(index+1)
                    },500)
                }else{
                    document.getElementById("button_name").innerHTML="全部冷却中"

                }
            }).error(function(data){
                 document.getElementById("button_name").innerHTML = "制作失败,2s后自动开始下一个"
                 setTimeout(function(){
                    create(index+1)
                 },2000)
         });
}

//过滤和展示全部之间进行切换
function convertStatus(){
    let originSeletor = document.getElementById("booster_game_selector")
     originSeletor.options.length=0;
    if(!showAll){
        totalGame.map((item)=>{
            originSeletor.add(item)
        })
        document.getElementById("show_all_name").innerHTML="过滤"
    }else{
        opitonArray.map((item)=>{
            originSeletor.add(item)
        })
        document.getElementById("show_all_name").innerHTML="展示全部"
    }
    showAll = !showAll

}