Steam Guide Subscribe All

Subscribe all guides in the page from Steam workshop in 1 click

  1. // ==UserScript==
  2. // @name Steam Guide Subscribe All
  3. // @author popiazaza
  4. // @namespace popiazaza
  5. // @home-url https://github.com/popiazaza/Steam-Guide-Subscribe-All
  6. // @homepageURL https://github.com/popiazaza/Steam-Guide-Subscribe-All
  7. // @description Subscribe all guides in the page from Steam workshop in 1 click
  8. // @version 1.7
  9. // @include https://steamcommunity.com/id/*/myworkshopfiles/?section=guides*
  10. // @include https://steamcommunity.com/profiles/*/myworkshopfiles/?section=guides*
  11. // @grant none
  12. // @license MIT
  13. // ==/UserScript==
  14.  
  15. function dota2workshopsubnext(loaded = 0, subscribe = true) {
  16. if (
  17. jQuery(".pagebtn.disabled").length &&
  18. jQuery(".pagebtn.disabled:first").text() == ">"
  19. ) {
  20. if (subscribe) {
  21. ShowAlertDialog(
  22. "Success!",
  23. "You have subsribed to " + loaded + " guides!"
  24. ).done(function () {
  25. window.location = "?section=guides";
  26. });
  27. } else {
  28. ShowAlertDialog(
  29. "Success!",
  30. "You have unsubsribed to " + loaded + " guides!"
  31. ).done(function () {
  32. window.location = "?section=guides";
  33. });
  34. }
  35. } else {
  36. jQuery(".pagebtn").each(function () {
  37. if (jQuery(this).text() == ">" && jQuery(this).attr("href")) {
  38. var thislocation = jQuery(this)
  39. .attr("href")
  40. .replace(/&d2wg_all=(\d*)/, "");
  41. thislocation = thislocation.replace(/&d2wg_un=(\d*)/, "");
  42. if (subscribe) {
  43. window.location = thislocation + "&d2wg_all=" + loaded;
  44. } else {
  45. window.location = thislocation + "&d2wg_un=" + loaded;
  46. }
  47. }
  48. });
  49. }
  50. }
  51. function dota2workshopbackfirst(subscribe = true) {
  52. thislocation = window.location.href.replace(/&p=(\d*)/, "");
  53. if (subscribe) {
  54. window.location = thislocation + "&d2wg_all=" + 999999;
  55. } else {
  56. window.location = thislocation + "&d2wg_un=" + 999999;
  57. }
  58. }
  59. function dota2workshopsubnownuke() {
  60. //dota2workshopsubnow(999999);
  61. dota2workshopbackfirst();
  62. }
  63. function dota2workshopunsubnow() {
  64. dota2workshopsubnow(0, false);
  65. }
  66. function dota2workshopunsubnownuke() {
  67. //dota2workshopsubnow(999999,false);
  68. dota2workshopbackfirst(false);
  69. }
  70. function dota2workshopsubnow(d2wg_all = 0, subscribe = true) {
  71. var guideList = [];
  72. var subscribedList = [];
  73.  
  74. jQuery("script").each(function () {
  75. var guidematch = jQuery(this)
  76. .html()
  77. .match(/SharedFileBindMouseHover\( "(.*?)", true, (.*?) \);/);
  78. if (guidematch) {
  79. var guidedetail = JSON.parse(guidematch[2].replace(/(\r\n|\n|\r)/gm, ""));
  80. guideList.push(guidedetail.id);
  81. subscribedList[guidedetail.id] = guidedetail.user_subscribed;
  82. }
  83. });
  84.  
  85. var i = 0,
  86. loaded = 0,
  87. package = 0,
  88. total = guideList.length,
  89. modal = ShowBlockingWaitDialog(
  90. "Executing…",
  91. "Please wait until all requests finish. Ignore all the errors, let it finish."
  92. );
  93.  
  94. for (; i < total; i++) {
  95. guideid = guideList[i];
  96. //function below doesn't work because steam doesn't support it yet
  97. //if( subscribedList[ guideid ] )
  98. //{
  99. // loaded++;
  100. // continue;
  101. //}
  102.  
  103. if (subscribe) {
  104. var subscribeurl = "//steamcommunity.com/sharedfiles/subscribe";
  105. } else {
  106. var subscribeurl = "//steamcommunity.com/sharedfiles/unsubscribe";
  107. }
  108.  
  109. jQuery
  110. .post(subscribeurl, {
  111. appid: 570,
  112. id: guideid,
  113. sessionid: g_sessionID,
  114. })
  115. .always(function () {
  116. loaded++;
  117.  
  118. modal.Dismiss();
  119.  
  120. if (loaded >= total) {
  121. if (d2wg_all) {
  122. if (d2wg_all !== 999999) {
  123. loaded = d2wg_all + loaded;
  124. }
  125. if (subscribe) {
  126. dota2workshopsubnext(loaded);
  127. } else {
  128. dota2workshopsubnext(loaded, false);
  129. }
  130. } else {
  131. if (subscribe) {
  132. ShowAlertDialog(
  133. "Success!",
  134. "You have subsribed to " + loaded + " guides!"
  135. ).done(function () {
  136. location.reload();
  137. });
  138. } else {
  139. ShowAlertDialog(
  140. "Success!",
  141. "You have unsubsribed to " + loaded + " guides!"
  142. ).done(function () {
  143. location.reload();
  144. });
  145. }
  146. }
  147. } else {
  148. modal = ShowBlockingWaitDialog(
  149. "Executing…",
  150. "Loaded <b>" + loaded + "</b>/" + total + "."
  151. );
  152. }
  153. });
  154. }
  155. }
  156.  
  157. (function () {
  158. if (location.search.split("d2wg_all=")[1]) {
  159. dota2workshopsubnow(parseInt(location.search.split("d2wg_all=")[1]));
  160. } else if (location.search.split("d2wg_un=")[1]) {
  161. dota2workshopsubnow(parseInt(location.search.split("d2wg_un=")[1]), false);
  162. }
  163. jQuery(".followStatsBlock").append(
  164. '<a href="javascript:void(0);" id="dota2workshopsuball" class="btn_darkblue_white_innerfade btn_medium"><span>Subscribe all on this page</span></a>'
  165. );
  166. document
  167. .getElementById("dota2workshopsuball")
  168. .addEventListener("click", dota2workshopsubnow, false);
  169. jQuery(".followStatsBlock").append(
  170. '<br><br><a href="javascript:void(0);" id="dota2workshopsuballnuke" class="btn_darkblue_white_innerfade btn_medium"><span>Subscribe all from this person</span></a>'
  171. );
  172. document
  173. .getElementById("dota2workshopsuballnuke")
  174. .addEventListener("click", dota2workshopsubnownuke, false);
  175. jQuery(".followStatsBlock").append(
  176. '<br><br><a href="javascript:void(0);" id="dota2workshopunsuball" class="btn_darkblue_white_innerfade btn_medium"><span>Unsubscribe all on this page</span></a>'
  177. );
  178. document
  179. .getElementById("dota2workshopunsuball")
  180. .addEventListener("click", dota2workshopunsubnow, false);
  181. jQuery(".followStatsBlock").append(
  182. '<br><br><a href="javascript:void(0);" id="dota2workshopunsuballnuke" class="btn_darkblue_white_innerfade btn_medium"><span>Unsubscribe all from this person</span></a>'
  183. );
  184. document
  185. .getElementById("dota2workshopunsuballnuke")
  186. .addEventListener("click", dota2workshopunsubnownuke, false);
  187. })();