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.

  1. // ==UserScript==
  2. // @name RR Continue Reading Anywhere
  3. // @namespace ultrabenosaurus.RoyalRoad
  4. // @version 0.8
  5. // @description When viewing any chapter on Royal Road, this will add a button to continue reading from your current place in the story.
  6. // @author Ultrabenosaurus
  7. // @license GNU AGPLv3
  8. // @source https://greasyfork.org/en/users/437117-ultrabenosaurus?sort=name
  9. // @match https://www.royalroad.com/fiction/*/*/chapter/*
  10. // @icon https://www.google.com/s2/favicons?domain=royalroad.com
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. var ficHome = window.location.pathname.split("/chapter/")[0].split("/");
  18. ficHome.pop();
  19. ficHome = ficHome.join("/");
  20. if(document.querySelectorAll('div.row.fic-header div.row div.fic-buttons a.btn-primary[href^="'+ficHome+'"]').length!=0){
  21. UBaddContinueReadingAnywhereButton();
  22. }
  23. ficHome = null;
  24. })();
  25.  
  26. function UBaddContinueReadingAnywhereButton() {
  27. 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>';
  28. document.querySelectorAll('div.row.fic-header div.row div.fic-buttons')[0].insertAdjacentHTML("beforeend", btnElem);
  29.  
  30. for(var i=document.querySelectorAll('div.chapter-inner.chapter-content ~ hr ~ div.row .btn.btn-primary.col-xs-4').length;i--;i>0){
  31. document.querySelectorAll('div.chapter-inner.chapter-content ~ hr ~ div.row .btn.btn-primary.col-xs-4')[i].className = "btn btn-primary col-xs-3";
  32. }
  33.  
  34. btnElem = '<a id="UBcontinueReadingAnywhereBTM" href="javascript:void(0);" class="btn btn-primary col-xs-3">Continue <br class="visible-xs">Reading</a>';
  35. document.querySelectorAll('div.chapter-inner.chapter-content ~ hr ~ div.row .btn.btn-primary.col-xs-3')[1].insertAdjacentHTML("afterend", btnElem);
  36.  
  37. var yccBtn = document.getElementById('UBcontinueReadingAnywhere');
  38. if(yccBtn){
  39. yccBtn.addEventListener("click", UBcontinueReadingAnywhere, false);
  40. }
  41. yccBtn = document.getElementById('UBcontinueReadingAnywhereBTM');
  42. if(yccBtn){
  43. yccBtn.addEventListener("click", UBcontinueReadingAnywhere, false);
  44. }
  45. yccBtn = btnElem = null;
  46. }
  47.  
  48. function UBcontinueReadingAnywhere() {
  49. $.ajax({
  50. type: "GET",
  51. url: document.querySelectorAll('div.row.fic-header div.fic-buttons a.btn-primary')[0].href,
  52. success: function(t){
  53. var fictionPage = document.implementation.createHTMLDocument();
  54. fictionPage.body.innerHTML = t;
  55. var a = fictionPage.querySelector("a.btn.btn-lg.btn-primary");
  56. window.location.href = a.href;
  57. a = fictionPage = null;
  58. },
  59. error: function (request, status, error) {
  60. console.error("--RR Continue Reading Anywhere--");
  61. console.error("Failed to determine the proper chapter URL; below are the AJAX error details.");
  62. console.error("Request object:");
  63. console.error(request);
  64. console.error("Status: "+(status||"null"));
  65. console.error("HTTP Error: "+(error||"null"));
  66. console.error("--RR Continue Reading Anywhere--");
  67. }
  68. });
  69. }