Greasy Fork

TorrentGalaxy: Default values for uploads

Lets you set up defaults for the upload page on TGx

目前为 2019-07-26 提交的版本。查看 最新版本

// ==UserScript==
// @name         TorrentGalaxy: Default values for uploads
// @namespace    NotNeo
// @version      0.1
// @description  Lets you set up defaults for the upload page on TGx
// @author       NotNeo
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js
// @match        https://torrentgalaxy.to/torrents-upload.php
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

(function() {
    'use strict';

    var icons = {
        save: `<svg aria-hidden="true" focusable="false" data-prefix="far" data-icon="save" class="svg-inline--fa fa-save fa-w-14" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path fill="currentColor" d="M433.941 129.941l-83.882-83.882A48 48 0 0 0 316.118 32H48C21.49 32 0 53.49 0 80v352c0 26.51 21.49 48 48 48h352c26.51 0 48-21.49 48-48V163.882a48 48 0 0 0-14.059-33.941zM272 80v80H144V80h128zm122 352H54a6 6 0 0 1-6-6V86a6 6 0 0 1 6-6h42v104c0 13.255 10.745 24 24 24h176c13.255 0 24-10.745 24-24V83.882l78.243 78.243a6 6 0 0 1 1.757 4.243V426a6 6 0 0 1-6 6zM224 232c-48.523 0-88 39.477-88 88s39.477 88 88 88 88-39.477 88-88-39.477-88-88-88zm0 128c-22.056 0-40-17.944-40-40s17.944-40 40-40 40 17.944 40 40-17.944 40-40 40z"></path></svg>`,

    }

    var torNameDefault = GM_getValue("torNameDefault", "");
    var torIMDBDefault = GM_getValue("torIMDBDefault", "");
    var torTypeDefault = GM_getValue("torTypeDefault", "0");
    var torLangDefault = GM_getValue("torLangDefault", "1");
    var torDescDefault = GM_getValue("torDescDefault", "");

    //insert styles
    {
        $("head").append(`<style>
.DVfU_button > svg {
height: 20px;
margin: 5px;
vertical-align: top;
}
.DVfU_button:hover,
.DVfU_button:active {
cursor: pointer;
}

form[name='upload'] td input:first-child:nth-last-child(2),
form[name='upload'] td select:first-child:nth-last-child(2),
form[name='upload'] td textarea:first-child:nth-last-child(2){
width: calc(100% - 27.5px);
display: inline-block;
}

.DVfU_msg {
display: none;
position: fixed;
bottom: 20px;
right: 20px;
background-color: #555;
color: white;
border-radius: 10px;
font-size: 20px;
padding: 15px 20px;
}
</style>`);
    }

    //insert buttons, initialize listeners and load defaults
    {
        $("form[name='upload'] td input[name='name']").val(torNameDefault).after(CreateSaveButton("DVfU_saveNameButton"));
        $("#DVfU_saveNameButton").click(function(){
            torNameDefault = $(this).prev().val();
            GM_setValue("torNameDefault", torNameDefault);
            ShowMessage();
        });

        $("form[name='upload'] td input[name='imdb']").val(torIMDBDefault).after(CreateSaveButton("DVfU_saveIMDBButton"));
        $("#DVfU_saveIMDBButton").click(function(){
            torIMDBDefault = $(this).prev().val();
            GM_setValue("torIMDBDefault", torIMDBDefault);
            ShowMessage();
        });

        $("form[name='upload'] td select[name='type']").val(torTypeDefault).after(CreateSaveButton("DVfU_saveTypeButton"));
        $("#DVfU_saveTypeButton").click(function(){
            torTypeDefault = $(this).prev().val();
            GM_setValue("torTypeDefault", torTypeDefault);
            ShowMessage();
        });

        $("form[name='upload'] td select[name='lang']").val(torLangDefault).after(CreateSaveButton("DVfU_saveLangButton"));
        $("#DVfU_saveLangButton").click(function(){
            torLangDefault = $(this).prev().val();
            GM_setValue("torLangDefault", torLangDefault);
            ShowMessage();
        });

        $("form[name='upload'] td textarea[name='descr']").val(torDescDefault).after(CreateSaveButton("DVfU_saveDescButton"));
        $("#DVfU_saveDescButton").click(function(){
            torDescDefault = $(this).prev().val();
            GM_setValue("torDescDefault", torDescDefault);
            ShowMessage();
        });
    }




    function CreateSaveButton(id) {
        return '<a id="'+id+'" class="DVfU_button" title="Save as the default value">'+icons["save"]+'</a>';
    }
    function ShowMessage(text = "Saved!") {
        let uniqueId = "DVfU_msg_"+new Date().getTime();
        $("body").after('<span id="'+uniqueId+'" class="DVfU_msg">'+text+'</span>');
        let msg = $("#"+uniqueId);
        msg.fadeIn(200, function(){
            setTimeout(function(){
                msg.fadeOut(200, function(){
                    msg.remove();
                });
            }, 1500);
        });
    }

})();