joshu / BUAABT Comic Seeds Quick Publish

// ==UserScript==
// @name         BUAABT Comic Seeds Quick Publish
// @version      0.1.1
// @description  根据旧种子快速填写新种子的信息
// @author       joshu
// @match        http://buaabt.cn/publish.aspx?type=comic
// @match        http://ipv4.buaabt.cn/publish.aspx?type=comic
// @match        http://ipv6.buaabt.cn/publish.aspx?type=comic
// @match        http://bt.buaa.edu.cn/publish.aspx?type=comic
// @require      https://code.jquery.com/jquery-3.2.1.min.js
// @updateURL    https://openuserjs.org/meta/joshu/BUAABT_Comic_Seeds_Quick_Publish.meta.js
// @grant        GM_log
// ==/UserScript==

unsafeWindow.GetSourceData = function()
{
    const SELECTORs = ["#comic_region", "#comic_cname", "#comic_ename", "#comic_type", "#comic_language", "#comic_format", "#comic_source", "#comic_subtitle", "#comic_subtitlegroup"];
    const TEXTAREA_SELECTOR = "#e_textarea";
    const DATE_SELECTOR = "#newpost > tbody:nth-child(2) > tr:nth-child(16) > td > a";
    const URL_SELECTOR = "#comic_src";
    const SEASON_SELECTOR = "#comic_season";
    const NUMBER_REGEX = /^\d+$/;

    //MDZZ
    $ = jQuery;

    var url = $("#comic_src")[0].value;
    if (url.match(NUMBER_REGEX)!=null) {
        url = "/edit.aspx?seedid=" + url;
    } else {
        alert("来源地址不合法:" + url);
    }
    GM_log("Fetching: " + url);

    $.ajax({
        url: url,
        async: true,
        success: function(data){
            var htmlData = $.parseHTML(data);
            $.each(SELECTORs,function(index,data){
                var content = $(data, $(htmlData));
                if (!!content[0]) {
                    $(data).attr("value", content.attr("value"));
                }
            });

            $(DATE_SELECTOR).click();

            var content = $(TEXTAREA_SELECTOR, $(htmlData));
            if (!!content[0]) {
                $("#e_switcher").click();
                editdoc.value = content.text();
                $("#e_switcher").click();
            }

            $("#comic_season").focus();
        },
        error: function() {
            alert("来源获取失败!");
        }
    });
};

(function() {
    'use strict';
    unsafeWindow.titles = ["阿松", "Code:Realize"];
    unsafeWindow.seedids = [216901, 216709];
    $("#newpost > tbody:nth-child(2) > tr:nth-child(4)").after('<tr><th><span class="b">快速复制</span></th><td><input name="comic_src" type="text" id="comic_src" size="60" value title>&nbsp;<input class="file_btn" type="button" onclick="GetSourceData();" value="获取内容"></td></tr>');
    for (var i=0;i<seedids.length;i++)
    {
        jQuery("#comic_src").parent().append('   <a onclick="jQuery(\'#comic_src\').attr(\'value\', ' + seedids[i] +  ');" class="PublishTag">' + titles[i] + '</a>   ');
    }
})();