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.

当前为 2022-02-18 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name RR Continue Reading Anywhere
  3. // @namespace ultrabenosaurus.RoyalRoad
  4. // @version 0.6
  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];
  18. if(document.querySelectorAll('div.row.fic-header div.row div.fic-buttons a.btn-primary[href="'+ficHome+'"]').length!=0){
  19. UBaddContinueReadingAnywhereButton();
  20. }
  21. ficHome = null;
  22. })();
  23.  
  24. function UBaddContinueReadingAnywhereButton() {
  25. 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>';
  26. document.querySelectorAll('div.row.fic-header div.row div.fic-buttons')[0].insertAdjacentHTML("beforeend", btnElem);
  27.  
  28. for(var i=document.querySelectorAll('div.chapter-inner.chapter-content + hr + div.row a.btn.btn-primary.col-xs-4').length;i--;i>0){
  29. document.querySelectorAll('div.chapter-inner.chapter-content + hr + div.row a.btn.btn-primary.col-xs-4')[i].className = "btn btn-primary col-xs-3";
  30. }
  31.  
  32. btnElem = '<a id="UBcontinueReadingAnywhereBTM" href="javascript:void(0);" class="btn btn-primary col-xs-3">Continue <br class="visible-xs">Reading</a>';
  33. document.querySelectorAll('div.chapter-inner.chapter-content + hr + div.row a.btn.btn-primary.col-xs-3')[1].insertAdjacentHTML("afterend", btnElem);
  34.  
  35. var yccBtn = document.getElementById('UBcontinueReadingAnywhere');
  36. if(yccBtn){
  37. yccBtn.addEventListener("click", UBcontinueReadingAnywhere, false);
  38. }
  39. yccBtn = document.getElementById('UBcontinueReadingAnywhereBTM');
  40. if(yccBtn){
  41. yccBtn.addEventListener("click", UBcontinueReadingAnywhere, false);
  42. }
  43. yccBtn = btnElem = null;
  44. }
  45.  
  46. function UBcontinueReadingAnywhere() {
  47. $.ajax({
  48. type: "GET",
  49. url: document.querySelectorAll('div.row.fic-header div.fic-buttons a.btn-primary')[0].href,
  50. success: function(t){
  51. var fictionPage = document.implementation.createHTMLDocument();
  52. fictionPage.body.innerHTML = t;
  53. var a = fictionPage.querySelector("a.btn.btn-lg.btn-primary");
  54. window.location.href = a.href;
  55. a = fictionPage = null;
  56. },
  57. error: function (request, status, error) {
  58. console.error("--RR Continue Reading Anywhere--");
  59. console.error("Failed to determine the proper chapter URL; below are the AJAX error details.");
  60. console.error("Request object:");
  61. console.error(request);
  62. console.error("Status: "+(status||"null"));
  63. console.error("HTTP Error: "+(error||"null"));
  64. console.error("--RR Continue Reading Anywhere--");
  65. }
  66. });
  67. }