Greasy Fork

Greasy Fork is available in English.

Syosetu Chapter Copy

Copy the chapter content from a Syosetu chapter page.

目前为 2020-09-09 提交的版本。查看 最新版本

// ==UserScript==
// @name         Syosetu Chapter Copy
// @namespace    ultrabenosaurus.Syosetu
// @version      0.5
// @description  Copy the chapter content from a Syosetu chapter page.
// @author       Ultrabenosaurus
// @source       http://greasyfork.icu/en/users/437117-ultrabenosaurus?sort=name
// @match        https://ncode.syosetu.com/*/*/
// @grant        GM.setClipboard
// @grant        GM_setClipboard
// ==/UserScript==

(function() {
    'use strict';

    var mobile = 0;
    let txtBox = document.createElement("textarea");
    var btnElem = "<br /><input type='button' id='UBsyosetuChapterCopy' value='Copy Chapter' />";

    var subTitle = document.querySelectorAll('div#novel_color p.novel_subtitle');
    if(subTitle.length == 0) {
        mobile = 1;
        subTitle = document.querySelectorAll('div#novel_color div.novel_subtitle');
    }

    subTitle[0].insertAdjacentHTML("beforeend", btnElem);
    var sccBtn = document.getElementById('UBsyosetuChapterCopy');
    if(sccBtn){
        sccBtn.addEventListener("click", UBsyosetuChapterCopy, false);

        txtBox.id = "UBsyosetuChapterContent";
        txtBox.name = "UBsyosetuChapterContent";
        txtBox.style = "width: 0; height: 0; border: none;";
        document.body.appendChild(txtBox);
        txtBox.value = (mobile ? subTitle[0].innerText.split("\n")[1] : subTitle[0].textContent) + "\n\n" + document.querySelectorAll('div#novel_honbun')[0].textContent;
    }
    sccBtn = btnElem = txtBox = subTitle = null;
})();

function UBsyosetuChapterCopy() {
    let txtBox = document.getElementById('UBsyosetuChapterContent');
    txtBox.select();
    txtBox.setSelectionRange(0, 99999);
    document.execCommand("copy");
    //console.log(txtBox.value);
    //console.log(window.getSelection().toString());
}