东方永页机 - 自动翻页脚本

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

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