TruyenCV.com QuickPaste

QuickPaste for Add Chapter

目前為 2017-03-30 提交的版本,檢視 最新版本

// ==UserScript==
// @name         TruyenCV.com QuickPaste
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  QuickPaste for Add Chapter
// @author       Mkbyme
// @match        http://truyencv.com/account/add_chapter/*
// @grant        none
// @required https://code.jquery.com/jquery-3.2.1.min.js
// ==/UserScript==
//create element
function ce(n)
{
    return document.createElement(n);
}
//add style
function addStyle(style)
{
    var s = ce("style"),h = document.head || document.getElementsByTagName("head")[0];
    s.type="text/css";
    s.appendChild(document.createTextNode(style));
    h.appendChild(s);
}
//add CSS
function addCss()
{
    var s = "";
    s+="#qpmk{background-color: #2d2d2d;padding: 3px 15px;color: #ebebeb;border-radius: 5px 5px 0px 0px;margin-bottom: 15px;}";
    s+="#qpmk>.form-group>div{font-size: 13px;color: #bef385;}";
    s+="#qpmk>p{font-size:13px;color: #c7c7c7;text-align: right;}";
    addStyle(s);
}
function createInjectHTML()
{
    var h = "";
    h+="<div id=\"qpmk\"><h3>Đăng Truyện Nhanh  Script</h3><div class=\"form-group\">";
    h+="<div>Ví dụ tên Chương 1, Chương 2, Chương n thì điền \"Chương \" để thực hiện dán tự động<br>";
    h+="<ol><li>Nhập số chương cần đăng = số_hiện_tại + số_chương_đăng</li>";
    h+="<li>Mở tệp chứa nội dung đã convert chọn và copy đoạn chứa số_chương_đăng</li><li>Dán vào DÁN VÀO ĐÂY</li>";
    h+="<li>Nhấn <b>1-Tiếp Tục</b></li><li>Sau khi chuyển trang lần 2 dà soát tên chương và số chương.</li><li>Nhấn <b>2-Đăng Chương</b></li></ol>";
    h+="<span style=\"color:red\">* </span>Trước khi nhấn nút <b class=\"text-info\">Đăng Chương</b> thì phải thực hiện sao chép nội dung truyện trước.";
    h+="<br><span style=\"color:red\">* </span>Để tăng độ chính xác thì Tên Chương nên ở <u>1 dòng riêng</u> và <u>không có khoảng trắng</u> phía trước";
    h+=" như \"&nbsp;&nbsp;&nbsp;Chương\" mà nên là \"Chương...\".</div>";
    h+="<label>Tiêu Đề Chương(để ngăn cách)</label>";
    h+="<input type=\"text\" id=\"qpmks\" class=\"form-control\" value=\"Chương \" placeholder=\"Nhập tiêu đề chứa từ cách chương/chapter\"></div>";
    h+="<div class=\"form-group\"><label>Dán Vào Đây(CTRL + V)</label>";
    h+="<textarea placeholder=\"dán nội dung vào đây - CTRL + V\" id=\"qpv\" class=\"form-control\" rows=\"5\"></textarea></div>";
    h+="<button type=\"submit\" id=\"qpmkd\" class=\"btn btn-disable\" onclick=\"javascript:;\">1-Tiếp Tục</button><span id=\"qpn\" style=\"margin:0px 15px;font-weight:bold\"></span>";
    h+="<button class=\"btn btn-read\"onclick=\"document.getElementById('btnAddchapter2').click();\">2-Đăng Chương</button><span id=\"qpn\" style=\"margin-left:15px;font-weight:bold\"></span>";
    h+="<p>© by <a href=\"fb.me/mkbyme\">Mkbyme</a></p></div>";
    $(".form-horizontal").before(h);
}
function process()
{
    $("#qpv").on("paste",function(e){
        $(this).val("");

        setTimeout(function(){
            var a = "\n"+$("#qpv").val(),s=$("#qpmks").val(),ta=$("textarea[id^=url]");
            a = a.split("\n"+s).filter(function(entry){return entry.trim()!=="";});
            $.each(ta, (function(k, v) {
                if (k < a.length)
                    $(this).val(s+a[k]);
                else {
                    //alert("Số chương copy chưa đủ đâu nhé,copy thêm " + (ta.length - a.length) + " chương nữa nhé");
                    $("#qpn").text("Số chương copy chưa đủ,Cần sao thêm " + (ta.length - a.length) + " chương nữa, Hãy thử lại!").removeClass("text-notify").addClass("text-danger");
                    $("#qpv").val("");
                    $("#qpmkd").attr("onclick","javascript:void();").removeClass("btn-read").addClass("btn-disable");
                    return false;
                }
                $("#qpmkd").attr("onclick","javascript:document.getElementById('ok').click();").removeClass("btn-disable").addClass("btn-read");
                $("#qpn").removeClass("text-danger").addClass("text-notify").text("OK, 1-Nhấn Tiếp Tục sau đó nhấn 2-Đăng Chương");
              
            }));
        },500);
    });


}
function init()
{
    addCss();
    createInjectHTML();
    process();
    $("#qkv").focus();
}
init();