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-06-06 提交的版本,檢視 最新版本

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