// ==UserScript==
// @name Syosetu Chapter Copy
// @namespace ultrabenosaurus.Syosetu
// @version 0.5
// @description Copy the chapter content from a Syosetu chapter page.
// @author Ultrabenosaurus
// @source https://greasyfork.org/en/users/437117-ultrabenosaurus?sort=name
// @match https://ncode.syosetu.com/*/*/
// @grant GM.setClipboard
// @grant GM_setClipboard
// @downloadURL none
// ==/UserScript==
(function() {
'use strict';
var mobile = 0;
let txtBox = document.createElement("textarea");
var btnElem = "
";
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());
}