东方永页机

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

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

  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.11
  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(".next>a")||
  831. curPage.querySelector(".next>button")||
  832. curPage.querySelector("a[alt=next]")||
  833. curPage.querySelector("[title=next]");
  834. if(!next){
  835. let nexts=curPage.querySelectorAll("a.next");
  836. if(nexts.length>0){
  837. if(nexts.length==1){
  838. next=nexts[0];
  839. if(/^([上前首][一1]?[页頁张張]|previous(\s*page)?\s*›?$|前のページ)/i.test(next.innerText.trim())){
  840. next=null;
  841. }
  842. }else{
  843. next=nexts[nexts.length-1];
  844. }
  845. }
  846. }
  847. if(next && (!next.href || /^javascript:/.test(next.href))){
  848. jsNext=next;
  849. next=null;
  850. }
  851. if(!next){
  852. next=curPage.querySelectorAll("[aria-label='Next']");
  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. next=curPage.querySelectorAll("[aria-label='Next page']");
  865. if(next && next.length==1){
  866. next=next[0];
  867. if(!next.href || /^javascript:/.test(next.href)){
  868. jsNext=next;
  869. next=null;
  870. }
  871. }else{
  872. next=null;
  873. }
  874. }
  875. if(!next){
  876. let pageDiv=curPage.querySelector("div.wp-pagenavi");
  877. if(pageDiv){
  878. cur=pageDiv.querySelector("span.current");
  879. if(cur){
  880. next=cur.nextSibling;
  881. }
  882. }else{
  883. cur=curPage.querySelector("div.article-paging>span");
  884. if(cur){
  885. next=cur.nextElementSibling;
  886. }
  887. }
  888. }
  889. if(!next){
  890. let pageDiv=curPage.querySelector("div.pages>ul");
  891. if(pageDiv){
  892. cur=pageDiv.querySelector("li>b");
  893. if(cur)next=cur.parentNode.nextElementSibling;
  894. if(next)next=next.querySelector("a");
  895. }
  896. }
  897. if(!next){
  898. cur=curPage.querySelector(".number>ul>li.active");
  899. if(cur)next=cur.nextElementSibling;
  900. if(next)next=next.querySelector("a");
  901. }
  902. if(!next){
  903. let aTags=curPage.querySelectorAll("a");
  904. let next1,next2,next3,next4,nextJs1,nextJs2,nextJs3;
  905. for(i=aTags.length-1;i>=0;i--){
  906. let aTag=aTags[i];
  907. if(aTag.innerText=="§")continue;
  908. if(aTag.style.display=="none")continue;
  909. if(next1 && next2 && next3 && next4)break;
  910. if(aTag.href && /next$/i.test(aTag.href))continue;
  911. if(!next1){
  912. if(/^[下后後][一1]?[页頁张張]|^next( page)?\s*›?$|次のページ/i.test(aTag.innerText.trim())){
  913. if(aTag.innerText.length>15)continue;
  914. if(!aTag.href || /^javascript:/.test(aTag.href)){
  915. if(!nextJs1)nextJs1=aTag;
  916. }else{
  917. next1=aTag;
  918. }
  919. }
  920. }
  921. if(!next2){
  922. if(/^[下后後][一1]?[章话話]/i.test(aTag.innerText.trim())){
  923. if(!aTag.href || /^javascript:/.test(aTag.href)){
  924. if(!nextJs2)nextJs2=aTag;
  925. }else{
  926. next2=aTag;
  927. }
  928. }
  929. }
  930. if(!next3){
  931. if(aTag.innerText=="&gt;" || aTag.innerText=="▶" || aTag.innerText==">" || aTag.innerText=="›" || /nextpage/i.test(aTag.className)){
  932. if(!aTag.href || /^javascript:/.test(aTag.href)){
  933. if(!nextJs3)nextJs3=aTag;
  934. }else{
  935. next3=aTag;
  936. }
  937. }
  938. }
  939. if(!aTag.href || /^javascript:/.test(aTag.href))continue;
  940. if(!next4){
  941. if(pageNum<999 && aTag.href.replace("?&","?").replace("#!","").replace("index.php?","?").replace(preStr,"").replace(afterStr,"")==pageNum+1){
  942. next4=aTag;
  943. }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,""))){
  944. let curHref=aTag.getAttribute("href");
  945. let pageOne=curHref.replace(/\/2(\/|\?|&|$)/,"/1$1");
  946. if(pageOne==curHref)pageOne=null;
  947. else pageOne=curPage.querySelector(`a[href='${pageOne}']`);
  948. if(!pageOne)next4=aTag;
  949. }
  950. }
  951. }
  952. next=next1||next3||next4||next2||nextJs1||nextJs3||nextJs2;
  953. }
  954. if(!next)next=jsNext;
  955. if(next && next.classList.contains("results-more"))next=null;
  956. return {next:next,canSave:canSave};
  957. }
  958.  
  959. canonicalUri(src, base_path) {
  960. if(src.charAt(0)=="#")return location.href+src;
  961. var root_page = /^[^?#]*\//.exec(location.href)[0],
  962. root_domain = /^\w+\:\/\/\/?[^\/]+/.exec(root_page)[0],
  963. absolute_regex = /^\w+\:\/\//;
  964. src=src.replace(/\.\//,"");
  965. if (/^\/\/\/?/.test(src)){
  966. src = location.protocol + src;
  967. }
  968. else if (!absolute_regex.test(src) && src.charAt(0) != "/"){
  969. src = (base_path || "") + src;
  970. }
  971. return (absolute_regex.test(src) ? src : ((src.charAt(0) == "/" ? root_domain : root_page) + src));
  972. }
  973.  
  974. getLinkByPage(url, pageNum) {
  975. if(!url)return;
  976. if(this.curSiteRule.pageNum){
  977. let result=this.curSiteRule.pageNum;
  978. let strMatch=result.match(/\{.*?}/);
  979. if(!strMatch)return null;
  980. let urlReg=new RegExp("("+result.replace(strMatch[0], ")\\d+(")+")");
  981. let code=strMatch[0].replace(/^{/,"").replace(/}$/,"").replace(/\$p/g,pageNum);
  982. if(code==pageNum){
  983. result=url.replace(urlReg,"$1"+code+"$2");
  984. }else{
  985. try{
  986. code=Function('"use strict";return ' + code)();
  987. result=url.replace(urlReg,"$1"+code+"$2");
  988. }catch(e){
  989. debug(e);
  990. }
  991. }
  992. return result==url?url.replace(/([&\/\?](p=|page[=\/]))\d+/i, "$1"+pageNum):result;
  993. }else{
  994. return url.replace(/([&\/\?](p=|page[=\/]))\d+/i, "$1"+pageNum);
  995. }
  996. }
  997.  
  998. getNextLink(doc) {
  999. let nextLink=null,page;
  1000. if(this.curSiteRule.pageElementByJs){
  1001. this.nextLinkHref="#";
  1002. return true;
  1003. }else if(this.curSiteRule.nextLinkByJs){
  1004. try{
  1005. let targetUrl=Function("doc",'"use strict";' + this.curSiteRule.nextLinkByJs)(doc);
  1006. if(targetUrl)nextLink={href:targetUrl};
  1007. }catch(e){
  1008. debug(e);
  1009. }
  1010. }else if(this.curSiteRule.nextLinkByUrl){
  1011. let targetUrl=this.curUrl.replace(new RegExp(this.curSiteRule.nextLinkByUrl[0]), this.curSiteRule.nextLinkByUrl[1]);
  1012. if(targetUrl != this.curUrl){
  1013. let reps=targetUrl.match(/{.*?}/g);
  1014. if(reps){
  1015. reps.forEach(rep=>{
  1016. let code=rep.replace("{","").replace("}","");
  1017. let result=code.match(/^(\d+)\+1$/);
  1018. if(result){
  1019. result=parseInt(result[1])+1;
  1020. }else{
  1021. try{
  1022. result=Function('"use strict";return ' + code)();
  1023. }catch(e){
  1024. debug(e);
  1025. }
  1026. }
  1027. targetUrl=targetUrl.replace(rep, result);
  1028. });
  1029. }
  1030. }
  1031. nextLink={href:targetUrl};
  1032. }else if(this.curSiteRule.nextLink){
  1033. if(this.curSiteRule.nextLink!="0"){
  1034. nextLink=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.nextLink,doc,doc):doc.querySelector(this.curSiteRule.nextLink);
  1035. }
  1036. }else{
  1037. page=this.getPage(doc);
  1038. nextLink=page.next;
  1039. if(nextLink){
  1040. if(nextLink.tagName=="INPUT" && nextLink.parentNode.tagName=="FORM"){
  1041. let params=[];
  1042. let form=nextLink.parentNode;
  1043. [].forEach.call(form.querySelectorAll("input"), input=>{
  1044. params.push(input.name+'='+input.value);
  1045. });
  1046. nextLink.href=form.action+'?'+params.join('&');
  1047. }
  1048. if(nextLink.classList.contains("noClick")){
  1049. this.nextLinkHref=false;
  1050. return null;
  1051. }else if(doc==document){
  1052. if((!nextLink.href || /^javascript:/.test(nextLink.href)) && !isVisible(nextLink, _unsafeWindow)){
  1053. this.nextLinkHref=false;
  1054. return null;
  1055. }else{
  1056. let nextLinkCs=_unsafeWindow.getComputedStyle(nextLink);
  1057. if(nextLinkCs.cursor=="not-allowed"){
  1058. this.nextLinkHref=false;
  1059. return null;
  1060. }
  1061. }
  1062. }
  1063. }
  1064. }
  1065. if(nextLink){
  1066. let needUrl=(this.curSiteRule.action==0 || this.curSiteRule.action==1);
  1067. if(nextLink.href==="" && needUrl){
  1068. this.nextLinkHref=false;
  1069. }else if(nextLink.href && (nextLink.href==this.curUrl || nextLink.href==this.oldUrl) && needUrl){
  1070. this.nextLinkHref=false;
  1071. }else if(/^javascript:/.test(nextLink.href) && needUrl){
  1072. this.nextLinkHref=false;
  1073. }else{
  1074. this.nextLinkHref=(nextLink.href && !/^javascript:/.test(nextLink.href) && nextLink.href!=location.href)?this.canonicalUri(nextLink.href):"#";
  1075. if(doc==document)debug(nextLink);
  1076. }
  1077. }else{
  1078. this.nextLinkHref=false;
  1079. }
  1080. this.preload();
  1081. return nextLink;
  1082. }
  1083.  
  1084. preload(){
  1085. if(!rulesData.preload)return;
  1086. if(!this.nextLinkHref || this.nextLinkHref=="#")return;
  1087. let self=this;
  1088. if(this.curSiteRule && this.curSiteRule.action==1){
  1089. if(!this.preloadIframe){
  1090. this.preloadIframe = document.createElement('iframe');
  1091. let iframe = this.preloadIframe;
  1092. iframe.name = 'pagetual-iframe';
  1093. iframe.width = '100%';
  1094. iframe.height = '0';
  1095. iframe.frameBorder = '0';
  1096. if(ruleParser.curSiteRule.sandbox!=false){
  1097. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1098. }
  1099. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1100. iframe.addEventListener('load', function (e) {
  1101. try{
  1102. let doc=iframe.contentDocument || iframe.contentWindow.document;
  1103. var body = doc.body;
  1104. if (body && body.firstChild) {
  1105. self.lazyImgAction(body.children);
  1106. }
  1107. }catch(e){
  1108. return;
  1109. }
  1110. }, false);
  1111. document.body.appendChild(iframe);
  1112. }
  1113. this.preloadIframe.src = this.nextLinkHref;
  1114. }else{
  1115. _GM_xmlhttpRequest({
  1116. url: this.nextLinkHref,
  1117. method: 'GET',
  1118. overrideMimeType: 'text/html;charset='+document.charset,
  1119. headers: {
  1120. 'Referer': location.href
  1121. },
  1122. timeout: 5000,
  1123. onload: function(res) {
  1124. var doc=null;
  1125. try {
  1126. doc=document.implementation.createHTMLDocument('');
  1127. doc.documentElement.innerHTML=res.response;
  1128. var body = doc.body;
  1129. if (body && body.firstChild) {
  1130. self.lazyImgAction(body.children);
  1131. }
  1132. if(!self.preloadDiv){
  1133. self.preloadDiv = document.createElement('div');
  1134. self.preloadDiv.id = "pagetual-preload";
  1135. self.preloadDiv.style.cssText = 'display:none!important;';
  1136. document.body.appendChild(self.preloadDiv);
  1137. self.checkedImgs={};
  1138. }
  1139. [].forEach.call(doc.images, i=>{
  1140. let iSrc=i.src;
  1141. if(iSrc && !self.checkedImgs[iSrc]){
  1142. self.checkedImgs[iSrc] = true;
  1143. let img = document.createElement('img');
  1144. img.src = iSrc;
  1145. self.preloadDiv.appendChild(img);
  1146. }
  1147. });
  1148. }
  1149. catch (e) {
  1150. return;
  1151. }
  1152. }
  1153. });
  1154. }
  1155. }
  1156.  
  1157. getInsert(refresh) {
  1158. if(refresh){
  1159. this.insert=null;
  1160. }
  1161. if(this.insert && !refresh){
  1162. let parent=this.insert;
  1163. while(parent && parent.nodeName!="BODY"){
  1164. parent=parent.parentNode;
  1165. }
  1166. if(parent && parent.nodeName=="BODY"){
  1167. return this.insert;
  1168. }
  1169. }
  1170. if(this.curSiteRule.insert){
  1171. this.insert=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.insert,document):document.querySelector(this.curSiteRule.insert);
  1172. }else{
  1173. let pageElement=this.getPageElement(document, _unsafeWindow);
  1174. if(pageElement && pageElement.length>0){
  1175. var pELast = pageElement[pageElement.length - 1];
  1176. this.insert = pELast.nextSibling ? pELast.nextSibling : pELast.parentNode.appendChild(document.createTextNode(' '));
  1177. }
  1178. }
  1179. return this.insert;
  1180. }
  1181.  
  1182. pageInit(doc,eles){
  1183. let code=this.curSiteRule.pageInit;
  1184. if(code){
  1185. try{
  1186. Function("doc","eles",'"use strict";' + code)(doc,eles);
  1187. }catch(e){
  1188. debug(e);
  1189. }
  1190. }
  1191. }
  1192.  
  1193. pageAction(doc,eles){
  1194. let code=this.curSiteRule.pageAction;
  1195. if(code){
  1196. try{
  1197. Function("doc","eles",'"use strict";' + code)(doc,eles);
  1198. }catch(e){
  1199. debug(e);
  1200. }
  1201. }
  1202. this.lazyImgAction(eles);
  1203. }
  1204.  
  1205. lazyImgAction(eles){
  1206. let setLazyImg=img=>{
  1207. let realSrc;
  1208. if(img.getAttribute("_src") && !img.src){
  1209. realSrc=img.getAttribute("_src");
  1210. }else if(img.dataset && img.dataset.original){
  1211. realSrc=img.dataset.original;
  1212. }else if(img.dataset && img.dataset.src){
  1213. realSrc=img.dataset.src;
  1214. }else if(img._lazyrias && img._lazyrias.srcset){
  1215. realSrc=img._lazyrias.srcset[img._lazyrias.srcset.length-1];
  1216. }else if(img.dataset && img.dataset.origFile){
  1217. realSrc=img.dataset.origFile;
  1218. }else if(img.srcset){
  1219. var srcs=img.srcset.split(","),largeSize=0;
  1220. srcs.forEach(srci=>{
  1221. let srcInfo=srci.trim().split(" "),curSize=parseInt(srcInfo[1]);
  1222. if(srcInfo[1] && curSize>largeSize){
  1223. largeSize=curSize;
  1224. realSrc=srcInfo[0];
  1225. }
  1226. });
  1227. }
  1228. if(realSrc){
  1229. img.src=realSrc;
  1230. img.style.display="block";
  1231. }
  1232. };
  1233. [].forEach.call(eles, ele=>{
  1234. if(ele.tagName=="IMG"){
  1235. setLazyImg(ele);
  1236. }else{
  1237. [].forEach.call(ele.querySelectorAll("img"), img=>{
  1238. setLazyImg(img);
  1239. });
  1240. }
  1241. if(ele.tagName=="A" && ele.classList.contains("lazyload")){
  1242. if(ele.dataset.original){
  1243. ele.style.backgroundImage='url("'+ele.dataset.original+'")';
  1244. }
  1245. }else{
  1246. [].forEach.call(ele.querySelectorAll("a.lazyload"), a=>{
  1247. if(a.dataset.original){
  1248. a.style.backgroundImage='url("'+a.dataset.original+'")';
  1249. }
  1250. });
  1251. }
  1252. });
  1253. let lazyImgSrc=this.curSiteRule.lazyImgSrc;
  1254. if(lazyImgSrc){
  1255. [].forEach.call(eles, ele=>{
  1256. [].forEach.call(ele.querySelectorAll("img"), img=>{
  1257. if(img.getAttribute(lazyImgSrc)){
  1258. img.src=img.getAttribute(lazyImgSrc);
  1259. }
  1260. });
  1261. });
  1262. }
  1263. }
  1264.  
  1265. initPage(callback){
  1266. let self=this;
  1267. curPage=1;
  1268. //if(this.curSiteRule.url && !this.curSiteRule.singleUrl)return;
  1269. this.curSiteRule={};
  1270. this.pageDoc=document;
  1271. this.nextLinkHref=null;
  1272. this.curUrl=location.href;
  1273. this.getRule(()=>{
  1274. if(self.curSiteRule.enable==0){
  1275. debug("Stop as rule disable");
  1276. isPause=true;
  1277. return;
  1278. }
  1279. if(self.curSiteRule && !self.curSiteRule.singleUrl){
  1280. self.hpRules=self.hpRules.filter(item=>{return item&&item.url!=self.curSiteRule.url});
  1281. self.hpRules.unshift(self.curSiteRule);
  1282. if(self.hpRules.length>30){
  1283. self.hpRules.pop();
  1284. }
  1285. storage.setItem("hpRules", self.hpRules);
  1286. }
  1287. let css=self.curSiteRule.css;
  1288. if(css){
  1289. _GM_addStyle(css);
  1290. }
  1291. let code=self.curSiteRule.init;
  1292. if(code){
  1293. try{
  1294. Function('doc','win','"use strict";' + code)(null,null);
  1295. }catch(e){
  1296. debug(e);
  1297. }
  1298. }
  1299. self.getNextLink(document);
  1300. callback();
  1301. });
  1302. }
  1303.  
  1304. insertPage(doc, eles, url, callback, tried){
  1305. this.oldUrl=this.curUrl;
  1306. let oldTitle=this.pageDoc.title;
  1307. this.pageDoc=doc;
  1308. this.curUrl=url;
  1309. let nextLink=this.getNextLink(doc);
  1310. if(curPage==1 && !tried && !nextLink && this.curSiteRule.singleUrl && this.curSiteRule.pageElement && this.curSiteRule.action!=0){
  1311. this.curSiteRule.action=1;
  1312. this.curUrl=location.href;
  1313. return false;
  1314. }
  1315. if(callback)callback(eles);
  1316. this.getInsert();
  1317. var self=this,newEles=[];
  1318. if(!eles || eles.length==0 || !self.insert || !self.insert.parentNode){
  1319. }else{
  1320. this.pageInit(doc, eles);
  1321. [].forEach.call(eles, ele=>{
  1322. let newEle=ele.cloneNode(true);
  1323. let oldCanvass=ele.querySelectorAll("canvas");
  1324. let newCanvass=newEle.querySelectorAll("canvas");
  1325. for(let i=0;i<oldCanvass.length;i++){
  1326. let oldCanvas=oldCanvass[i];
  1327. let newCanvas=newCanvass[i];
  1328. newCanvas.getContext('2d').drawImage(oldCanvas, 0, 0);
  1329. }
  1330. if(self.curSiteRule.insertPos==2){
  1331. self.insert.appendChild(newEle);
  1332. }else{
  1333. self.insert.parentNode.insertBefore(newEle, self.insert);
  1334. }
  1335. newEles.push(newEle);
  1336. });
  1337. }
  1338. this.pageAction(doc, newEles);
  1339. if(this.oldUrl!=location.href){
  1340. let isJs=/^(javascript|#)/.test(this.oldUrl.replace(location.href,""));
  1341. if(rulesData.enableHistory && !isJs){
  1342. _unsafeWindow.history.replaceState(undefined, oldTitle, this.oldUrl);
  1343. document.title=oldTitle;
  1344. }
  1345. }
  1346. return true;
  1347. }
  1348. }
  1349. var ruleParser = new RuleParser();
  1350.  
  1351. function initConfig(){
  1352. _GM_registerMenuCommand(i18n(forceState==1?"enable":"disableSite"), ()=>{
  1353. storage.setItem("forceState_"+location.host, (forceState==1?0:1));
  1354. location.reload();
  1355. });
  1356. _GM_registerMenuCommand(i18n("update"), ()=>{
  1357. updateRules(()=>{
  1358. alert(i18n("updateSucc"));
  1359. location.reload();
  1360. },(rule,err)=>{
  1361. alert("Update "+rule.url+" rules fail!");
  1362. });
  1363. alert(i18n("beginUpdate"));
  1364. });
  1365.  
  1366. var configCon,insertPos;
  1367. if(ruleImportUrlReg.test(location.href)){
  1368. document.addEventListener("click", e=>{
  1369. if(e.target.tagName=="PRE"){
  1370. let nameAttr=e.target.getAttribute("name");
  1371. if(nameAttr=="pagetual" || nameAttr=="user-content-pagetual"){
  1372. let rules=e.target.innerText.trim().split("\n");
  1373. let diff=false;
  1374. for(let c=0;c<rules.length;c++){
  1375. let urlArr=rules[c].split("|"),url,type=1;
  1376. if(urlArr.length==1){
  1377. url=urlArr[0].trim();
  1378. if(!/^http/.test(url)){
  1379. alert("Wrong url, check again!");
  1380. return;
  1381. }
  1382. }else if(urlArr.length==2){
  1383. type=urlArr[0].trim();
  1384. url=urlArr[1].trim();
  1385. if(!/^http/.test(url)){
  1386. alert("Wrong url, check again!");
  1387. return;
  1388. }
  1389. }else{
  1390. break;
  1391. }
  1392. let maxId=0,hasUrl=false;
  1393. if(!rulesData.urls){
  1394. rulesData.urls=[];
  1395. maxId=1;
  1396. }else{
  1397. rulesData.urls.forEach(u=>{
  1398. if(maxId<u.id){
  1399. maxId=u.id;
  1400. }
  1401. if(u.url==url){
  1402. hasUrl=true;
  1403. }
  1404. });
  1405. if(hasUrl)break;
  1406. }
  1407. diff=true;
  1408. if(!rulesData.sort)rulesData.sort=[1];
  1409. rulesData.urls.push({id:maxId+1,url:url,type:type});
  1410. rulesData.sort.unshift(maxId+1);
  1411. }
  1412. if(!diff)return;
  1413. storage.setItem("rulesData", rulesData);
  1414.  
  1415. if(rulesData.urls)ruleUrls=ruleUrls.concat(rulesData.urls);
  1416. if(rulesData.sort){
  1417. let urls=[];
  1418. rulesData.sort.forEach(id=>{
  1419. for(let s=0;s<ruleUrls.length;s++){
  1420. if(id==ruleUrls[s].id){
  1421. urls.push(ruleUrls[s]);
  1422. break;
  1423. }
  1424. }
  1425. });
  1426. ruleUrls=urls;
  1427. }
  1428. alert("OK");
  1429. }
  1430. }
  1431. });
  1432. }
  1433. if(location.href==configPage){
  1434. _GM_addStyle(`
  1435. p>span:nth-child(1),p>span:nth-child(2),p>span:nth-child(3){
  1436. cursor: pointer;
  1437. user-select: none;
  1438. }
  1439. p>span:nth-child(1):hover,p>span:nth-child(2):hover,p>span:nth-child(3):hover{
  1440. color:red;
  1441. }
  1442. .updateDate{
  1443. cursor: pointer;
  1444. user-select: none;
  1445. }
  1446. .updateDate:hover{
  1447. color:red;
  1448. }
  1449. `);
  1450. document.querySelector("[name='user-content-click2import']").innerText=i18n("click2ImportRule")
  1451. configCon=document.querySelector(".markdown-body");
  1452. insertPos=configCon.querySelector("hr");
  1453. }else return false;
  1454. class Rulebar {
  1455. init(ruleUrl){
  1456. this.ruleUrl=ruleUrl;
  1457. this.item=document.createElement("p");
  1458. this.item.title=ruleUrl.type==0?"AutoPagerize Rules":"Pagetual Rules";
  1459. this.item.dataset.id=this.ruleUrl.id;
  1460. let url=document.createElement("span");
  1461. url.innerHTML=ruleUrl.url;
  1462. let up=document.createElement("span");
  1463. up.innerHTML="↑ ";
  1464. up.title=i18n("sortTitle");
  1465. let down=document.createElement("span");
  1466. down.innerHTML="↓ ";
  1467. down.title=i18n("sortTitle");
  1468. let del=document.createElement("span");
  1469. del.innerHTML="× ";
  1470. up.onclick=e=>{
  1471. this.moveUp();
  1472. };
  1473. down.onclick=e=>{
  1474. this.moveDown();
  1475. };
  1476. del.onclick=e=>{
  1477. this.del();
  1478. };
  1479. this.item.appendChild(up);
  1480. this.item.appendChild(down);
  1481. this.item.appendChild(del);
  1482. this.item.appendChild(url);
  1483. configCon.insertBefore(this.item, insertPos);
  1484. }
  1485. saveSort(){
  1486. let sort=[];
  1487. [].forEach.call(this.item.parentNode.querySelectorAll("p[data-id]"), i=>{
  1488. sort.push(i.dataset.id);
  1489. });
  1490. rulesData.sort=sort;
  1491. storage.setItem("rulesData", rulesData);
  1492. }
  1493. moveUp(){
  1494. let preE=this.item.previousElementSibling;
  1495. if(preE.tagName=="P" && preE.children.length>1){
  1496. this.item.parentNode.insertBefore(this.item,preE);
  1497. this.saveSort();
  1498. }
  1499. }
  1500. moveDown(){
  1501. let nextE=this.item.nextElementSibling;
  1502. if(nextE.tagName=="P" && nextE.children.length>1){
  1503. this.item.parentNode.insertBefore(nextE,this.item);
  1504. this.saveSort();
  1505. }
  1506. }
  1507. del(){
  1508. if(this.ruleUrl.id<2){
  1509. alert(i18n("cantDel"));
  1510. }else if(window.confirm(i18n("confirmDel"))){
  1511. for(let u=0;u<rulesData.urls.length;u++){
  1512. if(this.ruleUrl.id==rulesData.urls[u].id){
  1513. rulesData.urls.splice(u,1);
  1514. break;
  1515. }
  1516. }
  1517. for(let u=0;u<rulesData.sort.length;u++){
  1518. if(this.ruleUrl.id==rulesData.sort[u]){
  1519. rulesData.sort.splice(u,1);
  1520. break;
  1521. }
  1522. }
  1523. storage.setItem("rulesData", rulesData);
  1524. ruleParser.rules=ruleParser.rules.filter(item=>{return item.from!=this.ruleUrl.id});
  1525. storage.setItem("rules", ruleParser.rules);
  1526. this.item.parentNode.removeChild(this.item);
  1527. //location.reload();
  1528. }
  1529. }
  1530. }
  1531. let updateP=document.createElement("p"),i=0;
  1532. let now=new Date().getTime(),inUpdate=false;
  1533.  
  1534.  
  1535. let pastDate=(new Date(updateDate)).toString(),passStr;
  1536. let passTime=(now-updateDate)/1000;
  1537. if(isNaN(passTime)){
  1538. passStr=i18n("firstUpdate");
  1539. }else if(passTime<60){
  1540. passStr=i18n("passSec", parseInt(passTime))+" ← "+i18n("click2update");
  1541. }else if(passTime<60*60){
  1542. passStr=i18n("passMin", parseInt(passTime/60))+" ← "+i18n("click2update");
  1543. }else if(passTime<60*60*24){
  1544. passStr=i18n("passHour", parseInt(passTime/3600))+" ← "+i18n("click2update");
  1545. }else{
  1546. passStr=i18n("passDay", parseInt(passTime/86400))+" ← "+i18n("click2update");
  1547. }
  1548.  
  1549.  
  1550. updateP.className="updateDate";
  1551. updateP.innerHTML=passStr;
  1552. updateP.title=i18n("update")+" - "+pastDate;
  1553. updateP.onclick=e=>{
  1554. updateRules(()=>{
  1555. alert(i18n("updateSucc"));
  1556. updateP.innerHTML=i18n("passSec", 0);
  1557. updateP.title=i18n("update");
  1558. },(rule,err)=>{
  1559. alert("Update "+rule.url+" rules fail!");
  1560. });
  1561. alert(i18n("beginUpdate"));
  1562. };
  1563. configCon.insertBefore(updateP, insertPos);
  1564. if(ruleUrls){
  1565. ruleUrls.forEach(ruleUrl=>{
  1566. var rulebar=new Rulebar();
  1567. rulebar.init(ruleUrl);
  1568. });
  1569. }
  1570. let customUrlsTitle=document.createElement("h2");
  1571. customUrlsTitle.innerHTML=i18n("customUrls");
  1572. configCon.insertBefore(customUrlsTitle, insertPos);
  1573. let customUrlsInput=document.createElement("textarea");
  1574. customUrlsInput.style.width="100%";
  1575. customUrlsInput.placeholder="0|http://wedata.net/databases/AutoPagerize/items_all.json";
  1576. configCon.insertBefore(customUrlsInput, insertPos);
  1577.  
  1578. let opacityTitle=document.createElement("h2");
  1579. opacityTitle.innerHTML=i18n("opacity");
  1580. let opacityInput=document.createElement("input");
  1581. opacityInput.value=rulesData.opacity*100;
  1582. opacityInput.type="number";
  1583. opacityInput.style.width="50px";
  1584. opacityInput.style.margin="0 0 0 10px";
  1585. opacityTitle.appendChild(opacityInput);
  1586. configCon.insertBefore(opacityTitle, insertPos);
  1587.  
  1588. function createCheckbox(innerText, val){
  1589. let title=document.createElement("h2");
  1590. title.innerHTML=innerText;
  1591. let input=document.createElement("input");
  1592. input.type="checkbox";
  1593. input.style.width="50px";
  1594. input.style.height="20px";
  1595. input.checked=val;
  1596. title.appendChild(input);
  1597. configCon.insertBefore(title, insertPos);
  1598. return input;
  1599. }
  1600.  
  1601. let hideBarInput=createCheckbox(i18n("hideBar"), rulesData.hideBar);
  1602. let dbClick2StopInput=createCheckbox(i18n("dbClick2Stop"), rulesData.dbClick2Stop);
  1603. let enableWhiteListInput=createCheckbox(i18n("autoRun"), rulesData.enableWhiteList!=true);
  1604. let enableDebugInput=createCheckbox(i18n("enableDebug"), rulesData.enableDebug!=false);
  1605. let enableHistoryInput=createCheckbox(i18n("enableHistory"), rulesData.enableHistory===true);
  1606. let initRunInput=createCheckbox(i18n("initRun"), rulesData.initRun!=false);
  1607. let preloadInput=createCheckbox(i18n("preload"), rulesData.preload);
  1608.  
  1609. let customRulesTitle=document.createElement("h2");
  1610. customRulesTitle.innerHTML=i18n("customRules")
  1611. configCon.insertBefore(customRulesTitle, insertPos);
  1612. let customRulesInput=document.createElement("textarea");
  1613. customRulesInput.style.width="100%";
  1614. customRulesInput.style.height="500px";
  1615. 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]`;
  1616. customRulesInput.value=getFormatJSON(ruleParser.customRules);
  1617. configCon.insertBefore(customRulesInput, insertPos);
  1618. let saveBtn=document.createElement("button");
  1619. saveBtn.innerHTML=i18n("save");
  1620. saveBtn.style.width="100%";
  1621. configCon.insertBefore(saveBtn, insertPos);
  1622. saveBtn.onclick=e=>{
  1623. try{
  1624. storage.setItem("hpRules", []);
  1625. if(customRulesInput.value==""){
  1626. storage.setItem("customRules", "");
  1627. }else{
  1628. let customRules=JSON.parse(customRulesInput.value);
  1629. if(Array && Array.isArray && !Array.isArray(customRules)){
  1630. alert("Rules must be a Array!");
  1631. return;
  1632. }
  1633. debug(customRules);
  1634. storage.setItem("customRules", customRules);
  1635. }
  1636. }catch(e){
  1637. debug(e);
  1638. alert("JSON error, check again!");
  1639. return;
  1640. }
  1641. rulesData.opacity=opacityInput.value/100;
  1642. rulesData.hideBar=hideBarInput.checked;
  1643. rulesData.dbClick2Stop=dbClick2StopInput.checked;
  1644. rulesData.enableWhiteList=!enableWhiteListInput.checked;
  1645. rulesData.enableDebug=enableDebugInput.checked;
  1646. rulesData.enableHistory=enableHistoryInput.checked;
  1647. rulesData.initRun=initRunInput.checked;
  1648. rulesData.preload=preloadInput.checked;
  1649. storage.setItem("rulesData", rulesData);
  1650. let customUrls=customUrlsInput.value.trim();
  1651. if(customUrls){
  1652. customUrls=customUrls.split(/\n/);
  1653. for(let c=0;c<customUrls.length;c++){
  1654. let urlArr=customUrls[c].split("|"),url,type=1;
  1655. if(urlArr.length==1){
  1656. url=urlArr[0].trim();
  1657. if(!/^http/.test(url)){
  1658. alert("Wrong url, check again!");
  1659. return;
  1660. }
  1661. }else if(urlArr.length==2){
  1662. type=urlArr[0].trim();
  1663. url=urlArr[1].trim();
  1664. if(!/^http/.test(url)){
  1665. alert("Wrong url, check again!");
  1666. return;
  1667. }
  1668. }else{
  1669. break;
  1670. }
  1671. let maxId=0,hasUrl=false;
  1672. if(!rulesData.urls){
  1673. rulesData.urls=[];
  1674. maxId=1;
  1675. }else{
  1676. rulesData.urls.forEach(u=>{
  1677. if(maxId<u.id){
  1678. maxId=u.id;
  1679. }
  1680. if(u.url==url){
  1681. hasUrl=true;
  1682. }
  1683. });
  1684. if(hasUrl)break;
  1685. }
  1686. if(!rulesData.sort)rulesData.sort=[1];
  1687. rulesData.urls.push({id:maxId+1,url:url,type:type});
  1688. rulesData.sort.push(maxId+1);
  1689. storage.setItem("rulesData", rulesData);
  1690. }
  1691. }
  1692. alert("The settings are saved");
  1693. location.reload();
  1694. };
  1695. return true;
  1696. }
  1697.  
  1698. var inUpdate=false;
  1699. function updateRules(success,fail){
  1700. if(inUpdate)return;
  1701. inUpdate=true;
  1702. let ruleIndex=ruleUrls.length-1;
  1703. storage.setItem("hpRules", []);
  1704. function addNextRule(){
  1705. if(ruleIndex<0){
  1706. let now=new Date().getTime();
  1707. storage.setItem("ruleLastUpdate", now);
  1708. storage.setItem("rules", ruleParser.rules);
  1709. inUpdate=false;
  1710. success();
  1711. }else{
  1712. let rule=ruleUrls[ruleIndex--];
  1713. ruleParser.addRuleByUrl(rule.url, rule.type, rule.id, (json,err)=>{
  1714. if(!json){
  1715. fail(rule,err);
  1716. }
  1717. addNextRule();
  1718. })
  1719. }
  1720. }
  1721. addNextRule();
  1722. }
  1723.  
  1724. function objIsArr(obj) {
  1725. return obj &&
  1726. typeof obj === 'object' &&
  1727. typeof obj.length === 'number' &&
  1728. !(obj.propertyIsEnumerable('length'));
  1729. }
  1730.  
  1731. function isVisible(el, win) {
  1732. if(!el.offsetParent)return false;
  1733. var loopable = true,
  1734. visible = el.tagName && win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  1735. while(loopable && visible) {
  1736. el = el.parentNode;
  1737.  
  1738. if(el && el.tagName && el.tagName!="BODY") {
  1739. visible = win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  1740. }else {
  1741. loopable = false;
  1742. }
  1743. }
  1744. return visible;
  1745. }
  1746.  
  1747. function getFormatJSON(obj){
  1748. if(!objIsArr(obj))return "";
  1749. let ret="[\n";
  1750. let len=obj.length,i=0,isLast;
  1751. obj.forEach(item=>{
  1752. ret+=" {\n";
  1753. let iLen=Object.keys(item).length,j=0;
  1754. for(let key in item){
  1755. isLast=(++j)==iLen;
  1756. let value=item[key];
  1757. if(objIsArr(value)){
  1758. let vstr="[",v=0,vIsLast=false;
  1759. value.forEach(vi=>{
  1760. vIsLast=(++v)==value.length;
  1761. vstr+="\""+vi.replace(/\\/g,"\\\\")+"\""+(vIsLast?"":",");
  1762. });
  1763. vstr+="]";
  1764. ret+=" \""+key+"\":"+vstr+""+(isLast?"":",")+"\n";
  1765. }else{
  1766. if(typeof value=="string"){
  1767. value=value.replace(/\\/g,"\\\\").replace(/"/g,"\\\"");
  1768. value="\""+value+"\"";
  1769. }
  1770. ret+=" \""+key+"\":"+value+""+(isLast?"":",")+"\n";
  1771. }
  1772. }
  1773. isLast=(++i)==len;
  1774. ret+=" }"+(isLast?"":",")+"\n";
  1775. });
  1776. ret+="]";
  1777. return ret;
  1778. }
  1779.  
  1780. function initRules(callback) {
  1781. /*0 wedata格式,1 pagetual格式*/
  1782. ruleUrls=[
  1783. {
  1784. id:1,
  1785. url:'http://wedata.net/databases/AutoPagerize/items_all.json',
  1786. type:0,
  1787. }
  1788. ];var i=0,j=0;
  1789.  
  1790. ruleParser.initSavedRules(()=>{
  1791. storage.getItem("rulesData", data=>{
  1792. if(data){
  1793. rulesData=data;
  1794. if(data.urls)ruleUrls=ruleUrls.concat(data.urls);
  1795. if(data.sort){
  1796. let urls=[];
  1797. data.sort.forEach(id=>{
  1798. for(let s=0;s<ruleUrls.length;s++){
  1799. if(id==ruleUrls[s].id){
  1800. urls.push(ruleUrls[s]);
  1801. break;
  1802. }
  1803. }
  1804. });
  1805. ruleUrls=urls;
  1806. }
  1807. }
  1808. if(typeof(rulesData.opacity)=="undefined"){
  1809. rulesData.opacity=0.3;
  1810. }
  1811. if(typeof(rulesData.hideBar)=="undefined"){
  1812. rulesData.hideBar=false;
  1813. }
  1814. if(typeof(rulesData.dbClick2Stop)=="undefined"){
  1815. rulesData.dbClick2Stop=true;
  1816. }
  1817. if(typeof(rulesData.enableWhiteList)=="undefined"){
  1818. rulesData.enableWhiteList=false;
  1819. }
  1820. if(typeof(rulesData.enableHistory)=="undefined"){
  1821. rulesData.enableHistory=false;
  1822. }
  1823. if(typeof(rulesData.enableDebug)=="undefined"){
  1824. rulesData.enableDebug=true;
  1825. }
  1826. if(typeof(rulesData.initRun)=="undefined"){
  1827. rulesData.initRun=true;
  1828. }
  1829. if(typeof(rulesData.preload)=="undefined"){
  1830. rulesData.preload=false;
  1831. }
  1832. enableDebug=rulesData.enableDebug;
  1833. storage.getItem("forceState_"+location.host, v=>{
  1834. storage.getItem("ruleLastUpdate", date=>{
  1835. if(typeof(v)=="undefined"){
  1836. v=(rulesData.enableWhiteList?1:0);
  1837. }
  1838. forceState=v;
  1839. updateDate=date;
  1840. if(initConfig())return;
  1841. if(forceState==1)return;
  1842. let now=new Date().getTime();
  1843. if(!date || now-date>2*24*60*60*1000){
  1844. //storage.setItem("ruleLastUpdate", now);
  1845. updateRules(()=>{
  1846. //callback();
  1847. },(rule,err)=>{});
  1848. }
  1849. callback();
  1850. });
  1851. });
  1852. });
  1853. });
  1854. }
  1855.  
  1856. function requestDoc(url, callback){
  1857. _GM_xmlhttpRequest({
  1858. url: url,
  1859. method: 'GET',
  1860. overrideMimeType: 'text/html;charset='+document.charset,
  1861. headers: {
  1862. 'Referer': location.href
  1863. },
  1864. timeout: 5000,
  1865. onload: function(res) {
  1866. var doc=null;
  1867. try {
  1868. doc=document.implementation.createHTMLDocument('');
  1869. doc.documentElement.innerHTML=res.response;
  1870. }
  1871. catch (e) {
  1872. debug('parse error'+e.toString());
  1873. }
  1874. let pageElement=ruleParser.getPageElement(doc);
  1875. //只有1的話怕不是圖片哦
  1876. if(pageElement && (pageElement.length>1 || (pageElement.length==1 && pageElement[0].tagName!="IMG") )){
  1877. let result=ruleParser.insertPage(doc, pageElement, url, callback, false);
  1878. if(!result){
  1879. ruleParser.curSiteRule.action=1;
  1880. requestFromIframe(url, (doc, eles)=>{
  1881. loadPageOver();
  1882. if(eles){
  1883. ruleParser.insertPage(doc, eles, url, callback, true);
  1884. }
  1885. });
  1886. }
  1887. }else if(ruleParser.curSiteRule.singleUrl){
  1888. ruleParser.curSiteRule.action=1;
  1889. requestFromIframe(url, (doc, eles)=>{
  1890. loadPageOver();
  1891. if(eles){
  1892. ruleParser.insertPage(doc, eles, url, callback, true);
  1893. }
  1894. });
  1895. }else{
  1896. isPause=true;
  1897. callback(false);
  1898. }
  1899. },
  1900. onerror: function(e){
  1901. debug(e);
  1902. callback(false);
  1903. },
  1904. ontimeout: function(e){
  1905. debug(e);
  1906. callback(false);
  1907. }
  1908. });
  1909. }
  1910.  
  1911. var failFromIframe=0;
  1912. function requestFromIframe(url, callback){
  1913. let orgPage,curPage;
  1914. let iframe = document.createElement('iframe');
  1915. iframe.name = 'pagetual-iframe';
  1916. iframe.width = '100%';
  1917. iframe.height = '0';
  1918. iframe.frameBorder = '0';
  1919. if(ruleParser.curSiteRule.sandbox!=false){
  1920. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1921. }
  1922. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1923. iframe.addEventListener("load", e=>{
  1924. let waitTime=500,checkEval;
  1925. if(ruleParser.curSiteRule.wait){
  1926. if(isNaN(ruleParser.curSiteRule.wait)){
  1927. try{
  1928. checkEval=Function("doc",'"use strict";' + ruleParser.curSiteRule.wait);
  1929. }catch(e){
  1930. debug(e);
  1931. }
  1932. }else{
  1933. waitTime=ruleParser.curSiteRule.wait;
  1934. }
  1935. }
  1936. setTimeout(()=>{
  1937. let tryTimes=0;
  1938. function checkIframe(){
  1939. try{
  1940. let doc=iframe.contentDocument || iframe.contentWindow.document;
  1941. let eles=ruleParser.getPageElement(doc, iframe.contentWindow);
  1942. if(eles && eles.length>0 && (!checkEval || checkEval(doc))){
  1943. callback(doc, eles);
  1944. }else if(tryTimes++ < 10){
  1945. setTimeout(()=>{
  1946. checkIframe();
  1947. },waitTime);
  1948. return;
  1949. }else{
  1950. if(failFromIframe++ > 2){
  1951. failFromIframe=0;
  1952. debug("Stop as failFromIframe");
  1953. isPause=true;
  1954. callback(false, false);
  1955. }else{
  1956. callback(false, false);
  1957. }
  1958. }
  1959. }catch(e){
  1960. debug("Stop as cors");
  1961. //isPause=true;
  1962. if(!ruleParser.curSiteRule.pageElement)ruleParser.curSiteRule.pageElement=allOfBody;
  1963. ruleParser.curSiteRule.action=0;
  1964. ruleParser.getInsert(true);
  1965. ruleParser.nextLinkHref=url;
  1966. callback(false, false);
  1967. nextPage();
  1968. }
  1969. document.body.removeChild(iframe);
  1970. }
  1971. checkIframe();
  1972. },waitTime);
  1973. });
  1974. iframe.src=url;
  1975. document.body.appendChild(iframe);
  1976. }
  1977.  
  1978. function initPage(){
  1979. ruleParser.initPage(()=>{
  1980. if(ruleParser.nextLinkHref){
  1981. initView();
  1982. let isJs=/^(javascript|#)/.test(ruleParser.nextLinkHref.replace(location.href,""));
  1983. if(!isJs){
  1984. _GM_registerMenuCommand(i18n(forceState==2?"cancelForceIframe":"forceIframe"), ()=>{
  1985. storage.setItem("forceState_"+location.host, (forceState==2?"":2));
  1986. location.reload();
  1987. });
  1988. }
  1989. _GM_registerMenuCommand(i18n("loadNow"), ()=>{
  1990. let loadNum=window.prompt(i18n("loadConfirm"), "1");
  1991. if(loadNum==="" || loadNum===null)return;
  1992. autoLoadNum=Math.abs(parseInt(loadNum));
  1993. nextPage();
  1994. });
  1995. }
  1996. initListener();
  1997. if(rulesData.initRun && ruleParser.curSiteRule.initRun!=0)nextPage();
  1998. });
  1999. }
  2000.  
  2001. function initView(){
  2002. _GM_addStyle(`
  2003. .pagetual_pageBar.stop {
  2004. -webkit-filter: invert(100%);
  2005. filter: invert(100%);
  2006. opacity: 1!important;
  2007. }
  2008. .pagetual_pageBar.hide {
  2009. display: none!important;
  2010. }
  2011. .pagetual_pageBar:hover {
  2012. opacity: 1!important;
  2013. }
  2014. .pagetual_pageBar span {
  2015. vertical-align: super;
  2016. }
  2017.  
  2018. .pagetual_pageBar span>svg:hover {
  2019. animation: touhouAni 1s infinite;
  2020. }
  2021. .pagetual_pageBar .pagetual_pageNum{
  2022. color: #55555f;
  2023. }
  2024. .pagetual_pageBar .pagetual_pageNum:hover{
  2025. color: #ff6464;
  2026. }
  2027.  
  2028. @keyframes touhouAni{
  2029. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  2030. to {transform: rotate(360deg);}
  2031. }
  2032. @-webkit-keyframes touhouAni{
  2033. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  2034. to {transform: rotate(360deg);}
  2035. }
  2036. `);
  2037. 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;`;
  2038. }
  2039. var loadingDiv=document.createElement("div");
  2040. loadingDiv.className="pagetual_loading";
  2041. 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;";
  2042. 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>`;
  2043.  
  2044. 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>`;
  2045. 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>`;
  2046. var pageBarStyle;
  2047. 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;`;
  2048. 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);`;
  2049.  
  2050. var isPause=false,isLoading=false,curPage=1,forceState=0,bottomGap=1000,autoLoadNum=-1;
  2051.  
  2052. function changeStop(stop, hide){
  2053. isPause=stop;
  2054. [].forEach.call(document.querySelectorAll(".pagetual_pageBar"), bar=>{
  2055. if(isPause){
  2056. bar.classList.add("stop");
  2057. if(hide)bar.classList.add("hide");
  2058. }else{
  2059. bar.classList.remove("stop");
  2060. if(hide)bar.classList.remove("hide");
  2061. }
  2062. });
  2063. }
  2064.  
  2065. function isInViewPort(element) {
  2066. if(!element.parentNode)return false;
  2067. if(_unsafeWindow.getComputedStyle(element).display=="none")return false;
  2068. const viewWidth = window.innerWidth || document.documentElement.clientWidth;
  2069. const viewHeight = window.innerHeight || document.documentElement.clientHeight;
  2070. const {
  2071. top,
  2072. right,
  2073. bottom,
  2074. left,
  2075. } = element.getBoundingClientRect();
  2076.  
  2077. return (
  2078. top >= 0 &&
  2079. left >= 0 &&
  2080. right <= viewWidth &&
  2081. bottom <= viewHeight
  2082. );
  2083. }
  2084.  
  2085. var urlChanged=false;
  2086. var _wr = function(type) {
  2087. var orig = history[type];
  2088. return function() {
  2089. var rv = orig.apply(this, arguments);
  2090. var e = new Event(type);
  2091. e.arguments = arguments;
  2092. window.dispatchEvent(e);
  2093. return rv;
  2094. };
  2095. };
  2096. history.pushState = _wr('pushState');
  2097. window.addEventListener('pushState', function(e) {
  2098. urlChanged=true;
  2099. isPause=true;
  2100. setTimeout(()=>{
  2101. if(location.href==configPage){
  2102. location.reload();
  2103. }
  2104. },1);
  2105. });
  2106.  
  2107. function initListener(){
  2108. let loadmoreBtn,loading=true;
  2109. setTimeout(()=>{
  2110. loadmoreBtn=getLoadMore(document);
  2111. if(loadmoreBtn && isVisible(loadmoreBtn, _unsafeWindow)){
  2112. loading=false;
  2113. }
  2114. },500);
  2115. let checkScrollReach=()=>{
  2116. let scrolly=window.scrollY;
  2117. let windowHeight=window.innerHeight || document.documentElement.clientHeight;
  2118. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  2119. if(scrollH-scrolly-windowHeight<bottomGap){
  2120. nextPage();
  2121. }
  2122. };
  2123. document.addEventListener('scroll', e=>{
  2124. if(urlChanged){
  2125. ruleParser.initPage(()=>{
  2126. if(ruleParser.nextLinkHref)initView();
  2127. });
  2128. urlChanged=false;
  2129. isPause=false;
  2130. }
  2131. if(isPause)return;
  2132. if(!loading){
  2133. loading=true;
  2134. setTimeout(()=>{loading=false},200);
  2135. if(!loadmoreBtn || !loadmoreBtn.parentNode){
  2136. loadmoreBtn=getLoadMore(document);
  2137. }
  2138. if(loadmoreBtn){
  2139. if(isInViewPort(loadmoreBtn)){
  2140. emuClick(loadmoreBtn);
  2141. }
  2142. }
  2143. }
  2144. setTimeout(()=>{
  2145. if(!isLoading){
  2146. checkScrollReach();
  2147. }
  2148. },100);
  2149. }, true);
  2150. document.addEventListener('dblclick', e=>{
  2151. if(rulesData.dbClick2Stop){
  2152. setTimeout(()=>{
  2153. changeStop(!isPause, rulesData.hideBar);
  2154. if(!isPause){
  2155. checkScrollReach();
  2156. }
  2157. },200);
  2158. }
  2159. });
  2160. }
  2161.  
  2162. function getLoadMore(doc){
  2163. if(ruleParser.curSiteRule.loadMore==="")return null;
  2164. let btnSel=ruleParser.curSiteRule.loadMore||".LoadMore,.load-more";
  2165. let loadmoreBtn=doc.querySelector(btnSel);
  2166. if(!loadmoreBtn){
  2167. let buttons=doc.querySelectorAll("input,button,a,div[onclick]"),loadmoreReg=/^\s*(加载更多|加載更多|load\s*more|もっと読み込む)\s*$/i;
  2168. for(let i=0;i<buttons.length;i++){
  2169. let button=buttons[i];
  2170. if(button && loadmoreReg.test(button.innerText)){
  2171. loadmoreBtn=button;
  2172. break;
  2173. }
  2174. }
  2175. }
  2176. return loadmoreBtn;
  2177. }
  2178.  
  2179. var hasPageNum=true;
  2180. function createPageBar(url){
  2181. let insert=ruleParser.getInsert();
  2182. if(!insert || !insert.parentNode)return;
  2183. curPage++;
  2184. if(rulesData.opacity==0)return;
  2185. let example=ruleParser.curSiteRule.insertPos==2?insert.children[0]:(insert.previousElementSibling||insert);
  2186. if(!example || !example.parentNode)example=insert;
  2187. let inTable=example.parentNode.tagName=="TABLE" ||
  2188. example.tagName=="TR" ||
  2189. example.tagName=="TBODY" ||
  2190. (example.previousElementSibling && example.previousElementSibling.tagName=="TR") ||
  2191. (example.previousElementSibling && example.previousElementSibling.tagName=="TBODY");
  2192. let inLi=example.tagName=="LI" || (example.previousElementSibling && example.previousElementSibling.tagName=="LI");
  2193. let pageBar=document.createElement(inTable?"tr":(inLi?"li":"div"));
  2194. let upSpan=document.createElement("span");
  2195. let downSpan=document.createElement("span");
  2196. let pageText=document.createElement("a");
  2197. let pageNum;
  2198. pageBar.className="pagetual_pageBar";
  2199. pageBar.id="pagetual_pageBar";
  2200. if(isPause){
  2201. pageBar.classList.add("stop");
  2202. }
  2203. pageBar.style.cssText=pageBarStyle;
  2204. pageBar.title=i18n(isPause?"enable":"disable");
  2205. upSpan.innerHTML=upSvg;
  2206. upSpan.title=i18n("toTop");
  2207. downSpan.innerHTML=downSvg;
  2208. downSpan.title=i18n("toBottom");
  2209. upSpan.style.cssText=initStyle;
  2210. downSpan.style.cssText=initStyle;
  2211. pageText.href=url;
  2212. pageText.style.cssText=pageTextStyle;
  2213. pageText.title=i18n("current");
  2214. pageBar.appendChild(upSpan);
  2215. pageBar.appendChild(pageText);
  2216. if(ruleParser.curSiteRule.pageNum || (hasPageNum && /[&\/\?](p=|page[=\/])\d+/.test(url))){
  2217. pageText.innerHTML="Page ";
  2218. pageNum=document.createElement("span");
  2219. pageNum.innerText=curPage;
  2220. pageNum.className="pagetual_pageNum";
  2221. pageNum.title=i18n("inputPageNum");
  2222. pageNum.style.cssText=pageTextStyle;
  2223. pageNum.style.cursor="pointer";
  2224. pageNum.style.color="";
  2225. pageNum.addEventListener("click", e=>{
  2226. let pageInput=prompt(i18n("inputPageNum"), "1");
  2227. if(pageInput){
  2228. let pageLink=ruleParser.getLinkByPage(url, pageInput);
  2229. if(pageLink){
  2230. _GM_openInTab(pageLink,{active:true});
  2231. }
  2232. }
  2233. e.preventDefault();
  2234. e.stopPropagation();
  2235. });
  2236. pageBar.appendChild(pageNum);
  2237. }else{
  2238. pageText.innerHTML="Page "+curPage;
  2239. hasPageNum=false;
  2240. }
  2241. pageBar.appendChild(downSpan);
  2242. let parentStyle=_unsafeWindow.getComputedStyle(example.parentNode);
  2243. pageBar.style.width=parseInt(parentStyle.width)-10+"px";
  2244. if(parentStyle.display=="grid" || parentStyle.display=="inline-grid"){
  2245. pageBar.style.gridColumnStart=1;
  2246. pageBar.style.gridColumnEnd=1+parseInt(example.parentNode.offsetWidth/example.offsetWidth);
  2247. }
  2248. if(inTable){
  2249. example=(example.tagName=="TR" || example.tagName=="TBODY")?example:example.previousElementSibling;
  2250. if(example.previousElementSibling)example=example.previousElementSibling;
  2251. let tdNum=0;
  2252. [].forEach.call(example.querySelectorAll("td,th"), td=>{
  2253. tdNum+=td.colSpan||1;
  2254. });
  2255. pageBar.style.display="table-row";
  2256. pageBar.style.backgroundColor="unset";
  2257. let td=document.createElement("td");
  2258. td.style.backgroundColor="rgb(240 240 240 / 80%)";
  2259. td.style.borderRadius="20px";
  2260. td.colSpan=tdNum||1;
  2261. td.style.padding="0 0";
  2262. td.style.textAlign="center";
  2263. td.appendChild(upSpan);
  2264. td.appendChild(pageText);
  2265. if(pageNum)td.appendChild(pageNum);
  2266. td.appendChild(downSpan);
  2267. pageBar.appendChild(td);
  2268. }else if(inLi){
  2269. example=example.tagName=="LI"?example:example.previousElementSibling;
  2270. pageBar.style.display="table-row";
  2271. pageBar.style.backgroundColor="unset";
  2272. let td=document.createElement("td");
  2273. td.style.backgroundColor="rgb(240 240 240 / 80%)";
  2274. td.style.borderRadius="20px";
  2275. td.colSpan=example.children.length;
  2276. td.style.padding="0 0";
  2277. td.style.textAlign="center";
  2278. td.style.minWidth="150px";
  2279. td.appendChild(upSpan);
  2280. td.appendChild(pageText);
  2281. td.style.width=pageBar.style.width;
  2282. if(pageNum)td.appendChild(pageNum);
  2283. td.appendChild(downSpan);
  2284. pageBar.appendChild(td);
  2285. }
  2286.  
  2287. upSpan.addEventListener("click", e=>{
  2288. document.body.scrollTop=0;
  2289. document.documentElement.scrollTop=0;
  2290. e.preventDefault();
  2291. e.stopPropagation();
  2292. });
  2293. downSpan.addEventListener("click", e=>{
  2294. changeStop(true);
  2295. pageBar.title=i18n(isPause?"enable":"disable");
  2296. document.body.scrollTop=9999999;
  2297. document.documentElement.scrollTop=9999999;
  2298. e.preventDefault();
  2299. e.stopPropagation();
  2300. });
  2301. pageBar.addEventListener("click", e=>{
  2302. changeStop(!isPause);
  2303. pageBar.title=i18n(isPause?"enable":"disable");
  2304. });
  2305. pageText.addEventListener("click", e=>{
  2306. e.stopPropagation();
  2307. });
  2308. if(ruleParser.curSiteRule.insertPos==2){
  2309. insert.appendChild(pageBar);
  2310. }else{
  2311. insert.parentNode.insertBefore(pageBar, insert);
  2312. }
  2313. if(ruleParser.curSiteRule.pageBar){
  2314. try{
  2315. Function("pageBar",'"use strict";' + ruleParser.curSiteRule.pageBar)(pageBar);
  2316. }catch(e){
  2317. debug(e);
  2318. }
  2319. }
  2320.  
  2321. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  2322. let posEle=pageBar.nextElementSibling||pageBar;
  2323. while(posEle && !posEle.offsetParent){
  2324. posEle=posEle.previousElementSibling||posEle.parentNode;
  2325. }
  2326. if(posEle){
  2327. let actualTop = posEle.offsetTop;
  2328. let current = posEle.parentNode.offsetParent;
  2329. while (current !== null){
  2330. actualTop += current.offsetTop;
  2331. current = current.offsetParent;
  2332. }
  2333. bottomGap=scrollH-actualTop+(window.innerHeight||document.documentElement.clientHeight)*(ruleParser.curSiteRule.rate||1);
  2334. if(bottomGap<100)bottomGap=100;
  2335. }else{
  2336. bottomGap=1000;
  2337. }
  2338. return pageBar;
  2339. }
  2340.  
  2341. function emuClick(btn){
  2342. if(!PointerEvent)return btn.click();
  2343. let eventParam={
  2344. isTrusted: true,
  2345. altKey: false,
  2346. azimuthAngle: 0,
  2347. bubbles: true,
  2348. button: 0,
  2349. buttons: 0,
  2350. clientX: 1,
  2351. clientY: 1,
  2352. cancelBubble: false,
  2353. cancelable: true,
  2354. composed: true,
  2355. ctrlKey: false,
  2356. defaultPrevented: false,
  2357. detail: 1,
  2358. eventPhase: 2,
  2359. fromElement: null,
  2360. height: 1,
  2361. isPrimary: false,
  2362. metaKey: false,
  2363. pointerId: 1,
  2364. pointerType: "mouse",
  2365. pressure: 0,
  2366. relatedTarget: null,
  2367. returnValue: true,
  2368. shiftKey: false,
  2369. toElement: null,
  2370. twist: 0,
  2371. type: "click",
  2372. which: 1
  2373. };
  2374. var mouseclick = new PointerEvent("click",eventParam);
  2375. btn.dispatchEvent(mouseclick);
  2376. }
  2377.  
  2378. var emuIframe;
  2379. function emuPage(callback){
  2380. let orgPage=null,curPage,iframeDoc,times=0,loadmoreBtn,loadmoreEnd=false,waitTimes=10;
  2381. function checkPage(){
  2382. if(isPause)return;
  2383. try{
  2384. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  2385. }catch(e){
  2386. debug("Stop as cors");
  2387. isPause=true;
  2388. callback(false, false);
  2389. return;
  2390. }
  2391.  
  2392. let nextLink=ruleParser.getNextLink(iframeDoc);
  2393. let waitTime=500,checkEval;
  2394. if(ruleParser.curSiteRule.wait){
  2395. if(isNaN(ruleParser.curSiteRule.wait)){
  2396. try{
  2397. checkEval=Function("doc",'"use strict";' + ruleParser.curSiteRule.wait);
  2398. }catch(e){
  2399. debug(e);
  2400. }
  2401. }else{
  2402. waitTime=ruleParser.curSiteRule.wait;
  2403. }
  2404. }
  2405.  
  2406. if(!orgPage){
  2407. if(!loadmoreEnd){
  2408. loadmoreBtn=getLoadMore(iframeDoc);
  2409. if(loadmoreBtn && isVisible(loadmoreBtn, iframeDoc.defaultView)){
  2410. emuClick(loadmoreBtn);
  2411. let intv=setInterval(()=>{
  2412. loadmoreBtn=getLoadMore(iframeDoc);
  2413. if(!loadmoreBtn || !loadmoreBtn.parentNode || !isVisible(loadmoreBtn, iframeDoc.defaultView)){
  2414. clearInterval(intv);
  2415. loadmoreEnd=true;
  2416. setTimeout(()=>{
  2417. checkPage();
  2418. },500);
  2419. }else{
  2420. emuClick(loadmoreBtn);
  2421. }
  2422. },200);
  2423. return;
  2424. }else{
  2425. loadmoreEnd=true;
  2426. }
  2427. }
  2428. let pageEle=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true);
  2429. if(!nextLink || !pageEle || (checkEval && !checkEval(iframeDoc))){
  2430. if(ruleParser.curSiteRule.wait && waitTimes-->0){
  2431. setTimeout(()=>{
  2432. checkPage();
  2433. },waitTime);
  2434. return;
  2435. }
  2436. }
  2437. orgPage=pageEle;
  2438. if(!orgPage || orgPage.length==0){
  2439. debug("Stop as no page when emu");
  2440. isPause=true;
  2441. callback(false, false);
  2442. return;
  2443. }
  2444. if(orgPage && orgPage[0].tagName=="UL")orgPage=orgPage[0].children;
  2445. if(orgPage && nextLink){
  2446. orgPage=orgPage[parseInt(orgPage.length/2)];
  2447. if(!isVisible(nextLink, iframeDoc.defaultView)){
  2448. debug("Stop as next hide when emu");
  2449. isPause=true;
  2450. callback(false, false);
  2451. }else{
  2452. emuClick(nextLink);
  2453. setTimeout(()=>{
  2454. checkPage();
  2455. },500);
  2456. }
  2457. }else{
  2458. debug("Stop as no next when emu");
  2459. isPause=true;
  2460. callback(false, false);
  2461. }
  2462. return;
  2463. }
  2464. if(times++ > 20){
  2465. //emuClick(nextLink);
  2466. debug("Stop as timeout when emu");
  2467. isPause=true;
  2468. callback(false, false);
  2469. return;
  2470. }
  2471. let eles=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true),checkItem;
  2472. if(eles && eles.length>0){
  2473. checkItem=eles;
  2474. if(eles[0].tagName=="UL"){
  2475. checkItem=eles[0].children;
  2476. }
  2477. checkItem=checkItem[parseInt(checkItem.length/2)];
  2478. }
  2479. if(!checkItem || orgPage == checkItem || (checkEval && !checkEval(iframeDoc))){
  2480. setTimeout(()=>{
  2481. checkPage();
  2482. },waitTime);
  2483. }else{
  2484. callback(iframeDoc, eles);
  2485. }
  2486. }
  2487. if(!emuIframe){
  2488. let loaded=false;
  2489. emuIframe = document.createElement('iframe');
  2490. emuIframe.name = 'pagetual-iframe';
  2491. if(ruleParser.curSiteRule.sandbox!=false){
  2492. emuIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  2493. }
  2494. emuIframe.width = '100%';
  2495. emuIframe.height = '0';
  2496. emuIframe.frameBorder = '0';
  2497. emuIframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  2498. emuIframe.addEventListener("load", e=>{
  2499. setTimeout(()=>{
  2500. try{
  2501. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  2502. }catch(e){
  2503. debug("Stop as cors");
  2504. isPause=true;
  2505. callback(false, false);
  2506. return;
  2507. }
  2508. let code=ruleParser.curSiteRule.init;
  2509. if(code){
  2510. try{
  2511. Function('doc','win','"use strict";' + code)(iframeDoc, iframeDoc.defaultView);
  2512. }catch(e){
  2513. debug(e);
  2514. }
  2515. }
  2516. if(loaded)return;
  2517. loaded=true;
  2518. checkPage();
  2519. },500);
  2520. });
  2521. emuIframe.src=location.href;
  2522. document.body.appendChild(emuIframe);
  2523. }else{
  2524. checkPage();
  2525. }
  2526. }
  2527.  
  2528. function forceIframe(url, callback){
  2529. let curIframe = document.createElement('iframe'),iframeDoc;
  2530. curIframe.name = 'pagetual-iframe';
  2531. curIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  2532. curIframe.frameBorder = '0';
  2533. curIframe.scrolling="no";
  2534. 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;';
  2535. curIframe.addEventListener("load", e=>{
  2536. try{
  2537. iframeDoc=curIframe.contentDocument || curIframe.contentWindow.document;
  2538. }catch(e){
  2539. debug("Stop as cors");
  2540. isPause=true;
  2541. callback(false, false);
  2542. return;
  2543. }
  2544. ruleParser.insertPage(iframeDoc, [], url, null, true);
  2545. callback(curIframe, true);
  2546. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  2547. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  2548. });
  2549. let inAction=false;
  2550. let forceRefresh=e=>{
  2551. if(inAction || !iframeDoc)return;
  2552. inAction=true;
  2553. setTimeout(()=>{
  2554. inAction=false;
  2555. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  2556. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  2557. if(!ruleParser.nextLinkHref){
  2558. ruleParser.getNextLink(iframeDoc);
  2559. if(ruleParser.nextLinkHref){
  2560. document.removeEventListener("scroll", forceRefresh);
  2561. }
  2562. }else{
  2563. document.removeEventListener("scroll", forceRefresh);
  2564. }
  2565. },500);
  2566. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  2567. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  2568. };
  2569. document.addEventListener("scroll", forceRefresh);
  2570. curIframe.src=url;
  2571. let insert=ruleParser.getInsert();
  2572. document.body.appendChild(curIframe);
  2573. return curIframe;
  2574. }
  2575.  
  2576. function loadPageOver(){
  2577. isLoading=false;
  2578. if(loadingDiv.parentNode){
  2579. loadingDiv.parentNode.removeChild(loadingDiv);
  2580. }
  2581. setTimeout(()=>{
  2582. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  2583. if(scrollH < (window.innerHeight || document.documentElement.clientHeight)){
  2584. nextPage();
  2585. }
  2586. },1);
  2587. }
  2588.  
  2589. function nextPage(){
  2590. if(isPause || isLoading)return;
  2591. let nextLink=ruleParser.nextLinkHref;
  2592. if(!nextLink)return;
  2593. let pvGallery=document.querySelector("span.pv-gallery-container");
  2594. if(pvGallery && pvGallery.style.display!="none")return;
  2595. let insert=ruleParser.getInsert();
  2596. if(insert){
  2597. let isJs=/^(javascript|#)/.test(nextLink.replace(location.href,""));
  2598. if(location.protocol=="https:" && /^http:/.test(nextLink)){
  2599. nextLink=nextLink.replace(/^http/,"https");
  2600. }
  2601. isLoading=true;
  2602. document.body.appendChild(loadingDiv);
  2603. let sleep=ruleParser.curSiteRule.sleep||0;
  2604. setTimeout(()=>{
  2605. if(ruleParser.curSiteRule.pageElementByJs){
  2606. var over=ele=>{
  2607. loadPageOver();
  2608. if(ele){
  2609. createPageBar(nextLink);
  2610. ruleParser.insertPage(null, ele, nextLink, null, true);
  2611. if(autoLoadNum>=0){
  2612. if(autoLoadNum!=0 && --autoLoadNum==0){
  2613. autoLoadNum=-1;
  2614. }else{
  2615. nextPage();
  2616. }
  2617. }
  2618. }else{
  2619. debug("Stop as no page when get by js");
  2620. isPause=true;
  2621. }
  2622. };
  2623. try{
  2624. Function("over",'"use strict";' + ruleParser.curSiteRule.pageElementByJs)(over);
  2625. }catch(e){
  2626. debug(e);
  2627. }
  2628. }else if(ruleParser.curSiteRule.action==1 && !isJs){
  2629. requestFromIframe(nextLink, (doc, eles)=>{
  2630. loadPageOver();
  2631. if(eles){
  2632. createPageBar(nextLink);
  2633. ruleParser.insertPage(doc, eles, nextLink, null, true);
  2634. if(autoLoadNum>=0){
  2635. if(autoLoadNum!=0 && --autoLoadNum==0){
  2636. autoLoadNum=-1;
  2637. }else{
  2638. nextPage();
  2639. }
  2640. }
  2641. }
  2642. });
  2643. }else if((forceState==2||ruleParser.curSiteRule.action==2) && !isJs){
  2644. forceIframe(nextLink, (iframe, eles)=>{
  2645. loadPageOver();
  2646. let pageBar=createPageBar(nextLink);
  2647. iframe.parentNode.insertBefore(pageBar, iframe);
  2648. if(autoLoadNum>=0){
  2649. if(autoLoadNum!=0 && --autoLoadNum==0){
  2650. autoLoadNum=-1;
  2651. }else{
  2652. nextPage();
  2653. }
  2654. }
  2655. });
  2656. }else{
  2657. if(!isJs){
  2658. requestDoc(nextLink, (eles)=>{
  2659. loadPageOver();
  2660. if(eles){
  2661. createPageBar(nextLink);
  2662. if(autoLoadNum>=0){
  2663. if(autoLoadNum!=0 && --autoLoadNum==0){
  2664. autoLoadNum=-1;
  2665. }else{
  2666. nextPage();
  2667. }
  2668. }
  2669. }
  2670. });
  2671. }else{
  2672. emuPage((doc, eles)=>{
  2673. loadPageOver();
  2674. if(eles){
  2675. createPageBar(nextLink);
  2676. ruleParser.insertPage(doc, eles, "", null, true);
  2677. if(autoLoadNum>=0){
  2678. if(autoLoadNum!=0 && --autoLoadNum==0){
  2679. autoLoadNum=-1;
  2680. }else{
  2681. nextPage();
  2682. }
  2683. }
  2684. }
  2685. });
  2686. }
  2687. }
  2688. },sleep);
  2689. }
  2690. }
  2691.  
  2692. function init(){
  2693. initRules(()=>{
  2694. initPage();
  2695. });
  2696. }
  2697. setTimeout(()=>{
  2698. init();
  2699. },300);
  2700. })();