EXH预加载脚本

用于对ex站预加载,看本更流畅(滑稽

  1. // ==UserScript==
  2. // @name EXH预加载脚本
  3. // @namespace http://tampermonkey.net/
  4. // @version 5.0
  5. // @description 用于对ex站预加载,看本更流畅(滑稽
  6. // @author Mmx
  7. // @match https://exhentai.org/s/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. 'use strict';
  13. var imgg = document.getElementById('img');
  14. var next = document.getElementById('next');
  15. if (window.frames.length == parent.frames.length) { //母页
  16. //初始化提示信息
  17. var load_data = document.createElement('div');
  18. load_data.setAttribute("style", "position: absolute; width: 100%; z-index: 998; margin-top: 90px;");
  19. load_data.innerHTML = '<a>预加载已开始 :: </a><a id="data2">已加载好0页 :: </a><a id="data3">第N页已载入</a>';
  20. var temp = document.getElementById('i2').getElementsByTagName('div')[2];
  21. document.styleSheets[0].insertRule('#i2>.sn+div{margin-bottom:' + (temp.offsetHeight + 2) + 'px;}', 0);
  22. load_data.style.marginTop = (temp.offsetHeight + temp.offsetTop + 1) + 'px';
  23. document.body.insertBefore(load_data, document.getElementById('i1'));
  24.  
  25. //创建iframe
  26. window["preload_count"] = 0; //预加载计数
  27. var newi = document.createElement("iframe");
  28. newi.hidden = "hidden";
  29. newi.src = next.href;
  30. if (window.complete) document.body.appendChild(newi);
  31. else window.addEventListener("load", () => {
  32. document.body.appendChild(newi)
  33. });
  34.  
  35. //更新提示通道
  36. window["preload_count"] = 0; // 计数
  37. window["preload_message"] = (page) => {
  38. preload_count++;
  39. document.getElementById("data2").innerHTML = "已加载好" + preload_count + "页 :: ";
  40. document.getElementById("data3").innerHTML = "第" + page + "页已载入";
  41. }
  42.  
  43. //图片强制缓存机制
  44. window["preload_imgs"] = []; //图片信息
  45. window["preload_force"] = (id) => { //强制缓存
  46. temp = document.createElement("img");
  47. temp.hidden = "hidden";
  48. temp.src = preload_imgs[id];
  49. document.body.appendChild(temp);
  50. }
  51.  
  52. } else { //子页
  53. var NextButton = document.getElementById("next");
  54.  
  55. function NextPage() {
  56. if (location.href.split('?')[0] == NextButton.href.split('?')[0]) { //加载完毕
  57.  
  58. return
  59. }
  60. window["_load_image"] = (e, f, d) => { //解除加载频率限制
  61. return true;
  62. }
  63. NextButton.click();
  64. window["load_image_dispatch"] = () => { //回调
  65. var a = api_response(dispatch_xhr);
  66. if (a != false) {
  67. if (a.error != undefined) {
  68. document.location = document.location + ""
  69. } else {
  70. history.replaceState({
  71. page: a.p,
  72. imgkey: a.k,
  73. json: a,
  74. expire: get_unixtime() + 300
  75. }, document.title, base_url + a.s);
  76. apply_json_state(a)
  77. work();
  78. }
  79. dispatch_xhr = undefined
  80. }
  81. }
  82. }
  83.  
  84. window["work"] = () => {
  85. var this_page = location.pathname.split("-")[1];
  86. var imgg = document.getElementById('img');
  87. parent.preload_imgs[this_page] = imgg.src;
  88. parent.preload_force(this_page);
  89. parent.preload_message(this_page);
  90. if (imgg.complete) NextPage();
  91. else imgg.addEventListener("load", NextPage);
  92. }
  93. work();
  94. }
  95. })();