RR Continue Reading Anywhere

When viewing any chapter on Royal Road, this will add a button to continue reading from your current place in the story.

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

// ==UserScript==
// @name         RR Continue Reading Anywhere
// @namespace    ultrabenosaurus.RoyalRoad
// @version      0.1
// @description  When viewing any chapter on Royal Road, this will add a button to continue reading from your current place in the story.
// @author       Ultrabenosaurus
// @source       https://greasyfork.org/en/users/437117-ultrabenosaurus?sort=name
// @match        https://www.royalroad.com/fiction/*/*/chapter/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var ficHome = window.location.pathname.split("/chapter/")[0];
    if(document.querySelectorAll('div.row.fic-header div.row div.fic-buttons a.btn-primary[href="'+ficHome+'"]').length!=0){
        UBaddContinueReadingAnywhereButton();
    }
    ficHome = null;
})();

function UBaddContinueReadingAnywhereButton() {
    var btnElem = '<a id="UBcontinueReadingAnywhere" href="javascript:void(0);" class="btn btn-block btn-primary margin-bottom-5"><i class="fa fa-play-circle"></i>&nbsp;&nbsp;Continue Reading</a>';
    document.querySelectorAll('div.row.fic-header div.row div.fic-buttons')[0].insertAdjacentHTML("beforeend", btnElem);

    var yccBtn = document.getElementById('UBcontinueReadingAnywhere');
    if(yccBtn){
        yccBtn.addEventListener("click", UBcontinueReadingAnywhere, false);
    }
    yccBtn = btnElem = null;
}

function UBcontinueReadingAnywhere() {
    $.ajax({
        type: "GET",
        url: document.querySelectorAll('div.row.fic-header div.fic-buttons a.btn-primary')[0].href,
        success: function(t){
            var fictionPage = document.implementation.createHTMLDocument();
            fictionPage.body.innerHTML = t;
            var a = fictionPage.querySelector("a.btn.btn-lg.btn-primary");
            window.location.href = a.href;
            a = fictionPage = null;
        }
    });
}