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-01-14 提交的版本,查看 最新版本

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