KAT [katcr.co] - Default values for Uploads

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

目前為 2018-08-20 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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
// ==/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('<button id="saveCat" style="float: right;">Save</button>');
            $("#saveCat").click(function(e){
                e.preventDefault();
                dMainCat = $("#torrent_info__categories").val();
                GM.setValue("dMainCat", dMainCat);
                $("#saveCat").html('<span style="color: green;">Saved!</span>');
                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('<button id="saveSubCat" style="float: right;">Save</button>');
            $("#saveSubCat").click(function(e){
                e.preventDefault();
                dSubCat = $("#torrent_info__subcategories").val();
                GM.setValue("dSubCat", dSubCat);
                $("#saveSubCat").html('<span style="color: green;">Saved!</span>');
                setTimeout(function(){
                    $("#saveSubCat").html('Save');
                },1200);
            });

            //save title
            $("#torrent_info__title").after('<button id="saveTitle" style="float: right;">Save</button>');
            $("#saveTitle").click(function(e){
                e.preventDefault();
                dTitle = $("#torrent_info__title").val();
                GM.setValue("dTitle", dTitle);
                $("#saveTitle").html('<span style="color: green;">Saved!</span>');
                setTimeout(function(){
                    $("#saveTitle").html('Save');
                },1200);
            });

            //save default desc
            $("#torrent_description").after('<button id="saveDesc" style="float: right;">Save</button>');
            $("#saveDesc").click(function(e){
                e.preventDefault();
                dDesc = $("#torrent_description").val();
                GM.setValue("dDesc", dDesc);
                $("#saveDesc").html('<span style="color: green;">Saved!</span>');
                setTimeout(function(){
                    $("#saveDesc").html('Save');
                },1200);
            });

            //Cat specific desc save
            $("#torrent_description").after('<button id="saveDescForCat" style="float: right;">Save for category</button>');
            $("#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('<span style="color: green;">Saved!</span>');
                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]);
        }
    }
}