KAT [katcr.co] - Default values for Uploads

Lets you set up defaults in the upload section of KAT (custom default description for every category)

  1. // ==UserScript==
  2. // @name KAT [katcr.co] - Default values for Uploads
  3. // @namespace NotNeo
  4. // @description Lets you set up defaults in the upload section of KAT (custom default description for every category)
  5. // @include http*://katcr.co/upload-form/user/*
  6. // @include http*://katcr.co/edit-form/user/*/torrent/*
  7. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
  8. // @require https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js
  9. // @version 1.4
  10. // @grant GM_setValue
  11. // @grant GM_getValue
  12. // @grant GM.setValue
  13. // @grant GM.getValue
  14. // ==/UserScript==
  15.  
  16. //=========================================================//
  17. //=========================================================//
  18. // YOU SHOULD NO LONGER TOUCH ANYTHING INSIDE THE SCRIPT //
  19. // EVERYTHING CAN NOW BE DONE FROM THE PAGE //
  20. //=========================================================//
  21. //=========================================================//
  22.  
  23.  
  24. //setting defaults
  25. var dName = "";
  26. var dMainCat = "Category";
  27. var dSubCat = 0;
  28. var dTitle = "";
  29. var dDesc = "";
  30. var dLang = 1;
  31. var dCod = false;
  32. var dTrailer = "";
  33. var dRes = false;
  34. var dForm = false;
  35.  
  36. var pageWidth = 75;
  37. var descHeight = 13;
  38.  
  39. var catDescs = [];
  40. var catDescString = "";
  41.  
  42. var cusDescs = [];
  43. var cusDescString = "";
  44.  
  45. var IMDBs = [];
  46. var IMDBsString = "";
  47.  
  48. (async function() { // Getting the runtime variables from local storage
  49. if( (await GM.getValue("pageWidth")) != null ) {
  50. pageWidth = await GM.getValue("pageWidth");
  51. }
  52. if( (await GM.getValue("descHeight")) != null ) {
  53. descHeight = await GM.getValue("descHeight");
  54. }
  55. if( (await GM.getValue("dName")) != null ) {
  56. dName = await GM.getValue("dName");
  57. }
  58. if( (await GM.getValue("dMainCat")) != null ) {
  59. dMainCat = await GM.getValue("dMainCat");
  60. }
  61. if( (await GM.getValue("dSubCat")) != null ) {
  62. dSubCat = await GM.getValue("dSubCat");
  63. }
  64. if( (await GM.getValue("dTitle")) != null ) {
  65. dTitle = await GM.getValue("dTitle");
  66. }
  67. if( (await GM.getValue("dDesc")) != null ) {
  68. dDesc = await GM.getValue("dDesc");
  69. }
  70. if( (await GM.getValue("dLang")) != null ) {
  71. dLang = await GM.getValue("dLang");
  72. }
  73. if( (await GM.getValue("dTrailer")) != null ) {
  74. dTrailer = await GM.getValue("dTrailer");
  75. }
  76. if( (await GM.getValue("dCod")) != null ) {
  77. dCod = await GM.getValue("dCod");
  78. }
  79. if( (await GM.getValue("dRes")) != null ) {
  80. dRes = await GM.getValue("dRes");
  81. }
  82. if( (await GM.getValue("dForm")) != null ) {
  83. dForm = await GM.getValue("dForm");
  84. }
  85. if( (await GM.getValue("catDescString")) != null ) {
  86. catDescString = await GM.getValue("catDescString");
  87. if(catDescString) {
  88. catDescs = JSON.parse(catDescString);
  89. }
  90. }
  91. if( (await GM.getValue("cusDescString")) != null ) {
  92. cusDescString = await GM.getValue("cusDescString");
  93. if(cusDescString) {
  94. cusDescs = JSON.parse(cusDescString);
  95. }
  96. }
  97. if( (await GM.getValue("IMDBsString")) != null ) {
  98. IMDBsString = await GM.getValue("IMDBsString");
  99. if(IMDBsString) {
  100. IMDBs = JSON.parse(IMDBsString);
  101. }
  102. }
  103.  
  104. $("head").append(`
  105. <style>
  106. .dv-butt {
  107. margin: 1px;
  108. }
  109.  
  110. .dvfu-cont {
  111. width: `+pageWidth+`%;
  112. }
  113.  
  114. #pageWidthSet, #setDescHeight {
  115. float: right;
  116. }
  117. #dvfu-imdb-drop {
  118. float: right;
  119. }
  120. </style>
  121. `);
  122. mainScript();
  123. })();
  124.  
  125. function mainScript() {
  126. $(function(){//wait for page load
  127. if(window.location.href.indexOf("upload-form") > -1) { //upload page
  128. $("#torrent_info__categories > option[value=Category]").removeAttr("selected");
  129. $("#torrent_info__categories > option[value="+dMainCat+"]").prop("selected", "selected");
  130.  
  131. $("#torrent_info__categories").after('<button id="saveCat" class="dv-butt" style="float: right;">Save</button>');
  132. $("#saveCat").click(function(e){
  133. e.preventDefault();
  134. dMainCat = $("#torrent_info__categories").val();
  135. GM.setValue("dMainCat", dMainCat);
  136. $("#saveCat").html('<span style="color: green;">Saved!</span>');
  137. setTimeout(function(){
  138. $("#saveCat").html('Save');
  139. },1200);
  140. });
  141. }
  142. else { //edit page (upload page 2)
  143. //set page width and add button to change it
  144. $(".mx-auto").prop("class", "mx-auto dvfu-cont").prepend('<button id="pageWidthSet">Set Page Width</button>');
  145. $("#pageWidthSet").click(function(e){
  146. e.preventDefault();
  147. var pageWidthTemp = parseInt(prompt("Give the page width (in percent):"), 10);
  148. if(pageWidthTemp && pageWidthTemp >= 10 && pageWidthTemp <= 100) {
  149. pageWidth = pageWidthTemp;
  150. GM.setValue("pageWidth", pageWidth);
  151. $(".dvfu-cont").prop("style", "width: "+pageWidth+"%;");
  152.  
  153. $("#pageWidthSet").html('<span style="color: green;">Saved!</span>');
  154. setTimeout(function(){
  155. $("#pageWidthSet").html('Set Page Width');
  156. },1200);
  157. }
  158. });
  159.  
  160. //set desc box height
  161. $("#torrent_description").prop("rows", descHeight);
  162.  
  163. //load defaults
  164. $("#torrent_info__subcategories > option[value=Sub-Category]").removeAttr("selected");
  165. $("#torrent_info__subcategories > option[value="+dSubCat+"]").prop("selected", "selected");
  166. $("#torrent_info__title").val(dTitle);
  167. $("#torrent_info__trailer").val(dTrailer);
  168. $("#torrent_info__language > option[value='']").removeAttr("selected");
  169. $("#torrent_info__language > option[value="+dLang+"]").prop("selected", "selected");
  170. if(dCod) { $("#torrent_info__video_codec > option[value="+dCod+"]").prop("selected", "selected"); }
  171. if(dRes) { $("#torrent_info__resolution > option[value="+dRes+"]").prop("selected", "selected"); }
  172. if(dForm) { $("#torrent_info__format > option[value="+dForm+"]").prop("selected", "selected"); }
  173.  
  174. //load desc for current cat if found
  175. LoadDescForCat();
  176.  
  177. //save subcat
  178. $("#torrent_info__subcategories").after('<button id="saveSubCat" class="dv-butt" style="float: right;">Save</button>');
  179. $("#saveSubCat").click(function(e){
  180. e.preventDefault();
  181. dSubCat = $("#torrent_info__subcategories").val();
  182. GM.setValue("dSubCat", dSubCat);
  183. $("#saveSubCat").html('<span style="color: green;">Saved!</span>');
  184. setTimeout(function(){
  185. $("#saveSubCat").html('Save');
  186. },1200);
  187. });
  188.  
  189. //save language
  190. $("#torrent_info__subcategories").after('<button id="saveSubCat" class="dv-butt" style="float: right;">Save</button>');
  191. $("#saveSubCat").click(function(e){
  192. e.preventDefault();
  193. dSubCat = $("#torrent_info__subcategories").val();
  194. GM.setValue("dSubCat", dSubCat);
  195. $("#saveSubCat").html('<span style="color: green;">Saved!</span>');
  196. setTimeout(function(){
  197. $("#saveSubCat").html('Save');
  198. },1200);
  199. });
  200.  
  201. //save codec
  202. $("#torrent_info__video_codec").after('<button id="saveCodec" class="dv-butt" style="float: right;">Save</button>');
  203. $("#saveCodec").click(function(e){
  204. e.preventDefault();
  205. dCod = $("#torrent_info__video_codec").val();
  206. GM.setValue("dCod", dCod);
  207. $("#saveCodec").html('<span style="color: green;">Saved!</span>');
  208. setTimeout(function(){
  209. $("#saveCodec").html('Save');
  210. },1200);
  211. });
  212.  
  213. //save resolution
  214. $("#torrent_info__resolution").after('<button id="saveRes" class="dv-butt" style="float: right;">Save</button>');
  215. $("#saveRes").click(function(e){
  216. e.preventDefault();
  217. dRes = $("#torrent_info__resolution").val();
  218. GM.setValue("dRes", dRes);
  219. $("#saveRes").html('<span style="color: green;">Saved!</span>');
  220. setTimeout(function(){
  221. $("#saveRes").html('Save');
  222. },1200);
  223. });
  224.  
  225. //save format
  226. $("#torrent_info__format").after('<button id="saveForm" class="dv-butt" style="float: right;">Save</button>');
  227. $("#saveForm").click(function(e){
  228. e.preventDefault();
  229. dForm = $("#torrent_info__format").val();
  230. GM.setValue("dForm", dForm);
  231. $("#saveForm").html('<span style="color: green;">Saved!</span>');
  232. setTimeout(function(){
  233. $("#saveForm").html('Save');
  234. },1200);
  235. });
  236.  
  237. //save title
  238. $("#torrent_info__language").after('<button id="saveLang" class="dv-butt" style="float: right;">Save</button>');
  239. $("#saveLang").click(function(e){
  240. e.preventDefault();
  241. dLang = $("#torrent_info__language").val();
  242. GM.setValue("dLang", dLang);
  243. $("#saveLang").html('<span style="color: green;">Saved!</span>');
  244. setTimeout(function(){
  245. $("#saveLang").html('Save');
  246. },1200);
  247. });
  248.  
  249. //save trailer
  250. $("#torrent_info__trailer").after('<button id="saveTrailer" class="dv-butt" style="float: right;">Save</button>');
  251. $("#saveTrailer").click(function(e){
  252. e.preventDefault();
  253. dTrailer = $("#torrent_info__trailer").val();
  254. GM.setValue("dTrailer", dTrailer);
  255. $("#saveTrailer").html('<span style="color: green;">Saved!</span>');
  256. setTimeout(function(){
  257. $("#saveTrailer").html('Save');
  258. },1200);
  259. });
  260.  
  261. //save default desc
  262. $("#torrent_description").after('<button id="saveDesc" class="dv-butt" style="float: right;">Save</button>');
  263. $("#saveDesc").click(function(e){
  264. e.preventDefault();
  265. dDesc = $("#torrent_description").val();
  266. GM.setValue("dDesc", dDesc);
  267. $("#saveDesc").html('<span style="color: green;">Saved!</span>');
  268. setTimeout(function(){
  269. $("#saveDesc").html('Save');
  270. },1200);
  271. });
  272.  
  273. //Cat specific desc save
  274. $("#torrent_description").after('<button id="saveDescForCat" class="dv-butt" style="float: right;">Save for category</button>');
  275. $("#saveDescForCat").click(function(e){
  276. e.preventDefault();
  277. var currentCat = $("#torrent_info__subcategories").val();
  278. var currentDesc = $("#torrent_description").val();
  279. var found = false;
  280. for(var i = 0, len = catDescs.length; i < len; i++) {
  281. if(catDescs[i][0] == currentCat) {
  282. catDescs[i][1] = currentDesc;
  283. found = true;
  284. }
  285. }
  286. if(!found) {
  287. var catDescTemp = [currentCat, currentDesc];
  288. catDescs.push(catDescTemp);
  289. }
  290.  
  291. catDescString = JSON.stringify(catDescs); //turn array into a single string
  292. GM.setValue("catDescString", catDescString); //save that string to local storage
  293.  
  294. $("#saveDescForCat").html('<span style="color: green;">Saved!</span>');
  295. setTimeout(function(){
  296. $("#saveDescForCat").html('Save for category');
  297. },1200);
  298. });
  299.  
  300. //imdb save
  301. $("#torrent_info__ttimdb").after('<button id="saveIMDB" class="dv-butt" style="float: right;">Save</button>');
  302. $("#saveIMDB").click(function(e){
  303. e.preventDefault();
  304. var currentIMDB = $("#torrent_info__ttimdb").val();
  305. var IMDBname = prompt("Give a name for this IMDB code:");
  306. if(IMDBname){
  307. var found = false;
  308. for(var i = 0, len = IMDBs.length; i < len; i++) {
  309. if(IMDBs[i][0] == IMDBname) {
  310. IMDBs[i][1] = currentIMDB;
  311. found = true;
  312. }
  313. else if(IMDBs[i][1] == currentIMDB) {
  314. IMDBs[i][0] = IMDBname;
  315. found = true;
  316. }
  317. }
  318. if(!found) {
  319. IMDBs.push([IMDBname, currentIMDB]);
  320. }
  321.  
  322. IMDBsString = JSON.stringify(IMDBs); //turn array into a single string
  323. GM.setValue("IMDBsString", IMDBsString); //save that string to local storage
  324.  
  325. $("#saveIMDB").html('<span style="color: green;">Saved!</span>');
  326. setTimeout(function(){
  327. $("#saveIMDB").html('Save');
  328. },1200);
  329. }
  330. });
  331.  
  332. //load imdbs
  333. var SelectOptionsIMDB = "";
  334. for(let i = 0, len = IMDBs.length; i < len; i++) {
  335. SelectOptionsIMDB += "<option value='"+i+"'>"+IMDBs[i][0]+"</option>\n";
  336. }
  337.  
  338. //show imdbs
  339. $("#torrent_info__ttimdb").before(`
  340. <select id="dvfu-imdb-drop">
  341. <option selected disabled>Saved IMDB codes...</option>
  342. `+SelectOptionsIMDB+`
  343. </select>
  344. `);
  345.  
  346. //custom desc save
  347. $("#torrent_description").after('<button id="saveDescForCus" class="dv-butt" style="float: right;">Save as Custom</button>');
  348. $("#saveDescForCus").click(function(e){
  349. e.preventDefault();
  350. var currentDesc = $("#torrent_description").val();
  351. var cusname = prompt("Give a name for this custom Description:");
  352. if(cusname){
  353. var found = false;
  354. for(var i = 0, len = cusDescs.length; i < len; i++) {
  355. if(cusDescs[i][0] == cusname) {
  356. catDescs[i][1] = currentDesc;
  357. found = true;
  358. }
  359. }
  360. if(!found) {
  361. cusDescs.push([cusname, currentDesc]);
  362. }
  363.  
  364. cusDescString = JSON.stringify(cusDescs); //turn array into a single string
  365. GM.setValue("cusDescString", cusDescString); //save that string to local storage
  366.  
  367. $("#saveDescForCus").html('<span style="color: green;">Saved!</span>');
  368. setTimeout(function(){
  369. $("#saveDescForCus").html('Save as Custom');
  370. },1200);
  371. }
  372. });
  373.  
  374. //load custom descs
  375. var SelectOptionsCus = "";
  376. for(let i = 0, len = cusDescs.length; i < len; i++) {
  377. SelectOptionsCus += "<option value='"+i+"'>"+cusDescs[i][0]+"</option>\n";
  378. }
  379.  
  380. //show custom descs
  381. $("div.bbcode_editor").before(`
  382. <select id="dvfu-cus-drop">
  383. <option selected disabled>Saved Custom Descriptions...</option>
  384. `+SelectOptionsCus+`
  385. </select>
  386. `);
  387.  
  388. //description height button
  389. $("div.bbcode_editor").before('<button id="setDescHeight">Description height</button>');
  390. $("#setDescHeight").click(function(e){
  391. e.preventDefault();
  392. var descHeightTemp = parseInt(prompt("Give the Description box height (row count):"), 10);
  393. if(descHeightTemp && descHeightTemp >= 1 && descHeightTemp <= 100) {
  394. descHeight = descHeightTemp;
  395. GM.setValue("descHeight", descHeight);
  396. $("#torrent_description").prop("rows", descHeight);
  397.  
  398. $("#setDescHeight").html('<span style="color: green;">Saved!</span>');
  399. setTimeout(function(){
  400. $("#setDescHeight").html('Description height');
  401. },1200);
  402. }
  403. });
  404.  
  405. //apply selected custom desc
  406. $("#dvfu-cus-drop").change(function(){
  407. $("#torrent_description").val(cusDescs[$("#dvfu-cus-drop").val()][1]);
  408. });
  409.  
  410. //apply selected imdb
  411. $("#dvfu-imdb-drop").change(function(){
  412. $("#torrent_info__ttimdb").val(IMDBs[$("#dvfu-imdb-drop").val()][1]);
  413. });
  414.  
  415. //load desc for category on category change
  416. $("#torrent_info__subcategories").change(function(){
  417. LoadDescForCat();
  418. });
  419. }
  420. });
  421. }
  422.  
  423. function LoadDescForCat() {
  424. for(var i = 0, len = catDescs.length; i < len; i++) {
  425. if(catDescs[i][0] == $("#torrent_info__subcategories").val()) {
  426. $("#torrent_description").val(catDescs[i][1]);
  427. return;
  428. }
  429. }
  430. $("#torrent_description").val(dDesc);
  431. }
  432.  
  433.  
  434.  
  435.