NU Scroll To Chapter List

Make NovelUpdates scroll to the chapter list automatically when you click on pagination

目前為 2020-05-30 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name NU Scroll To Chapter List
  3. // @namespace ultrabenosaurus.novelupdates
  4. // @version 0.6
  5. // @description Make NovelUpdates scroll to the chapter list automatically when you click on pagination
  6. // @author Ultrabenosaurus
  7. // @source https://greasyfork.org/en/users/437117-ultrabenosaurus?sort=name
  8. // @match https://www.novelupdates.com/series/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. UBaddHash();
  16. UBaddPageOne();
  17. UBaddChapterHomeButton();
  18.  
  19. setTimeout(function(){
  20. if(UBgetCookie('UBpaginationUpdated')!=""){
  21. UBaddHash();
  22. UBaddPageOne();
  23. UBaddChapterHomeButton();
  24. UBsetCookie('UBpaginationUpdated','',-30);
  25. }
  26. }, 2000);
  27. })();
  28.  
  29. function UBaddHash(){
  30. var pages=document.querySelectorAll('.digg_pagination>a');
  31. var pLength=pages.length;
  32. for(var i=0;i<pLength;i++){
  33. if(pages[i].hash.split("#myTable").length!=2){
  34. pages[i].hash+="#myTable";
  35. }
  36. }
  37. pages=null;
  38. pLength=null;
  39. i=null;
  40. }
  41. function UBaddPageOne(){
  42. if(document.querySelectorAll('.digg_pagination>a.previous_page').length>0){
  43. document.querySelectorAll('.digg_pagination>a:nth-child(2)')[0].search="pg=1";
  44. }
  45. }
  46. function UBaddChapterHomeButton(){
  47. var hbCSS = "<style>#chBtn::before {content:'';position:relative;top:1px;float:left;width:12px;height:12px;margin-top:0.5em;background:url(/wp-content/themes/ndupdates-child/js/gh-icons.png) 0 99px no-repeat;background-position:0 -168px;}</style>";
  48. document.querySelectorAll('div.digg_pagination')[0].insertAdjacentHTML("afterbegin", hbCSS);
  49. var hbElem = "<a href='"+location.pathname+"' id='chBtn'>&nbsp;</a>";
  50. document.querySelectorAll('div.digg_pagination')[0].insertAdjacentHTML("afterbegin", hbElem);
  51. }
  52.  
  53. function UBsetCookie(cname, cvalue, exdays) {
  54. var d = new Date();
  55. d.setTime(d.getTime() + (exdays*24*60*60*1000));
  56. var expires = "expires="+ d.toUTCString();
  57. document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
  58. }
  59. function UBgetCookie(cname) {
  60. var name = cname + "=";
  61. var decodedCookie = decodeURIComponent(document.cookie);
  62. var ca = decodedCookie.split(';');
  63. for(var i = 0; i <ca.length; i++) {
  64. var c = ca[i];
  65. while (c.charAt(0) == ' ') {
  66. c = c.substring(1);
  67. }
  68. if (c.indexOf(name) == 0) {
  69. return c.substring(name.length, c.length);
  70. }
  71. }
  72. return "";
  73. }