// ==UserScript== // @name KAT [katcr.co] - Default values for Uploads // @namespace NotNeo // @description Lets you set up defaults in the upload section of KAT (custom default description for every category) // @include http*://katcr.co/upload-form/user/* // @include http*://katcr.co/edit-form/user/*/torrent/* // @require https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js // @require https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js // @version 1.1 // @grant GM_setValue // @grant GM_getValue // @grant GM.setValue // @grant GM.getValue // @downloadURL none // ==/UserScript== //=========================================================// //=========================================================// // YOU SHOULD NO LONGER TOUCH ANYTHING INSIDE THE SCRIPT // // EVERYTHING CAN NOW BE DONE FROM THE PAGE // //=========================================================// //=========================================================// //setting defaults var dName = ""; var dMainCat = "Category"; var dSubCat = 0; var dTitle = ""; var dDesc = ""; var catDescs = []; var catDescString = ""; (async function() { // Getting the runtime variables from local storage if( (await GM.getValue("dName")) != null ) { dName = await GM.getValue("dName"); } if( (await GM.getValue("dMainCat")) != null ) { dMainCat = await GM.getValue("dMainCat"); } if( (await GM.getValue("dSubCat")) != null ) { dSubCat = await GM.getValue("dSubCat"); } if( (await GM.getValue("dTitle")) != null ) { dTitle = await GM.getValue("dTitle"); } if( (await GM.getValue("dDesc")) != null ) { dDesc = await GM.getValue("dDesc"); } if( (await GM.getValue("catDescString")) != null ) { catDescString = await GM.getValue("catDescString"); if(catDescString) { catDescs = JSON.parse(catDescString); } } mainScript(); })(); function mainScript() { $(function(){//wait for page load if(window.location.href.indexOf("upload-form") > -1) { //upload page $("#torrent_info__categories > option[value=Category]").removeAttr("selected"); $("#torrent_info__categories > option[value="+dMainCat+"]").prop("selected", "selected"); $("#torrent_info__categories").after(''); $("#saveCat").click(function(e){ e.preventDefault(); dMainCat = $("#torrent_info__categories").val(); GM.setValue("dMainCat", dMainCat); $("#saveCat").html('Saved!'); setTimeout(function(){ $("#saveCat").html('Save'); },1200); }); } else { //edit page (upload page 2) //load defaults $("#torrent_info__subcategories > option[value=Sub-Category]").removeAttr("selected"); $("#torrent_info__subcategories > option[value="+dSubCat+"]").prop("selected", "selected"); $("#torrent_info__title").val(dTitle); $("#torrent_description").val(dDesc); //load desc for current cat if found LoadDescForCat(); //save subcat $("#torrent_info__subcategories").after(''); $("#saveSubCat").click(function(e){ e.preventDefault(); dSubCat = $("#torrent_info__subcategories").val(); GM.setValue("dSubCat", dSubCat); $("#saveSubCat").html('Saved!'); setTimeout(function(){ $("#saveSubCat").html('Save'); },1200); }); //save title $("#torrent_info__title").after(''); $("#saveTitle").click(function(e){ e.preventDefault(); dTitle = $("#torrent_info__title").val(); GM.setValue("dTitle", dTitle); $("#saveTitle").html('Saved!'); setTimeout(function(){ $("#saveTitle").html('Save'); },1200); }); //save default desc $("#torrent_description").after(''); $("#saveDesc").click(function(e){ e.preventDefault(); dDesc = $("#torrent_description").val(); GM.setValue("dDesc", dDesc); $("#saveDesc").html('Saved!'); setTimeout(function(){ $("#saveDesc").html('Save'); },1200); }); //Cat specific desc save $("#torrent_description").after(''); $("#saveDescForCat").click(function(e){ e.preventDefault(); var currentCat = $("#torrent_info__subcategories").val(); var currentDesc = $("#torrent_description").val(); var found = false; for(var i = 0, len = catDescs.length; i < len; i++) { if(catDescs[i][0] == currentCat) { catDescs[i][1] = currentDesc; found = true; } } if(!found) { var catDescTemp = [currentCat, currentDesc]; catDescs.push(catDescTemp); } catDescString = JSON.stringify(catDescs); //turn array into a single string GM.setValue("catDescString", catDescString); //save that string to local storage $("#saveDescForCat").html('Saved!'); setTimeout(function(){ $("#saveDescForCat").html('Save for category'); },1200); }); $("#torrent_info__subcategories").change(function(){ LoadDescForCat(); }); } }); } function LoadDescForCat() { for(var i = 0, len = catDescs.length; i < len; i++) { if(catDescs[i][0] == $("#torrent_info__subcategories").val()) { $("#torrent_description").val(catDescs[i][1]); } } }