1337X - Upload page improved

Improves the upload page. Let's you set up default descriptions for categories and other defaults like title, tags etc. and more

目前为 2018-03-08 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name 1337X - Upload page improved
  3. // @namespace NotNeo
  4. // @author NotNeo
  5. // @description Improves the upload page. Let's you set up default descriptions for categories and other defaults like title, tags etc. and more
  6. // @include http*://1337x.to/upload
  7. // @include http*://1337x.st/upload
  8. // @include http*://1337x.ws/upload
  9. // @include http*://1337x.eu/upload
  10. // @require https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
  11. // @require https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js
  12. // @version 2.1.3
  13. // @grant GM_setValue
  14. // @grant GM_getValue
  15. // @grant GM.setValue
  16. // @grant GM.getValue
  17. // ==/UserScript==
  18.  
  19. //============================//
  20. //============================//
  21. // YOU SHOULD NO LONGER TOUCH //
  22. // ANYTHING INSIDE THE SCRIPT //
  23. // ALL SETTINGS ARE NOW //
  24. // AVAILABLE ON THE PAGE! //
  25. //============================//
  26. //============================//
  27.  
  28.  
  29. //setting defaults
  30. var dName = "";
  31. var dLanguage = "English";
  32. var dDesc = "";
  33. var dTags = "";
  34. var showOnlyUpload = true;
  35. var descHeight = "400";
  36. var reminder = true;
  37. var catDelay = 2;
  38.  
  39.  
  40.  
  41. (async function() { // Getting the runtime variables from local storage
  42. if( (await GM.getValue("reminder")) != null ) {
  43. reminder = await GM.getValue("reminder");
  44. }
  45. if( (await GM.getValue("dDesc")) != null ) {
  46. dDesc = await GM.getValue("dDesc");
  47. }
  48. if( (await GM.getValue("dName")) != null ) {
  49. dName = await GM.getValue("dName");
  50. }
  51. if( (await GM.getValue("dLanguage")) != null ) {
  52. dLanguage = await GM.getValue("dLanguage");
  53. }
  54. if( (await GM.getValue("dTags")) != null ) {
  55. dTags = await GM.getValue("dTags");
  56. }
  57. if( (await GM.getValue("showOnlyUpload")) != null ) {
  58. showOnlyUpload = await GM.getValue("showOnlyUpload");
  59. }
  60. if( (await GM.getValue("descHeight")) != null ) {
  61. descHeight = await GM.getValue("descHeight");
  62. }
  63. if( (await GM.getValue("catDelay")) != null ) {
  64. catDelay = await GM.getValue("catDelay");
  65. }
  66.  
  67. var savCatNamArr = [];
  68. var savCatDescArr = [];
  69.  
  70.  
  71. if( (await GM.getValue("savCatNamArrStr")) != null ) {
  72. var savCatNamArrStr = GM.getValue("savCatNamArrStr"); //get array from storage as string
  73. if(savCatNamArrStr) { savCatNamArr = JSON.parse(savCatNamArrStr); } //parse the string to an array
  74. }
  75. if( (await GM.getValue("savCatDescArrStr")) != null ) {
  76. var savCatDescArrStr = GM.getValue("savCatDescArrStr"); //get array from storage as string
  77. if(savCatDescArrStr) { savCatDescArr = JSON.parse(savCatDescArrStr); } //parse the string to an array
  78. }
  79. mainScript();
  80. })();
  81.  
  82.  
  83. function checkForAndLoadSavedCatDesc() {
  84. var currentCat = $("#category").parent().find(".trigger").text();
  85. var currentSubCat = $("#type").parent().find(".trigger").text();
  86. //alert(currentCat + ": " + currentSubCat);
  87.  
  88. for (i = 0; i < savCatNamArr.length; i++) {
  89. if(savCatNamArr[i][0] == currentCat) { //if saved description for current main cat is found...
  90. for (j = 1; j < savCatNamArr[i].length; j++) {
  91. if(savCatNamArr[i][j] == currentSubCat) { //if saved description for current main SubCat is found...
  92. //alert(savCatDescArr[i][j-1]);
  93. $(".sceditor-toolbar").next("iframe").next("textarea").val(savCatDescArr[i][j-1]);
  94. }
  95. }
  96. }
  97. }
  98. }
  99.  
  100. function alertDesc(cat, subCat) {
  101. for(i = 0; i < savCatNamArr.length; i++) {
  102. if(savCatNamArr[i][0] == cat) {
  103. for(j = 1; j < savCatNamArr[i].length; j++) {
  104. if(savCatNamArr[i][j] == subCat) {
  105. alert("Description:\n\n" + savCatDescArr[i][j-1] + "\n\nAdded for " + savCatNamArr[i][0] + ": " + savCatNamArr[i][j]);
  106. }
  107. }
  108. }
  109. }
  110. }
  111.  
  112. function saveArrays() {
  113. savCatNamArrStr = JSON.stringify(savCatNamArr); //turn array into a single string
  114. GM.setValue("savCatNamArrStr", savCatNamArrStr); //save that string to local storage
  115. savCatDescArrStr = JSON.stringify(savCatDescArr); //turn array into a single string
  116. GM.setValue("savCatDescArrStr", savCatDescArrStr); //save that string to local storage
  117. alert(savCatNamArrStr + "\n\n" + savCatDescArrStr);
  118. }
  119.  
  120. function addToArrays(cat, subCat, desc) {
  121. for(i = 0; i < savCatNamArr.length; i++) {
  122. if(savCatNamArr[i][0] == cat) {
  123. for(j = 1; j < savCatNamArr[i].length; j++) {
  124. if(savCatNamArr[i][j] == subCat) { //if already exists, replace
  125. savCatDescArr[i][j] = desc;
  126. saveArrays();
  127. return;
  128. }
  129. }
  130. //main cat exist, but subCat doesn't
  131. savCatNamArr[i].push(subCat);
  132. savCatDescArr[i].push(desc);
  133. saveArrays();
  134. return;
  135. }
  136. }
  137. //sub nor main cat exists
  138. var newCats = [ cat, subCat ];
  139. savCatNamArr.push(newCats);
  140. var newDescForNewCats = [ desc ];
  141. savCatDescArr.push(newDescForNewCats);
  142. saveArrays();
  143. return;
  144.  
  145. /* Remember!!!
  146. descriptions are stored in an index one lower than their descName counterparts!
  147. i.e.
  148. if Other -> Ebooks is in savCatNamArr[3][2], then it's description is in savCatDescArr[3][1]
  149. because the first item in each sub-array within the savCatNamArr is the name of the main category.
  150. i.e.
  151. if Other -> Ebooks is in savCatNamArr[3][2] then savCatNamArr[3][0] is "Other", while savCatDescArr[3][0] would be the description for savCatNamArr[3][1]
  152. */
  153. }
  154.  
  155. function mainScript() {
  156. $(".box-info-heading.bordered").append(' <div style="float: right;"><label for="showUpCheckB">Show only upload</label><input type="checkbox" id="showUpCheckB"></div> '); //showOnlyUpload setting UI
  157. $("#category").parent().before(' <a href="#" id="reminderOp" style="float: right; font-size: 10px; margin-top: 10px;">Reminder?</a> '); //reminder option UI
  158. $("#type").parent().before(' <a href="#" id="delayOp" style="float: right; font-size: 10px; margin-top: 10px;">Delay?</a> '); //delay option UI
  159.  
  160. $("#delayOp").click(function(e) {
  161. e.preventDefault();
  162. var catDelayTemp = prompt("When you change the main category, there is a delay before the subcategory loads.\nFor some reason this delay can be suprisingly long.\n" +
  163. "The script will check if the current main + sub category has a saved description. Here you can set the delay before that check.\n" +
  164. "i.e. if the subcategory delay is around 2 seconds, then set this to 2.5 for example.\nThis is not a problem when changing the subcategory. The delay is only used when you change the main category." +
  165. "\nCurrent delay is " + catDelay);
  166. if(catDelayTemp != null && catDelayTemp != "" && !(isNaN(catDelayTemp))) {
  167. catDelay = catDelayTemp;
  168. GM.setValue("catDelay", catDelay);
  169. }
  170. });
  171.  
  172. if (reminder) {
  173. $("#category").parent().before("<span id='theReminder' style='color:red; font-size: 15px; margin-left: 5px;'>Choose before editing the description!</span>"); //setting reminder, if true
  174. }
  175.  
  176. $("#reminderOp").click(function(e) { //reminder option changer
  177. e.preventDefault();
  178. var reminderTemp = confirm("Remind me to choose the category before editing the description?\n(Red text next to category)\nWhy? \nBecause changing the category causes the description to change to the saved description for the category you choose.\nMeaning you'll lose any changes you made to the description prior.\n\nPress \"OK\" to show it, \"Cancel\" to not.");
  179. if(!reminderTemp) {
  180. reminder = false;
  181. $("#theReminder").remove();
  182. } else {
  183. reminder = true;
  184. $("#theReminder").remove();
  185. $("#category").parent().before("<span id='theReminder' style='color:red; font-size: 15px; margin-left: 5px;'>Choose before editing the description!</span>");
  186. }
  187. GM.setValue("reminder", reminder);
  188. });
  189.  
  190. if (showOnlyUpload) { //hiding stuff if showOnlyUpload is true
  191. $("h1:contains(' Want to upload a torrent? No problem! Please use the announce URLs: ')").parent().parent().hide();
  192. $("h1:contains('New upload categories')").parent().parent().hide();
  193. $(".upload-info").parent().hide();
  194. $("#showUpCheckB").attr("checked", true);
  195. }
  196.  
  197. $("#showUpCheckB").change(function() { //showOnlyUpload option changer
  198. $("h1:contains(' Want to upload a torrent? No problem! Please use the announce URLs: ')").parent().parent().toggle();
  199. $("h1:contains('New upload categories')").parent().parent().toggle();
  200. $(".upload-info").parent().toggle();
  201. $("#showUpCheckB").attr("checked", !($("#showUpCheckB").attr("checked")));
  202. showOnlyUpload = !showOnlyUpload;
  203. GM.setValue("showOnlyUpload", showOnlyUpload);
  204. });
  205.  
  206. $(document).ready(function() {
  207. $("[name='title']").val(dName); //set default title
  208. $("[name='tags']").val(dTags); //set default tags
  209.  
  210. //description saver UI
  211. $("[name='upload']").parent().append('<input id="savDescDef" style="float: right; margin: 0px 5px;" value="Save Desc (Default)" title="Saves the current description as the global default. (Loaded with the page. Overriden by category specific descriptions.)" class="btn btn-green" type="submit">');
  212. $("[name='upload']").parent().append('<input id="savDescCat" style="float: right;" value="Save Desc (for category)" title="Saves the current description as the default for the currently selected category." class="btn btn-green" type="submit">');
  213.  
  214. //default title, language and tags UI
  215. $("[name='title']").before(' <a href="#" id="savDefTit" style="float: right; margin-top: 10px; font-size: 10px;">Save as default Title</a> ');
  216. $("#language").parent().before(' <a href="#" id="savDefLan" style="float: right; margin-top: 10px; font-size: 10px;">Save as default Language</a> ');
  217. $("[name='tags']").before(' <a href="#" id="savDefTags" style="float: right; margin-top: 10px; font-size: 10px;">Save as default Tags</a> ');
  218.  
  219. $("#savDefTit").click(function(e){
  220. e.preventDefault();
  221. dName = $("[name='title']").val();
  222. GM.setValue("dName", dName);
  223. alert("New default Title saved:\n\n" + dName);
  224. });
  225. $("#savDefLan").click(function(e){
  226. e.preventDefault();
  227. dLanguage = $("#language").parent().find(".trigger").text();
  228. GM.setValue("dLanguage", dLanguage);
  229. alert("New default Language saved:\n\n" + dLanguage);
  230. });
  231. $("#savDefTags").click(function(e){
  232. e.preventDefault();
  233. dTags = $("[name='tags']").val();
  234. GM.setValue("dTags", dTags);
  235. alert("New default Tags saved:\n\n" + dTags);
  236. });
  237.  
  238. setTimeout(function(){ //everything below is done with a delay of 1s, to allow the description iframe to load
  239.  
  240. //$(".sceditor-toolbar").next("iframe").hide();
  241. $(".sceditor-toolbar").next("iframe").next("textarea").attr("style", "width: 100%; height: " + descHeight + "px;"); //setting custom height for text box
  242. $(".sceditor-toolbar").next("iframe").next("textarea").val(dDesc); //setting default description
  243.  
  244. $("[name='description']").before(' <a href="#" id="setDescH" style="float: right; margin-top: 5px; font-size: 10px;">Set description box height</a> ');
  245.  
  246. $("#setDescH").click(function(e) {
  247. e.preventDefault();
  248. var descHeightTemp = prompt("Give a new height for the description box. (in pixels)\nThe current height is: "+descHeight);
  249. if(descHeightTemp != null && descHeightTemp != "") {
  250. descHeight = descHeightTemp;
  251. GM.setValue("descHeight", descHeight);
  252. $(".sceditor-toolbar").next("iframe").next("textarea").attr("style", "width: 100%; height: " + descHeight + "px;");
  253. }
  254. });
  255.  
  256. //setting default Language ---------------------------------------------------
  257. $("#language").parent().find(".options").find("li").each(function() {
  258. $(this).removeAttr("class");
  259. });
  260. $("#language").parent().find(".trigger").text(dLanguage);
  261. $("#language").parent().find(".options").find("li:contains('" + dLanguage + "')").attr("class", "selected");
  262. //----------------------------------------------------------------------------
  263.  
  264. $("#savDescDef").click(function(e) {
  265. e.preventDefault();
  266. //dDesc = $(".sceditor-toolbar").next("iframe").contents().find("body").html();
  267. dDesc = $(".sceditor-toolbar").next("iframe").next("textarea").val();
  268. GM.setValue("dDesc", dDesc);
  269. alert("Description:\n\n"+dDesc+"\n\nSaved as the global default description.");
  270. });
  271. $("#savDescCat").click(function(e) {
  272. e.preventDefault();
  273. var currCat = $("#category").parent().find(".trigger").text();
  274. var currSubCat = $("#type").parent().find(".trigger").text();
  275. var currDesc = $(".sceditor-toolbar").next("iframe").next("textarea").val();
  276. //alert(currCat + ", " + currSubCat + ", \n" + currDesc);
  277. addToArrays(currCat, currSubCat, currDesc);
  278. //alertDesc(currCat, currSubCat);
  279. });
  280. $(".scroll-top").click(function() {
  281. //alert("click");
  282.  
  283. });
  284.  
  285. $("#category").parent().find(".options").click(function() {
  286. setTimeout(checkForAndLoadSavedCatDesc, catDelay*1000); // loading the subcategory after changing main categories takes a while so have to use a delay here.
  287. });
  288.  
  289. $("#type").parent().find(".options").click(checkForAndLoadSavedCatDesc);
  290.  
  291. }, 1000);
  292. });
  293. }
  294. //var isFirefox = typeof InstallTrigger !== 'undefined';
  295.