Advertisement
Guest User

Untitled

a guest
May 25th, 2016
1,537
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.07 KB | None | 0 0
  1. // ==UserScript==
  2. // @author Sycam Inc (origionally Alvaro)
  3. // @name Enhanced Steam Workshop Downloader
  4. // @description Adds an extra button to download, supports collections and new workshop layout
  5. // @include *steamcommunity.com/sharedfiles/filedetails/?id=*
  6. // @include *steamcommunity.com/workshop/filedetails/?id=*
  7. // @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js
  8. // @grant GM_xmlhttpRequest
  9. // @version 2.1
  10. // @license MIT
  11. // @namespace https://greasyfork.org/users/6073
  12. // ==/UserScript==
  13.  
  14. var patt = new RegExp("[0-9]{2,15}");
  15. var id = patt.exec(document.URL);
  16. var baseURL = "http://api.steampowered.com/ISteamRemoteStorage/GetPublishedFileDetails/v0001/";
  17. var baseURLCtn = "http://api.steampowered.com/ISteamRemoteStorage/GetCollectionDetails/v0001/";
  18.  
  19. if (document.URL.indexOf("steamcommunity.com") != -1) {
  20. if (document.URL.indexOf("workshop") != -1) {
  21. addCollectionBtn(id);
  22. } else {
  23. addWorkshopBtn(id);
  24. }
  25. }
  26.  
  27.  
  28.  
  29. function prepareDownload(url, id) {
  30. GM_xmlhttpRequest({
  31. method: "POST",
  32. url: url,
  33. data: "itemcount=1&publishedfileids[0]=" + id + "&format=json",
  34. headers: {
  35. "Content-Type": "application/x-www-form-urlencoded"
  36. },
  37. onload: function (response) {
  38. //console.log(response.responseText);
  39. //debugger;
  40. data = jQuery.parseJSON(response.responseText);
  41. var fileurl = data.response.publishedfiledetails[0].file_url;
  42. $("#SubscribeItemOptionAdd2").click(function (e) {
  43. e.preventDefault(); //stop the browser from following
  44. window.location.href = fileurl;
  45. });
  46. },
  47. onerror: function (reponse) {
  48. //alert('error');
  49. console.log(reponse);
  50. }
  51. });
  52. }
  53.  
  54. function download(url, id) {
  55. GM_xmlhttpRequest({
  56. method: "POST",
  57. url: url,
  58. data: "itemcount=1&publishedfileids[0]=" + id + "&format=json",
  59. headers: {
  60. "Content-Type": "application/x-www-form-urlencoded"
  61. },
  62. onload: function (response) {
  63. //console.log(response.responseText);
  64. //debugger;
  65. data = jQuery.parseJSON(response.responseText);
  66. var fileurl = data.response.publishedfiledetails[0].file_url;
  67. console.log(fileurl);
  68. window.open(fileurl);
  69. },
  70. onerror: function (reponse) {
  71. //alert('error');
  72. console.log(reponse);
  73. }
  74. });
  75. }
  76.  
  77.  
  78. function addWorkshopBtn(id) {
  79. var element = document.getElementById("AddToCollectionBtn");
  80. var button = document.createElement('span');
  81. button.setAttribute('class', 'general_btn share tooltip');
  82. //button.setAttribute('href', baseURLCtn + id);
  83.  
  84. button.innerHTML = '<span id="SubscribeItemOptionAdd2"><span>Download</span></span>';
  85. // Append the element after the real subscribe button
  86. if (element.nextSibling) {
  87. element.parentNode.insertBefore(button, element.nextSibling);
  88. } else {
  89. element.parentNode.appendChild(button);
  90. }
  91. prepareDownload(baseURL, id);
  92. // Change the stupid text to the left of it
  93. document.querySelectorAll(".game_area_purchase_game")[0].getElementsByTagName('h1')[0].setAttribute('style', 'width: 300px;');
  94. }
  95.  
  96. function addCollectionBtn(id) {
  97. var element = document.getElementById("AddToCollectionBtn");
  98.  
  99. var button = document.createElement('span');
  100. button.setAttribute('class', 'general_btn share tooltip');
  101. //button.setAttribute('href', baseURLCtn + id);
  102.  
  103. button.innerHTML = '<span id="SubscribeItemOptionAdd2"><span>Download</span></span>';
  104.  
  105. // Append the element after the real subscribe button
  106. if (element.nextSibling) {
  107. element.parentNode.insertBefore(button, element.nextSibling);
  108. } else {
  109. element.parentNode.appendChild(button);
  110. }
  111. prepareDownloadCtn(baseURLCtn, id);
  112. // Change the stupid text to the left of it
  113. document.querySelectorAll(".game_area_purchase_game")[0].getElementsByTagName('h1')[0].setAttribute('style', 'width: 300px;');
  114. }
  115.  
  116. function prepareDownloadCtn(url, id) {
  117. GM_xmlhttpRequest({
  118. method: "POST",
  119. url: url,
  120. data: "collectioncount=1&publishedfileids[0]=" + id + "&format=json",
  121. headers: {
  122. "Content-Type": "application/x-www-form-urlencoded"
  123. },
  124. onload: function (response) {
  125. //console.log(response);
  126. data = jQuery.parseJSON(response.responseText);
  127. $("#SubscribeItemOptionAdd2").click(function (e) {
  128. e.preventDefault(); //stop the browser from following
  129. $.each(data.response.collectiondetails[0].children, function(index, element) {
  130. download(baseURL,element.publishedfileid);
  131. });
  132. });
  133. },
  134. onerror: function (reponse) {
  135. //alert('error');
  136. console.log(reponse);
  137. }
  138. });
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement