漫画下一话

x键下一话,滑轮到底下一话,支持非下拉式转下拉式阅读

  1. // ==UserScript==
  2. // @name 漫画下一话
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.24
  5. // @description x键下一话,滑轮到底下一话,支持非下拉式转下拉式阅读
  6. // @author You
  7. // @match https://www.2mzx.com/manhua/*
  8. // @match https://manga.bilibili.com/*
  9. // @match http://www.6mh7.com/*
  10. // @match http://www.manhuaju.com/*
  11. // @match https://www.kanbl.cc/chapter/*
  12. // @license MIT
  13. // @grant unsafeWindow
  14. // @run-at document-end
  15. // ==/UserScript==
  16.  
  17. (function() {
  18. let window = unsafeWindow
  19. //对应域名规则
  20. let ruler={
  21. //优先用button,然后是url切换下一话
  22. 'www.2mzx.com':{//下拉式
  23. 'add_button':"body > div:nth-child(14) > a.next",//修改某个按钮为下一话,可选
  24. 'next_button_or_function':'',//已有的下一话button或者函数,没有为空,如果是函数,结尾必须为(),用于切换下一页时点击或执行,与url至少有一个
  25. 'url':/(\d+)\.html/,//下一话url,用于切换下一页,没有为空,与next_button至少有一个
  26. 'min_height':10000,//最小文档高度,小于此高度时,认为没有划到底
  27. 'observer':'',//出现时换页 [出现的对象,另外的验证方法]
  28. },
  29. 'manga.bilibili.com':{//自建frame
  30. 'add_button':"",
  31. 'next_button_or_function':"div.load-next-btn-container > button",
  32. 'url':/\/(\d+)/,
  33. 'min_height':0,
  34. 'observer':["div.load-next-btn-container > button",function(){return(/\d+/.exec(document.querySelector(" div.ps__rail-y > div").style.top)[0]>200)}] //出现时换页 [出现的对象,另外的验证方法] 弃用 ->//监控scroll无效时[对象,属性,值]
  35. },
  36. 'www.6mh7.com':{//下拉式
  37. 'add_button':"",
  38. 'next_button_or_function':"#mainControlNext",
  39. 'url':/(\d+)\.html/,
  40. 'min_height':0,
  41. 'observer':["#mainControlNext",function(){return(document.querySelector("#comicContain").childElementCount>=1)}] //出现时换页 [下页按钮出现时,已经加载至少1张图片] 弃用 ->//监控scroll无效时[对象,属性,值]
  42. },
  43. 'www.manhuaju.com':{//单页阅读式漫画
  44. 'init':function(){//初始化函数,页面加载后将先进行,将单页阅读的漫画改为下拉式阅读
  45. let urls = window.qTcms_S_m_murl;
  46. urls=urls.split("$qingtiandy$")
  47. let s=''
  48. for(let i of urls){
  49. s+='<img width="1200" src="'+i+'">'
  50. }
  51. document.querySelector("#qTcms_Pic_middle > tbody > tr > td").innerHTML=s},
  52. 'add_button':"",
  53. 'next_button_or_function':"a_f_qTcms_Pic_nextarr_Href()",//下一话为执行函数
  54. 'url':'',
  55. 'min_height':0,
  56. 'observer':["div.footer",function(){return(document.querySelector("#qTcms_Pic_middle > tbody > tr > td").childElementCount>=2)}] //出现时换页 [下页按钮出现时,已经加载至少2张图片] 弃用 ->//监控scroll无效时[对象,属性,值]
  57. },
  58. 'www.kanbl.cc':{
  59. // 'init':function(){alert(1)},//不需要初始化
  60. 'add_button':"",
  61. 'tmpfunction': function(){//因为这个网站比较复杂,写个函数来操作下一页,函数名随意,在next_button_or_function调用
  62. let page = document.querySelector("body > div.container > div.footpage > select");
  63. if(page.childElementCount == Number(page.value)){
  64. //最後一頁
  65. document.querySelector("body > div.container > div.footpage > a.btn.nextpage").click();
  66. }else{
  67. let url = window.location.origin+window.location.pathname;
  68. let nexturl = url+'?page='+(Number(page.value)+1);
  69. window.location.href = nexturl;
  70. }
  71. },
  72. 'next_button_or_function':"ruler['www.kanbl.cc']['tmpfunction']()",//下一话为执行函数
  73. 'url':'',
  74. 'min_height':0,
  75. 'observer':["div.footpage",function(){return(document.querySelector("#content > div.comiclist").childElementCount>=1)}] //出现时换页 [下页按钮出现时,已经加载至少2张图片]
  76. },
  77. }
  78.  
  79.  
  80.  
  81. ///////////////////////////////////////////////// main ///////////////////////////////////////////////////////
  82. // 滚动条在Y轴上的滚动距离
  83. function getScrollTop() {
  84. var scrollTop = 0, bodyScrollTop = 0, documentScrollTop = 0;
  85. if (document.body) {
  86. bodyScrollTop = document.body.scrollTop;
  87. }
  88. if (document.documentElement) {
  89. documentScrollTop = document.documentElement.scrollTop;
  90. }
  91. scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop;
  92. return scrollTop;
  93. }
  94.  
  95. // 文档的总高度
  96. function getScrollHeight() {
  97. var scrollHeight = 0, bodyScrollHeight = 0, documentScrollHeight = 0;
  98. if (document.body) {
  99. bodyScrollHeight = document.body.scrollHeight;
  100. }
  101. if (document.documentElement) {
  102. documentScrollHeight = document.documentElement.scrollHeight;
  103. }
  104. scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight;
  105. return scrollHeight;
  106. }
  107.  
  108. // 浏览器视口的高度
  109. function getWindowHeight() {
  110. var windowHeight = 0;
  111. if (document.compatMode == "CSS1Compat") {
  112. windowHeight = document.documentElement.clientHeight;
  113. } else {
  114. windowHeight = document.body.clientHeight;
  115. }
  116. return windowHeight;
  117. }
  118.  
  119. // 距离底部 px 距离返回 true
  120. function ifBottom() {
  121. if (getScrollTop() + getWindowHeight()>= getScrollHeight()) {
  122. return true;
  123. }
  124. return false;
  125. }
  126. function isString(str){
  127. return (typeof str=='string')&&str.constructor==String;
  128. }
  129. function checkInPage(){//是否出现在页面上
  130. let el = document.querySelector(data.observer[0])
  131. const pageHeight = document.documentElement.clientHeight
  132.  
  133. const contentTop = el.getBoundingClientRect().top
  134. const contentHeight = el.offsetHeight
  135. return (contentTop<pageHeight && contentTop>=0) || (contentTop<0 && (contentTop+contentHeight>0));
  136. }
  137. function wheel(event){
  138. var delta = 0;
  139. if (!event) event = window.event;
  140. if (event.wheelDelta) {//IE、chrome浏览器使用的是wheelDelta,并且值为“正负120”
  141. delta = event.wheelDelta/120;
  142. if (window.opera) delta = -delta;//因为IE、chrome等向下滚动是负值,FF是正值,为了处理一致性,在此取反处理
  143. } else if (event.detail) {//FF浏览器使用的是detail,其值为“正负3”
  144. delta = -event.detail/3;
  145. }//上下滚动时的具体处理函数
  146. if(delta){
  147. if(checkInPage() &&data.observer[1]()){
  148. window.nextp()
  149.  
  150. }
  151. };
  152. }
  153. function observe_wheel(){ //监控滚轮,出现某对象时调用方法
  154. if(window.addEventListener)//FF,火狐浏览器会识别该方法
  155. {window.addEventListener('DOMMouseScroll', wheel, false);
  156. window.onmousewheel = document.onmousewheel = wheel;//W3C
  157. }
  158. }
  159. /* 弃用--->>>>> setTimeout(()=>{//延时加载监控某属性值
  160. let item=data.observer
  161. var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
  162. let pass = setInterval(function() {
  163. var element = document.querySelector(item[0]);
  164. if (element) {
  165. clearInterval(pass)
  166. var observer = new MutationObserver(function(mutations) {
  167. console.log(element.style.top)
  168. if(isString(item[2])){
  169. if(element.style.top==item[2]){//达到监控值
  170. window.next()
  171. }
  172. }else{
  173. if(element.style.top>=item[2]){//达到监控值
  174. window.next()
  175. }
  176. }
  177. });
  178. observer.observe(element, {
  179. attributes: true,
  180. attributeFilter: ['style']
  181. });
  182. }})
  183. },3000) */
  184. ///////////////////////////////////////////////// 开始执行 ///////////////////////////////////////////////////////
  185. let data = ruler[window.location.hostname]
  186. //执行初始化函数,如将原先单页阅读的改为下拉式的
  187. if(data.init){data.init()}
  188.  
  189. window.nextp = function(){//注册(不可用)全局方法
  190. //通过点击button或者改变url来换下一页
  191. if(data.next_button_or_function){
  192. if(data.next_button_or_function.indexOf('()')>-1){//function
  193. eval(data.next_button_or_function)
  194. }else{//btn
  195. document.querySelector(data.next_button_or_function).click()
  196. }
  197. }else if(data.url){
  198. let tmp = data.url.exec(window.location.href)[1] //去除要改变的url
  199. window.location.href = window.location.href.replace(tmp,String(parseInt(tmp)+1))//数字加一,下一话
  200. }else{
  201. console.log('!!!!!!!!!!!!error:没有配置下一话的操作')
  202. return
  203. }
  204. }
  205. //统一处理滚轮滚动事件
  206. //滑到底加载下一话,有的需要监控某值,其他默认为监控scroll划到底
  207. if(data.observer){
  208. setTimeout(
  209. observe_wheel//滚轮出现某元素时下一话
  210. ,5000)
  211. }else{
  212. window.document.addEventListener("scroll", function(){
  213. console.log(ifBottom(),getScrollHeight(),data.min_height)
  214. if(ifBottom() && (getScrollHeight()>=(data.min_height|| 1))){
  215. window.nextp()
  216. }
  217. })
  218. }
  219.  
  220.  
  221. //改变button
  222. if(data.add_button){
  223. document.querySelector(data.add_button).href = "javascript:nextp()"
  224. }
  225. //添加按键侦听 x键下一话
  226. window.document.addEventListener("keydown", function(event){
  227. if(window.event.keyCode==88){
  228. window.nextp()
  229. }
  230. }
  231.  
  232. )
  233. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址