東方永頁機

自動加載並拼接下一分頁內容(適用於論壇、漫畫站、小說站、資訊站、博客等),無需規則支持所有網頁

目前為 2022-03-12 提交的版本,檢視 最新版本

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