gazellegames GGn New Uploady

Steam Uploady Fork for GGn | Greasemonkey 4.1: ✕ Tampermonkey 4.4: ✔

当前为 2018-06-16 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name gazellegames GGn New Uploady
  3. // @namespace https://gazellegames.net/
  4. // @version 6.3
  5. // @description Steam Uploady Fork for GGn | Greasemonkey 4.1: ✕ Tampermonkey 4.4: ✔
  6. // @author NeutronNoir
  7. // @match https://gazellegames.net/upload.php*
  8. // @require https://code.jquery.com/jquery-3.1.1.min.js
  9. // @grant GM_xmlhttpRequest
  10. // ==/UserScript==
  11.  
  12.  
  13. var askScreens = false;
  14.  
  15. function html2bb(str) {
  16. if(typeof str === "undefined") return "";
  17.  
  18. str = str.replace(/\r/g, "");
  19. str = str.replace(/\n/g, "");
  20. str = str.replace(/< *br *\/*>/g, "\n");
  21. str = str.replace(/< *u *>/g, "[u]");
  22. str = str.replace(/< *h1*>/g, "[align=center][u]");
  23. str = str.replace(/< *\/h1*>/g, "[/u]\n\n[/align]");
  24. str = str.replace(/< *\/p*>/g, "");
  25. str = str.replace(/< *p*>/g, "");
  26. str = str.replace(/< *\/ *u *>/g, "[/u]");
  27. str = str.replace(/< *\/ *li *>/g, "");
  28. str = str.replace(/< *li *>/g, "[*]");
  29. str = str.replace(/< *\/ *ul *>/g, "");
  30. str = str.replace(/< *ul *class=\\*\"bb_ul\\*\" *>/g, "");
  31. str = str.replace(/< *h2 *class=\"bb_tag\" *>/g, "\n\n[u]");
  32. str = str.replace(/< *\/ *h2 *>/g, "[/u]\n\n");
  33. str = str.replace(/< *strong *>/g, "[b]");
  34. str = str.replace(/< *\/ *strong *>/g, "[/b]");
  35. str = str.replace(/< *i *>/g, "[i]");
  36. str = str.replace(/< *\/ *i *>/g, "[/i]");
  37. str = str.replace(/\&quot;/g, "\"");
  38. str = str.replace(/< *img *src="([^"]*)" *>/g, "");
  39. str = str.replace(/< *b *>/g, "[b]");
  40. str = str.replace(/< *\/ *b *>/g, "[/b]");
  41. str = str.replace(/< *a [^>]*>/g, "");
  42. str = str.replace(/< *\/ *a *>/g, "");
  43. str = str.replace(/\n\n\n/g, "\n\n");
  44. //Yeah, all these damn stars. Because people put spaces where they shouldn't.
  45. return str;
  46. }
  47.  
  48. function clickAllPtp(){
  49. var list = document.querySelectorAll("input");
  50. for (var i = 0; i < list.length; i++) { if(list[i].value=='PTPImg It'){list[i].click()}}
  51. }
  52.  
  53. (function() {
  54. 'use strict';
  55. if (window.location.href.search("action=editgroup") != -1) {
  56. $("td.center").parent().after("<tr><td class='label'>Steam ID</td><td><input id='steamid' /></td></tr>");
  57. document.getElementById("steamid").addEventListener("blur", function() { //After the "appid" input loses focus
  58. var request = new GM_xmlhttpRequest({method: "GET", //We call the Steam API to get info on the game
  59. url: "http://store.steampowered.com/api/appdetails?l=en&appids=" + document.getElementById("steamid").value,
  60. responseType: "json",
  61. onload: function(response) {
  62.  
  63. var gameInfo = response.response[document.getElementById("steamid").value].data; //We store the data in gameInfo, since it's much easier to access this way
  64. var addScreens = true;
  65. if (askScreens === true) addScreens = confirm("Fill the screenshot boxes ?");
  66.  
  67. if (addScreens === true) {
  68. $("input[name='image']").val(gameInfo.header_image.split("?")[0]); //Get the image URL
  69. var screens = document.getElementsByName("screens[]"); //Get each element corresponding to a screenshot
  70. var add_screen = $("#image_block a[href='#']").first(); //This is a shortcut to add a screenshot field.
  71. //If I didn't do this, people with access to "whatimg it" wouldn't have it, or inversely people without access would have it (which causes some bugs)
  72. gameInfo.screenshots.forEach( function(screen, index) { //We iterate on Steam screenshots from the API
  73. if (index >= 16) return; //The site doesn't accept more than 16 screenshots
  74. if (index >= 3) add_screen.click(); //There's 3 screenshot boxes by default. If we need to add more, we do as if the user clicked on the "[+]" (for reasons mentioned above)
  75. screens[index].value = screen.path_full.split("?")[0]; //Finally store the screenshot link in the right screen field.
  76. });
  77. }
  78. }
  79. });
  80. });
  81. }
  82. else {
  83. document.getElementById("steamid").addEventListener("blur", function() { //After the "appid" input loses focus
  84. var request = new GM_xmlhttpRequest({method: "GET", //We call the Steam API to get info on the game
  85. url: "http://store.steampowered.com/api/appdetails?l=en&appids=" + document.getElementById("steamid").value,
  86. responseType: "json",
  87. onload: function(response) {
  88.  
  89. var gameInfo = response.response[document.getElementById("steamid").value].data; //We store the data in gameInfo, since it's much easier to access this way
  90. document.getElementById("title").value = gameInfo.name; //Get the name of the game
  91. document.getElementById("album_desc").value = "[align=center][b][u]About the game[/u][/b][/align]\n" + html2bb(gameInfo.about_the_game); //Get the description, formatted appropriately
  92. document.getElementById("year").value = gameInfo.release_date.date.split(", ").pop(); //Get the year, which is actually the last number of "release_date.date"
  93.  
  94. //Genres are in an object array. Need to make them lowercase, replace spaces with dots and separate them with ", "
  95. var genres = [];
  96. gameInfo.genres.forEach(function (genre) {
  97. var tag = genre.description.toLowerCase().replace(/ /g, "."); //Each genre is formatted as mentioned above and added to the "genres" array
  98. switch (tag) {
  99. case "rpg":
  100. genres.push("role.playing.game");
  101. break;
  102. case "early.access":
  103. break;
  104. case "sexual.content":
  105. genres.push("adult");
  106. break;
  107. default:
  108. genres.push(tag);
  109. break;
  110. }
  111.  
  112. });
  113. document.getElementById("tags").value = genres.join(", "); //Every string in the "genres" array is then concatenated with ", " between them
  114.  
  115. var addScreens = true;
  116. if (askScreens === true) addScreens = confirm("Fill the screenshot boxes ?");
  117.  
  118. if (addScreens === true) {
  119. document.getElementById("image").value = gameInfo.header_image.split("?")[0]; //Get the image URL
  120. var screens = document.getElementsByName("screens[]"); //Get each element corresponding to a screenshot
  121. var add_screen = $("#image_block a[href='#']").first(); //This is a shortcut to add a screenshot field.
  122. //If I didn't do this, people with access to "whatimg it" wouldn't have it, or inversely people without access would have it (which causes some bugs)
  123. gameInfo.screenshots.forEach( function(screen, index) { //We iterate on Steam screenshots from the API
  124. if (index >= 16) return; //The site doesn't accept more than 16 screenshots
  125. if (index >= 3) add_screen.click(); //There's 3 screenshot boxes by default. If we need to add more, we do as if the user clicked on the "[+]" (for reasons mentioned above)
  126. screens[index].value = screen.path_full.split("?")[0]; //Finally store the screenshot link in the right screen field.
  127. });
  128. }
  129.  
  130.  
  131. //Now let's get the requirements
  132. document.getElementById("album_desc").value += "\n\n[quote][align=center][b][u]System Requirements[/u][/b][/align]"; //The requirements need to be in the description of the torrent.
  133. switch (document.getElementById("platform").value) {
  134. case "Windows":
  135. document.getElementById("album_desc").value += html2bb(gameInfo.pc_requirements.minimum) + "\n\n" + html2bb(gameInfo.pc_requirements.recommended); //We add the requirements, both minimal and recommended, formatted appropriately.
  136. break;
  137. case "Linux":
  138. document.getElementById("album_desc").value += html2bb(gameInfo.linux_requirements.minimum) + "\n\n" + html2bb(gameInfo.linux_requirements.recommended);
  139. break;
  140. case "Mac":
  141. document.getElementById("album_desc").value += html2bb(gameInfo.mac_requirements.minimum) + "\n\n" + html2bb(gameInfo.mac_requirements.recommended);
  142. break;
  143. }
  144. document.getElementById("album_desc").value += "[/quote]";
  145. }
  146. });
  147. });
  148. }
  149. })();