AO3: Fic's Style and Bookmarks

Change font, size, width.. + estimated reading time + full screen mode + bookmarks: save the position you stopped reading a fic

目前為 2015-08-04 提交的版本,檢視 最新版本

// ==UserScript==
// @name         AO3: Fic's Style and Bookmarks
// @namespace    https://greasyfork.org/it/users/12632-schegge
// @version      2.0
// @description  Change font, size, width.. + estimated reading time + full screen mode + bookmarks: save the position you stopped reading a fic
// @author       Schegge
// @include      http://archiveofourown.org/*
// @include      https://archiveofourown.org/*
// @grant        none
// @icon         data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC4AAAAuCAYAAABXuSs3AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyBpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBXaW5kb3dzIiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOjEyNjY3MDJGMzdD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9+YihaazN5HYamm4ORCUE3hKoyhgsbMc7TdNuthx0nsgcxbaK9rhGVeB+V1gotNz13K2LaVTnIWr01gWnKzsZrCF/Mj3uacqq7nS0e6emhXWw3xbGSwOMCPXoGjtQ7lKr+gce2D36ARGgglZzVQSB4JcG8XxWszNrzDr18KO838S0TD+miyusJ1ePFs5NGHm2RQYTPJehX31vC+vuFKfn8cnWAoQU9fwhh3D/LZZsgNmg4zEhrm/5+p+neh51L70eouHKIj6JHbf0ncHhBFR/ohY/Z/+f8IMABr14xjEa9p0AAAAABJRU5ErkJggg==
// ==/UserScript==

(function($) {    

    // BOOKMARKS
    var Bookmarks = {
        getAll: function() {
            var bookmarks = localStorage.getItem("ficstyle_bookmarks");
            if ( !bookmarks ) {
                bookmarks = "";
                localStorage.setItem("ficstyle_bookmarks", bookmarks);
            }
            return bookmarks;
        },
        getSingles: function() {
            var all = this.getAll();
            return all.split("@");
        },
        getElements: function() { // 0 = url, 1 = title, 2 = scrolltop
            var els = [];
            var singles = this.getSingles();
            for(var i = 1; i < singles.length; i++) { // from 1 because the first element is empty (storage starts with a @)
                els.push( singles[i].split("#") );
            }
            return els;
        },
        getUrl: window.location.pathname.split("/works/")[1], // work id
        getTitle: function() {
            var title = $("#workskin .preface.group h2.title.heading").text().trim();            
            title = title.substring(0, 28); // to cut long titles
            if ( /chapters/.test(window.location.pathname) ) { // if chapter by chapter, also storaging the number of the chapter
                var chapter = $("#chapters > .chapter > div.chapter.preface.group > h3 > a").text();
                chapter = chapter.replace("Chapter ", "ch");
                title += " (" + chapter + ")";
            }
            title = title.replace(/#/g, " "); // just in case
            title = title.replace(/@/g, " ");
            return title;
        },
        getNewBook : function() {       
            var newbook = $(document).scrollTop(); // current position of the scroll bar
            var chs = $("dl.stats dd.chapters").text(); // # chapters
            if ( /(\d+)\/\1/.test(chs) || /chapters/.test(window.location.pathname) ) { // if work completed (if number/number is the same) or chapter by chapter view
                newbook = ( newbook / $(document).height() ).toFixed(4) + "%"; // calculate in percent
            }
            return newbook;
        },
        checkIfExist: function(a) {
            var url = this.getUrl;
            var els = this.getElements();

            for(var i = 0; i < els.length; i++) {
                if ( els[i][0] == url ) { // if a bookmark already existed for the current fic
                    if ( a == "book" ) { // retrieve the bookmark
                        var book = els[i][2];
                        if ( book.indexOf("%") !== -1 ) {
                            book = book.replace("%", "");
                            book = parseFloat(book);
                            book = book * $(document).height();
                        }
                        book = parseFloat(book);
                        return book;
                    } else if ( a == "cancel" ) { // delete the old bookmark
                        return "@" + els[i][0] + "#" + els[i][1] + "#" + els[i][2];
                    } else {
                        return true;
                    }
                }
            }
        },
        cancel: function() {
            var newBookmarks = this.getAll();
            var cancel = this.checkIfExist("cancel");
            if ( cancel ) {
                newBookmarks = newBookmarks.replace(cancel, "");
            }
            return newBookmarks;
        },
        getNew: function() {
            var url = this.getUrl;
            var title = this.getTitle();
            var newbook = this.getNewBook();

            var newBookmarks = this.cancel(); // if the the fic was already bookmarked, delete the old bookmark
            newBookmarks += "@" + url + '#' + title + '#' + newbook; // add new bookmark
            localStorage.setItem("ficstyle_bookmarks", newBookmarks);
        }
    };

    // create bookmarks' menu
    $("#header > ul").append(
        '<li id="menu-bookmarks" class="dropdown" aria-haspopup="true">' +
        '<a>Bookmarks</a>' +
        '<ul class="menu dropdown-menu" role="menu"></ul></li>'
    );

    var els = Bookmarks.getElements();
    for(var z = 0; z < els.length; z++) {
        $("#menu-bookmarks > ul.menu").append(
            "<li role='menu-item'>" +
            "<a href='http://archiveofourown.org/works/" + els[z][0] + "'>" + els[z][1] + "</a>" +
            "</li>"
        );
    }

    // add estimated reading time
    $words = $("dl.stats dd.words");
    if ( $words.length ){
        $words.each(function() {
            var numWords = $(this).text();
            numWords = numWords.replace(",", "");
            var timeReading = parseInt( numWords ) / 200; // 200 words per minute
            if ( timeReading < 60 ) {
                timeReading = Math.round ( timeReading ) + "min";
            } else {
                timeReading = ( timeReading / 60 ).toFixed(2);
                timeReading = timeReading.toString();
                timeReading = timeReading.split(".");
                var hours = timeReading[0];
                var minutes = Math.round ( parseInt(timeReading[1]) / 100 * 60 );
                timeReading = hours + "hr & " + minutes.toString() + "min";
            }
            $(this).after("<dt>Time:</dt><dd>" + timeReading + "</dd>");
        });
    }

    //*//*//*//*//*//*//*// everything below is going to be shown only on the fic's page //*//*//*//*//*//*//*//

    var windowUrl = window.location.pathname;
    // include: (whatever)/works/(numbers) and (whatever)/works/(numbers)/chapters/(numbers) and exclude: navigate
    if ( /.*\/works\/\d+(\/chapters\/\d+)?/.test(windowUrl) && !/navigate/.test(windowUrl)) {

        fontNameDefault = $("body").css("font-family"); // the font-family used by AO3
        ////////////////////////////////////////////////////////////////////////////////////////////////////////
        var Options = {
            fontName: [fontNameDefault, "Georgia", "Garamond", "Book Antiqua", "Verdana", "Segoe UI"],
            fontSize: 100, //%
            fontColor: "#000",
            chapterWidth: 90, //% ( min = 10; max = 90 )
            showBackground: "no", //or "yes"
            backgroundColor: "#f6f6f6"
        };
        ////////////////////////////////////////////////////////////////////////////////////////////////////////

        var chaptersCSS;
        numChapters = $("#chapters > .chapter").length; // it counts how many chapters the fic has
        if (numChapters) { // if the fic has several chapters, even if only one chapter is displayed
            chapters = $("#chapters > .chapter");
            chaptersCSS = "#chapters > .chapter";
        } else { // if the fic is a one-shot
            chapters = $("#chapters");
            chaptersCSS = "#chapters";
        }

        // general CSS changes
        var addGlobalCSS = function(css) {
            $head = $("head");
            $style = $("<style type='text/css'>" + css + "</style>");
            $head.append($style);
        };

        addGlobalCSS(
            chaptersCSS + " { " +
            "color: " + Options.fontColor + "; " +
            "margin: auto; " +
            "text-align: justify; " +
            "padding-top: 30px; " +
            "padding-bottom: 30px; " +
            "border-radius: 100% / 60px; " +
            "margin-bottom: 20px; " +
            "padding-right: 3%; " +
            "padding-left: 3%; " +
            "} " +
            ".chapter .preface { " +
            "margin-bottom: 0; " +
            "} " +
            ".chapter .preface[role='complementary'] { " +
            "margin-top: 0; " +
            "padding-top: 0; " +
            "} " +
            "#workskin .notes, #workskin .summary { " +
            "font-size: .91rem; " +
            "} " +
            "#chapters .userstuff p { " +
            "font-family: inherit; " +
            "margin: 0.6em auto; " +
            "text-align: justify; " +
            "} " +
            "#chapters .userstuff blockquote { " +
            "font-family: inherit; " +
            "padding-top: 1px; " +
            "padding-bottom: 1px; " +
            "margin: 0 .5em; " +
            "} " +
            ".userstuff hr { " +
            "width: 100%; " +
            "height: 1px; " +
            "border: 0; " +
            "background-image: linear-gradient(to right, transparent, rgba(0, 0, 0, .5), transparent); " +
            "} " +
            ".userstuff img { " +
            "max-width: 100%; " +
            "height: auto; " +
            "} " +
            "#options, .ficleft { " +
            "position: fixed; " +
            "bottom: 15px; " +
            "margin: 0; " +
            "padding: 0; " +
            "font-family: Consolas, monospace; " +
            "font-size: 16px; " +
            "color: #000; " +
            "text-shadow: 0 0 2px rgba(0, 0, 0, .4); " +
            "z-index: 999; " +
            "} " +
            "#options { " +
            "right: 15px; " +
            "} " +
            ".ficleft { " +
            "left: 15px; " +
            "} " +
            "#options > div { " +
            "margin: 5px 0 0 0; " +
            "padding: 0 5px; " +
            "cursor: pointer; " +
            "} " +
            "#options > div:last-child { " +
            "padding: 2px 5px; " +
            "color: #fff; " +
            "background-color: rgba(0, 0, 0, .2); " +
            "} " +
            ".ficleft a, #options a { " +
            "border: 0; " +
            "} " +
            "div.preface .notes, div.preface .summary, div.preface .series, div.preface .children {" +
            "min-height: 0; " +
            "} " +
            "#notes { " +
            "display: none; " +
            "} " +
            ".notes-hidden { " +
            "cursor: pointer; " +
            "position: fixed; " +
            "width: 50%; " +
            "max-height: 50%; " +
            "left: 50px; " +
            "bottom: 50px; " +
            "background-color: #fff; " +
            "padding: 10px; " +
            "box-shadow: 0 0 2px 1px rgba(0, 0, 0, .4); " +
            "margin: 0; " +
            "overflow: auto; " +
            "z-index: 999; " +
            "display: none; " +
            "} " +
            ".notes-headings { " +
            "cursor: pointer; " +
            "border-bottom-width: 0!important; " +
            "margin-bottom: 0; " +
            "text-align: center; " +
            "color: #666; " +
            "} "
        );

        // CSS changes depending on the user
        var Variables = {
            fontName: function() {
                var fontName = localStorage.getItem("ficstyle_fontName");
                if (!fontName) {
                    fontName = Options.fontName[0];
                    localStorage.setItem("ficstyle_fontName", fontName);
                }
                return fontName;
            },
            fontSize: function() {
                var fontSize = localStorage.getItem("ficstyle_fontSize");
                if (!fontSize) {
                    fontSize = Options.fontSize;
                    localStorage.setItem("ficstyle_fontSize", fontSize);
                }
                return fontSize;
            },
            chapterWidth: function() {
                var chapterWidth = localStorage.getItem("ficstyle_chapterWidth");
                if (!chapterWidth) {
                    chapterWidth = Options.chapterWidth;
                    localStorage.setItem("ficstyle_chapterWidth", chapterWidth);
                }
                return chapterWidth;
            },
            showBackground: function() {
                var showBackground = localStorage.getItem("ficstyle_showBackground");
                if(!showBackground) {
                    showBackground = Options.showBackground;
                    localStorage.setItem("ficstyle_showBackground", showBackground);
                }
                return showBackground;
            },
            hide: function() {
                var hide = localStorage.getItem("ficstyle_hide");
                if (!hide) {
                    hide = "no";
                    localStorage.setItem("ficstyle_hide", hide);
                }
                return hide;
            },
            background: function() {
                chapters.css({
                    "background-color": Options.backgroundColor,
                    "box-shadow": "inset 0 0 8px 0 rgba(0, 0, 0, .2)"
                });
                $(".chapter .preface[role='complementary']").css("border-top-width", "0"); // the chapter title
                $("#chapters .userstuff blockquote").css({
                    "background-image": "linear-gradient(to right, rgba(0, 0, 0, .035), transparent)",
                    "border-width": "0"
                });
            },
            noBackground: function() {
                chapters.css({
                    "background-color": "transparent",
                    "box-shadow": "none"
                });
                $(".chapter .preface[role='complementary']").css("border-top-width", "1px"); // the chapter title
                $("#chapters .userstuff blockquote").css({
                    "background-image": "none",
                    "border-width": "2px",
                    "border-color": "rgba(0, 0, 0, .1)"
                });
            },
            changingCSS: function(a, b) { // a = "Variables" (user changes) or "Options" (default); b = "no" background or "yes"
                var chapterWidth, fontName, fontSize;
                if (a == "Variables") {
                    chapterWidth = this.chapterWidth();
                    fontName = this.fontName();
                    fontSize = this.fontSize();
                } else { // a = "Options"
                    chapterWidth = Options.chapterWidth;
                    fontName = Options.fontName[0];
                    fontSize = Options.fontSize;
                }
                chapters.css({
                    "width": chapterWidth + "%",
                    "font-family": fontName,
                    "font-size": fontSize + "%"
                });
                if (b == "no") {
                    this.noBackground();
                } else { // b = "yes"
                    this.background();
                }
            }
        };

        // more CSS changes
        Variables.changingCSS("Variables", Variables.showBackground()); // saved changes by user
        $("#chapters .userstuff p").each(function() { // it removes empty paragraphs
            if( !$(this).text().trim().length && !$(this).children("img").length ) {
                $(this).remove();
            }
        });
        $("#chapters .userstuff br").after("<p>").remove(); // replace '<br>' with paragraphs

        // the options displayed on the page
        $options = $("<div>", {id: "options"})
        .append( $("<div>", {html: "«", id: "font-name-minus", attr: {"title": "previous font"} }) )
        .append( $("<div>", {html: "»", id: "font-name-plus", attr: {"title": "next font"} }) )
        .append( $("<div>", {html: "-", id: "font-size-minus", attr: {"title": "decrease font size"} }) )
        .append( $("<div>", {html: "+", id: "font-size-plus", attr: {"title": "increase font size"} }) )
        .append( $("<div>", {html: "&#9643;", id: "chapter-width-minus", attr: {"title": "decrease width"} }) )
        .append( $("<div>", {html: "&#9633;", id: "chapter-width-plus", attr: {"title": "increase width"} }) )
        .append( $("<div>", {html: "b", id: "chapter-background", attr: {"title": "add/remove background"} }) )
        .append( $("<div>", {html: "r", id: "reset-local-storage", attr: {"title": "reset"} }) )
        .append( $("<div>", {html: "&#9776;", id: "show-hide", attr: {"title": "show/hide menu"} }) );
        $("body").append($options);

        if ( Variables.hide() == "no" ) {
            $("#options > div").css("display", "block");
        } else {
            $("#options > div:nth-last-child(n+2)").css("display", "none");
        }

        // to remain more or less on in the same position in the text when changes are happening
        var percent,
            checkPosition = function() {
                documentTopB = $(document).scrollTop();
                documentHeightB = $(document).height();
                percent = documentTopB / documentHeightB;
            },
            returnBack = function() {
                documentHeightA = $(document).height();
                var r = percent * documentHeightA;
                if ( documentTopB > $("#chapters").offset().top ) {
                    $("html, body").scrollTop(r);
                }
            };

        // changes triggered by the user
        $("#show-hide").click(function() {
            $("#options > div:nth-last-child(n+2)").slideToggle("300");
            if(localStorage.getItem("ficstyle_hide") == "no") {
                localStorage.setItem("ficstyle_hide", "yes");
            } else { localStorage.setItem("ficstyle_hide", "no"); }
        });

        $("#reset-local-storage").click(function() {
            checkPosition();
            localStorage.setItem("ficstyle_fontName", Options.fontName[0]);
            localStorage.setItem("ficstyle_fontSize", Options.fontSize);
            localStorage.setItem("ficstyle_chapterWidth", Options.chapterWidth);
            localStorage.setItem("ficstyle_showBackground", Options.showBackground);
            Variables.changingCSS("Options", Options.showBackground);
            returnBack();
        });

        $("#chapter-background").click(function() {
            if(localStorage.getItem("ficstyle_showBackground") == "no") {
                localStorage.setItem("ficstyle_showBackground", "yes");
                Variables.background();
            } else {
                localStorage.setItem("ficstyle_showBackground", "no");
                Variables.noBackground();
            }
        });

        var curFont, curFontIncr;
        $("#font-name-minus").click(function() {
            checkPosition();
            curFont = localStorage.getItem("ficstyle_fontName");
            for(var i = 0; i < Options.fontName.length; i++) {
                if(curFont == Options.fontName[i]) {
                    var j = i - 1;
                    if(j === -1) {
                        var u = Options.fontName.length - 1;
                        curFontIncr = Options.fontName[u];
                    } else {
                        curFontIncr = Options.fontName[j];
                    }
                    $(chapters).css("font-family", curFontIncr);
                    localStorage.setItem("ficstyle_fontName", curFontIncr);
                }
            }
            returnBack();
        });
        $("#font-name-plus").click(function() {
            checkPosition();
            curFont = localStorage.getItem("ficstyle_fontName");
            for(var i = 0; i < Options.fontName.length; i++) {
                if(curFont == Options.fontName[i]) {
                    var j = i + 1;
                    if(j === Options.fontName.length) {
                        curFontIncr = Options.fontName[0];
                    } else {
                        curFontIncr = Options.fontName[j];
                    }
                    $(chapters).css("font-family", curFontIncr);
                    localStorage.setItem("ficstyle_fontName", curFontIncr);
                }
            }
            returnBack();
        });

        var curSize;
        $("#font-size-minus").click(function() {
            checkPosition();
            curSize = parseFloat(localStorage.getItem("ficstyle_fontSize")) - 2.5;
            $(chapters).css("font-size", curSize+"%");
            localStorage.setItem("ficstyle_fontSize", curSize);
            returnBack();
        });
        $("#font-size-plus").click(function() {
            checkPosition();
            curSize = parseFloat(localStorage.getItem("ficstyle_fontSize")) + 2.5;
            $(chapters).css("font-size", curSize+"%");
            localStorage.setItem("ficstyle_fontSize", curSize);
            returnBack();
        });

        var curWidth;
        $("#chapter-width-minus").click(function() {
            checkPosition();
            curWidth = parseInt(localStorage.getItem("ficstyle_chapterWidth")) - 10;
            if(curWidth < 10) { curWidth = 10; }
            $(chapters).css("width", curWidth+"%");
            localStorage.setItem("ficstyle_chapterWidth", curWidth);
            returnBack();
        });
        $("#chapter-width-plus").click(function() {
            checkPosition();
            curWidth = parseInt(localStorage.getItem("ficstyle_chapterWidth")) + 10;
            if(curWidth > 90) { curWidth = 90; }
            $(chapters).css("width", curWidth+"%");
            localStorage.setItem("ficstyle_chapterWidth", curWidth);
            returnBack();
        });

        // full screen mode
        $workskin = $("#workskin");

        $divbuttonsFS = $("<div class='actions' style='float: right; margin-bottom: 50px'></div>");

        $fullScreen = $("<div>", {id: "full-screen", html: "<a>Full Screen &#9635;</a>"});
        $gobook = $("<div>", {id: "go-to-book", html: "<a>Go to Bookmark</a>"});
        $deletebook = $("<div>", {id: "delete-book", html: "<a>Delete Bookmark</a>"});
        $divbuttonsFS
        .append($gobook.hide())
        .append($deletebook.hide())
        .append($fullScreen);
        $("#workskin > div:nth-child(1)").prepend($divbuttonsFS);

        $scrollT = $("<div class='ficleft'><a id='arrow'>&#8593;</a> <a id='bookmark' style='font-size: 70%; letter-spacing: -1px'>set bookmark</a></div>");
        $("body").append($scrollT.hide());

        if ( $("#main > div.work > div.wrapper").length ) {
            $wrapper = $("#main > div.work > div.wrapper");
        } else { $wrapper = $("#main > div.wrapper"); }

        // changes to create full screen mode
        var fullscreen = false,
            fullScreenTrue = function() {
                $("#outer").children().hide();
                $("body").append($workskin);

                $("#workskin .preface .userstuff").addClass("notes-hidden");          
                $("#workskin .preface .summary h3, #workskin .preface .notes h3").addClass("notes-headings")
                .each(function() { var text = $(this).text(); text = text.replace(":", ""); $(this).text(text); });
                $("#workskin .preface .notes h3").siblings(".jump").removeClass("jump").addClass("userstuff notes-hidden");
                $("div.preface .module").css({ "width": "10%", "margin": "auto", "padding": "0" });

                $divbuttonsFS.css("font-size", "80%");
                $fullScreen.children("a").prepend("Exit from ");
                $scrollT.show();                
                if ( Bookmarks.checkIfExist() ) {
                    $deletebook.show();
                    $gobook.show();
                }

                $(document).scrollTop(0);

                $workskin.append($("#feedback > ul.actions").css({ "font-size": "80%", "width": "100%", "padding": " 0 0 10px 0" }));
                $("#workskin > ul.actions > li:nth-child(1), #show_comments_link").remove();

                fullscreen = true;
            };

        $("#workskin .preface .module").click(function() { // show/hide summary and notes
            $(this).children(".userstuff.notes-hidden").fadeToggle(300);
        });

        $("#full-screen").click(function() { // open/close full screen mode
            if ( !fullscreen ) {
                fullScreenTrue();
            } else {
                window.location.reload();
            }
        });

        $("#arrow").click(function() { // go to top
            $("html, body").animate({scrollTop:0}, 900);
        });

        $("#bookmark").click(function() { // set new bookmark
            Bookmarks.getNew();
            $deletebook.show();
            $gobook.show();
            $span = $("<span style='margin-left: 5px; font-family: sans-serif; color: #900;'>&#10004;</span>")
            .appendTo( $(this) );
            setTimeout(function() {
                $span.remove();
            }, 1000);
        });

        $("#go-to-book").click(function() { // go to the position of the bookmark
            var book = Bookmarks.checkIfExist("book");
            $("html, body").animate({scrollTop:book}, 900);
        });

        $("#delete-book").click(function() { // delete bookmark
            var newBookmarks = Bookmarks.cancel();
            localStorage.setItem("ficstyle_bookmarks", newBookmarks);
            $deletebook.hide();
            $gobook.hide();
        });

    } // end of regex

})(window.jQuery);