// ==UserScript== // @name Printable and Readable Books Downloader for Fanfiction and Fictionpress // @namespace Azazar's Scripts // @description Allows generation of printable HTML, that can be fed to e-book readers // @include https://www.fanfiction.net/* // @include https://www.fictionpress.com/* // @version 1.5 // @grant GM_xmlhttpRequest // @license MIT // @downloadURL https://update.greasyfork.icu/scripts/496931/Printable%20and%20Readable%20Books%20Downloader%20for%20Fanfiction%20and%20Fictionpress.user.js // @updateURL https://update.greasyfork.icu/scripts/496931/Printable%20and%20Readable%20Books%20Downloader%20for%20Fanfiction%20and%20Fictionpress.meta.js // ==/UserScript== (function() { let printFicBtn = null; function htmlEntities(str) { let e = document.createElement('span'); e.appendChild(document.createTextNode(str)); return e.innerHTML; } function onAllChapters(author, title, chapters) { let html = ""; html += '
'; html += '';
for(let chapterNo = 0; chapterNo < chapters.count; chapterNo++) {
let chapter = chapters[chapterNo];
html += '' + htmlEntities(chapter.title) + '
';
}
html += '
' + chapter.html + '
'; } html += ''; let blob = new Blob([html], {type: "text/html"}); let url = window.URL.createObjectURL(blob); printFicBtn.href = url; printFicBtn.dataset.download = title + '.html'; printFicBtn.innerHTML = '🔗 Printable Version'; printFicBtn.onmousedown = function(ev) { if (ev.button === 2) { printFicBtn.download = title + '.html'; } else { printFicBtn.removeAttribute('download'); } } } $('ⳠDownload Printable Version').insertAfter('#profile_top > button'); printFicBtn = document.getElementById('printfic_btn'); printFicBtn.addEventListener('click', function() { if (printFicBtn.hasAttribute('href')) { return; } $.ajaxSetup({ async: false }); let n = 0; let chapters = {count: document.getElementById('chap_select').options.length}; setTimeout(function() { for (let i = 1; i <= document.getElementById('chap_select').options.length; i++) { let chapTitle = document.getElementById('chap_select').options[i - 1].textContent; n++; console.log("Downloading " + document.location.pathname.substring(3, 8).replace("/", "") + " chapter " + i + " (" + chapTitle + ")"); let $div = $('