Fanfiction+

Makes subtle improvements to improve readability on fanfiction.net

Stan na 14-09-2016. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name        Fanfiction+
// @namespace   DanielVestol.Fanfiction.net
// @description Makes subtle improvements to improve readability on fanfiction.net
// @include     https://www.fanfiction.net/s/*
// @version     1.10
// @grant       GM_xmlhttpRequest
// ==/UserScript==

// SETTINGS
config = {
    ebookServer: "http://41e606ed.ngrok.io",
};
// END OF SETTINGS

console.log("DOM fully loaded and parsed");
document.getElementById('content_wrapper').style.maxWidth = '800px';
review = document.getElementById('review');
review.getElementsByTagName('TD')[0].remove();
review.getElementsByTagName('TD')[0].remove(); // Remove element 1 which is now 0
review.getElementsByTagName('DIV')[0].style.maxWidth = '765px';
review.getElementsByTagName('DIV')[0].style.margin = '10px';
document.getElementById('review_name_value').style.maxWidth = '780px';
document.getElementById('review_review').style.maxWidth = '780px';
// Better change between mobile and desktop edition.
// Credits to SirCxyrtyx for snippet
var mobileVersion = 'location = "https://m.fanfiction.net' + document.location.pathname + '"';
// console.log(mobileVersion);
document.getElementsByClassName('icon-kub-mobile')[0].setAttribute('onclick', mobileVersion);
// Show whole book function
$('#content_wrapper_inner > span:nth-child(7)').append('<button id="myShit" class="btn" type="BUTTON">Show whole book</button>');
document.getElementById('myShit').addEventListener('click', function() {
    document.getElementById('storytextp').innerHTML = "<div id='topSuprSecret' style='position:fixed;top:100px;left:100px;width:400px;height:70px;background-color:#A2DEF2;'><h1>Loading book...</h1></div>";
    $.ajaxSetup({
        async: false
    });
    for (i = chapter; i < document.getElementById('chap_select').options.length; i++) {
        console.log("Downloading " + document.location.pathname.substr(3, 8).replace("/", "") + " chapter " + i);
        var $div = $('<div>');
        $div.load('https://www.fanfiction.net/s/' + document.location.pathname.substr(3, 8).replace("/", "") + '/' + i + ' #storytext', function(){
            // now $(this)[0].innerHTML contains #storytext
            $("#storytextp").append($(this)[0].innerHTML);
        });
    }
    document.getElementById('topSuprSecret').outerHTML = '';
});
$('#content_wrapper_inner > span:nth-child(7)').append('<button id="getEbook" class="btn" type="BUTTON">ebook</button>');
document.getElementById('getEbook').addEventListener('click', function() {
    document.getElementById('storytextp').innerHTML = "<div id='topSuprSecret' style='position:fixed;top:100px;left:100px;width:400px;height:70px;background-color:#A2DEF2;'><h1>Loading book...</h1></div>";
    $.ajaxSetup({
        async: false
    });
    data = {
        title: document.querySelector("#profile_top > b").innerHTML,
        contents: [],
        bookID: document.location.pathname.substr(3, 8).replace("/", "")
    };
    for (i = chapter; i < document.getElementById('chap_select').options.length; i++) {
        console.log("Downloading " + document.location.pathname.substr(3, 8).replace("/", "") + " chapter " + i);
        var $div = $('<div>');
        $div.load('https://www.fanfiction.net/s/' + document.location.pathname.substr(3, 8).replace("/", "") + '/' + i + ' #storytext', function(){
            // now $(this)[0].innerHTML contains #storytext
            $("#storytextp").append($(this)[0].innerHTML);
            // insert our chapter into the data object
            data.contents[data.contents.length] = {
                title: document.getElementById('chap_select').options[i].innerHTML,
                data: $(this)[0].innerHTML,
                id: i
            };
        });
    }
    console.log(data);
    GM_xmlhttpRequest({
        method: "POST",
        url: config.ebookServer + "/epubify",
        data: JSON.stringify(data),
        headers:    {
            "Content-Type": "application/json"
        },
        onload:function(response) {
            console.log(response.responseText + " book is done");
            location.href = config.ebookServer + "/" + document.location.pathname.substr(3, 8).replace("/", "") + ".epub";
        }
    });
    document.getElementById('topSuprSecret').outerHTML = '';
});