// ==UserScript== // @name Badge Autocraft 2 // @icon https://store.steampowered.com/favicon.ico // @namespace steam // @version 2.6.1 // @description Thanks to Psy0ch and MrSteakPotato for testing! Inspired by 10101000's Steam-AutoCraft. Allows you to craft remaining badges in one click. Works much more faster, takes much less resources. // @author Lutymane // @match https://steamcommunity.com/*/*/badges // @match https://steamcommunity.com/*/*/badges/ // @match https://steamcommunity.com/*/*/badges/?p=* // @homepageURL https://github.com/Lutymane/Steam-Scripts // @supportURL https://github.com/Lutymane/Steam-Scripts/issues // @updateURL https://github.com/Lutymane/Steam-Scripts/raw/master/Badge-Autocraft-2/Badge-Autocraft-2.meta.js // @downloadURL https://github.com/Lutymane/Steam-Scripts/raw/master/Badge-Autocraft-2/Badge-Autocraft-2.user.js // @require https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js // ==/UserScript== var NumberOfBadgesToCraftOnPage = 0, DataButtons = '

Toggle Autocraft
', ModalBlockData = '', BlackListAppIDs = [], ModalInfo = null, BadgeNumber = 0, LevelsCrafted = 0, BadgesSkipped = 0, CurrentAppID = 0, Border = 0, IgnoreFoils = false, IgnoreNormal = false, PageNumber = 1, PostURL = ''; function CleanArray(Source) { var CleanedArray = []; for (var i = 0; i < Source.length; i++) { if (Source[i]) { CleanedArray.push(Source[i]); } } return CleanedArray; } function ApplySettings() { BlackListAppIDs = CleanArray($('#BlackList').val().replace(/\s+/g, '').split(',')); if ($('#IgnoreFoilBadges').prop('checked')) { window.localStorage.setItem('IgnoreFoils', 'true'); IgnoreFoils = true; } else { window.localStorage.setItem('IgnoreFoils', 'false'); IgnoreFoils = false; } if ($('#IgnoreNormalBadges').prop('checked')) { window.localStorage.setItem('IgnoreNormal', 'true'); IgnoreNormal = true; } else { window.localStorage.setItem('IgnoreNormal', 'false'); IgnoreNormal = false; } window.localStorage.setItem('BlackList', BlackListAppIDs); $('#ModalBlock').css('display', 'none'); } function ResetSettings() { window.localStorage.setItem('BlackList', ''); window.localStorage.setItem('IgnoreFoils', 'false'); window.localStorage.setItem('IgnoreNormal', 'false'); BlackListAppIDs = []; $('#BlackList').val(''); IgnoreFoils = false; $('#IgnoreFoilBadges').prop('checked', false); IgnoreNormal = false; $('#IgnoreNormalBadges').prop('checked', false); } function SettingsModal() { $('#ModalBlock').css('display', 'block'); $('#BlackList').val(window.localStorage.getItem('BlackList')); if (window.localStorage.getItem('IgnoreFoils') == 'true') { $('#IgnoreFoilBadges').prop('checked', true); } else { $('#IgnoreFoilBadges').prop('checked', false); } if (window.localStorage.getItem('IgnoreNormal') == 'true') { $('#IgnoreNormalBadges').prop('checked', true); } else { $('#IgnoreNormalBadges').prop('checked', false); } } function IsInBlackList(id) { for (var i = 0; i < BlackListAppIDs.length; i++) { if (id == BlackListAppIDs[i]) { return true; } } return false; } function ToggleAutocraft(i) { BadgeNumber = i + 1; ModalInfo = ShowBlockingWaitDialog("Crafting on a current page...", "Badge " + BadgeNumber + "/" + NumberOfBadgesToCraftOnPage + " is being processed!
Earned during the session: " + LevelsCrafted * 100 + "XP
Badges skipped: " + BadgesSkipped + ""); CurrentAppID = $('.badge_craft_button').eq(i).attr('href').split('/')[6].split('?')[0]; if ($('.badge_craft_button').eq(i).attr('href').includes("?border=1")) Border = 1; else Border = 0; if (IsInBlackList(CurrentAppID) || (Border == 1 && IgnoreFoils == true) || (Border == 0 && IgnoreNormal == true)) { BadgesSkipped++; if (BadgeNumber < NumberOfBadgesToCraftOnPage) { ModalInfo.Dismiss(); ToggleAutocraft(++i); } else { ModalInfo.Dismiss(); window.localStorage.setItem('PageFlag', '1'); window.localStorage.setItem('Skipped', BadgesSkipped); window.localStorage.setItem('LevelsCrafted', LevelsCrafted); window.location.reload(); } } else { $.post(PostURL, { appid: CurrentAppID, series: 1, border_color: Border, sessionid: g_sessionID }).done(function (data) { console.log('AppID: ' + CurrentAppID + ' | XP: ' + data.Badge.xp); window.localStorage.setItem('LevelsCrafted', ++LevelsCrafted); if ((data.success == 1) && (Border != 1) && (data.Badge.xp != "500")) { ModalInfo.Dismiss(); ToggleAutocraft(i); } else { if (BadgeNumber < NumberOfBadgesToCraftOnPage) { ModalInfo.Dismiss(); ToggleAutocraft(++i); } else { ModalInfo.Dismiss(); window.localStorage.setItem('PageFlag', '1'); window.localStorage.setItem('Skipped', BadgesSkipped); window.location.reload(); } } }).fail(function (data) { try { switch (data.responseJSON.success) { case 42: console.log('AppID: ' + CurrentAppID + " | You don't own all cards to craft a badge!"); break; case 11: console.log('AppID: ' + CurrentAppID + " | Badge's maximum level has been reached!"); break; default: console.log('AppID: ' + CurrentAppID + " | Unknown error code: " + data.responseJSON.success); } } catch (e) { console.log(data); console.log(e); } if (BadgeNumber < NumberOfBadgesToCraftOnPage) { ModalInfo.Dismiss(); ToggleAutocraft(++i); } else { ModalInfo.Dismiss(); window.localStorage.setItem('PageFlag', '1'); window.localStorage.setItem('Skipped', BadgesSkipped); window.location.reload(); } }); } } $(document).ready(function () { if (location.href.includes("/badges")) { PostURL = window.location.href.split('?')[0].replace("badges", 'ajaxcraftbadge'); $('.badge_details_set_favorite').append(DataButtons); $('.responsive_page_frame.with_header').after(ModalBlockData); $('#ToggleAutocraft').click(function () { if (confirm('Do you want to toggle autocraft?')) { if (IgnoreFoils && IgnoreNormal) { ShowAlertDialog("Info", "Oops... You can't ignore normal badges and foil badges at the same time!
Check your settings, please"); return; } else { if (NumberOfBadgesToCraftOnPage == 0) { window.localStorage.setItem('PageFlag', '0'); window.localStorage.setItem('Skipped', '0'); ShowAlertDialog("Info", "There are no badges to craft!"); return; } else { ToggleAutocraft(0); } } } }); $('#Settings').click(function () { SettingsModal(); }); $('#ApplySettings').click(function () { ApplySettings(); }); $('#ResetSettings').click(function () { ResetSettings(); }); $('.newmodal_close').click(function () { $('#ModalBlock').css('display', 'none'); }); NumberOfBadgesToCraftOnPage = $('.badge_craft_button').length; if (window.localStorage.getItem('BlackList') == null || window.localStorage.getItem('IgnoreFoils') == null || window.localStorage.getItem('IgnoreNormal') == null) { alert("Badge Autocraft script can't read settings values! It may occur because of the script got an update. Please set up script's settings again, since they are cleared now"); return; } if (window.localStorage.getItem('BlackList') != '') { BlackListAppIDs = window.localStorage.getItem('BlackList').split(','); } if (window.localStorage.getItem('IgnoreFoils') == 'true') { IgnoreFoils = true; } if (window.localStorage.getItem('IgnoreNormal') == 'true') { IgnoreNormal = true; } if (window.localStorage.getItem('PageFlag') == '1') { window.localStorage.setItem('PageFlag', '0'); LevelsCrafted = parseInt(window.localStorage.getItem('LevelsCrafted')); if (NumberOfBadgesToCraftOnPage > window.localStorage.getItem('Skipped')) { ToggleAutocraft(0); } else { if (window.localStorage.getItem('Skipped') == '150') { window.localStorage.setItem('Skipped', '0'); if (window.location.href.split('?')[1] == null) { window.location = window.location.href.split('?')[0] + "?p=2"; } else { PageNumber += parseInt(window.location.href.split('?')[1].split('&')[0].split('=')[1]); window.location = window.location.href.split('?')[0] + "?p=" + PageNumber; } } else { window.localStorage.setItem('PageFlag', '0'); window.localStorage.setItem('Skipped', '0'); window.localStorage.setItem('LevelsCrafted', '0'); if (LevelsCrafted == 0) { ShowAlertDialog('Info', 'No badges have been crafted! It seems, that you\'ve set up the script wrong. Please, check the settings'); LevelsCrafted = 0; } else { ShowAlertDialog('Info', 'Crafting is done!
Earned during the session: ' + LevelsCrafted * 100 + " XP"); LevelsCrafted = 0; } } } } } });