Advertisement
Guest User

AutoCraft Steam Community Badges

a guest
Jun 9th, 2016
703
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Steam-AutoCraft
  3. // @version 1.3.1
  4. // @description AutoCraft Steam Community Badges
  5. // @author Noteim Porta
  6. // @match *://steamcommunity.com/*/gamecards/*
  7. // @match *://steamcommunity.com/*/badges/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. // Isolate jQuery for compatibility with other scripts
  12. jQuery.noConflict();
  13.  
  14.  
  15. // Vars
  16. var craftBadgeState = 0;
  17. var craftBadgesState = 0;
  18. var craftRefreshTimeoutms = 2000;
  19. var pageRefreshTimeoutms = 10000;
  20. // Badges
  21. var badgeLinks = jQuery('.badge_details_set_favorite');
  22. // Badge Details
  23. var invLinks = jQuery('.gamecards_inventorylink');
  24.  
  25. // Run
  26. jQuery(document).ready(function(){
  27. // Check for badges to craft
  28. if (jQuery('.badge_progress_tasks').length >= 1){
  29. checkBadges();
  30. } else if (jQuery('.gamecard_badge_progress').length >= 1){
  31. checkBadge();
  32. }
  33.  
  34. if (window.sessionStorage.craftRecursive && craftBadgesState == 1){
  35. window.location.href = jQuery('div').find('.badge_row a.badge_row_overlay').attr('href');
  36. autoCraft();
  37. } else if (window.sessionStorage.craftRecursive && craftBadgesState === 0 && craftBadgeState === 0 && jQuery('.gamecard_badge_progress').length >= 1){
  38. window.location.href = jQuery('div').find('.profile_small_header_text a.whiteLink').attr('href') + '/badges/';
  39. } else if (!window.sessionStorage.craftRecursive && craftBadgesState === 0 && craftBadgeState === 0 && jQuery('.gamecard_badge_progress').length >= 1){
  40. delete window.sessionStorage.autoCraftState;
  41. } else if (window.sessionStorage.craftRecursive && craftBadgesState === 0 && craftBadgeState === 0 && jQuery('.badge_progress_tasks').length >= 1){
  42. delete window.sessionStorage.craftRecursive;
  43. delete window.sessionStorage.autoCraftState;
  44. }
  45.  
  46. // Always add button
  47. addButton();
  48.  
  49. // Start autoCraft
  50. if (window.sessionStorage.autoCraftState){
  51. autoCraft();
  52. }
  53. });
  54.  
  55. function addButton(){
  56. // Add button to badge details page
  57. if (invLinks.length >= 1){
  58. if (craftBadgeState == 1){
  59. invLinks.append('<a><button type="button" class="btn_grey_grey btn_small_thin" id="autocraft"><span>AutoCraft remaining badges</span></button></a>');
  60. jQuery('#autocraft').click(function(){ autoCraft(); });
  61. } else {
  62. invLinks.append('<a><button type="button" class="btn_disabled btn_grey_grey btn_small_thin" id="autocraft" disabled><span>AutoCraft remaining badges</span></button></a>');
  63. }
  64. return;
  65. }
  66.  
  67. // Add button to badges page
  68. if (badgeLinks.length >= 1){
  69. if (craftBadgesState == 1){
  70. badgeLinks.append('<a><button type="button" class="btn_grey_black btn_small_thin" id="autocraft"><span>AutoCraft remaining badges</span></button></a>');
  71. jQuery('#autocraft').click(function(){ window.sessionStorage.craftRecursive = 1; window.location.href = jQuery('div').find('.badge_row a.badge_row_overlay').attr('href'); autoCraft(); });
  72. } else {
  73. badgeLinks.append('<a><button type="button" class="btn_disabled btn_grey_black btn_small_thin" id="autocraft" disabled><span>AutoCraft remaining badges</span></button></a>');
  74. }
  75. return;
  76. }
  77. }
  78.  
  79. // Check for badges to craft
  80. function checkBadge(){
  81. if (jQuery('.badge_craft_button').length >= 1){
  82. craftBadgeState = 1;
  83. }
  84. }
  85.  
  86. function checkBadges(){
  87. if (jQuery('.badge_craft_button').length >= 1){
  88. craftBadgesState = 1;
  89. }
  90. }
  91.  
  92. // Craft badge and refresh page
  93. function craftBadge(){
  94. jQuery('.badge_craft_button').click();
  95. setTimeout(function(){ window.location.reload(true); }, craftRefreshTimeoutms);
  96. }
  97.  
  98. // Auto-craft all potential badges
  99. function autoCraft(){
  100. craftBadge();
  101. setTimeout(function(){ checkBadge(); window.location.reload(true); }, pageRefreshTimeoutms);
  102. window.sessionStorage.autoCraftState = 1;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement