东方永页机

自动加载并拼接下一分页内容(适用于论坛、漫画站、小说站、资讯站、博客等),无需规则支持所有网页

当前为 2022-03-10 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Pagetual
  3. // @name:zh-CN 东方永页机
  4. // @name:zh-TW 東方永頁機
  5. // @name:ja 東方永頁機
  6. // @name:ru Пейджетуал
  7. // @name:de Pagetual
  8. // @name:es Pagetual
  9. // @name:fr Pagetual
  10. // @name:it Pagetual
  11. // @name:ko 東方永頁機
  12. // @namespace hoothin
  13. // @version 1.5.6.9
  14. // @description Most compatible Auto pager script ever! Simply auto loading paginated web pages.
  15. // @description:zh-CN 自动加载并拼接下一分页内容(适用于论坛、漫画站、小说站、资讯站、博客等),无需规则支持所有网页
  16. // @description:zh-TW 自動加載並拼接下一分頁內容(適用於論壇、漫畫站、小說站、資訊站、博客等),無需規則支持所有網頁
  17. // @description:ja Webページを自動で読み込み継ぎ足し表示を行うブラウザ拡張です
  18. // @description:ru Просто автоматически загрузите следующую страницу
  19. // @description:de Laden Sie einfach automatisch die nächste Seite
  20. // @description:es Carga automática de páginas web paginadas
  21. // @description:fr Chargement automatique des pages Web paginées
  22. // @description:it Caricamento automatico di pagine Web impaginate
  23. // @description:ko 다음 페이지를 자동으로 로드하세요
  24. // @author hoothin
  25. // @include http://*
  26. // @include https://*
  27. // @license MIT
  28. // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAAdVBMVEUAAAD3VU33VU32VEz8U073VU32VU33VU32VUz0Uk/3VE32VU32VUz2VU32VU32VU32VU33VU33U0z2VU34Wkv3VE32VUz/mpj/nJj2VUz2VU32VE33VEz2VU32VU32VUz3VE32VEz3VE3/mZf2Vkz2VU3/mpilFFolAAAAJXRSTlMA3Lp/GvTBT5YQLuawZ/DOyZwlPQeKc21N04+FX1bqpm9DNoB4T68ePwAAAitJREFUWMPt1tuasiAUBuCFCG5Rs3QybTPV1/1f4v/3PDkyIojn8x5qBrI+ltAfh32/yysmBKvyXb+njb6bDL9kzTd5SzjDAsYT8nFoGSxYe6BVqoNDp2jFDit25BRgVUAODB4YWcETWVTwVNGiGN5iWtBgg4YMCpsoI38dNunmmWyxUTvbPwwbsYR0fIzZLQ0pTG8eieRmBLMmpdH9uimQEf6TNRnXXKLZHixpJtywLzOgMHtFCqdM64DahHRnOE1dsrekm9wr2WtLcAlpdHwcp1pAJySXYnERclzp4+v19jXdmcTvQUJtz+ZaI4i05/V/UGYrCxbaAsOYoNfIKEQxpqQuzCgJJJ/3f42O8ywEZuMVWi/8hODxGj3GW2b0udkbGULLDOjimAG0S3fLGlBnXQM9irG1CiQdVQi0dqQsOSDlyEEz7Vy9OxxfR71VCXsSB23jMrKJYZXSjw57sqgLn5Z0wolsOCz0RyJkyeYjgz7pwwVq20eboZwtVUl2EnN5gJ50dQZFdryATvABRTr/tJXkUMdaAK5pwtCapwtFLskguwuyMh/Sd9WChQ4sIvIUYSk3PYqQvCQlOC04IfN7PkdjOyRKWhdKXMmiAFt9i3sJ5jxoRuR0vqAghxxwHuqfQE5OHGDKOrwEnqs1DgAZ2e4Eev1d45TN7JfhrQLKgfwMFYAsvp33dXII073aVQLI2gN5S58lfmGnKKFtah7nkgnBZB7zlP7Y/QNiTM6sYNzawwAAAABJRU5ErkJggg==
  29. // @grant GM_xmlhttpRequest
  30. // @grant GM_registerMenuCommand
  31. // @grant GM_notification
  32. // @grant GM_getValue
  33. // @grant GM_setValue
  34. // @grant GM_addStyle
  35. // @grant GM_openInTab
  36. // @grant GM_deleteValue
  37. // @grant GM.xmlHttpRequest
  38. // @grant GM.registerMenuCommand
  39. // @grant GM.notification
  40. // @grant GM.getValue
  41. // @grant GM.setValue
  42. // @grant GM.addStyle
  43. // @grant GM.openInTab
  44. // @grant GM.deleteValue
  45. // @supportURL https://github.com/hoothin/UserScripts/issues
  46. // @connect wedata.net
  47. // @connect githubusercontent.com
  48. // @run-at document-idle
  49. // @exclude http://www.toodledo.com/tasks/*
  50. // @exclude http*://maps.google.com*/*
  51. // @exclude *://www.google.*/_/chrome/newtab*
  52. // @exclude *://mega.*/*
  53. // @exclude *://*.mega.*/*
  54. // @exclude *://*.youku.com/v_*
  55. // @exclude *://*pan.baidu.com
  56. // @exclude *://*.iqiyi.com/v_*
  57. // @exclude *://*.iqiyi.com/w_*
  58. // @exclude *://*.iqiyi.com/a_*
  59. // @exclude *://*.le.com/ptv/vplay/*
  60. // @exclude *://v.qq.com/x/cover/*
  61. // @exclude *://v.qq.com/x/page/*
  62. // @exclude *://v.qq.com/tv/*
  63. // @exclude *://*.tudou.com/listplay/*
  64. // @exclude *://*.tudou.com/albumplay/*
  65. // @exclude *://*.tudou.com/programs/view/*
  66. // @exclude *://*.mgtv.com/b/*
  67. // @exclude *://film.sohu.com/album/*
  68. // @exclude *://tv.sohu.com/v/*
  69. // @exclude *://*.bilibili.com/video/*
  70. // @exclude *://*.bilibili.com/bangumi/play/*
  71. // @exclude *://*.baofeng.com/play/*
  72. // @exclude *://vip.pptv.com/show/*
  73. // @exclude *://v.pptv.com/show/*
  74. // @exclude *://www.le.com/ptv/vplay/*
  75. // @exclude *://www.wasu.cn/Play/show/*
  76. // @exclude *://m.v.qq.com/*
  77. // @exclude *://m.iqiyi.com/*
  78. // @exclude *://m.youku.com/alipay_video/*
  79. // @exclude *://m.mgtv.com/b/*
  80. // @exclude *://m.tv.sohu.com/v/*
  81. // @exclude *://m.film.sohu.com/album/*
  82. // @exclude *://m.le.com/ptv/vplay/*
  83. // @exclude *://m.pptv.com/show/*
  84. // @exclude *://m.acfun.cn/v/*
  85. // @exclude *://m.bilibili.com/video/*
  86. // @exclude *://m.bilibili.com/anime/*
  87. // @exclude *://m.bilibili.com/bangumi/play/*
  88. // @exclude *://m.wasu.cn/Play/show/*
  89. // @exclude *://www.youtube.com
  90. // @exclude *://www.youtube.com/
  91. // @exclude *://www.youtube.com/watch*
  92. // @exclude *://baike.baidu.com/*
  93. // @exclude *://*.instagram.com/*
  94. // @exclude *://order.jd.com/*
  95. // @exclude *://pagetual.hoothin.com/*
  96. // @exclude *://hoothin.github.io/PagetualGuide/*
  97. // @connect *
  98. // ==/UserScript==
  99.  
  100. (function() {
  101. 'use strict';
  102.  
  103. if (window.name === 'pagetual-iframe' || (window.frameElement && window.frameElement.name === 'pagetual-iframe')) {
  104. var domloaded = function (){
  105. window.scroll(window.scrollX, 999999);
  106. window.scroll(window.scrollY, 999999);
  107. //window.parent.postMessage('pagetual-iframe:DOMLoaded', '*');
  108. };
  109. if(window.opera){
  110. document.addEventListener('DOMContentLoaded', domloaded, false);
  111. } else {
  112. domloaded();
  113. }
  114. return;
  115. }
  116.  
  117. if(window.top != window.self){
  118. try{
  119. if (top.location.hostname != window.location.hostname || window.top != window.parent) {
  120. return;
  121. }
  122. }catch(e){
  123. return;
  124. }
  125. }
  126.  
  127. const lang = navigator.appName=="Netscape"?navigator.language:navigator.userLanguage;
  128. var i18n=(name, param)=>{
  129. let config={};
  130. switch (lang){
  131. case "zh-CN":
  132. case "zh-SG":
  133. config={
  134. enableDebug:"调试模式,输出信息至控制台",
  135. disable:"暂时禁用",
  136. disableSite:"在此站禁用",
  137. enable:"启用翻页",
  138. toTop:"回到顶部",
  139. toBottom:"前往页尾",
  140. current:"当前页",
  141. forceIframe:"强制拼接",
  142. cancelForceIframe:"取消强制拼接",
  143. configure:"打开配置页",
  144. firstUpdate:"点击此处初始化规则",
  145. update:"更新规则",
  146. click2update:"点击立即更新规则",
  147. loadNow:"立即翻页",
  148. loadConfirm:"要翻几页?(0为不间断)",
  149. noNext:"没有找到下一页,请新建规则",
  150. passSec:"更新于 #t# 秒前",
  151. passMin:"更新于 #t# 分钟前",
  152. passHour:"更新于 #t# 小时前",
  153. passDay:"更新于 #t# 天前",
  154. cantDel:"无法删除内置规则",
  155. confirmDel:"是否确认要删除此规则?",
  156. updateSucc:"更新成功",
  157. beginUpdate:"正在更新,请稍候",
  158. customUrls:"导入规则url,一行一条,AutoPagerize 格式规则需要以\"0|\"开头",
  159. customRules:"输入【东方永页机】格式的自定义规则",
  160. save:"保存设置",
  161. loadingText:"少女祈祷中...",
  162. opacity:"分页隔条不透明值",
  163. hideBar:"空白处双击隐藏分页隔条",
  164. dbClick2Stop:"空白处双击暂停翻页",
  165. sortTitle:"排序在下次更新规则后生效",
  166. autoRun:"自动启用,否则为白名单模式",
  167. inputPageNum:"输入页码跳转",
  168. enableHistory:"翻页后写入历史记录",
  169. initRun:"打开页面后立即尝试翻页,否则滚动至页尾再翻页",
  170. preload:"翻页前预读下一页,加速浏览",
  171. click2ImportRule:"点击下方添加特殊规则库:"
  172. };
  173. break;
  174. case "zh-TW":
  175. case "zh-HK":
  176. config={
  177. enableDebug:"調試模式,輸出信息至控制台",
  178. disable:"暫時禁用",
  179. disableSite:"在此站禁用",
  180. enable:"啟用翻頁",
  181. toTop:"回到頂部",
  182. toBottom:"前往頁尾",
  183. current:"當前頁",
  184. forceIframe:"強制拼接",
  185. cancelForceIframe:"取消强制拼接",
  186. configure:"打開配置頁",
  187. firstUpdate:"點擊此處初始化規則",
  188. update:"更新規則",
  189. click2update:"點擊立即更新規則",
  190. loadNow:"立即翻頁",
  191. loadConfirm:"要翻几頁?(0為不間斷)",
  192. noNext:"沒有找到下一頁,請新建規則",
  193. passSec:"更新于 #t# 秒前",
  194. passMin:"更新于 #t# 分鐘前",
  195. passHour:"更新于 #t# 小時前",
  196. passDay:"更新于 #t# 天前",
  197. cantDel:"無法刪除内置規則",
  198. confirmDel:"是否確認要刪除此規則?",
  199. updateSucc:"更新成功",
  200. beginUpdate:"正在更新,請稍候",
  201. customUrls:"導入規則url,一行一條,AutoPagerize 格式規則需要以\"0|\"開頭",
  202. customRules:"輸入【東方永頁機】格式的自定義規則",
  203. save:"存儲設置",
  204. loadingText:"少女祈禱中...",
  205. opacity:"分頁隔條不透明值",
  206. hideBar:"空白處雙擊隱藏分頁隔條",
  207. dbClick2Stop:"空白處雙擊暫停翻頁",
  208. sortTitle:"排序在下次更新規則後生效",
  209. autoRun:"自動啓用,否則為白名單模式",
  210. inputPageNum:"輸入頁碼跳轉",
  211. enableHistory:"翻頁后寫入歷史記錄",
  212. initRun:"打開頁面后立即嘗試翻頁,否則滾動至頁尾再翻頁",
  213. preload:"翻頁前預讀下一頁,加速瀏覽",
  214. click2ImportRule:"點擊下方添加特殊規則庫:"
  215. };
  216. break;
  217. case "ja":
  218. config = {
  219. enableDebug:"デバッグモード",
  220. disable: "一時的に無効にする",
  221. disableSite:"このサイト無効",
  222. enable: "ページめくりを有効にする",
  223. toTop: "トップに戻る",
  224. toBottom: "ページの下部に移動",
  225. current: "現在のページ",
  226. forceIframe: "強制ステッチ",
  227. cancelForceIframe: "強制ステッチをキャンセル",
  228. configure: "設定ページを開く",
  229. firstUpdate:"ここをクリックしてルールを初期化します",
  230. update: "更新ルール",
  231. click2update:"今すぐルールを更新してください",
  232. loadNow:"今すぐページをめくる",
  233. loadConfirm:"数ページめくりたいですか?(0は途切れない)",
  234. noNext:"次のページが見つかりません、新しいルールを作成してください",
  235. passSec: "#t#秒前に更新",
  236. passMin: "#t#分前に更新",
  237. passHour: "#t#時間前に更新",
  238. passDay: "#t#日前に更新",
  239. cantDel: "組み込みルールを削除できません",
  240. confirmDel: "このルールを削除してもよろしいですか?",
  241. updateSucc: "更新に成功しました",
  242. beginUpdate: "更新中、お待ちください",
  243. customUrls: "インポートルールのURL、1行に1つ、AutoPagerizeフォーマットルールは\"0|\"で始まる必要があります",
  244. customRules: "【東方永頁機】の形式でカスタムルールを入力してください",
  245. save: "設定を保存",
  246. loadingText: "少女祈祷中...",
  247. opacity:"ページネーションバーの不透明値",
  248. hideBar:"空白部分をダブルクリックして、ページ区切り文字を非表示にします",
  249. dbClick2Stop:"空白部分をダブルクリックしてページめくりを一時停止します",
  250. sortTitle:"並べ替えは、次のルールの更新後に有効になります",
  251. autoRun:"自動的に有効",
  252. inputPageNum:"ジャンプするページ番号を入力",
  253. enableHistory:"ページめくり後の履歴を書く",
  254. initRun:"Webページを開いた直後にページをめくる",
  255. preload:"事前に次のページを読む",
  256. click2ImportRule:"以下をクリックして、ルールベースを追加します:"
  257. };
  258. break;
  259. default:
  260. config={
  261. enableDebug:"Enable debug output",
  262. disable:"Disable",
  263. disableSite:"Disable on the site",
  264. enable:"Enable",
  265. toTop:"To Top",
  266. toBottom:"To Bottom",
  267. current:"Current Page",
  268. forceIframe:"Force to join",
  269. cancelForceIframe:"Cancel Force join",
  270. configure:"Configure",
  271. firstUpdate:"Click here to initialize the rules",
  272. update:"Update rules",
  273. click2update:"Click to update rules from url now",
  274. loadNow:"Load next now",
  275. loadConfirm:"How much pages do you want to load? (0 means infinite)",
  276. noNext:"No next link found, please create a new rule",
  277. passSec:"Updated #t# seconds ago",
  278. passMin:"Updated #t# minutes ago",
  279. passHour:"Updated #t# hours ago",
  280. passDay:"Updated #t# days ago",
  281. cantDel:"Can't delete buildin rules",
  282. confirmDel:"Are you sure you want to delete this rule?",
  283. updateSucc:"Update succeeded",
  284. beginUpdate:"Begin update, wait a minute please",
  285. customUrls:"Import rule url, One url per line, rules on AutoPagerize format need to start with \"0|\"",
  286. customRules:"Input custom rules with [Pagetual] format",
  287. save:"Save",
  288. loadingText:"Shojo Now Loading...",
  289. opacity:"Pagination spacer opacity",
  290. hideBar:"Double-click on the blank space to hide the paging spacer",
  291. dbClick2Stop:"Double-click on the blank space to stop",
  292. sortTitle:"Sorting takes effect after the next rule update",
  293. autoRun:"Auto run",
  294. inputPageNum:"Enter page number to jump",
  295. enableHistory:"Write history after page turning",
  296. initRun:"Turn pages immediately after opening",
  297. preload:"Preload next page",
  298. click2ImportRule:"Click to import base rules:"
  299. };
  300. break;
  301. }
  302. return config[name]?config[name].replace("#t#",param):name;
  303. };
  304.  
  305. var noRuleTest=false;
  306. var enableDebug=true;
  307. var debug=str=>{
  308. if(enableDebug){
  309. console.debug(str);
  310. }
  311. };
  312.  
  313. var _GM_xmlhttpRequest,_GM_registerMenuCommand,_GM_notification,_GM_addStyle,_GM_openInTab;
  314. if(typeof GM_xmlhttpRequest!='undefined'){
  315. _GM_xmlhttpRequest=GM_xmlhttpRequest;
  316. }else if(typeof GM!='undefined' && typeof GM.xmlHttpRequest!='undefined'){
  317. _GM_xmlhttpRequest=GM.xmlHttpRequest;
  318. }else{
  319. _GM_xmlhttpRequest=(f)=>{fetch(f.url).then(response=>response.text()).then(data=>{let res={response:data};f.onload(res)}).catch(f.onerror())};
  320. }
  321. if(typeof GM_registerMenuCommand!='undefined'){
  322. _GM_registerMenuCommand=GM_registerMenuCommand;
  323. }else if(typeof GM!='undefined' && typeof GM.registerMenuCommand!='undefined'){
  324. _GM_registerMenuCommand=GM.registerMenuCommand;
  325. }else{
  326. _GM_registerMenuCommand=(s,f)=>{};
  327. }
  328. if(typeof GM_notification!='undefined'){
  329. _GM_notification=GM_notification;
  330. }else if(typeof GM!='undefined' && typeof GM.notification!='undefined'){
  331. _GM_notification=GM.notification;
  332. }else{
  333. _GM_notification=(s)=>{alert(s)};
  334. }
  335. if(typeof GM_openInTab!='undefined'){
  336. _GM_openInTab=GM_openInTab;
  337. }else if(typeof GM!='undefined' && typeof GM.openInTab!='undefined'){
  338. _GM_openInTab=GM.openInTab;
  339. }else{
  340. _GM_openInTab=(s,t)=>{window.open(s)};
  341. }
  342. if(typeof GM_addStyle!='undefined'){
  343. _GM_addStyle=GM_addStyle;
  344. }else if(typeof GM!='undefined' && typeof GM.addStyle!='undefined'){
  345. _GM_addStyle=GM.addStyle;
  346. }else{
  347. _GM_addStyle=cssStr=>{
  348. let styleEle=document.createElement("style");
  349. styleEle.innerHTML=cssStr;
  350. document.head.appendChild(styleEle);
  351. };
  352. }
  353. var _unsafeWindow=(typeof unsafeWindow=='undefined')?window:unsafeWindow;//兼容 ios userscripts 的寫法
  354. var storage={
  355. supportGM: typeof GM_getValue=='function' && typeof GM_getValue('a','b')!='undefined',
  356. supportGMPromise: typeof GM!='undefined' && typeof GM.getValue=='function' && typeof GM.getValue('a','b')!='undefined',
  357. mxAppStorage:(function(){
  358. try{
  359. return window.external.mxGetRuntime().storage;
  360. }catch(e){
  361. }
  362. })(),
  363. operaUJSStorage:(function(){
  364. try{
  365. return window.opera.scriptStorage;
  366. }catch(e){
  367. }
  368. })(),
  369. setItem:function(key,value){
  370. if(this.operaUJSStorage){
  371. this.operaUJSStorage.setItem(key,value);
  372. }else if(this.mxAppStorage){
  373. this.mxAppStorage.setConfig(key,value);
  374. }else if(this.supportGM){
  375. GM_setValue(key,value);
  376. if(value==="" && typeof GM_deleteValue!='undefined'){
  377. GM_deleteValue(key);
  378. }
  379. }else if(this.supportGMPromise){
  380. GM.setValue(key,value);
  381. if(value==="" && typeof GM!='undefined' && typeof GM.deleteValue!='undefined'){
  382. GM.deleteValue(key);
  383. }
  384. }else if(window.localStorage){
  385. window.localStorage.setItem(key,value);
  386. }
  387. },
  388. getItem:function(key,cb){
  389. var value;
  390. if(this.operaUJSStorage){
  391. value=this.operaUJSStorage.getItem(key);
  392. }else if(this.mxAppStorage){
  393. value=this.mxAppStorage.getConfig(key);
  394. }else if(this.supportGM){
  395. value=GM_getValue(key);
  396. }else if(this.supportGMPromise){
  397. value=GM.getValue(key).then(v=>{cb(v)});
  398. return;
  399. }else if(window.localStorage){
  400. value=window.localStorage.getItem(key);
  401. };
  402. cb(value);
  403. }
  404. };
  405. var rulesData={},ruleUrls,updateDate,configPage="https://github.com/hoothin/UserScripts/tree/master/Pagetual";
  406. var ruleImportUrlReg=/greasyfork\.org\/.*scripts\/438684[^\/]*(\/discussions|\/?$)|github\.com\/hoothin\/UserScripts\/(tree\/master\/Pagetual|issues)/i;
  407. var allOfBody="body>*";
  408. _GM_registerMenuCommand(i18n("configure"), ()=>{
  409. _GM_openInTab(configPage,{active:true});
  410. });
  411.  
  412. function getElementByXpath(xpath, contextNode, doc){
  413. doc = doc || document;
  414. contextNode = contextNode || doc;
  415. try {
  416. var result = doc.evaluate(xpath, contextNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
  417. return result.singleNodeValue && result.singleNodeValue.nodeType === 1 && result.singleNodeValue;
  418. } catch (err) {
  419. throw new Error(`Invalid xpath: ${xpath}`);
  420. }
  421. }
  422.  
  423. function getAllElementsByXpath(xpath, contextNode, doc){
  424. doc = doc || document;
  425. contextNode = contextNode || doc;
  426. var result = [];
  427. try {
  428. var query = doc.evaluate(xpath, contextNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  429. for (var i = 0; i < query.snapshotLength; i++) {
  430. var node = query.snapshotItem(i);
  431. if (node.nodeType === 1) result.push(node);
  432. }
  433. } catch (err) {
  434. throw new Error(`Invalid xpath: ${xpath}`);
  435. }
  436. return result;
  437. }
  438.  
  439. class RuleParser {
  440. constructor() {
  441. this.hpRules=[];
  442. this.customRules=[];
  443. this.rules=[];
  444. this.pageDoc=document;
  445. this.nextLinkHref=null;
  446. this.oldUrl="";
  447. this.curUrl=location.href;
  448. this.curSiteRule={};
  449. }
  450.  
  451. initSavedRules(callback){
  452. var self=this;
  453. storage.getItem("hpRules", hpRules=>{
  454. if(hpRules)self.hpRules=hpRules;
  455. storage.getItem("customRules", customRules=>{
  456. if(customRules)self.customRules=customRules;
  457. storage.getItem("rules", rules=>{
  458. if(rules)self.rules=rules;
  459. callback();
  460. });
  461. });
  462. });
  463. }
  464.  
  465. saveCurSiteRule(){
  466. if(!this.curSiteRule || !this.curSiteRule.url || this.curSiteRule.singleUrl)return;
  467. this.hpRules=this.hpRules.filter(item=>{return item&&item.url!=this.curSiteRule.url});
  468. this.hpRules.unshift(this.curSiteRule);
  469. if(this.hpRules.length>30){
  470. this.hpRules.pop();
  471. }
  472. storage.setItem("hpRules", this.hpRules);
  473. }
  474.  
  475. requestJSON(url, callback){
  476. _GM_xmlhttpRequest({
  477. url: url,
  478. method: 'GET',
  479. timeout: 20000,
  480. onload: function(res) {
  481. let json=null;
  482. try{
  483. json=JSON.parse(res.response||res.responseText);
  484. }catch(e){
  485. debug(e);
  486. }
  487. callback(json);
  488. },
  489. onerror: function(e) {
  490. callback(null, e);
  491. },
  492. ontimeout: function(e) {
  493. callback(null, e);
  494. }
  495. });
  496. }
  497.  
  498. formatRule(item, type, from){
  499. switch(type){
  500. case 0:
  501. return {
  502. from:from,
  503. type:type,
  504. name:item.name,
  505. action:item.data.forceIframe=="true"?1:0,
  506. url:item.data.url,
  507. pageElement:item.data.pageElement,
  508. nextLink:item.data.nextLink,
  509. insert:item.data.insertBefore,
  510. insertPos:1,
  511. updatedAt:item.data.updated_at,
  512. css:item.data.Stylus+item.data.CSS,
  513. pageAction:item.data.bookmarklet
  514. };
  515. break;
  516. case 1:
  517. default:
  518. item.from=from;
  519. if(typeof(item.type) == "undefined")item.type=type;
  520. return item;
  521. break;
  522. }
  523. return null;
  524. }
  525.  
  526. addRuleByUrl(url, type, from, callback) {
  527. if(url.indexOf("?")==-1){
  528. url=url+"?"+Date.now();
  529. }else{
  530. url=url+"&"+Date.now();
  531. }
  532. this.requestJSON(url, (json,err)=>{
  533. if(!json){
  534. debug("Update "+url+" rules fail!");
  535. debug(err);
  536. }
  537. this.addRules(json, type, from);
  538. callback(json, err);
  539. });
  540. }
  541.  
  542. addRules(rules, type, from) {
  543. if(rules && rules.length>0){
  544. this.rules=this.rules.filter(item=>{return item.from!=from});
  545. rules.forEach(item=>{
  546. let rule=this.formatRule(item, type, from);
  547. if(rule){
  548. this.rules.unshift(rule);
  549. }
  550. });
  551. }
  552. }
  553.  
  554. getRule(callback) {
  555. if(noRuleTest){
  556. this.curSiteRule={};
  557. this.curSiteRule.url=location.origin+location.pathname;
  558. this.curSiteRule.singleUrl=true;
  559. callback();
  560. return;
  561. }
  562. if(this.curSiteRule && this.curSiteRule.url){
  563. return this.curSiteRule;
  564. }
  565. var self=this;
  566.  
  567. function setRule(r){
  568. self.curSiteRule=r;
  569. debug(r);
  570. callback();
  571. }
  572.  
  573. function ruleMatch(r){
  574. let pageElement,nextLink,insert;
  575. if(r.pageElement)pageElement=r.type==0?getElementByXpath(r.pageElement):document.querySelector(r.pageElement);
  576. if(r.nextLink)nextLink=r.type==0?getElementByXpath(r.nextLink):document.querySelector(r.nextLink);
  577. if(r.insert)insert=r.type==0?getElementByXpath(r.insert):document.querySelector(r.insert);
  578. return !((r.pageElement && !pageElement) ||
  579. (r.nextLink && !nextLink) ||
  580. (r.insert && !insert));
  581. }
  582.  
  583. function checkRule(r){
  584. let urlReg=new RegExp(r.url, "i");
  585. if(urlReg.test(location.href)){
  586. if(r.wait){
  587. let waitTime=500,checkEval;
  588. if(isNaN(r.wait)){
  589. try{
  590. checkEval=Function("doc",'"use strict";' + r.wait);
  591. }catch(e){
  592. debug(e);
  593. }
  594. }else{
  595. waitTime=r.wait;
  596. }
  597. let checkReady=()=>{
  598. setTimeout(()=>{
  599. if(!ruleMatch(r) || (checkEval && !checkEval(document))){
  600. checkReady();
  601. }else{
  602. setRule(r);
  603. }
  604. },parseInt(waitTime));
  605. };
  606. checkReady();
  607. return true;
  608. }
  609. if(r.pinUrl){
  610. setRule(r);
  611. return true;
  612. }
  613. if(!ruleMatch(r)){
  614. return false;
  615. }
  616. setRule(r);
  617. return true;
  618. }
  619. return false;
  620. }
  621.  
  622. for(let i in this.hpRules){
  623. let rule=this.hpRules[i];
  624. if(!rule || !rule.url)continue;
  625. if(rule.singleUrl){
  626. if(location.origin+location.pathname==rule.url){
  627. setRule(rule);
  628. return;
  629. }
  630. continue;
  631. }
  632. if(checkRule(rule))return;
  633. }
  634. for(let i in this.customRules){
  635. let rule=this.customRules[i];
  636. if(!rule || !rule.url)continue;
  637. if(checkRule(rule))return;
  638. }
  639. let r=0;
  640. function searchByTime(){
  641. setTimeout(()=>{
  642. let end=r+80;
  643. end=end>self.rules.length?self.rules.length:end;
  644. for(;r<end;r++){
  645. let rule=self.rules[r];
  646. if(checkRule(rule))return;
  647. }
  648. if(end>=self.rules.length){
  649. self.curSiteRule={};
  650. self.curSiteRule.url=location.origin+location.pathname;
  651. self.curSiteRule.singleUrl=true;
  652. callback();
  653. return;
  654. }else{
  655. searchByTime();
  656. }
  657. },20);
  658. }
  659. searchByTime();
  660. }
  661.  
  662. geneSelector(ele){
  663. let selector=ele.tagName;
  664. //Google id class都是隨機。百度更過分,style script順序都是隨機的
  665. //if(ele.id) selector += '#' + ele.id;
  666. //if(ele.classList) selector += [].map.call(ele.classList,d=>'.'+d).join('');
  667. let parent = ele.parentElement;
  668. if(parent){
  669. let i,j=0;
  670. for(i=0;i<parent.children.length;i++){
  671. if(parent.children[i].tagName==selector){
  672. j++;
  673. if(parent.children[i]==ele){
  674. break;
  675. }
  676. }
  677. }
  678. selector = this.geneSelector(parent) + ' > ' + selector + (parent.tagName=="HTML"?"":`:nth-of-type(${j})`);
  679. }
  680. return selector;
  681. }
  682.  
  683. getPageElement(doc, curWin, dontFind) {
  684. let pageElement=null;
  685. let self=this;
  686. if(this.curSiteRule.pageElement){
  687. pageElement=this.curSiteRule.type==0?getAllElementsByXpath(this.curSiteRule.pageElement,doc,doc):doc.querySelectorAll(this.curSiteRule.pageElement);
  688. }
  689. if((!pageElement || pageElement.length==0) && curWin && !dontFind){
  690. let body=doc.body;
  691. if(!body)return null;
  692. let bodyHeight=parseInt(body.scrollHeight);
  693. let curHeight=bodyHeight;
  694. function checkElement(ele){
  695. if(ele.childNodes && ele.childNodes.length==1)ele=ele.childNodes[0];
  696. if(ele.tagName=="PICTURE"){
  697. self.curSiteRule.pageElement=self.geneSelector(ele.parentNode)+">"+ele.tagName;
  698. debug(self.curSiteRule.pageElement);
  699. return [ele];
  700. }
  701. if(curHeight/bodyHeight<=0.30){
  702. self.curSiteRule.pageElement=allOfBody;
  703. debug(self.curSiteRule.pageElement);
  704. return [body];
  705. }
  706. if(ele.tagName=="TBODY" || ele.tagName=="UL"){
  707. self.curSiteRule.pageElement=self.geneSelector(ele)+">*";
  708. if(ele.children.length>0 && ele.children[0].querySelector("th")){
  709. self.curSiteRule.pageElement+=":not(:first-child)";
  710. }
  711. debug(self.curSiteRule.pageElement);
  712. return ele.children;
  713. }
  714. if(ele.children.length==0 && !self.curSiteRule.pageElement){
  715. if(ele.parentNode.tagName=="P")ele=ele.parentNode;
  716. self.curSiteRule.pageElement=self.geneSelector(ele.parentNode)+">"+ele.tagName;
  717. debug(self.curSiteRule.pageElement);
  718. return [ele];
  719. }
  720. let i,maxHeight=curHeight*0.6,curMaxEle=null,curMaxArea=0,maxWidth=0;
  721. let isHori=true;
  722. let offsetTop=ele.children[0].offsetTop;
  723. for(i=1;i<ele.children.length;i++){
  724. if(ele.children[i].offsetTop!=offsetTop){
  725. isHori=false;
  726. break;
  727. }
  728. }
  729. for(i=0;i<ele.children.length;i++){
  730. let curNode=ele.children[i];
  731. if(curNode.tagName=="CANVAS")continue;
  732. if(curNode.tagName!="IMG" && curNode.innerHTML=="")continue;
  733. let comStyle=curWin.getComputedStyle(curNode);
  734. let h=parseInt(curNode.scrollHeight);
  735. let w=parseInt(curNode.scrollWidth);
  736. if(isNaN(h) || isNaN(w))continue;
  737. if(isHori && h==0)continue;
  738. let a=h*w+h,moreChild=curNode.children[0];
  739. while(moreChild){
  740. comStyle=curWin.getComputedStyle(moreChild);
  741. let ch=parseInt(moreChild.scrollHeight);
  742. let cw=parseInt(moreChild.scrollWidth);
  743. if(h<ch)h=ch;
  744. if(moreChild.innerText!="" && !isNaN(ch) && !isNaN(cw)){
  745. a+=ch*cw;
  746. }
  747. moreChild=moreChild.nextElementSibling;
  748. }
  749. let isMax=false;
  750. if(isHori){
  751. if(maxWidth<w){
  752. isMax=true;
  753. }else if(maxWidth==w && curMaxArea<a){
  754. isMax=true;
  755. }
  756. }else{
  757. isMax=curMaxArea<a;
  758. }
  759. if(curMaxEle==null || isMax){
  760. if(h>0 || !isHori)curHeight=h;
  761. curMaxArea=a;
  762. maxWidth=w;
  763. curMaxEle=curNode;
  764. }
  765. }
  766. if(curMaxEle && (isHori || curHeight>maxHeight)){
  767. return checkElement(curMaxEle);
  768. }
  769. if(ele.tagName=="P" || ele.tagName=="BR")ele=ele.parentNode;
  770. self.curSiteRule.pageElement=self.geneSelector(ele);
  771. if(ele.children.length>1){
  772. let middleChild=ele.children[parseInt(ele.children.length/2)];
  773. if((middleChild.style && middleChild.style.position=="absolute" && middleChild.style.left && middleChild.style.top) || ele.tagName=="UL" || curHeight==0){
  774. ele=[ele];
  775. }else{
  776. self.curSiteRule.pageElement+=">*";
  777. ele=ele.children;
  778. }
  779. }else{
  780. ele=[ele];
  781. }
  782. debug(self.curSiteRule.pageElement);
  783. return ele;
  784. }
  785. pageElement=checkElement(body);
  786. if(pageElement)this.saveCurSiteRule();
  787. }
  788. /*if(this.insert && this.insert.parentNode && pageElement && pageElement[0]){
  789. let example=this.insertPos==2?this.insert.children[0]:this.insert;
  790. let inTable=example.parentNode.tagName=="TABLE" ||
  791. example.tagName=="TR" ||
  792. example.tagName=="TBODY" ||
  793. (example.previousElementSibling && example.previousElementSibling.tagName=="TR") ||
  794. (example.previousElementSibling && example.previousElementSibling.tagName=="TBODY");
  795. if(inTable && pageElement[0].tagName!="TR" && pageElement[0].tagName!="TBODY"){
  796. pageElement=null;
  797. }
  798. }*/
  799. return pageElement;
  800. }
  801.  
  802. getPage(doc){
  803. if(_unsafeWindow.Discourse)return {};
  804. let canSave=false;//發現頁碼選擇器在其他頁對不上,還是別保存了
  805. let url=this.curUrl.replace("#!","").replace("index.php?","?");
  806. let pageNum=1,preStr="",afterStr="";
  807. let pageMatch1=url.match(/(.*[a-z\/\-_](?:p|page)?\/?)(\d+)(\.s?html?$|\/?$)/i);
  808. let pageMatch2=url.match(/(.*[\?&]p(?:age)?=)(\d+)($|[#&].*)/i);
  809. if(pageMatch1){
  810. preStr=pageMatch1[1];
  811. pageNum=parseInt(pageMatch1[2]);
  812. afterStr=pageMatch1[3];
  813. }else if(pageMatch2){
  814. preStr=pageMatch2[1];
  815. pageNum=parseInt(pageMatch2[2]);
  816. afterStr=pageMatch2[3];
  817. }
  818. let curPage=doc,i,cur,jsNext;
  819. let next=curPage.querySelector(".page-next>a")||
  820. curPage.querySelector("a.next_page")||
  821. curPage.querySelector("#next_page")||
  822. curPage.querySelector(".nextPage")||
  823. curPage.querySelector("a[data-pagination=next]")||
  824. curPage.querySelector(".pagination a[rel=next]")||
  825. curPage.querySelector(".pagination-nav__item--next>a")||
  826. curPage.querySelector("a[title='Next page']")||
  827. curPage.querySelector("a.pageright")||
  828. curPage.querySelector("a#rightFix")||
  829. curPage.querySelector("a.next")||
  830. curPage.querySelector("a#next")||
  831. curPage.querySelector(".next>a")||
  832. curPage.querySelector(".next>button")||
  833. curPage.querySelector("a[alt=next]")||
  834. curPage.querySelector("[title=next]");
  835. if(next && (!next.href || /^javascript:/.test(next.href))){
  836. jsNext=next;
  837. next=null;
  838. }
  839. if(!next){
  840. next=curPage.querySelectorAll("[aria-label='Next']");
  841. if(next && next.length==1){
  842. next=next[0];
  843. if(!next.href || /^javascript:/.test(next.href)){
  844. jsNext=next;
  845. next=null;
  846. }
  847. }else{
  848. next=null;
  849. }
  850. }
  851. if(!next){
  852. next=curPage.querySelectorAll("[aria-label='Next page']");
  853. if(next && next.length==1){
  854. next=next[0];
  855. if(!next.href || /^javascript:/.test(next.href)){
  856. jsNext=next;
  857. next=null;
  858. }
  859. }else{
  860. next=null;
  861. }
  862. }
  863. if(!next){
  864. let pageDiv=curPage.querySelector("div.wp-pagenavi");
  865. if(pageDiv){
  866. cur=pageDiv.querySelector("span.current");
  867. if(cur){
  868. next=cur.nextSibling;
  869. }
  870. }else{
  871. cur=curPage.querySelector("div.article-paging>span");
  872. if(cur){
  873. next=cur.nextElementSibling;
  874. }
  875. }
  876. }
  877. if(!next){
  878. let pageDiv=curPage.querySelector("div.pages>ul");
  879. if(pageDiv){
  880. cur=pageDiv.querySelector("li>b");
  881. if(cur)next=cur.parentNode.nextElementSibling;
  882. if(next)next=next.querySelector("a");
  883. }
  884. }
  885. if(!next){
  886. cur=curPage.querySelector(".number>ul>li.active");
  887. if(cur)next=cur.nextElementSibling;
  888. if(next)next=next.querySelector("a");
  889. }
  890. if(!next){
  891. let aTags=curPage.querySelectorAll("a");
  892. let next1,next2,next3,next4,nextJs1,nextJs2,nextJs3;
  893. for(i=aTags.length-1;i>=0;i--){
  894. let aTag=aTags[i];
  895. if(aTag.innerText=="§")continue;
  896. if(aTag.style.display=="none")continue;
  897. if(next1 && next2 && next3 && next4)break;
  898. if(aTag.href && /next$/i.test(aTag.href))continue;
  899. if(!next1){
  900. if(/^[下后後][一1]?[页頁张張]|^next( page)?\s*›?$|次のページ/i.test(aTag.innerText.trim())){
  901. if(aTag.innerText.length>15)continue;
  902. if(!aTag.href || /^javascript:/.test(aTag.href)){
  903. if(!nextJs1)nextJs1=aTag;
  904. }else{
  905. next1=aTag;
  906. }
  907. }
  908. }
  909. if(!next2){
  910. if(/^[下后後][一1]?[章话話]/i.test(aTag.innerText.trim())){
  911. if(!aTag.href || /^javascript:/.test(aTag.href)){
  912. if(!nextJs2)nextJs2=aTag;
  913. }else{
  914. next2=aTag;
  915. }
  916. }
  917. }
  918. if(!next3){
  919. if(aTag.innerText=="&gt;" || aTag.innerText=="▶" || aTag.innerText==">" || aTag.innerText=="›" || /nextpage/i.test(aTag.className)){
  920. if(!aTag.href || /^javascript:/.test(aTag.href)){
  921. if(!nextJs3)nextJs3=aTag;
  922. }else{
  923. next3=aTag;
  924. }
  925. }
  926. }
  927. if(!aTag.href || /^javascript:/.test(aTag.href))continue;
  928. if(!next4){
  929. if(pageNum<999 && aTag.href.replace("?&","?").replace("#!","").replace("index.php?","?").replace(preStr,"").replace(afterStr,"")==pageNum+1){
  930. next4=aTag;
  931. }else if(this.curUrl!=aTag.href && aTag.href.replace("?&","?").replace("index.php?","?").indexOf(url)!=-1 && /^[\/\?&]?[_-]?(p|page)?=?\/?2(\/|\?|&|$)/i.test(aTag.href.replace(url,"").replace(/\.s?html?$/i,""))){
  932. let curHref=aTag.getAttribute("href");
  933. let pageOne=curHref.replace(/\/2(\/|\?|&|$)/,"/1$1");
  934. if(pageOne==curHref)pageOne=null;
  935. else pageOne=curPage.querySelector(`a[href='${pageOne}']`);
  936. if(!pageOne)next4=aTag;
  937. }
  938. }
  939. }
  940. next=next1||next3||next4||next2||nextJs1||nextJs3||nextJs2;
  941. }
  942. if(!next)next=jsNext;
  943. if(next && next.classList.contains("results-more"))next=null;
  944. return {next:next,canSave:canSave};
  945. }
  946.  
  947. canonicalUri(src, base_path) {
  948. if(src.charAt(0)=="#")return location.href+src;
  949. var root_page = /^[^?#]*\//.exec(location.href)[0],
  950. root_domain = /^\w+\:\/\/\/?[^\/]+/.exec(root_page)[0],
  951. absolute_regex = /^\w+\:\/\//;
  952. src=src.replace(/\.\//,"");
  953. if (/^\/\/\/?/.test(src)){
  954. src = location.protocol + src;
  955. }
  956. else if (!absolute_regex.test(src) && src.charAt(0) != "/"){
  957. src = (base_path || "") + src;
  958. }
  959. return (absolute_regex.test(src) ? src : ((src.charAt(0) == "/" ? root_domain : root_page) + src));
  960. }
  961.  
  962. getLinkByPage(url, pageNum) {
  963. if(!url)return;
  964. if(this.curSiteRule.pageNum){
  965. let result=this.curSiteRule.pageNum;
  966. let strMatch=result.match(/\{.*?}/);
  967. if(!strMatch)return null;
  968. let urlReg=new RegExp("("+result.replace(strMatch[0], ")\\d+(")+")");
  969. let code=strMatch[0].replace(/^{/,"").replace(/}$/,"").replace(/\$p/g,pageNum);
  970. if(code==pageNum){
  971. result=url.replace(urlReg,"$1"+code+"$2");
  972. }else{
  973. try{
  974. code=Function('"use strict";return ' + code)();
  975. result=url.replace(urlReg,"$1"+code+"$2");
  976. }catch(e){
  977. debug(e);
  978. }
  979. }
  980. return result==url?url.replace(/([&\/\?](p=|page[=\/]))\d+/i, "$1"+pageNum):result;
  981. }else{
  982. return url.replace(/([&\/\?](p=|page[=\/]))\d+/i, "$1"+pageNum);
  983. }
  984. }
  985.  
  986. getNextLink(doc) {
  987. let nextLink=null,page;
  988. if(this.curSiteRule.pageElementByJs){
  989. this.nextLinkHref="#";
  990. return true;
  991. }else if(this.curSiteRule.nextLinkByJs){
  992. try{
  993. let targetUrl=Function("doc",'"use strict";' + this.curSiteRule.nextLinkByJs)(doc);
  994. if(targetUrl)nextLink={href:targetUrl};
  995. }catch(e){
  996. debug(e);
  997. }
  998. }else if(this.curSiteRule.nextLinkByUrl){
  999. let targetUrl=this.curUrl.replace(new RegExp(this.curSiteRule.nextLinkByUrl[0]), this.curSiteRule.nextLinkByUrl[1]);
  1000. if(targetUrl != this.curUrl){
  1001. let reps=targetUrl.match(/{.*?}/g);
  1002. if(reps){
  1003. reps.forEach(rep=>{
  1004. let code=rep.replace("{","").replace("}","");
  1005. let result=code.match(/^(\d+)\+1$/);
  1006. if(result){
  1007. result=parseInt(result[1])+1;
  1008. }else{
  1009. try{
  1010. result=Function('"use strict";return ' + code)();
  1011. }catch(e){
  1012. debug(e);
  1013. }
  1014. }
  1015. targetUrl=targetUrl.replace(rep, result);
  1016. });
  1017. }
  1018. }
  1019. nextLink={href:targetUrl};
  1020. }else if(this.curSiteRule.nextLink){
  1021. if(this.curSiteRule.nextLink!="0"){
  1022. nextLink=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.nextLink,doc,doc):doc.querySelector(this.curSiteRule.nextLink);
  1023. }
  1024. }else{
  1025. page=this.getPage(doc);
  1026. nextLink=page.next;
  1027. if(nextLink){
  1028. if(nextLink.tagName=="INPUT" && nextLink.parentNode.tagName=="FORM"){
  1029. let params=[];
  1030. let form=nextLink.parentNode;
  1031. [].forEach.call(form.querySelectorAll("input"), input=>{
  1032. params.push(input.name+'='+input.value);
  1033. });
  1034. nextLink.href=form.action+'?'+params.join('&');
  1035. }
  1036. if(nextLink.classList.contains("noClick")){
  1037. this.nextLinkHref=false;
  1038. return null;
  1039. }else if(doc==document){
  1040. if((!nextLink.href || /^javascript:/.test(nextLink.href)) && !isVisible(nextLink, _unsafeWindow)){
  1041. this.nextLinkHref=false;
  1042. return null;
  1043. }else{
  1044. let nextLinkCs=_unsafeWindow.getComputedStyle(nextLink);
  1045. if(nextLinkCs.cursor=="not-allowed"){
  1046. this.nextLinkHref=false;
  1047. return null;
  1048. }
  1049. }
  1050. }
  1051. }
  1052. }
  1053. if(nextLink){
  1054. let needUrl=(this.curSiteRule.action==0 || this.curSiteRule.action==1);
  1055. if(nextLink.href==="" && needUrl){
  1056. this.nextLinkHref=false;
  1057. }else if(nextLink.href && (nextLink.href==this.curUrl || nextLink.href==this.oldUrl) && needUrl){
  1058. this.nextLinkHref=false;
  1059. }else if(/^javascript:/.test(nextLink.href) && needUrl){
  1060. this.nextLinkHref=false;
  1061. }else{
  1062. this.nextLinkHref=(nextLink.href && !/^javascript:/.test(nextLink.href) && nextLink.href!=location.href)?this.canonicalUri(nextLink.href):"#";
  1063. if(doc==document)debug(nextLink);
  1064. }
  1065. }else{
  1066. this.nextLinkHref=false;
  1067. }
  1068. this.preload();
  1069. return nextLink;
  1070. }
  1071.  
  1072. preload(){
  1073. if(!rulesData.preload)return;
  1074. if(!this.nextLinkHref || this.nextLinkHref=="#")return;
  1075. let self=this;
  1076. if(this.curSiteRule && this.curSiteRule.action==1){
  1077. if(!this.preloadIframe){
  1078. this.preloadIframe = document.createElement('iframe');
  1079. let iframe = this.preloadIframe;
  1080. iframe.name = 'pagetual-iframe';
  1081. iframe.width = '100%';
  1082. iframe.height = '0';
  1083. iframe.frameBorder = '0';
  1084. if(ruleParser.curSiteRule.sandbox!=false){
  1085. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1086. }
  1087. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1088. iframe.addEventListener('load', function (e) {
  1089. try{
  1090. let doc=iframe.contentDocument || iframe.contentWindow.document;
  1091. var body = doc.body;
  1092. if (body && body.firstChild) {
  1093. self.lazyImgAction(body.children);
  1094. }
  1095. }catch(e){
  1096. return;
  1097. }
  1098. }, false);
  1099. document.body.appendChild(iframe);
  1100. }
  1101. this.preloadIframe.src = this.nextLinkHref;
  1102. }else{
  1103. _GM_xmlhttpRequest({
  1104. url: this.nextLinkHref,
  1105. method: 'GET',
  1106. overrideMimeType: 'text/html;charset='+document.charset,
  1107. headers: {
  1108. 'Referer': location.href
  1109. },
  1110. timeout: 5000,
  1111. onload: function(res) {
  1112. var doc=null;
  1113. try {
  1114. doc=document.implementation.createHTMLDocument('');
  1115. doc.documentElement.innerHTML=res.response;
  1116. var body = doc.body;
  1117. if (body && body.firstChild) {
  1118. self.lazyImgAction(body.children);
  1119. }
  1120. if(!self.preloadDiv){
  1121. self.preloadDiv = document.createElement('div');
  1122. self.preloadDiv.id = "pagetual-preload";
  1123. self.preloadDiv.style.cssText = 'display:none!important;';
  1124. document.body.appendChild(self.preloadDiv);
  1125. self.checkedImgs={};
  1126. }
  1127. [].forEach.call(doc.images, i=>{
  1128. let iSrc=i.src;
  1129. if(iSrc && !self.checkedImgs[iSrc]){
  1130. self.checkedImgs[iSrc] = true;
  1131. let img = document.createElement('img');
  1132. img.src = iSrc;
  1133. self.preloadDiv.appendChild(img);
  1134. }
  1135. });
  1136. }
  1137. catch (e) {
  1138. return;
  1139. }
  1140. }
  1141. });
  1142. }
  1143. }
  1144.  
  1145. getInsert(refresh) {
  1146. if(refresh){
  1147. this.insert=null;
  1148. }
  1149. if(this.insert && !refresh){
  1150. let parent=this.insert;
  1151. while(parent && parent.nodeName!="BODY"){
  1152. parent=parent.parentNode;
  1153. }
  1154. if(parent && parent.nodeName=="BODY"){
  1155. return this.insert;
  1156. }
  1157. }
  1158. if(this.curSiteRule.insert){
  1159. this.insert=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.insert,document):document.querySelector(this.curSiteRule.insert);
  1160. }else{
  1161. let pageElement=this.getPageElement(document, _unsafeWindow);
  1162. if(pageElement && pageElement.length>0){
  1163. var pELast = pageElement[pageElement.length - 1];
  1164. this.insert = pELast.nextSibling ? pELast.nextSibling : pELast.parentNode.appendChild(document.createTextNode(' '));
  1165. }
  1166. }
  1167. return this.insert;
  1168. }
  1169.  
  1170. pageInit(doc,eles){
  1171. let code=this.curSiteRule.pageInit;
  1172. if(code){
  1173. try{
  1174. Function("doc","eles",'"use strict";' + code)(doc,eles);
  1175. }catch(e){
  1176. debug(e);
  1177. }
  1178. }
  1179. }
  1180.  
  1181. pageAction(doc,eles){
  1182. let code=this.curSiteRule.pageAction;
  1183. if(code){
  1184. try{
  1185. Function("doc","eles",'"use strict";' + code)(doc,eles);
  1186. }catch(e){
  1187. debug(e);
  1188. }
  1189. }
  1190. this.lazyImgAction(eles);
  1191. }
  1192.  
  1193. lazyImgAction(eles){
  1194. let setLazyImg=img=>{
  1195. let realSrc;
  1196. if(img.getAttribute("_src") && !img.src){
  1197. realSrc=img.getAttribute("_src");
  1198. }else if(img.dataset && img.dataset.original){
  1199. realSrc=img.dataset.original;
  1200. }else if(img.dataset && img.dataset.src){
  1201. realSrc=img.dataset.src;
  1202. }else if(img._lazyrias && img._lazyrias.srcset){
  1203. realSrc=img._lazyrias.srcset[img._lazyrias.srcset.length-1];
  1204. }else if(img.dataset && img.dataset.origFile){
  1205. realSrc=img.dataset.origFile;
  1206. }else if(img.srcset){
  1207. var srcs=img.srcset.split(","),largeSize=0;
  1208. srcs.forEach(srci=>{
  1209. let srcInfo=srci.trim().split(" "),curSize=parseInt(srcInfo[1]);
  1210. if(srcInfo[1] && curSize>largeSize){
  1211. largeSize=curSize;
  1212. realSrc=srcInfo[0];
  1213. }
  1214. });
  1215. }
  1216. if(realSrc){
  1217. img.src=realSrc;
  1218. img.style.display="block";
  1219. }
  1220. };
  1221. [].forEach.call(eles, ele=>{
  1222. if(ele.tagName=="IMG"){
  1223. setLazyImg(ele);
  1224. }else{
  1225. [].forEach.call(ele.querySelectorAll("img"), img=>{
  1226. setLazyImg(img);
  1227. });
  1228. }
  1229. if(ele.tagName=="A" && ele.classList.contains("lazyload")){
  1230. if(ele.dataset.original){
  1231. ele.style.backgroundImage='url("'+ele.dataset.original+'")';
  1232. }
  1233. }else{
  1234. [].forEach.call(ele.querySelectorAll("a.lazyload"), a=>{
  1235. if(a.dataset.original){
  1236. a.style.backgroundImage='url("'+a.dataset.original+'")';
  1237. }
  1238. });
  1239. }
  1240. });
  1241. let lazyImgSrc=this.curSiteRule.lazyImgSrc;
  1242. if(lazyImgSrc){
  1243. [].forEach.call(eles, ele=>{
  1244. [].forEach.call(ele.querySelectorAll("img"), img=>{
  1245. if(img.getAttribute(lazyImgSrc)){
  1246. img.src=img.getAttribute(lazyImgSrc);
  1247. }
  1248. });
  1249. });
  1250. }
  1251. }
  1252.  
  1253. initPage(callback){
  1254. let self=this;
  1255. curPage=1;
  1256. //if(this.curSiteRule.url && !this.curSiteRule.singleUrl)return;
  1257. this.curSiteRule={};
  1258. this.pageDoc=document;
  1259. this.nextLinkHref=null;
  1260. this.curUrl=location.href;
  1261. this.getRule(()=>{
  1262. if(self.curSiteRule.enable==0){
  1263. debug("Stop as rule disable");
  1264. isPause=true;
  1265. return;
  1266. }
  1267. if(self.curSiteRule && !self.curSiteRule.singleUrl){
  1268. self.hpRules=self.hpRules.filter(item=>{return item&&item.url!=self.curSiteRule.url});
  1269. self.hpRules.unshift(self.curSiteRule);
  1270. if(self.hpRules.length>30){
  1271. self.hpRules.pop();
  1272. }
  1273. storage.setItem("hpRules", self.hpRules);
  1274. }
  1275. let css=self.curSiteRule.css;
  1276. if(css){
  1277. _GM_addStyle(css);
  1278. }
  1279. let code=self.curSiteRule.init;
  1280. if(code){
  1281. try{
  1282. Function('doc','win','"use strict";' + code)(null,null);
  1283. }catch(e){
  1284. debug(e);
  1285. }
  1286. }
  1287. self.getNextLink(document);
  1288. callback();
  1289. });
  1290. }
  1291.  
  1292. insertPage(doc, eles, url, callback, tried){
  1293. this.oldUrl=this.curUrl;
  1294. let oldTitle=this.pageDoc.title;
  1295. this.pageDoc=doc;
  1296. this.curUrl=url;
  1297. let nextLink=this.getNextLink(doc);
  1298. if(curPage==1 && !tried && !nextLink && this.curSiteRule.singleUrl && this.curSiteRule.pageElement && this.curSiteRule.pageElement!=allOfBody){
  1299. this.curSiteRule.action=1;
  1300. this.curUrl=location.href;
  1301. return false;
  1302. }
  1303. if(callback)callback(eles);
  1304. this.getInsert();
  1305. var self=this,newEles=[];
  1306. if(!eles || eles.length==0 || !self.insert || !self.insert.parentNode){
  1307. }else{
  1308. this.pageInit(doc, eles);
  1309. [].forEach.call(eles, ele=>{
  1310. let newEle=ele.cloneNode(true);
  1311. let oldCanvass=ele.querySelectorAll("canvas");
  1312. let newCanvass=newEle.querySelectorAll("canvas");
  1313. for(let i=0;i<oldCanvass.length;i++){
  1314. let oldCanvas=oldCanvass[i];
  1315. let newCanvas=newCanvass[i];
  1316. newCanvas.getContext('2d').drawImage(oldCanvas, 0, 0);
  1317. }
  1318. if(self.curSiteRule.insertPos==2){
  1319. self.insert.appendChild(newEle);
  1320. }else{
  1321. self.insert.parentNode.insertBefore(newEle, self.insert);
  1322. }
  1323. newEles.push(newEle);
  1324. });
  1325. }
  1326. this.pageAction(doc, newEles);
  1327. if(this.oldUrl!=location.href){
  1328. let isJs=/^(javascript|#)/.test(this.oldUrl.replace(location.href,""));
  1329. if(rulesData.enableHistory && !isJs){
  1330. _unsafeWindow.history.replaceState(undefined, oldTitle, this.oldUrl);
  1331. document.title=oldTitle;
  1332. }
  1333. }
  1334. return true;
  1335. }
  1336. }
  1337. var ruleParser = new RuleParser();
  1338.  
  1339. function initConfig(){
  1340. _GM_registerMenuCommand(i18n(forceState==1?"enable":"disableSite"), ()=>{
  1341. storage.setItem("forceState_"+location.host, (forceState==1?0:1));
  1342. location.reload();
  1343. });
  1344. _GM_registerMenuCommand(i18n("update"), ()=>{
  1345. updateRules(()=>{
  1346. alert(i18n("updateSucc"));
  1347. location.reload();
  1348. },(rule,err)=>{
  1349. alert("Update "+rule.url+" rules fail!");
  1350. });
  1351. alert(i18n("beginUpdate"));
  1352. });
  1353.  
  1354. var configCon,insertPos;
  1355. if(ruleImportUrlReg.test(location.href)){
  1356. document.addEventListener("click", e=>{
  1357. if(e.target.tagName=="PRE"){
  1358. let nameAttr=e.target.getAttribute("name");
  1359. if(nameAttr=="pagetual" || nameAttr=="user-content-pagetual"){
  1360. let rules=e.target.innerText.trim().split("\n");
  1361. let diff=false;
  1362. for(let c=0;c<rules.length;c++){
  1363. let urlArr=rules[c].split("|"),url,type=1;
  1364. if(urlArr.length==1){
  1365. url=urlArr[0].trim();
  1366. if(!/^http/.test(url)){
  1367. alert("Wrong url, check again!");
  1368. return;
  1369. }
  1370. }else if(urlArr.length==2){
  1371. type=urlArr[0].trim();
  1372. url=urlArr[1].trim();
  1373. if(!/^http/.test(url)){
  1374. alert("Wrong url, check again!");
  1375. return;
  1376. }
  1377. }else{
  1378. break;
  1379. }
  1380. let maxId=0,hasUrl=false;
  1381. if(!rulesData.urls){
  1382. rulesData.urls=[];
  1383. maxId=1;
  1384. }else{
  1385. rulesData.urls.forEach(u=>{
  1386. if(maxId<u.id){
  1387. maxId=u.id;
  1388. }
  1389. if(u.url==url){
  1390. hasUrl=true;
  1391. }
  1392. });
  1393. if(hasUrl)break;
  1394. }
  1395. diff=true;
  1396. if(!rulesData.sort)rulesData.sort=[1];
  1397. rulesData.urls.push({id:maxId+1,url:url,type:type});
  1398. rulesData.sort.unshift(maxId+1);
  1399. }
  1400. if(!diff)return;
  1401. storage.setItem("rulesData", rulesData);
  1402.  
  1403. if(rulesData.urls)ruleUrls=ruleUrls.concat(rulesData.urls);
  1404. if(rulesData.sort){
  1405. let urls=[];
  1406. rulesData.sort.forEach(id=>{
  1407. for(let s=0;s<ruleUrls.length;s++){
  1408. if(id==ruleUrls[s].id){
  1409. urls.push(ruleUrls[s]);
  1410. break;
  1411. }
  1412. }
  1413. });
  1414. ruleUrls=urls;
  1415. }
  1416. alert("OK");
  1417. }
  1418. }
  1419. });
  1420. }
  1421. if(location.href==configPage){
  1422. _GM_addStyle(`
  1423. p>span:nth-child(1),p>span:nth-child(2),p>span:nth-child(3){
  1424. cursor: pointer;
  1425. user-select: none;
  1426. }
  1427. p>span:nth-child(1):hover,p>span:nth-child(2):hover,p>span:nth-child(3):hover{
  1428. color:red;
  1429. }
  1430. .updateDate{
  1431. cursor: pointer;
  1432. user-select: none;
  1433. }
  1434. .updateDate:hover{
  1435. color:red;
  1436. }
  1437. `);
  1438. document.querySelector("[name='user-content-click2import']").innerText=i18n("click2ImportRule")
  1439. configCon=document.querySelector(".markdown-body");
  1440. insertPos=configCon.querySelector("hr");
  1441. }else return false;
  1442. class Rulebar {
  1443. init(ruleUrl){
  1444. this.ruleUrl=ruleUrl;
  1445. this.item=document.createElement("p");
  1446. this.item.title=ruleUrl.type==0?"AutoPagerize Rules":"Pagetual Rules";
  1447. this.item.dataset.id=this.ruleUrl.id;
  1448. let url=document.createElement("span");
  1449. url.innerHTML=ruleUrl.url;
  1450. let up=document.createElement("span");
  1451. up.innerHTML="↑ ";
  1452. up.title=i18n("sortTitle");
  1453. let down=document.createElement("span");
  1454. down.innerHTML="↓ ";
  1455. down.title=i18n("sortTitle");
  1456. let del=document.createElement("span");
  1457. del.innerHTML="× ";
  1458. up.onclick=e=>{
  1459. this.moveUp();
  1460. };
  1461. down.onclick=e=>{
  1462. this.moveDown();
  1463. };
  1464. del.onclick=e=>{
  1465. this.del();
  1466. };
  1467. this.item.appendChild(up);
  1468. this.item.appendChild(down);
  1469. this.item.appendChild(del);
  1470. this.item.appendChild(url);
  1471. configCon.insertBefore(this.item, insertPos);
  1472. }
  1473. saveSort(){
  1474. let sort=[];
  1475. [].forEach.call(this.item.parentNode.querySelectorAll("p[data-id]"), i=>{
  1476. sort.push(i.dataset.id);
  1477. });
  1478. rulesData.sort=sort;
  1479. storage.setItem("rulesData", rulesData);
  1480. }
  1481. moveUp(){
  1482. let preE=this.item.previousElementSibling;
  1483. if(preE.tagName=="P" && preE.children.length>1){
  1484. this.item.parentNode.insertBefore(this.item,preE);
  1485. this.saveSort();
  1486. }
  1487. }
  1488. moveDown(){
  1489. let nextE=this.item.nextElementSibling;
  1490. if(nextE.tagName=="P" && nextE.children.length>1){
  1491. this.item.parentNode.insertBefore(nextE,this.item);
  1492. this.saveSort();
  1493. }
  1494. }
  1495. del(){
  1496. if(this.ruleUrl.id<2){
  1497. alert(i18n("cantDel"));
  1498. }else if(window.confirm(i18n("confirmDel"))){
  1499. for(let u=0;u<rulesData.urls.length;u++){
  1500. if(this.ruleUrl.id==rulesData.urls[u].id){
  1501. rulesData.urls.splice(u,1);
  1502. break;
  1503. }
  1504. }
  1505. for(let u=0;u<rulesData.sort.length;u++){
  1506. if(this.ruleUrl.id==rulesData.sort[u]){
  1507. rulesData.sort.splice(u,1);
  1508. break;
  1509. }
  1510. }
  1511. storage.setItem("rulesData", rulesData);
  1512. ruleParser.rules=ruleParser.rules.filter(item=>{return item.from!=this.ruleUrl.id});
  1513. storage.setItem("rules", ruleParser.rules);
  1514. this.item.parentNode.removeChild(this.item);
  1515. //location.reload();
  1516. }
  1517. }
  1518. }
  1519. let updateP=document.createElement("p"),i=0;
  1520. let now=new Date().getTime(),inUpdate=false;
  1521.  
  1522.  
  1523. let pastDate=(new Date(updateDate)).toString(),passStr;
  1524. let passTime=(now-updateDate)/1000;
  1525. if(isNaN(passTime)){
  1526. passStr=i18n("firstUpdate");
  1527. }else if(passTime<60){
  1528. passStr=i18n("passSec", parseInt(passTime))+" ← "+i18n("click2update");
  1529. }else if(passTime<60*60){
  1530. passStr=i18n("passMin", parseInt(passTime/60))+" ← "+i18n("click2update");
  1531. }else if(passTime<60*60*24){
  1532. passStr=i18n("passHour", parseInt(passTime/3600))+" ← "+i18n("click2update");
  1533. }else{
  1534. passStr=i18n("passDay", parseInt(passTime/86400))+" ← "+i18n("click2update");
  1535. }
  1536.  
  1537.  
  1538. updateP.className="updateDate";
  1539. updateP.innerHTML=passStr;
  1540. updateP.title=i18n("update")+" - "+pastDate;
  1541. updateP.onclick=e=>{
  1542. updateRules(()=>{
  1543. alert(i18n("updateSucc"));
  1544. updateP.innerHTML=i18n("passSec", 0);
  1545. updateP.title=i18n("update");
  1546. },(rule,err)=>{
  1547. alert("Update "+rule.url+" rules fail!");
  1548. });
  1549. alert(i18n("beginUpdate"));
  1550. };
  1551. configCon.insertBefore(updateP, insertPos);
  1552. if(ruleUrls){
  1553. ruleUrls.forEach(ruleUrl=>{
  1554. var rulebar=new Rulebar();
  1555. rulebar.init(ruleUrl);
  1556. });
  1557. }
  1558. let customUrlsTitle=document.createElement("h2");
  1559. customUrlsTitle.innerHTML=i18n("customUrls");
  1560. configCon.insertBefore(customUrlsTitle, insertPos);
  1561. let customUrlsInput=document.createElement("textarea");
  1562. customUrlsInput.style.width="100%";
  1563. customUrlsInput.placeholder="0|http://wedata.net/databases/AutoPagerize/items_all.json";
  1564. configCon.insertBefore(customUrlsInput, insertPos);
  1565.  
  1566. let opacityTitle=document.createElement("h2");
  1567. opacityTitle.innerHTML=i18n("opacity");
  1568. let opacityInput=document.createElement("input");
  1569. opacityInput.value=rulesData.opacity*100;
  1570. opacityInput.type="number";
  1571. opacityInput.style.width="50px";
  1572. opacityInput.style.margin="0 0 0 10px";
  1573. opacityTitle.appendChild(opacityInput);
  1574. configCon.insertBefore(opacityTitle, insertPos);
  1575.  
  1576. function createCheckbox(innerText, val){
  1577. let title=document.createElement("h2");
  1578. title.innerHTML=innerText;
  1579. let input=document.createElement("input");
  1580. input.type="checkbox";
  1581. input.style.width="50px";
  1582. input.style.height="20px";
  1583. input.checked=val;
  1584. title.appendChild(input);
  1585. configCon.insertBefore(title, insertPos);
  1586. return input;
  1587. }
  1588.  
  1589. let hideBarInput=createCheckbox(i18n("hideBar"), rulesData.hideBar);
  1590. let dbClick2StopInput=createCheckbox(i18n("dbClick2Stop"), rulesData.dbClick2Stop);
  1591. let enableWhiteListInput=createCheckbox(i18n("autoRun"), rulesData.enableWhiteList!=true);
  1592. let enableDebugInput=createCheckbox(i18n("enableDebug"), rulesData.enableDebug!=false);
  1593. let enableHistoryInput=createCheckbox(i18n("enableHistory"), rulesData.enableHistory===true);
  1594. let initRunInput=createCheckbox(i18n("initRun"), rulesData.initRun!=false);
  1595. let preloadInput=createCheckbox(i18n("preload"), rulesData.preload);
  1596.  
  1597. let customRulesTitle=document.createElement("h2");
  1598. customRulesTitle.innerHTML=i18n("customRules")
  1599. configCon.insertBefore(customRulesTitle, insertPos);
  1600. let customRulesInput=document.createElement("textarea");
  1601. customRulesInput.style.width="100%";
  1602. customRulesInput.style.height="500px";
  1603. customRulesInput.placeholder=`[\n {\n "name":"yande",\n "action":"0",\n "url":"^https:\/\/yande\\.re\/",\n "pageElement":"ul#post-list-posts>li",\n "nextLink":"a.next_page",\n "css":".javascript-hide {display: inline-block !important;}"\n },\n {\n "name":"tieba",\n "action":"1",\n "url":"^https:\/\/tieba\\.baidu.com\/f\\?kw=",\n "pageElement":"ul#thread_list>li",\n "nextLink":".next.pagination-item "\n }\n]`;
  1604. customRulesInput.value=getFormatJSON(ruleParser.customRules);
  1605. configCon.insertBefore(customRulesInput, insertPos);
  1606. let saveBtn=document.createElement("button");
  1607. saveBtn.innerHTML=i18n("save");
  1608. saveBtn.style.width="100%";
  1609. configCon.insertBefore(saveBtn, insertPos);
  1610. saveBtn.onclick=e=>{
  1611. try{
  1612. storage.setItem("hpRules", []);
  1613. if(customRulesInput.value==""){
  1614. storage.setItem("customRules", "");
  1615. }else{
  1616. let customRules=JSON.parse(customRulesInput.value);
  1617. if(Array && Array.isArray && !Array.isArray(customRules)){
  1618. alert("Rules must be a Array!");
  1619. return;
  1620. }
  1621. debug(customRules);
  1622. storage.setItem("customRules", customRules);
  1623. }
  1624. }catch(e){
  1625. debug(e);
  1626. alert("JSON error, check again!");
  1627. return;
  1628. }
  1629. rulesData.opacity=opacityInput.value/100;
  1630. rulesData.hideBar=hideBarInput.checked;
  1631. rulesData.dbClick2Stop=dbClick2StopInput.checked;
  1632. rulesData.enableWhiteList=!enableWhiteListInput.checked;
  1633. rulesData.enableDebug=enableDebugInput.checked;
  1634. rulesData.enableHistory=enableHistoryInput.checked;
  1635. rulesData.initRun=initRunInput.checked;
  1636. rulesData.preload=preloadInput.checked;
  1637. storage.setItem("rulesData", rulesData);
  1638. let customUrls=customUrlsInput.value.trim();
  1639. if(customUrls){
  1640. customUrls=customUrls.split(/\n/);
  1641. for(let c=0;c<customUrls.length;c++){
  1642. let urlArr=customUrls[c].split("|"),url,type=1;
  1643. if(urlArr.length==1){
  1644. url=urlArr[0].trim();
  1645. if(!/^http/.test(url)){
  1646. alert("Wrong url, check again!");
  1647. return;
  1648. }
  1649. }else if(urlArr.length==2){
  1650. type=urlArr[0].trim();
  1651. url=urlArr[1].trim();
  1652. if(!/^http/.test(url)){
  1653. alert("Wrong url, check again!");
  1654. return;
  1655. }
  1656. }else{
  1657. break;
  1658. }
  1659. let maxId=0,hasUrl=false;
  1660. if(!rulesData.urls){
  1661. rulesData.urls=[];
  1662. maxId=1;
  1663. }else{
  1664. rulesData.urls.forEach(u=>{
  1665. if(maxId<u.id){
  1666. maxId=u.id;
  1667. }
  1668. if(u.url==url){
  1669. hasUrl=true;
  1670. }
  1671. });
  1672. if(hasUrl)break;
  1673. }
  1674. if(!rulesData.sort)rulesData.sort=[1];
  1675. rulesData.urls.push({id:maxId+1,url:url,type:type});
  1676. rulesData.sort.push(maxId+1);
  1677. storage.setItem("rulesData", rulesData);
  1678. }
  1679. }
  1680. alert("The settings are saved");
  1681. location.reload();
  1682. };
  1683. return true;
  1684. }
  1685.  
  1686. var inUpdate=false;
  1687. function updateRules(success,fail){
  1688. if(inUpdate)return;
  1689. inUpdate=true;
  1690. let ruleIndex=ruleUrls.length-1;
  1691. storage.setItem("hpRules", []);
  1692. function addNextRule(){
  1693. if(ruleIndex<0){
  1694. let now=new Date().getTime();
  1695. storage.setItem("ruleLastUpdate", now);
  1696. storage.setItem("rules", ruleParser.rules);
  1697. inUpdate=false;
  1698. success();
  1699. }else{
  1700. let rule=ruleUrls[ruleIndex--];
  1701. ruleParser.addRuleByUrl(rule.url, rule.type, rule.id, (json,err)=>{
  1702. if(!json){
  1703. fail(rule,err);
  1704. }
  1705. addNextRule();
  1706. })
  1707. }
  1708. }
  1709. addNextRule();
  1710. }
  1711.  
  1712. function objIsArr(obj) {
  1713. return obj &&
  1714. typeof obj === 'object' &&
  1715. typeof obj.length === 'number' &&
  1716. !(obj.propertyIsEnumerable('length'));
  1717. }
  1718.  
  1719. function isVisible(el, win) {
  1720. if(!el.offsetParent)return false;
  1721. var loopable = true,
  1722. visible = el.tagName && win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  1723. while(loopable && visible) {
  1724. el = el.parentNode;
  1725.  
  1726. if(el && el.tagName && el.tagName!="BODY") {
  1727. visible = win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  1728. }else {
  1729. loopable = false;
  1730. }
  1731. }
  1732. return visible;
  1733. }
  1734.  
  1735. function getFormatJSON(obj){
  1736. if(!objIsArr(obj))return "";
  1737. let ret="[\n";
  1738. let len=obj.length,i=0,isLast;
  1739. obj.forEach(item=>{
  1740. ret+=" {\n";
  1741. let iLen=Object.keys(item).length,j=0;
  1742. for(let key in item){
  1743. isLast=(++j)==iLen;
  1744. let value=item[key];
  1745. if(objIsArr(value)){
  1746. let vstr="[",v=0,vIsLast=false;
  1747. value.forEach(vi=>{
  1748. vIsLast=(++v)==value.length;
  1749. vstr+="\""+vi.replace(/\\/g,"\\\\")+"\""+(vIsLast?"":",");
  1750. });
  1751. vstr+="]";
  1752. ret+=" \""+key+"\":"+vstr+""+(isLast?"":",")+"\n";
  1753. }else{
  1754. if(typeof value=="string"){
  1755. value=value.replace(/\\/g,"\\\\").replace(/"/g,"\\\"");
  1756. value="\""+value+"\"";
  1757. }
  1758. ret+=" \""+key+"\":"+value+""+(isLast?"":",")+"\n";
  1759. }
  1760. }
  1761. isLast=(++i)==len;
  1762. ret+=" }"+(isLast?"":",")+"\n";
  1763. });
  1764. ret+="]";
  1765. return ret;
  1766. }
  1767.  
  1768. function initRules(callback) {
  1769. /*0 wedata格式,1 pagetual格式*/
  1770. ruleUrls=[
  1771. {
  1772. id:1,
  1773. url:'http://wedata.net/databases/AutoPagerize/items_all.json',
  1774. type:0,
  1775. }
  1776. ];var i=0,j=0;
  1777.  
  1778. ruleParser.initSavedRules(()=>{
  1779. storage.getItem("rulesData", data=>{
  1780. if(data){
  1781. rulesData=data;
  1782. if(data.urls)ruleUrls=ruleUrls.concat(data.urls);
  1783. if(data.sort){
  1784. let urls=[];
  1785. data.sort.forEach(id=>{
  1786. for(let s=0;s<ruleUrls.length;s++){
  1787. if(id==ruleUrls[s].id){
  1788. urls.push(ruleUrls[s]);
  1789. break;
  1790. }
  1791. }
  1792. });
  1793. ruleUrls=urls;
  1794. }
  1795. }
  1796. if(typeof(rulesData.opacity)=="undefined"){
  1797. rulesData.opacity=0.3;
  1798. }
  1799. if(typeof(rulesData.hideBar)=="undefined"){
  1800. rulesData.hideBar=false;
  1801. }
  1802. if(typeof(rulesData.dbClick2Stop)=="undefined"){
  1803. rulesData.dbClick2Stop=true;
  1804. }
  1805. if(typeof(rulesData.enableWhiteList)=="undefined"){
  1806. rulesData.enableWhiteList=false;
  1807. }
  1808. if(typeof(rulesData.enableHistory)=="undefined"){
  1809. rulesData.enableHistory=false;
  1810. }
  1811. if(typeof(rulesData.enableDebug)=="undefined"){
  1812. rulesData.enableDebug=true;
  1813. }
  1814. if(typeof(rulesData.initRun)=="undefined"){
  1815. rulesData.initRun=true;
  1816. }
  1817. if(typeof(rulesData.preload)=="undefined"){
  1818. rulesData.preload=false;
  1819. }
  1820. enableDebug=rulesData.enableDebug;
  1821. storage.getItem("forceState_"+location.host, v=>{
  1822. storage.getItem("ruleLastUpdate", date=>{
  1823. if(typeof(v)=="undefined"){
  1824. v=(rulesData.enableWhiteList?1:0);
  1825. }
  1826. forceState=v;
  1827. updateDate=date;
  1828. if(initConfig())return;
  1829. if(forceState==1)return;
  1830. let now=new Date().getTime();
  1831. if(!date || now-date>2*24*60*60*1000){
  1832. //storage.setItem("ruleLastUpdate", now);
  1833. updateRules(()=>{
  1834. //callback();
  1835. },(rule,err)=>{});
  1836. }
  1837. callback();
  1838. });
  1839. });
  1840. });
  1841. });
  1842. }
  1843.  
  1844. function requestDoc(url, callback){
  1845. _GM_xmlhttpRequest({
  1846. url: url,
  1847. method: 'GET',
  1848. overrideMimeType: 'text/html;charset='+document.charset,
  1849. headers: {
  1850. 'Referer': location.href
  1851. },
  1852. timeout: 5000,
  1853. onload: function(res) {
  1854. var doc=null;
  1855. try {
  1856. doc=document.implementation.createHTMLDocument('');
  1857. doc.documentElement.innerHTML=res.response;
  1858. }
  1859. catch (e) {
  1860. debug('parse error'+e.toString());
  1861. }
  1862. let pageElement=ruleParser.getPageElement(doc);
  1863. //只有1的話怕不是圖片哦
  1864. if(pageElement && (pageElement.length>1 || (pageElement.length==1 && pageElement[0].tagName!="IMG") )){
  1865. let result=ruleParser.insertPage(doc, pageElement, url, callback, false);
  1866. if(!result){
  1867. ruleParser.curSiteRule.action=1;
  1868. requestFromIframe(url, (doc, eles)=>{
  1869. loadPageOver();
  1870. if(eles){
  1871. ruleParser.insertPage(doc, eles, url, callback, true);
  1872. }
  1873. });
  1874. }
  1875. }else if(ruleParser.curSiteRule.singleUrl){
  1876. ruleParser.curSiteRule.action=1;
  1877. requestFromIframe(url, (doc, eles)=>{
  1878. loadPageOver();
  1879. if(eles){
  1880. ruleParser.insertPage(doc, eles, url, callback, true);
  1881. }
  1882. });
  1883. }else{
  1884. isPause=true;
  1885. callback(false);
  1886. }
  1887. },
  1888. onerror: function(e){
  1889. debug(e);
  1890. callback(false);
  1891. },
  1892. ontimeout: function(e){
  1893. debug(e);
  1894. callback(false);
  1895. }
  1896. });
  1897. }
  1898.  
  1899. var failFromIframe=0;
  1900. function requestFromIframe(url, callback){
  1901. let orgPage,curPage;
  1902. let iframe = document.createElement('iframe');
  1903. iframe.name = 'pagetual-iframe';
  1904. iframe.width = '100%';
  1905. iframe.height = '0';
  1906. iframe.frameBorder = '0';
  1907. if(ruleParser.curSiteRule.sandbox!=false){
  1908. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1909. }
  1910. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1911. iframe.addEventListener("load", e=>{
  1912. let waitTime=500,checkEval;
  1913. if(ruleParser.curSiteRule.wait){
  1914. if(isNaN(ruleParser.curSiteRule.wait)){
  1915. try{
  1916. checkEval=Function("doc",'"use strict";' + ruleParser.curSiteRule.wait);
  1917. }catch(e){
  1918. debug(e);
  1919. }
  1920. }else{
  1921. waitTime=ruleParser.curSiteRule.wait;
  1922. }
  1923. }
  1924. setTimeout(()=>{
  1925. let tryTimes=0;
  1926. function checkIframe(){
  1927. try{
  1928. let doc=iframe.contentDocument || iframe.contentWindow.document;
  1929. let eles=ruleParser.getPageElement(doc, iframe.contentWindow);
  1930. if(eles && eles.length>0 && (!checkEval || checkEval(doc))){
  1931. callback(doc, eles);
  1932. }else if(tryTimes++ < 10){
  1933. setTimeout(()=>{
  1934. checkIframe();
  1935. },waitTime);
  1936. return;
  1937. }else{
  1938. if(failFromIframe++ > 2){
  1939. failFromIframe=0;
  1940. debug("Stop as failFromIframe");
  1941. isPause=true;
  1942. callback(false, false);
  1943. }else{
  1944. callback(false, false);
  1945. }
  1946. }
  1947. }catch(e){
  1948. debug("Stop as cors");
  1949. //isPause=true;
  1950. ruleParser.curSiteRule.pageElement=allOfBody;
  1951. ruleParser.curSiteRule.action=0;
  1952. ruleParser.getInsert(true);
  1953. ruleParser.nextLinkHref=url;
  1954. callback(false, false);
  1955. }
  1956. document.body.removeChild(iframe);
  1957. }
  1958. checkIframe();
  1959. },waitTime);
  1960. });
  1961. iframe.src=url;
  1962. document.body.appendChild(iframe);
  1963. }
  1964.  
  1965. function initPage(){
  1966. ruleParser.initPage(()=>{
  1967. if(ruleParser.nextLinkHref){
  1968. initView();
  1969. let isJs=/^(javascript|#)/.test(ruleParser.nextLinkHref.replace(location.href,""));
  1970. if(!isJs){
  1971. _GM_registerMenuCommand(i18n(forceState==2?"cancelForceIframe":"forceIframe"), ()=>{
  1972. storage.setItem("forceState_"+location.host, (forceState==2?"":2));
  1973. location.reload();
  1974. });
  1975. }
  1976. _GM_registerMenuCommand(i18n("loadNow"), ()=>{
  1977. let loadNum=window.prompt(i18n("loadConfirm"), "1");
  1978. if(loadNum==="" || loadNum===null)return;
  1979. autoLoadNum=Math.abs(parseInt(loadNum));
  1980. nextPage();
  1981. });
  1982. }
  1983. initListener();
  1984. if(rulesData.initRun && ruleParser.curSiteRule.initRun!=0)nextPage();
  1985. });
  1986. }
  1987.  
  1988. function initView(){
  1989. _GM_addStyle(`
  1990. .pagetual_pageBar.stop {
  1991. -webkit-filter: invert(100%);
  1992. filter: invert(100%);
  1993. opacity: 1!important;
  1994. }
  1995. .pagetual_pageBar.hide {
  1996. display: none!important;
  1997. }
  1998. .pagetual_pageBar:hover {
  1999. opacity: 1!important;
  2000. }
  2001. .pagetual_pageBar span {
  2002. vertical-align: super;
  2003. }
  2004.  
  2005. .pagetual_pageBar span>svg:hover {
  2006. animation: touhouAni 1s infinite;
  2007. }
  2008. .pagetual_pageBar .pagetual_pageNum{
  2009. color: #55555f;
  2010. }
  2011. .pagetual_pageBar .pagetual_pageNum:hover{
  2012. color: #ff6464;
  2013. }
  2014.  
  2015. @keyframes touhouAni{
  2016. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  2017. to {transform: rotate(360deg);}
  2018. }
  2019. @-webkit-keyframes touhouAni{
  2020. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  2021. to {transform: rotate(360deg);}
  2022. }
  2023. `);
  2024. pageBarStyle=`opacity:${rulesData.opacity};display:${rulesData.opacity==0?"none":"block"};padding:0;box-shadow: 0px 0px 10px 0px #000000aa;border-radius: 20px;background-color: rgb(240 240 240 / 80%);visibility: visible; position: initial; width: auto; height: 30px; float: none; clear: both; margin: 5px auto; text-align: center;`;
  2025. }
  2026. var loadingDiv=document.createElement("div");
  2027. loadingDiv.className="pagetual_loading";
  2028. loadingDiv.style.cssText="cy: initial;d: initial;dominant-baseline: initial;empty-cells: initial;fill: initial;fill-opacity: initial;fill-rule: initial;filter: initial;flex: initial;flex-flow: initial;float: initial;flood-color: initial;flood-opacity: initial;grid: initial;grid-area: initial;height: initial;hyphens: initial;image-orientation: initial;image-rendering: initial;inline-size: initial;inset-block: initial;inset-inline: initial;isolation: initial;letter-spacing: initial;lighting-color: initial;line-break: initial;list-style: initial;margin-block: initial;margin: 0px auto;margin-inline: initial;marker: initial;mask: initial;mask-type: initial;max-block-size: initial;max-height: initial;max-inline-size: initial;max-width: initial;min-block-size: initial;min-height: initial;min-inline-size: initial;min-width: initial;mix-blend-mode: initial;object-fit: initial;object-position: initial;offset: initial;opacity: initial;order: initial;origin-trial-test-property: initial;orphans: initial;outline: initial;outline-offset: initial;overflow-anchor: initial;overflow-clip-margin: initial;overflow-wrap: initial;overflow: initial;overscroll-behavior-block: initial;overscroll-behavior-inline: initial;overscroll-behavior: initial;padding-block: initial;padding: initial;padding-inline: initial;page: initial;page-orientation: initial;paint-order: initial;perspective: initial;perspective-origin: initial;pointer-events: initial;position: initial;quotes: initial;r: initial;resize: initial;ruby-position: initial;rx: initial;ry: initial;scroll-behavior: initial;scroll-margin-block: initial;scroll-margin: initial;scroll-margin-inline: initial;scroll-padding-block: initial;scroll-padding: initial;scroll-padding-inline: initial;scroll-snap-align: initial;scroll-snap-stop: initial;scroll-snap-type: initial;scrollbar-gutter: initial;shape-image-threshold: initial;shape-margin: initial;shape-outside: initial;shape-rendering: initial;size: initial;speak: initial;stop-color: initial;stop-opacity: initial;stroke: initial;stroke-dasharray: initial;stroke-dashoffset: initial;stroke-linecap: initial;stroke-linejoin: initial;stroke-miterlimit: initial;stroke-opacity: initial;stroke-width: initial;tab-size: initial;table-layout: initial;text-align: initial;text-align-last: initial;text-anchor: initial;text-combine-upright: initial;text-decoration: initial;text-decoration-skip-ink: initial;text-indent: initial;text-overflow: initial;text-shadow: initial;text-size-adjust: initial;text-transform: initial;text-underline-offset: initial;text-underline-position: initial;touch-action: initial;transform: initial;transform-box: initial;transform-origin: initial;transform-style: initial;transition: initial;user-select: initial;vector-effect: initial;vertical-align: initial;visibility: initial;border-spacing: initial;-webkit-border-image: initial;-webkit-box-align: initial;-webkit-box-decoration-break: initial;-webkit-box-direction: initial;-webkit-box-flex: initial;-webkit-box-ordinal-group: initial;-webkit-box-orient: initial;-webkit-box-pack: initial;-webkit-box-reflect: initial;-webkit-highlight: initial;-webkit-hyphenate-character: initial;-webkit-line-break: initial;-webkit-line-clamp: initial;-webkit-mask-box-image: initial;-webkit-mask: initial;-webkit-mask-composite: initial;-webkit-perspective-origin-x: initial;-webkit-perspective-origin-y: initial;-webkit-print-color-adjust: initial;-webkit-rtl-ordering: initial;-webkit-ruby-position: initial;-webkit-tap-highlight-color: initial;-webkit-text-combine: initial;-webkit-text-decorations-in-effect: initial;-webkit-text-emphasis: initial;-webkit-text-emphasis-position: initial;-webkit-text-fill-color: initial;-webkit-text-security: initial;-webkit-text-stroke: initial;-webkit-transform-origin-x: initial;-webkit-transform-origin-y: initial;-webkit-transform-origin-z: initial;-webkit-user-drag: initial;-webkit-user-modify: initial;white-space: initial;widows: initial;width: initial;will-change: initial;word-break: initial;word-spacing: initial;x: initial;y: initial;z-index: 2147483647;";
  2029. loadingDiv.innerHTML=`<p style=" display: block; position: initial; margin: auto auto 5px auto; shape-rendering: auto; vertical-align: middle; visibility: visible; width: initial; height: initial; text-align: center; color: #6e6e6e; ">${i18n("loadingText")}</p><svg width="120" height="30" viewBox="0 0 120 30" fill="#000000A0" style="display: block;position: initial;margin: auto;shape-rendering: auto;vertical-align: middle;visibility: visible;width: initial;height: initial;"><circle cx="15" cy="15" r="15"><animate attributeName="r" from="15" to="15" begin="0s" dur="0.8s" values="15;9;15" calcMode="linear" repeatCount="indefinite"></animate><animate attributeName="fill-opacity" from="1" to="1" begin="0s" dur="0.8s" values="1;.5;1" calcMode="linear" repeatCount="indefinite"></animate></circle><circle cx="60" cy="15" r="9" fill-opacity="0.3"><animate attributeName="r" from="9" to="9" begin="0s" dur="0.8s" values="9;15;9" calcMode="linear" repeatCount="indefinite"></animate><animate attributeName="fill-opacity" from="0.5" to="0.5" begin="0s" dur="0.8s" values=".5;1;.5" calcMode="linear" repeatCount="indefinite"></animate></circle><circle cx="105" cy="15" r="15"><animate attributeName="r" from="15" to="15" begin="0s" dur="0.8s" values="15;9;15" calcMode="linear" repeatCount="indefinite"></animate><animate attributeName="fill-opacity" from="1" to="1" begin="0s" dur="0.8s" values="1;.5;1" calcMode="linear" repeatCount="indefinite"></animate></circle></svg>`;
  2030.  
  2031. var upSvg=`<svg width="30" height="30" style="position:absolute;cursor: pointer;margin: 0 -45px;width: 30px;height: 30px;vertical-align: middle;fill: currentColor;overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="6364"><path d="M296 440c-44.1 0-80 35.9-80 80s35.9 80 80 80 80-35.9 80-80-35.9-80-80-80z" fill="#604b4a" p-id="6365"></path><path d="M960 512c0-247-201-448-448-448S64 265 64 512c0 1.8 0.1 3.5 0.1 5.3 0 0.9-0.1 1.8-0.1 2.7h0.2C68.5 763.3 267.7 960 512 960c236.2 0 430.1-183.7 446.7-415.7 0.1-0.8 0.1-1.6 0.2-2.3 0.4-4.6 0.5-9.3 0.7-13.9 0.1-2.7 0.4-5.3 0.4-8h-0.2c0-2.8 0.2-5.4 0.2-8.1z m-152 8c0 44.1-35.9 80-80 80s-80-35.9-80-80 35.9-80 80-80 80 35.9 80 80zM512 928C284.4 928 99 744.3 96.1 517.3 97.6 408.3 186.6 320 296 320c110.3 0 200 89.7 200 200 0 127.9 104.1 232 232 232 62.9 0 119.9-25.2 161.7-66-66 142.7-210.4 242-377.7 242z" fill="#604b4a" p-id="6366"></path></svg>`;
  2032. var downSvg=`<svg width="30" height="30" style="position:absolute;cursor: pointer;margin: 0 15px;width: 30px;height: 30px;vertical-align: middle;fill: currentColor;overflow: hidden;transform: rotate(180deg);" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="6364"><path d="M296 440c-44.1 0-80 35.9-80 80s35.9 80 80 80 80-35.9 80-80-35.9-80-80-80z" fill="#604b4a" p-id="6365"></path><path d="M960 512c0-247-201-448-448-448S64 265 64 512c0 1.8 0.1 3.5 0.1 5.3 0 0.9-0.1 1.8-0.1 2.7h0.2C68.5 763.3 267.7 960 512 960c236.2 0 430.1-183.7 446.7-415.7 0.1-0.8 0.1-1.6 0.2-2.3 0.4-4.6 0.5-9.3 0.7-13.9 0.1-2.7 0.4-5.3 0.4-8h-0.2c0-2.8 0.2-5.4 0.2-8.1z m-152 8c0 44.1-35.9 80-80 80s-80-35.9-80-80 35.9-80 80-80 80 35.9 80 80zM512 928C284.4 928 99 744.3 96.1 517.3 97.6 408.3 186.6 320 296 320c110.3 0 200 89.7 200 200 0 127.9 104.1 232 232 232 62.9 0 119.9-25.2 161.7-66-66 142.7-210.4 242-377.7 242z" fill="#604b4a" p-id="6366"></path></svg>`;
  2033. var pageBarStyle;
  2034. var initStyle=`display: contents;right: unset;left: unset;top: unset;bottom: unset;inset: unset;clear: both;cy: initial;d: initial;dominant-baseline: initial;empty-cells: initial;fill: initial;fill-opacity: initial;fill-rule: initial;filter: initial;flex: initial;flex-flow: initial;float: initial;flood-color: initial;flood-opacity: initial;grid: initial;grid-area: initial;height: initial;hyphens: initial;image-orientation: initial;image-rendering: initial;inline-size: initial;inset-block: initial;inset-inline: initial;isolation: initial;letter-spacing: initial;lighting-color: initial;line-break: initial;list-style: initial;margin-block: initial;margin: 0px auto;margin-inline: initial;marker: initial;mask: initial;mask-type: initial;max-block-size: initial;max-height: initial;max-inline-size: initial;max-width: initial;min-block-size: initial;min-height: initial;min-inline-size: initial;min-width: initial;mix-blend-mode: initial;object-fit: initial;object-position: initial;offset: initial;opacity: initial;order: initial;orphans: initial;outline: initial;outline-offset: initial;overflow-anchor: initial;overflow-clip-margin: initial;overflow-wrap: initial;overflow: initial;overscroll-behavior-block: initial;overscroll-behavior-inline: initial;overscroll-behavior: initial;padding-block: initial;padding: initial;padding-inline: initial;page: initial;page-orientation: initial;paint-order: initial;perspective: initial;perspective-origin: initial;pointer-events: initial;position: relative;quotes: initial;r: initial;resize: initial;ruby-position: initial;rx: initial;ry: initial;scroll-behavior: initial;scroll-margin-block: initial;scroll-margin: initial;scroll-margin-inline: initial;scroll-padding-block: initial;scroll-padding: initial;scroll-padding-inline: initial;scroll-snap-align: initial;scroll-snap-stop: initial;scroll-snap-type: initial;scrollbar-gutter: initial;shape-image-threshold: initial;shape-margin: initial;shape-outside: initial;shape-rendering: initial;size: initial;speak: initial;stop-color: initial;stop-opacity: initial;stroke: initial;stroke-dasharray: initial;stroke-dashoffset: initial;stroke-linecap: initial;stroke-linejoin: initial;stroke-miterlimit: initial;stroke-opacity: initial;stroke-width: initial;tab-size: initial;table-layout: initial;text-align: initial;text-align-last: initial;text-anchor: initial;text-combine-upright: initial;text-decoration: initial;text-decoration-skip-ink: initial;text-indent: initial;text-overflow: initial;text-shadow: initial;text-size-adjust: initial;text-transform: initial;text-underline-offset: initial;text-underline-position: initial;touch-action: initial;transform: initial;transform-box: initial;transform-origin: initial;transform-style: initial;transition: initial;user-select: initial;vector-effect: initial;vertical-align: initial;visibility: initial;border-spacing: initial;-webkit-border-image: initial;-webkit-box-align: initial;-webkit-box-decoration-break: initial;-webkit-box-direction: initial;-webkit-box-flex: initial;-webkit-box-ordinal-group: initial;-webkit-box-orient: initial;-webkit-box-pack: initial;-webkit-box-reflect: initial;-webkit-highlight: initial;-webkit-hyphenate-character: initial;-webkit-line-break: initial;-webkit-line-clamp: initial;-webkit-mask-box-image: initial;-webkit-mask: initial;-webkit-mask-composite: initial;-webkit-perspective-origin-x: initial;-webkit-perspective-origin-y: initial;-webkit-print-color-adjust: initial;-webkit-rtl-ordering: initial;-webkit-ruby-position: initial;-webkit-tap-highlight-color: initial;-webkit-text-combine: initial;-webkit-text-decorations-in-effect: initial;-webkit-text-emphasis: initial;-webkit-text-emphasis-position: initial;-webkit-text-fill-color: initial;-webkit-text-security: initial;-webkit-text-stroke: initial;-webkit-transform-origin-x: initial;-webkit-transform-origin-y: initial;-webkit-transform-origin-z: initial;-webkit-user-drag: initial;-webkit-user-modify: initial;white-space: initial;widows: initial;width: initial;will-change: initial;word-break: initial;word-spacing: initial;x: initial;y: initial;`;
  2035. var pageTextStyle=`line-height: 30px;text-decoration: none;user-select: none;visibility: visible;position: initial;width: auto;height: auto;float: none;clear: both;margin: 0px auto;text-align: center;display: inline;font-weight: bold;font-style: normal;font-size: 16px;letter-spacing: initial;vertical-align: super;color: rgb(85, 85, 95);`;
  2036.  
  2037. var isPause=false,isLoading=false,curPage=1,forceState=0,bottomGap=1000,autoLoadNum=-1;
  2038.  
  2039. function changeStop(stop, hide){
  2040. isPause=stop;
  2041. [].forEach.call(document.querySelectorAll(".pagetual_pageBar"), bar=>{
  2042. if(isPause){
  2043. bar.classList.add("stop");
  2044. if(hide)bar.classList.add("hide");
  2045. }else{
  2046. bar.classList.remove("stop");
  2047. if(hide)bar.classList.remove("hide");
  2048. }
  2049. });
  2050. }
  2051.  
  2052. function isInViewPort(element) {
  2053. if(!element.parentNode)return false;
  2054. if(_unsafeWindow.getComputedStyle(element).display=="none")return false;
  2055. const viewWidth = window.innerWidth || document.documentElement.clientWidth;
  2056. const viewHeight = window.innerHeight || document.documentElement.clientHeight;
  2057. const {
  2058. top,
  2059. right,
  2060. bottom,
  2061. left,
  2062. } = element.getBoundingClientRect();
  2063.  
  2064. return (
  2065. top >= 0 &&
  2066. left >= 0 &&
  2067. right <= viewWidth &&
  2068. bottom <= viewHeight
  2069. );
  2070. }
  2071.  
  2072. var urlChanged=false;
  2073. var _wr = function(type) {
  2074. var orig = history[type];
  2075. return function() {
  2076. var rv = orig.apply(this, arguments);
  2077. var e = new Event(type);
  2078. e.arguments = arguments;
  2079. window.dispatchEvent(e);
  2080. return rv;
  2081. };
  2082. };
  2083. history.pushState = _wr('pushState');
  2084. window.addEventListener('pushState', function(e) {
  2085. urlChanged=true;
  2086. isPause=true;
  2087. setTimeout(()=>{
  2088. if(location.href==configPage){
  2089. location.reload();
  2090. }
  2091. },1);
  2092. });
  2093.  
  2094. function initListener(){
  2095. let loadmoreBtn,loading=true;
  2096. setTimeout(()=>{
  2097. loadmoreBtn=getLoadMore(document);
  2098. if(loadmoreBtn && isVisible(loadmoreBtn, _unsafeWindow)){
  2099. loading=false;
  2100. }
  2101. },500);
  2102. let checkScrollReach=()=>{
  2103. let scrolly=window.scrollY;
  2104. let windowHeight=window.innerHeight || document.documentElement.clientHeight;
  2105. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  2106. if(scrollH-scrolly-windowHeight<bottomGap){
  2107. nextPage();
  2108. }
  2109. };
  2110. document.addEventListener('scroll', e=>{
  2111. if(urlChanged){
  2112. ruleParser.initPage(()=>{
  2113. if(ruleParser.nextLinkHref)initView();
  2114. });
  2115. urlChanged=false;
  2116. isPause=false;
  2117. }
  2118. if(isPause)return;
  2119. if(!loading){
  2120. loading=true;
  2121. setTimeout(()=>{loading=false},200);
  2122. if(!loadmoreBtn || !loadmoreBtn.parentNode){
  2123. loadmoreBtn=getLoadMore(document);
  2124. }
  2125. if(loadmoreBtn){
  2126. if(isInViewPort(loadmoreBtn)){
  2127. emuClick(loadmoreBtn);
  2128. }
  2129. }
  2130. }
  2131. setTimeout(()=>{
  2132. if(!isLoading){
  2133. checkScrollReach();
  2134. }
  2135. },100);
  2136. }, true);
  2137. document.addEventListener('dblclick', e=>{
  2138. if(rulesData.dbClick2Stop){
  2139. setTimeout(()=>{
  2140. changeStop(!isPause, rulesData.hideBar);
  2141. if(!isPause){
  2142. checkScrollReach();
  2143. }
  2144. },200);
  2145. }
  2146. });
  2147. }
  2148.  
  2149. function getLoadMore(doc){
  2150. if(ruleParser.curSiteRule.loadMore==="")return null;
  2151. let btnSel=ruleParser.curSiteRule.loadMore||".LoadMore,.load-more";
  2152. let loadmoreBtn=doc.querySelector(btnSel);
  2153. if(!loadmoreBtn){
  2154. let buttons=doc.querySelectorAll("input,button,a,div[onclick]"),loadmoreReg=/^\s*(加载更多|加載更多|load\s*more|もっと読み込む)\s*$/i;
  2155. for(let i=0;i<buttons.length;i++){
  2156. let button=buttons[i];
  2157. if(button && loadmoreReg.test(button.innerText)){
  2158. loadmoreBtn=button;
  2159. break;
  2160. }
  2161. }
  2162. }
  2163. return loadmoreBtn;
  2164. }
  2165.  
  2166. var hasPageNum=true;
  2167. function createPageBar(url){
  2168. let insert=ruleParser.getInsert();
  2169. if(!insert || !insert.parentNode)return;
  2170. curPage++;
  2171. if(rulesData.opacity==0)return;
  2172. let example=ruleParser.curSiteRule.insertPos==2?insert.children[0]:(insert.previousElementSibling||insert);
  2173. if(!example || !example.parentNode)example=insert;
  2174. let inTable=example.parentNode.tagName=="TABLE" ||
  2175. example.tagName=="TR" ||
  2176. example.tagName=="TBODY" ||
  2177. (example.previousElementSibling && example.previousElementSibling.tagName=="TR") ||
  2178. (example.previousElementSibling && example.previousElementSibling.tagName=="TBODY");
  2179. let inLi=example.tagName=="LI" || (example.previousElementSibling && example.previousElementSibling.tagName=="LI");
  2180. let pageBar=document.createElement(inTable?"tr":(inLi?"li":"div"));
  2181. let upSpan=document.createElement("span");
  2182. let downSpan=document.createElement("span");
  2183. let pageText=document.createElement("a");
  2184. let pageNum;
  2185. pageBar.className="pagetual_pageBar";
  2186. pageBar.id="pagetual_pageBar";
  2187. if(isPause){
  2188. pageBar.classList.add("stop");
  2189. }
  2190. pageBar.style.cssText=pageBarStyle;
  2191. pageBar.title=i18n(isPause?"enable":"disable");
  2192. upSpan.innerHTML=upSvg;
  2193. upSpan.title=i18n("toTop");
  2194. downSpan.innerHTML=downSvg;
  2195. downSpan.title=i18n("toBottom");
  2196. upSpan.style.cssText=initStyle;
  2197. downSpan.style.cssText=initStyle;
  2198. pageText.href=url;
  2199. pageText.style.cssText=pageTextStyle;
  2200. pageText.title=i18n("current");
  2201. pageBar.appendChild(upSpan);
  2202. pageBar.appendChild(pageText);
  2203. if(ruleParser.curSiteRule.pageNum || (hasPageNum && /[&\/\?](p=|page[=\/])\d+/.test(url))){
  2204. pageText.innerHTML="Page ";
  2205. pageNum=document.createElement("span");
  2206. pageNum.innerText=curPage;
  2207. pageNum.className="pagetual_pageNum";
  2208. pageNum.title=i18n("inputPageNum");
  2209. pageNum.style.cssText=pageTextStyle;
  2210. pageNum.style.cursor="pointer";
  2211. pageNum.style.color="";
  2212. pageNum.addEventListener("click", e=>{
  2213. let pageInput=prompt(i18n("inputPageNum"), "1");
  2214. if(pageInput){
  2215. let pageLink=ruleParser.getLinkByPage(url, pageInput);
  2216. if(pageLink){
  2217. _GM_openInTab(pageLink,{active:true});
  2218. }
  2219. }
  2220. e.preventDefault();
  2221. e.stopPropagation();
  2222. });
  2223. pageBar.appendChild(pageNum);
  2224. }else{
  2225. pageText.innerHTML="Page "+curPage;
  2226. hasPageNum=false;
  2227. }
  2228. pageBar.appendChild(downSpan);
  2229. let parentStyle=_unsafeWindow.getComputedStyle(example.parentNode);
  2230. pageBar.style.width=parseInt(parentStyle.width)-10+"px";
  2231. if(parentStyle.display=="grid" || parentStyle.display=="inline-grid"){
  2232. pageBar.style.gridColumnStart=1;
  2233. pageBar.style.gridColumnEnd=1+parseInt(example.parentNode.offsetWidth/example.offsetWidth);
  2234. }
  2235. if(inTable){
  2236. example=(example.tagName=="TR" || example.tagName=="TBODY")?example:example.previousElementSibling;
  2237. if(example.previousElementSibling)example=example.previousElementSibling;
  2238. let tdNum=0;
  2239. [].forEach.call(example.querySelectorAll("td,th"), td=>{
  2240. tdNum+=td.colSpan||1;
  2241. });
  2242. pageBar.style.display="table-row";
  2243. pageBar.style.backgroundColor="unset";
  2244. let td=document.createElement("td");
  2245. td.style.backgroundColor="rgb(240 240 240 / 80%)";
  2246. td.style.borderRadius="20px";
  2247. td.colSpan=tdNum||1;
  2248. td.style.padding="0 0";
  2249. td.style.textAlign="center";
  2250. td.appendChild(upSpan);
  2251. td.appendChild(pageText);
  2252. if(pageNum)td.appendChild(pageNum);
  2253. td.appendChild(downSpan);
  2254. pageBar.appendChild(td);
  2255. }else if(inLi){
  2256. example=example.tagName=="LI"?example:example.previousElementSibling;
  2257. pageBar.style.display="table-row";
  2258. pageBar.style.backgroundColor="unset";
  2259. let td=document.createElement("td");
  2260. td.style.backgroundColor="rgb(240 240 240 / 80%)";
  2261. td.style.borderRadius="20px";
  2262. td.colSpan=example.children.length;
  2263. td.style.padding="0 0";
  2264. td.style.textAlign="center";
  2265. td.style.minWidth="150px";
  2266. td.appendChild(upSpan);
  2267. td.appendChild(pageText);
  2268. td.style.width=pageBar.style.width;
  2269. if(pageNum)td.appendChild(pageNum);
  2270. td.appendChild(downSpan);
  2271. pageBar.appendChild(td);
  2272. }
  2273.  
  2274. upSpan.addEventListener("click", e=>{
  2275. document.body.scrollTop=0;
  2276. document.documentElement.scrollTop=0;
  2277. e.preventDefault();
  2278. e.stopPropagation();
  2279. });
  2280. downSpan.addEventListener("click", e=>{
  2281. changeStop(true);
  2282. pageBar.title=i18n(isPause?"enable":"disable");
  2283. document.body.scrollTop=9999999;
  2284. document.documentElement.scrollTop=9999999;
  2285. e.preventDefault();
  2286. e.stopPropagation();
  2287. });
  2288. pageBar.addEventListener("click", e=>{
  2289. changeStop(!isPause);
  2290. pageBar.title=i18n(isPause?"enable":"disable");
  2291. });
  2292. pageText.addEventListener("click", e=>{
  2293. e.stopPropagation();
  2294. });
  2295. if(ruleParser.curSiteRule.insertPos==2){
  2296. insert.appendChild(pageBar);
  2297. }else{
  2298. insert.parentNode.insertBefore(pageBar, insert);
  2299. }
  2300. if(ruleParser.curSiteRule.pageBar){
  2301. try{
  2302. Function("pageBar",'"use strict";' + ruleParser.curSiteRule.pageBar)(pageBar);
  2303. }catch(e){
  2304. debug(e);
  2305. }
  2306. }
  2307.  
  2308. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  2309. let posEle=pageBar.nextElementSibling||pageBar;
  2310. while(posEle && !posEle.offsetParent){
  2311. posEle=posEle.previousElementSibling||posEle.parentNode;
  2312. }
  2313. if(posEle){
  2314. let actualTop = posEle.offsetTop;
  2315. let current = posEle.parentNode.offsetParent;
  2316. while (current !== null){
  2317. actualTop += current.offsetTop;
  2318. current = current.offsetParent;
  2319. }
  2320. bottomGap=scrollH-actualTop+(window.innerHeight||document.documentElement.clientHeight)*(ruleParser.curSiteRule.rate||1);
  2321. if(bottomGap<100)bottomGap=100;
  2322. }else{
  2323. bottomGap=1000;
  2324. }
  2325. return pageBar;
  2326. }
  2327.  
  2328. function emuClick(btn){
  2329. if(!PointerEvent)return btn.click();
  2330. let eventParam={
  2331. isTrusted: true,
  2332. altKey: false,
  2333. azimuthAngle: 0,
  2334. bubbles: true,
  2335. button: 0,
  2336. buttons: 0,
  2337. clientX: 1,
  2338. clientY: 1,
  2339. cancelBubble: false,
  2340. cancelable: true,
  2341. composed: true,
  2342. ctrlKey: false,
  2343. defaultPrevented: false,
  2344. detail: 1,
  2345. eventPhase: 2,
  2346. fromElement: null,
  2347. height: 1,
  2348. isPrimary: false,
  2349. metaKey: false,
  2350. pointerId: 1,
  2351. pointerType: "mouse",
  2352. pressure: 0,
  2353. relatedTarget: null,
  2354. returnValue: true,
  2355. shiftKey: false,
  2356. toElement: null,
  2357. twist: 0,
  2358. type: "click",
  2359. which: 1
  2360. };
  2361. var mouseclick = new PointerEvent("click",eventParam);
  2362. btn.dispatchEvent(mouseclick);
  2363. }
  2364.  
  2365. var emuIframe;
  2366. function emuPage(callback){
  2367. let orgPage,curPage,iframeDoc,times=0,loadmoreBtn,loadmoreEnd=false,waitTimes=10;
  2368. function checkPage(){
  2369. if(isPause)return;
  2370. try{
  2371. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  2372. }catch(e){
  2373. debug("Stop as cors");
  2374. isPause=true;
  2375. callback(false, false);
  2376. return;
  2377. }
  2378.  
  2379. let nextLink=ruleParser.getNextLink(iframeDoc);
  2380. let waitTime=500,checkEval;
  2381. if(ruleParser.curSiteRule.wait){
  2382. if(isNaN(ruleParser.curSiteRule.wait)){
  2383. try{
  2384. checkEval=Function("doc",'"use strict";' + ruleParser.curSiteRule.wait);
  2385. }catch(e){
  2386. debug(e);
  2387. }
  2388. }else{
  2389. waitTime=ruleParser.curSiteRule.wait;
  2390. }
  2391. }
  2392.  
  2393. if(!orgPage){
  2394. if(!loadmoreEnd){
  2395. loadmoreBtn=getLoadMore(iframeDoc);
  2396. if(loadmoreBtn && isVisible(loadmoreBtn, iframeDoc.defaultView)){
  2397. emuClick(loadmoreBtn);
  2398. let intv=setInterval(()=>{
  2399. loadmoreBtn=getLoadMore(iframeDoc);
  2400. if(!loadmoreBtn || !loadmoreBtn.parentNode || !isVisible(loadmoreBtn, iframeDoc.defaultView)){
  2401. clearInterval(intv);
  2402. loadmoreEnd=true;
  2403. setTimeout(()=>{
  2404. checkPage();
  2405. },500);
  2406. }else{
  2407. emuClick(loadmoreBtn);
  2408. }
  2409. },200);
  2410. return;
  2411. }else{
  2412. loadmoreEnd=true;
  2413. }
  2414. }
  2415. let pageEle=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true);
  2416. if(!nextLink || !pageEle || (checkEval && !checkEval(iframeDoc))){
  2417. if(ruleParser.curSiteRule.wait && waitTimes-->0){
  2418. setTimeout(()=>{
  2419. checkPage();
  2420. },waitTime);
  2421. return;
  2422. }
  2423. }
  2424. orgPage=pageEle;
  2425. if(!orgPage || orgPage.length==0){
  2426. debug("Stop as no page when emu");
  2427. isPause=true;
  2428. callback(false, false);
  2429. return;
  2430. }
  2431. if(orgPage && orgPage[0].tagName=="UL")orgPage=orgPage[0].children;
  2432. if(orgPage && nextLink){
  2433. orgPage=orgPage[parseInt(orgPage.length/2)];
  2434. if(!isVisible(nextLink, iframeDoc.defaultView)){
  2435. debug("Stop as next hide when emu");
  2436. isPause=true;
  2437. callback(false, false);
  2438. }else{
  2439. emuClick(nextLink);
  2440. setTimeout(()=>{
  2441. checkPage();
  2442. },500);
  2443. }
  2444. }else{
  2445. debug("Stop as no next when emu");
  2446. isPause=true;
  2447. callback(false, false);
  2448. }
  2449. return;
  2450. }
  2451. if(times++ > 20){
  2452. //emuClick(nextLink);
  2453. debug("Stop as timeout when emu");
  2454. isPause=true;
  2455. callback(false, false);
  2456. return;
  2457. }
  2458. let eles=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true),checkItem=eles;
  2459. if(eles && eles.length>0 && eles[0].tagName=="UL")checkItem=eles[0].children;
  2460. if(!eles || eles.length==0 || orgPage == checkItem[parseInt(checkItem.length/2)] || (checkEval && !checkEval(iframeDoc))){
  2461. setTimeout(()=>{
  2462. checkPage();
  2463. },waitTime);
  2464. }else{
  2465. callback(iframeDoc, eles);
  2466. }
  2467. }
  2468. if(!emuIframe){
  2469. emuIframe = document.createElement('iframe');
  2470. emuIframe.name = 'pagetual-iframe';
  2471. if(ruleParser.curSiteRule.sandbox!=false){
  2472. emuIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  2473. }
  2474. emuIframe.width = '100%';
  2475. emuIframe.height = '0';
  2476. emuIframe.frameBorder = '0';
  2477. emuIframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  2478. emuIframe.addEventListener("load", e=>{
  2479. setTimeout(()=>{
  2480. try{
  2481. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  2482. }catch(e){
  2483. debug("Stop as cors");
  2484. isPause=true;
  2485. callback(false, false);
  2486. return;
  2487. }
  2488. let code=ruleParser.curSiteRule.init;
  2489. if(code){
  2490. try{
  2491. Function('doc','win','"use strict";' + code)(iframeDoc, iframeDoc.defaultView);
  2492. }catch(e){
  2493. debug(e);
  2494. }
  2495. }
  2496. checkPage();
  2497. },500);
  2498. });
  2499. emuIframe.src=location.href;
  2500. document.body.appendChild(emuIframe);
  2501. }else{
  2502. checkPage();
  2503. }
  2504. }
  2505.  
  2506. function forceIframe(url, callback){
  2507. let curIframe = document.createElement('iframe'),iframeDoc;
  2508. curIframe.name = 'pagetual-iframe';
  2509. curIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  2510. curIframe.frameBorder = '0';
  2511. curIframe.scrolling="no";
  2512. curIframe.style.cssText = 'display: block; visibility: visible; float: none; clear: both; width: 100%;height:0;background: initial; border: 0px; border-radius: 0px; margin: 0px 0px 2rem; padding: 0px; z-index: 2147483647;';
  2513. curIframe.addEventListener("load", e=>{
  2514. try{
  2515. iframeDoc=curIframe.contentDocument || curIframe.contentWindow.document;
  2516. }catch(e){
  2517. debug("Stop as cors");
  2518. isPause=true;
  2519. callback(false, false);
  2520. return;
  2521. }
  2522. ruleParser.insertPage(iframeDoc, [], url, null, true);
  2523. callback(curIframe, true);
  2524. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  2525. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  2526. });
  2527. let inAction=false;
  2528. let forceRefresh=e=>{
  2529. if(inAction || !iframeDoc)return;
  2530. inAction=true;
  2531. setTimeout(()=>{
  2532. inAction=false;
  2533. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  2534. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  2535. if(!ruleParser.nextLinkHref){
  2536. ruleParser.getNextLink(iframeDoc);
  2537. if(ruleParser.nextLinkHref){
  2538. document.removeEventListener("scroll", forceRefresh);
  2539. }
  2540. }else{
  2541. document.removeEventListener("scroll", forceRefresh);
  2542. }
  2543. },500);
  2544. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  2545. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  2546. };
  2547. document.addEventListener("scroll", forceRefresh);
  2548. curIframe.src=url;
  2549. let insert=ruleParser.getInsert();
  2550. document.body.appendChild(curIframe);
  2551. return curIframe;
  2552. }
  2553.  
  2554. function loadPageOver(){
  2555. isLoading=false;
  2556. if(loadingDiv.parentNode){
  2557. loadingDiv.parentNode.removeChild(loadingDiv);
  2558. }
  2559. setTimeout(()=>{
  2560. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  2561. if(scrollH < (window.innerHeight || document.documentElement.clientHeight)){
  2562. nextPage();
  2563. }
  2564. },1);
  2565. }
  2566.  
  2567. function nextPage(){
  2568. if(isPause || isLoading)return;
  2569. let nextLink=ruleParser.nextLinkHref;
  2570. if(!nextLink)return;
  2571. let pvGallery=document.querySelector("span.pv-gallery-container");
  2572. if(pvGallery && pvGallery.style.display!="none")return;
  2573. let insert=ruleParser.getInsert();
  2574. if(insert){
  2575. let isJs=/^(javascript|#)/.test(nextLink.replace(location.href,""));
  2576. if(location.protocol=="https:" && /^http:/.test(nextLink)){
  2577. nextLink=nextLink.replace(/^http/,"https");
  2578. }
  2579. isLoading=true;
  2580. document.body.appendChild(loadingDiv);
  2581. let sleep=ruleParser.curSiteRule.sleep||0;
  2582. setTimeout(()=>{
  2583. if(ruleParser.curSiteRule.pageElementByJs){
  2584. var over=ele=>{
  2585. loadPageOver();
  2586. if(ele){
  2587. createPageBar(nextLink);
  2588. ruleParser.insertPage(null, ele, nextLink, null, true);
  2589. if(autoLoadNum>=0){
  2590. if(autoLoadNum!=0 && --autoLoadNum==0){
  2591. autoLoadNum=-1;
  2592. }else{
  2593. nextPage();
  2594. }
  2595. }
  2596. }else{
  2597. debug("Stop as no page when get by js");
  2598. isPause=true;
  2599. }
  2600. };
  2601. try{
  2602. Function("over",'"use strict";' + ruleParser.curSiteRule.pageElementByJs)(over);
  2603. }catch(e){
  2604. debug(e);
  2605. }
  2606. }else if(ruleParser.curSiteRule.action==1 && !isJs){
  2607. requestFromIframe(nextLink, (doc, eles)=>{
  2608. loadPageOver();
  2609. if(eles){
  2610. createPageBar(nextLink);
  2611. ruleParser.insertPage(doc, eles, nextLink, null, true);
  2612. if(autoLoadNum>=0){
  2613. if(autoLoadNum!=0 && --autoLoadNum==0){
  2614. autoLoadNum=-1;
  2615. }else{
  2616. nextPage();
  2617. }
  2618. }
  2619. }
  2620. });
  2621. }else if((forceState==2||ruleParser.curSiteRule.action==2) && !isJs){
  2622. forceIframe(nextLink, (iframe, eles)=>{
  2623. loadPageOver();
  2624. let pageBar=createPageBar(nextLink);
  2625. iframe.parentNode.insertBefore(pageBar, iframe);
  2626. if(autoLoadNum>=0){
  2627. if(autoLoadNum!=0 && --autoLoadNum==0){
  2628. autoLoadNum=-1;
  2629. }else{
  2630. nextPage();
  2631. }
  2632. }
  2633. });
  2634. }else{
  2635. if(!isJs){
  2636. requestDoc(nextLink, (eles)=>{
  2637. loadPageOver();
  2638. if(eles){
  2639. createPageBar(nextLink);
  2640. if(autoLoadNum>=0){
  2641. if(autoLoadNum!=0 && --autoLoadNum==0){
  2642. autoLoadNum=-1;
  2643. }else{
  2644. nextPage();
  2645. }
  2646. }
  2647. }
  2648. });
  2649. }else{
  2650. emuPage((doc, eles)=>{
  2651. loadPageOver();
  2652. if(eles){
  2653. createPageBar(nextLink);
  2654. ruleParser.insertPage(doc, eles, "", null, true);
  2655. if(autoLoadNum>=0){
  2656. if(autoLoadNum!=0 && --autoLoadNum==0){
  2657. autoLoadNum=-1;
  2658. }else{
  2659. nextPage();
  2660. }
  2661. }
  2662. }
  2663. });
  2664. }
  2665. }
  2666. },sleep);
  2667. }
  2668. }
  2669.  
  2670. function init(){
  2671. initRules(()=>{
  2672. initPage();
  2673. });
  2674. }
  2675. setTimeout(()=>{
  2676. init();
  2677. },300);
  2678. })();