An auto-trainer??!! (SGChooChoo)

Make da whoooole train automagically :D

当前为 2016-06-10 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         An auto-trainer??!! (SGChooChoo)
// @namespace    https://digitalfishfun.com
// @version      0.1.1
// @description  Make da whoooole train automagically :D
// @author       joonatoona
// @include      https://www.steamgifts.com/giveaways/new*
// @include      https://www.steamgifts.com/giveaway/*
// @grant        none
// @run-at       document-end
// ==/UserScript==

var cTrain = sessionStorage.getItem("pGid");

var doCart = sessionStorage.getItem("doCart");

var timeOpen = sessionStorage.getItem("timeOpen");
var groupId = "1898";
var cL = sessionStorage.getItem("cL");
var desc = sessionStorage.getItem("desc");

function setupTrain() {
    timeOpen = prompt("It appears you haven't set up a train yet!\nHow long (In hours) would you like the giveaways to be open for?")*3600000;
    sessionStorage.setItem("timeOpen", timeOpen);
    cL = prompt("It appears you haven't set up a train yet!\nWhat should the minimum contributor level be?");
    sessionStorage.setItem("cL", cL);
    desc = prompt("It appears you haven't set up a train yet!\nWhat should the generic description be?");
    sessionStorage.setItem("desc", desc);
}

function formatTime(time) {
    var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
    var date = new Date(time);
    var year = date.getFullYear();
    var month = months[date.getMonth()];
    var day = date.getDate();
    var hour = date.getHours();
    var stamp = "am";
    if (hour >= 12) {
        stamp = "pm";
    }
    if (hour > 12) {
        hour -= 12;
    }
    if (hour === 0) {
        hour = 12;
    }
    var min = date.getMinutes();
    return month + " " + day + ", " + year + " " + hour + ":" + min + " " + stamp;
}

function applyDates() {
    $("input[name='start_time']").val(formatTime(Date.now()));

    $("input[name='end_time']").val(formatTime(Date.now()+timeOpen));
}

function applyRegionRestrictions() {
    $("div[data-checkbox-value='0']").trigger("click");
}

function applyGroup() {
    $("div[data-checkbox-value='invite_only']").trigger("click");
}

function applyLevel() {
    if (cL > 0) {
        $('input[name=contributor_level]').val(cL);
        $('.ui-slider-range').width(cL + '0%');
        $('.ui-slider-handle').css('left', cL + '0%');
        $('input[name=contributor_level]').next('div').find('span').text('level ' + cL);
    }
}

function applyGenericDescription(){
    var newDesc = $("textarea[name='description']").val().replace(desc, "") + "\n\n" + desc;
    $("textarea[name='description']").val(newDesc);
}

function clickCreate(){
    $("form").first().submit();
}

var cPath = window.location.href.split("/");

console.log(cPath);

if (cPath[cPath.length-1] == "new") {
    $(".form__rows").after('<br/><div id="addTrain" class="form__submit-button js__submit-form"><i class="fa fa-arrow-circle-right"></i> CHOOO CHOOOOOOO</div>');
    $("#addTrain").click(function() {
        if (timeOpen === null) {
            setupTrain();
        }
        applyDates();
        applyRegionRestrictions();
        applyGroup();
        applyLevel();
        applyGenericDescription();
        clickCreate();
    });
}

if (cPath[cPath.length-3] == "giveaway" && doCart) {
    
}