RR Continue Reading From Old Chapter

When viewing a chapter you have read before on Royal Road, this will add a button to continue reading from your actual place in the story.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         RR Continue Reading From Old Chapter
// @namespace    ultrabenosaurus.RoyalRoad
// @version      0.4
// @description  When viewing a chapter you have read before on Royal Road, this will add a button to continue reading from your actual place in the story.
// @author       Ultrabenosaurus
// @license      GNU AGPLv3
// @source       https://greasyfork.org/en/users/437117-ultrabenosaurus?sort=name
// @match        https://www.royalroad.com/fiction/*/*/chapter/*
// @icon         https://www.google.com/s2/favicons?domain=royalroad.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    if(document.querySelectorAll('div#rewind-container form.rewind-form button.btn.btn-primary').length!=0){
        UBaddContinueReadingButton();
    }
})();

function UBaddContinueReadingButton() {
    var btnElem = '<div class="col-xs-12 col-sm-4 col-md-3 col-lg-2 col-xl-2"><a id="UByourCurrentChapter" href="javascript:void(0);" class="btn btn-sm btn-primary" style="margin-top: -5px;"><i class="fa fa-play-circle"></i>&nbsp;&nbsp;Continue Reading</a></div>';
    document.querySelectorAll('div#rewind-container div div.row div[class^="col-"]:first-child')[0].className = "col-xs-12 col-sm-8 col-md-6 col-lg-8 text-center";
    document.querySelectorAll('div#rewind-container div div.row div[class^="col-"]:first-child')[0].insertAdjacentHTML("beforebegin", btnElem);

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

function UByourCurrentChapter() {
    $.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;
        }
    });
}