东方永页机

自动翻页脚本 - 自动加载并拼接下一分页内容,无需规则驱动支持任意网页

当前为 2022-05-29 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Pagetual
  3. // @name:zh-CN 东方永页机
  4. // @name:zh-TW 東方永頁機
  5. // @name:ja 東方永頁機
  6. // @name:ru Пейджетуал
  7. // @name:de Pagetual
  8. // @name:es Pagetual
  9. // @name:fr Pagetual
  10. // @name:it Pagetual
  11. // @name:ko 東方永頁機
  12. // @namespace hoothin
  13. // @version 1.9.2
  14. // @description Perpetual pages - Most powerful Auto Pager script. 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. // @match *://*/*
  26. // @license MIT
  27. // @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==
  28. // @grant GM_xmlhttpRequest
  29. // @grant GM_registerMenuCommand
  30. // @grant GM_notification
  31. // @grant GM_getValue
  32. // @grant GM_setValue
  33. // @grant GM_addStyle
  34. // @grant GM_openInTab
  35. // @grant GM_deleteValue
  36. // @grant GM.xmlHttpRequest
  37. // @grant GM.registerMenuCommand
  38. // @grant GM.notification
  39. // @grant GM.getValue
  40. // @grant GM.setValue
  41. // @grant GM.addStyle
  42. // @grant GM.openInTab
  43. // @grant GM.deleteValue
  44. // @supportURL https://github.com/hoothin/UserScripts/issues
  45. // @connect wedata.net
  46. // @connect githubusercontent.com
  47. // @run-at document-idle
  48. // @exclude http://www.toodledo.com/tasks/*
  49. // @exclude http*://maps.google.com*/*
  50. // @exclude *://www.google.*/_/chrome/newtab*
  51. // @exclude *://mega.*/*
  52. // @exclude *://*.mega.*/*
  53. // @exclude *://*.youku.com/v_*
  54. // @exclude *://*pan.baidu.com
  55. // @exclude *://*.iqiyi.com/v_*
  56. // @exclude *://*.iqiyi.com/w_*
  57. // @exclude *://*.iqiyi.com/a_*
  58. // @exclude *://*.le.com/ptv/vplay/*
  59. // @exclude *://v.qq.com/x/cover/*
  60. // @exclude *://v.qq.com/x/page/*
  61. // @exclude *://v.qq.com/tv/*
  62. // @exclude *://*.tudou.com/listplay/*
  63. // @exclude *://*.tudou.com/albumplay/*
  64. // @exclude *://*.tudou.com/programs/view/*
  65. // @exclude *://*.mgtv.com/b/*
  66. // @exclude *://film.sohu.com/album/*
  67. // @exclude *://tv.sohu.com/v/*
  68. // @exclude *://*.bilibili.com/video/*
  69. // @exclude *://*.bilibili.com/bangumi/play/*
  70. // @exclude *://*.baofeng.com/play/*
  71. // @exclude *://vip.pptv.com/show/*
  72. // @exclude *://v.pptv.com/show/*
  73. // @exclude *://www.le.com/ptv/vplay/*
  74. // @exclude *://www.wasu.cn/Play/show/*
  75. // @exclude *://m.v.qq.com/*
  76. // @exclude *://m.iqiyi.com/*
  77. // @exclude *://m.youku.com/alipay_video/*
  78. // @exclude *://m.mgtv.com/b/*
  79. // @exclude *://m.tv.sohu.com/v/*
  80. // @exclude *://m.film.sohu.com/album/*
  81. // @exclude *://m.le.com/ptv/vplay/*
  82. // @exclude *://m.pptv.com/show/*
  83. // @exclude *://m.acfun.cn/v/*
  84. // @exclude *://m.bilibili.com/video/*
  85. // @exclude *://m.bilibili.com/anime/*
  86. // @exclude *://m.bilibili.com/bangumi/play/*
  87. // @exclude *://m.wasu.cn/Play/show/*
  88. // @exclude *://www.youtube.com
  89. // @exclude *://www.youtube.com/
  90. // @exclude *://www.youtube.com/watch*
  91. // @exclude *://baike.baidu.com/*
  92. // @exclude *://*.instagram.com/*
  93. // @exclude *://order.jd.com/*
  94. // @exclude *://pagetual.hoothin.com/*
  95. // @exclude *://hoothin.github.io/PagetualGuide/*
  96. // @exclude *://wenku.baidu.com/view/*
  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.parent.postMessage('pagetual-iframe:DOMLoaded', '*');
  107. };
  108. if(window.opera){
  109. document.addEventListener('DOMContentLoaded', domloaded, false);
  110. } else {
  111. domloaded();
  112. }
  113. return;
  114. }
  115.  
  116. if(window.top != window.self){
  117. try{
  118. if (top.location.hostname != window.location.hostname || window.top != window.parent) {
  119. return;
  120. }
  121. }catch(e){
  122. return;
  123. }
  124. }
  125.  
  126. const lang = navigator.appName=="Netscape"?navigator.language:navigator.userLanguage;
  127. let config={};
  128. switch (lang){
  129. case "zh-CN":
  130. case "zh-SG":
  131. config={
  132. enableDebug:"调试模式,输出信息至控制台",
  133. disable:"暂时禁用",
  134. disableSite:"切换禁用状态",
  135. disableSiteTips:"已在此站禁用",
  136. enableSiteTips:"已在此站启用",
  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. openInNewTab:"使拼接页面的内容在新页面打开",
  174. importSucc:"导入成功",
  175. editCurrent:"自定义此站规则",
  176. editBlacklist:"编辑黑名单网址,一行一条,支持? *通配符",
  177. upBtnImg:"回到页首图标",
  178. downBtnImg:"前往页尾图标",
  179. dbClick2StopCtrl:"Ctrl 键",
  180. dbClick2StopAlt:"Alt 键",
  181. dbClick2StopShift:"Shift 键",
  182. dbClick2StopMeta:"Meta 键",
  183. dbClick2StopKey:"快捷键"
  184. };
  185. break;
  186. case "zh-TW":
  187. case "zh-HK":
  188. config={
  189. enableDebug:"調試模式,輸出信息至控制台",
  190. disable:"暫時禁用",
  191. disableSite:"切換禁用狀態",
  192. disableSiteTips:"已在此站禁用",
  193. enableSiteTips:"已在此站啟用",
  194. enable:"啟用翻頁",
  195. toTop:"回到頂部",
  196. toBottom:"前往頁尾",
  197. current:"當前頁",
  198. forceIframe:"強制拼接",
  199. cancelForceIframe:"取消强制拼接",
  200. configure:"打開配置頁",
  201. firstUpdate:"點擊此處初始化規則",
  202. update:"更新規則",
  203. click2update:"點擊立即更新規則",
  204. loadNow:"立即翻頁",
  205. loadConfirm:"要翻几頁?(0為不間斷)",
  206. noNext:"沒有找到下一頁,請新建規則",
  207. passSec:"更新于 #t# 秒前",
  208. passMin:"更新于 #t# 分鐘前",
  209. passHour:"更新于 #t# 小時前",
  210. passDay:"更新于 #t# 天前",
  211. cantDel:"無法刪除内置規則",
  212. confirmDel:"是否確認要刪除此規則?",
  213. updateSucc:"更新成功",
  214. beginUpdate:"正在更新,請稍候",
  215. customUrls:"導入規則url,一行一條,AutoPagerize 格式規則需要以\"0|\"開頭",
  216. customRules:"輸入【東方永頁機】格式的自定義規則",
  217. save:"存儲設置",
  218. loadingText:"少女祈禱中...",
  219. opacity:"分頁隔條不透明值",
  220. hideBar:"隱藏分頁隔條",
  221. dbClick2Stop:"空白處雙擊暫停翻頁",
  222. sortTitle:"排序在下次更新規則後生效",
  223. autoRun:"自動啓用,否則為白名單模式",
  224. inputPageNum:"輸入頁碼跳轉",
  225. enableHistory:"翻頁后寫入歷史記錄",
  226. initRun:"打開頁面后立即嘗試翻頁,否則滾動至頁尾再翻頁",
  227. preload:"翻頁前預讀下一頁,加速瀏覽",
  228. click2ImportRule:"點擊下方添加特殊規則庫,添加後再行更新:",
  229. forceAllBody:"是否拼接整個頁面?",
  230. openInNewTab:"使拼接頁面的内容在新頁面打開",
  231. importSucc:"導入成功",
  232. editCurrent:"自定義此站規則",
  233. editBlacklist:"編輯黑名單網址,一行一條,支持? *通配符",
  234. upBtnImg:"回到頁首圖標",
  235. downBtnImg:"前往頁尾圖標",
  236. dbClick2StopCtrl:"Ctrl 鍵",
  237. dbClick2StopAlt:"Alt 鍵",
  238. dbClick2StopShift:"Shift 鍵",
  239. dbClick2StopMeta:"Meta 鍵",
  240. dbClick2StopKey:"快捷鍵"
  241. };
  242. break;
  243. case "ja":
  244. config = {
  245. enableDebug:"デバッグモード",
  246. disable: "一時的に無効にする",
  247. disableSite:"無効状態の切り替え",
  248. disableSiteTips:"このサイトで既に無効になっています",
  249. enableSiteTips:"このサイトで既に有効になっています",
  250. enable: "ページめくりを有効にする",
  251. toTop: "トップに戻る",
  252. toBottom: "ページの下部に移動",
  253. current: "現在のページ",
  254. forceIframe: "強制ステッチ",
  255. cancelForceIframe: "強制ステッチをキャンセル",
  256. configure: "設定ページを開く",
  257. firstUpdate:"ここをクリックしてルールを初期化します",
  258. update: "更新ルール",
  259. click2update:"今すぐルールを更新してください",
  260. loadNow:"今すぐページをめくる",
  261. loadConfirm:"数ページめくりたいですか?(0は途切れない)",
  262. noNext:"次のページが見つかりません、新しいルールを作成してください",
  263. passSec: "#t#秒前に更新",
  264. passMin: "#t#分前に更新",
  265. passHour: "#t#時間前に更新",
  266. passDay: "#t#日前に更新",
  267. cantDel: "組み込みルールを削除できません",
  268. confirmDel: "このルールを削除してもよろしいですか?",
  269. updateSucc: "更新に成功しました",
  270. beginUpdate: "更新中、お待ちください",
  271. customUrls: "インポートルールのURL、1行に1つ、AutoPagerizeフォーマットルールは\"0|\"で始まる必要があります",
  272. customRules: "【東方永頁機】の形式でカスタムルールを入力してください",
  273. save: "設定を保存",
  274. loadingText: "少女祈祷中...",
  275. opacity:"ページネーションバーの不透明値",
  276. hideBar:"ページ区切り文字を非表示にします",
  277. dbClick2Stop:"空白部分をダブルクリックしてページめくりを一時停止します",
  278. sortTitle:"並べ替えは、次のルールの更新後に有効になります",
  279. autoRun:"自動的に有効",
  280. inputPageNum:"ジャンプするページ番号を入力",
  281. enableHistory:"ページめくり後の履歴を書く",
  282. initRun:"Webページを開いた直後にページをめくる",
  283. preload:"事前に次のページを読む",
  284. click2ImportRule:"以下をクリックして、ルールベースを追加します:",
  285. forceAllBody:"フルページ埋め込み?",
  286. openInNewTab:"スプライスされたページのコンテンツを新しいページで開きます",
  287. importSucc:"インポート完了",
  288. editCurrent:"現在のルールの編集",
  289. editBlacklist:"ブラックリストのURLを編集し、1行ずつ、サポート? *ワイルドカード",
  290. upBtnImg:"トップアイコンに戻る",
  291. downBtnImg:"フッターアイコンに移動",
  292. dbClick2StopCtrl:"Ctrlキー",
  293. dbClick2StopAlt:"Altキー",
  294. dbClick2StopShift:"Shiftキー",
  295. dbClick2StopMeta:"Metaキー",
  296. dbClick2StopKey:"Shortcutキー"
  297. };
  298. break;
  299. default:
  300. config={
  301. enableDebug:"Enable debug output",
  302. disable:"Disable",
  303. disableSite:"Toggle disabled state",
  304. disableSiteTips:"Disabled on this site",
  305. enableSiteTips:"Enabled on this site",
  306. enable:"Enable",
  307. toTop:"To Top",
  308. toBottom:"To Bottom",
  309. current:"Current Page",
  310. forceIframe:"Force to join",
  311. cancelForceIframe:"Cancel Force join",
  312. configure:"Configure",
  313. firstUpdate:"Click here to initialize the rules",
  314. update:"Update rules",
  315. click2update:"Click to update rules from url now",
  316. loadNow:"Load next now",
  317. loadConfirm:"How much pages do you want to load? (0 means infinite)",
  318. noNext:"No next link found, please create a new rule",
  319. passSec:"Updated #t# seconds ago",
  320. passMin:"Updated #t# minutes ago",
  321. passHour:"Updated #t# hours ago",
  322. passDay:"Updated #t# days ago",
  323. cantDel:"Can't delete buildin rules",
  324. confirmDel:"Are you sure you want to delete this rule?",
  325. updateSucc:"Update succeeded",
  326. beginUpdate:"Begin update, wait a minute please",
  327. customUrls:"Import rule url, One url per line, rules on AutoPagerize format need to start with \"0|\"",
  328. customRules:"Input custom rules with [Pagetual] format",
  329. save:"Save",
  330. loadingText:"Shojo Now Loading...",
  331. opacity:"Pagination spacer opacity",
  332. hideBar:"hide the paging spacer",
  333. dbClick2Stop:"Double-click on the blank space to pause",
  334. sortTitle:"Sorting takes effect after the next rule update",
  335. autoRun:"Auto run (black list mode)",
  336. inputPageNum:"Enter page number to jump",
  337. enableHistory:"Write history after page turning",
  338. initRun:"Turn pages immediately after opening",
  339. preload:"Preload next page for speeding up",
  340. click2ImportRule:"Click to import base rules link, then click to update rules:",
  341. forceAllBody:"Join full body of page?",
  342. openInNewTab:"Open urls of additions in new tab",
  343. importSucc:"Import completed",
  344. editCurrent:"Edit rule for current",
  345. editBlacklist:"Edit the blacklist urls, line by line, Support ? * for wildcard",
  346. upBtnImg:"Icon of back to top",
  347. downBtnImg:"Icon of go to footer",
  348. dbClick2StopCtrl:"Ctrl key",
  349. dbClick2StopAlt:"Alt key",
  350. dbClick2StopShift:"Shift key",
  351. dbClick2StopMeta:"Meta key",
  352. dbClick2StopKey:"Shortcut key"
  353. };
  354. break;
  355. }
  356. var i18n=(name, param)=>{
  357. return config[name]?config[name].replace("#t#",param):name;
  358. };
  359.  
  360. var noRuleTest=false;
  361. var enableDebug=true;
  362. var debug=str=>{
  363. if(enableDebug){
  364. console.debug(str);
  365. }
  366. };
  367.  
  368. var _GM_xmlhttpRequest,_GM_registerMenuCommand,_GM_notification,_GM_addStyle,_GM_openInTab;
  369. if(typeof GM_xmlhttpRequest!='undefined'){
  370. _GM_xmlhttpRequest=GM_xmlhttpRequest;
  371. }else if(typeof GM!='undefined' && typeof GM.xmlHttpRequest!='undefined'){
  372. _GM_xmlhttpRequest=GM.xmlHttpRequest;
  373. }else{
  374. _GM_xmlhttpRequest=(f)=>{fetch(f.url).then(response=>response.text()).then(data=>{let res={response:data};f.onload(res)}).catch(f.onerror())};
  375. }
  376. if(typeof GM_registerMenuCommand!='undefined'){
  377. _GM_registerMenuCommand=GM_registerMenuCommand;
  378. }else if(typeof GM!='undefined' && typeof GM.registerMenuCommand!='undefined'){
  379. _GM_registerMenuCommand=GM.registerMenuCommand;
  380. }else{
  381. _GM_registerMenuCommand=(s,f)=>{};
  382. }
  383. if(typeof GM_notification!='undefined'){
  384. _GM_notification=GM_notification;
  385. }else if(typeof GM!='undefined' && typeof GM.notification!='undefined'){
  386. _GM_notification=GM.notification;
  387. }else{
  388. _GM_notification=(s)=>{showTips(s)};
  389. }
  390. if(typeof GM_openInTab!='undefined'){
  391. _GM_openInTab=GM_openInTab;
  392. }else if(typeof GM!='undefined' && typeof GM.openInTab!='undefined'){
  393. _GM_openInTab=GM.openInTab;
  394. }else{
  395. _GM_openInTab=(s,t)=>{window.open(s)};
  396. }
  397. if(typeof GM_addStyle!='undefined'){
  398. _GM_addStyle=GM_addStyle;
  399. }else if(typeof GM!='undefined' && typeof GM.addStyle!='undefined'){
  400. _GM_addStyle=GM.addStyle;
  401. }else{
  402. _GM_addStyle=cssStr=>{
  403. let styleEle=document.createElement("style");
  404. styleEle.innerHTML=cssStr;
  405. document.head.appendChild(styleEle);
  406. };
  407. }
  408. var _unsafeWindow=(typeof unsafeWindow=='undefined')?window:unsafeWindow;//兼容 ios userscripts 的寫法
  409. var storage={
  410. supportGM: typeof GM_getValue=='function' && typeof GM_getValue('a','b')!='undefined',
  411. supportGMPromise: typeof GM!='undefined' && typeof GM.getValue=='function' && typeof GM.getValue('a','b')!='undefined',
  412. mxAppStorage:(function(){
  413. try{
  414. return window.external.mxGetRuntime().storage;
  415. }catch(e){
  416. }
  417. })(),
  418. operaUJSStorage:(function(){
  419. try{
  420. return window.opera.scriptStorage;
  421. }catch(e){
  422. }
  423. })(),
  424. setItem:function(key,value){
  425. if(this.operaUJSStorage){
  426. this.operaUJSStorage.setItem(key,value);
  427. }else if(this.mxAppStorage){
  428. this.mxAppStorage.setConfig(key,value);
  429. }else if(this.supportGM){
  430. GM_setValue(key,value);
  431. if(value==="" && typeof GM_deleteValue!='undefined'){
  432. GM_deleteValue(key);
  433. }
  434. }else if(this.supportGMPromise){
  435. GM.setValue(key,value);
  436. if(value==="" && typeof GM!='undefined' && typeof GM.deleteValue!='undefined'){
  437. GM.deleteValue(key);
  438. }
  439. }else if(window.localStorage){
  440. window.localStorage.setItem(key,value);
  441. }
  442. },
  443. getItem:function(key,cb){
  444. var value;
  445. if(this.operaUJSStorage){
  446. value=this.operaUJSStorage.getItem(key);
  447. }else if(this.mxAppStorage){
  448. value=this.mxAppStorage.getConfig(key);
  449. }else if(this.supportGM){
  450. value=GM_getValue(key);
  451. }else if(this.supportGMPromise){
  452. value=GM.getValue(key).then(v=>{cb(v)});
  453. return;
  454. }else if(window.localStorage){
  455. value=window.localStorage.getItem(key);
  456. };
  457. cb(value);
  458. }
  459. };
  460. var rulesData={},ruleUrls,updateDate,configPage="https://github.com/hoothin/UserScripts/tree/master/Pagetual";
  461. var ruleImportUrlReg=/greasyfork\.org\/.*scripts\/438684[^\/]*(\/discussions|\/?$)|github\.com\/hoothin\/UserScripts\/(tree\/master\/Pagetual|issues)/i;
  462. var allOfBody="body>*";
  463. _GM_registerMenuCommand(i18n("configure"), ()=>{
  464. _GM_openInTab(configPage,{active:true});
  465. });
  466. _GM_registerMenuCommand(i18n("editCurrent"), ()=>{
  467. let editTemp;
  468. if(ruleParser.curSiteRule.url && !ruleParser.curSiteRule.singleUrl){
  469. editTemp=ruleParser.curSiteRule;
  470. }else{
  471. editTemp={
  472. name: document.title,
  473. url: "^"+location.origin.replace(/\./g,"\\."),
  474. pageElement: ruleParser.curSiteRule.pageElement||""
  475. };
  476. }
  477. rulesData.editTemp=editTemp;
  478. storage.setItem("rulesData", rulesData);
  479. _GM_openInTab(configPage,{active:true});
  480. });
  481.  
  482. function getElementByXpath(xpath, contextNode, doc){
  483. doc = doc || document;
  484. contextNode = contextNode || doc;
  485. try {
  486. var result = doc.evaluate(xpath, contextNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
  487. return result.singleNodeValue && result.singleNodeValue.nodeType === 1 && result.singleNodeValue;
  488. } catch (err) {
  489. throw new Error(`Invalid xpath: ${xpath}`);
  490. }
  491. }
  492.  
  493. function getAllElementsByXpath(xpath, contextNode, doc){
  494. doc = doc || document;
  495. contextNode = contextNode || doc;
  496. var result = [];
  497. try {
  498. var query = doc.evaluate(xpath, contextNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  499. for (var i = 0; i < query.snapshotLength; i++) {
  500. var node = query.snapshotItem(i);
  501. if (node.nodeType === 1) result.push(node);
  502. }
  503. } catch (err) {
  504. throw new Error(`Invalid xpath: ${xpath}`);
  505. }
  506. return result;
  507. }
  508.  
  509. class RuleParser {
  510. constructor() {
  511. this.hpRules=[];
  512. this.customRules=[];
  513. this.rules=[];
  514. this.pageDoc=document;
  515. this.nextLinkHref=null;
  516. this.nextTitle="";
  517. this.oldUrl="";
  518. this.curUrl=location.href;
  519. this.curSiteRule={};
  520. }
  521.  
  522. initSavedRules(callback){
  523. var self=this;
  524. storage.getItem("hpRules", hpRules=>{
  525. if(hpRules)self.hpRules=hpRules;
  526. storage.getItem("customRules", customRules=>{
  527. if(customRules)self.customRules=customRules;
  528. storage.getItem("rules", rules=>{
  529. if(rules)self.rules=rules;
  530. callback();
  531. });
  532. });
  533. });
  534. }
  535.  
  536. saveCurSiteRule(){
  537. if(!this.curSiteRule || !this.curSiteRule.url || this.curSiteRule.singleUrl)return;
  538. this.hpRules=this.hpRules.filter(item=>{return item&&item.url!=this.curSiteRule.url});
  539. this.hpRules.unshift(this.curSiteRule);
  540. if(this.hpRules.length>30){
  541. this.hpRules.pop();
  542. }
  543. storage.setItem("hpRules", this.hpRules);
  544. }
  545.  
  546. requestJSON(url, callback){
  547. _GM_xmlhttpRequest({
  548. url: url,
  549. method: 'GET',
  550. timeout: 20000,
  551. onload: function(res) {
  552. let json=null;
  553. try{
  554. json=JSON.parse(res.response||res.responseText);
  555. }catch(e){
  556. debug(e);
  557. }
  558. callback(json);
  559. },
  560. onerror: function(e) {
  561. callback(null, e);
  562. },
  563. ontimeout: function(e) {
  564. callback(null, e);
  565. }
  566. });
  567. }
  568.  
  569. formatRule(item, type, from){
  570. switch(type){
  571. case 0:
  572. return {
  573. from:from,
  574. type:type,
  575. name:item.name,
  576. action:item.data.forceIframe=="true"?1:0,
  577. url:item.data.url,
  578. pageElement:item.data.pageElement,
  579. nextLink:item.data.nextLink,
  580. insert:item.data.insertBefore,
  581. insertPos:1,
  582. updatedAt:item.data.updated_at,
  583. css:item.data.Stylus+item.data.CSS,
  584. pageAction:item.data.bookmarklet
  585. };
  586. break;
  587. case 1:
  588. default:
  589. item.from=from;
  590. if(typeof(item.type) == "undefined")item.type=type;
  591. return item;
  592. break;
  593. }
  594. return null;
  595. }
  596.  
  597. addRuleByUrl(url, type, from, callback) {
  598. if(url.indexOf("?")==-1){
  599. url=url+"?"+Date.now();
  600. }else{
  601. url=url+"&"+Date.now();
  602. }
  603. this.requestJSON(url, (json,err)=>{
  604. if(!json){
  605. debug("Update "+url+" rules fail!");
  606. debug(err);
  607. }
  608. this.addRules(json, type, from);
  609. callback(json, err);
  610. });
  611. }
  612.  
  613. addRules(rules, type, from) {
  614. if(rules && rules.length>0){
  615. this.rules=this.rules.filter(item=>{return item.from!=from});
  616. rules.forEach(item=>{
  617. let rule=this.formatRule(item, type, from);
  618. if(rule){
  619. this.rules.unshift(rule);
  620. }
  621. });
  622. }
  623. }
  624.  
  625. getRule(callback) {
  626. if(noRuleTest){
  627. this.curSiteRule={};
  628. this.curSiteRule.url=location.origin+location.pathname;
  629. this.curSiteRule.singleUrl=true;
  630. callback();
  631. return;
  632. }
  633. if(this.curSiteRule && this.curSiteRule.url){
  634. return this.curSiteRule;
  635. }
  636. var self=this;
  637.  
  638. function setRule(r){
  639. self.curSiteRule=r;
  640. debug(r);
  641. callback();
  642. }
  643.  
  644. function ruleMatch(r){
  645. let pageElement,nextLink,insert;
  646. if(r.nextLink && r.nextLink!="0" && r.nextLink!=0){
  647. nextLink=r.type==0?getElementByXpath(r.nextLink):document.querySelector(r.nextLink);
  648. if(!nextLink)return false;
  649. }
  650. if(r.pageElement){
  651. pageElement=r.type==0?getElementByXpath(r.pageElement):document.querySelector(r.pageElement);
  652. if(!pageElement)return false;
  653. }
  654. if(r.insert){
  655. insert=r.type==0?getElementByXpath(r.insert):document.querySelector(r.insert);
  656. if(!insert)return false;
  657. }
  658. return true;
  659. }
  660.  
  661. function checkRule(r){
  662. let urlReg=new RegExp(r.url, "i");
  663. if(urlReg.test(location.href)){
  664. if(r.include){
  665. let include=r.type==0?getElementByXpath(r.include):document.querySelector(r.include);
  666. if(!include)return false;
  667. }
  668. if(r.wait){
  669. let waitTime=500,checkEval;
  670. if(isNaN(r.wait)){
  671. try{
  672. checkEval=Function("doc",'"use strict";' + r.wait);
  673. }catch(e){
  674. debug(e);
  675. }
  676. }else{
  677. waitTime=r.wait;
  678. }
  679. let checkReady=()=>{
  680. setTimeout(()=>{
  681. if(!ruleMatch(r) || (checkEval && !checkEval(document))){
  682. checkReady();
  683. }else{
  684. setRule(r);
  685. }
  686. },parseInt(waitTime));
  687. };
  688. checkReady();
  689. return true;
  690. }
  691. if(r.pinUrl){
  692. setRule(r);
  693. return true;
  694. }
  695. if(!ruleMatch(r)){
  696. return false;
  697. }
  698. setRule(r);
  699. return true;
  700. }
  701. return false;
  702. }
  703.  
  704. for(let i in this.hpRules){
  705. let rule=this.hpRules[i];
  706. if(!rule || !rule.url)continue;
  707. if(rule.singleUrl){
  708. if(location.origin+location.pathname==rule.url){
  709. setRule(rule);
  710. return;
  711. }
  712. continue;
  713. }
  714. if(checkRule(rule))return;
  715. }
  716. for(let i in this.customRules){
  717. let rule=this.customRules[i];
  718. if(!rule || !rule.url)continue;
  719. if(checkRule(rule))return;
  720. }
  721. let r=0;
  722. function searchByTime(){
  723. setTimeout(()=>{
  724. let end=r+50;
  725. end=end>self.rules.length?self.rules.length:end;
  726. for(;r<end;r++){
  727. let rule=self.rules[r];
  728. if(checkRule(rule))return;
  729. }
  730. if(end>=self.rules.length){
  731. self.curSiteRule={};
  732. self.curSiteRule.url=location.origin+location.pathname;
  733. self.curSiteRule.singleUrl=true;
  734. callback();
  735. return;
  736. }else{
  737. searchByTime();
  738. }
  739. },10);
  740. }
  741. searchByTime();
  742. }
  743.  
  744. geneSelector(ele){
  745. let selector=ele.tagName;
  746. //Google id class都是隨機。百度更過分,style script順序都是隨機的
  747. //if(ele.id) selector += '#' + ele.id;
  748. //if(ele.classList) selector += [].map.call(ele.classList,d=>'.'+d).join('');
  749. if(ele.tagName!="HTML" && ele.tagName!="BODY"){
  750. if(ele.className) selector += [].map.call(ele.classList,d=>'.'+d).join('');
  751. let parent = ele.parentElement;
  752. if(parent){
  753. selector = this.geneSelector(parent) + ' > ' + selector;
  754. if(!ele.className){
  755. let i,j=0;
  756. for(i=0;i<parent.children.length;i++){
  757. if(parent.children[i].tagName==ele.tagName){
  758. j++;
  759. if(parent.children[i]==ele){
  760. break;
  761. }
  762. }
  763. }
  764. selector += (parent.tagName=="HTML"?"":`:nth-of-type(${j})`);
  765. }
  766. }
  767. }
  768. return selector;
  769. }
  770.  
  771. getPageElement(doc, curWin, dontFind) {
  772. let pageElement=null;
  773. let self=this;
  774. let body=doc.body;
  775. if(this.curSiteRule.pageElement){
  776. pageElement=this.curSiteRule.type==0?getAllElementsByXpath(this.curSiteRule.pageElement,doc,doc):doc.querySelectorAll(this.curSiteRule.pageElement);
  777. }else if(!this.curSiteRule.singleUrl && this.curSiteRule.type==0){
  778. pageElement=[body];
  779. }
  780. if(this.curSiteRule.singleUrl && pageElement && pageElement.length>0 && pageElement[0].tagName=="TR"){
  781. let mainTr=this.insert.previousElementSibling,mainTdNum=0,newTdNum=0;
  782. [].forEach.call(mainTr.children, el=>{
  783. if(el.tagName=="TD" || el.tagName=="TH"){
  784. mainTdNum+=el.colSpan||1;
  785. }
  786. });
  787. [].forEach.call(pageElement[0].children, el=>{
  788. if(el.tagName=="TD" || el.tagName=="TH"){
  789. newTdNum+=el.colSpan||1;
  790. }
  791. });
  792. if(mainTdNum!=newTdNum){
  793. this.curSiteRule.pageElement=allOfBody;
  794. pageElement=[body];
  795. this.getInsert(true);
  796. }
  797. }
  798. if((this.curSiteRule.singleUrl || !this.curSiteRule.pageElement) && (!pageElement || pageElement.length==0) && curWin && !dontFind){
  799. if(!body)return null;
  800. let bodyHeight=parseInt(body.scrollHeight);
  801. let curHeight=bodyHeight;
  802. let windowHeight=window.innerHeight || document.documentElement.clientHeight;
  803. let needCheckNext=(doc==document && this.initNext);
  804. function checkElement(ele){
  805. if(ele.childNodes && ele.childNodes.length==1)ele=ele.childNodes[0];
  806. if(ele.tagName=="PICTURE"){
  807. self.curSiteRule.pageElement=self.geneSelector(ele.parentNode)+">"+ele.tagName;
  808. debug(self.curSiteRule.pageElement);
  809. return [ele];
  810. }
  811. if(curHeight/bodyHeight<=0.25){
  812. self.curSiteRule.pageElement=allOfBody;
  813. debug(self.curSiteRule.pageElement);
  814. return [body];
  815. }
  816. if(ele.tagName=="FORM"){
  817. self.curSiteRule.pageElement=self.geneSelector(ele)+">*";
  818. debug(self.curSiteRule.pageElement);
  819. return ele.children;
  820. }
  821. if(ele.children.length==0 && !self.curSiteRule.pageElement){
  822. if(ele.parentNode.tagName=="P")ele=ele.parentNode;
  823. self.curSiteRule.pageElement=self.geneSelector(ele.parentNode)+">"+ele.tagName;
  824. debug(self.curSiteRule.pageElement);
  825. return [ele];
  826. }
  827. let i,maxHeight=curHeight*0.55,curMaxEle=null,curMaxArea=0,maxWidth=0;
  828. let isHori=true;
  829. let offsetTop=ele.children[0].offsetTop;
  830. for(i=1;i<ele.children.length;i++){
  831. if(ele.children[i].offsetTop!=offsetTop){
  832. isHori=false;
  833. break;
  834. }
  835. }
  836. for(i=0;i<ele.children.length;i++){
  837. let curNode=ele.children[i];
  838. if(curNode.tagName=="CANVAS")continue;
  839. if(curNode.tagName!="IMG" && /^\s*$/.test(curNode.innerText))continue;
  840. if(needCheckNext && !curNode.contains(self.initNext) && getElementTop(curNode)>windowHeight){
  841. continue;
  842. }
  843. let comStyle=curWin.getComputedStyle(curNode);
  844. let h=parseInt(curNode.scrollHeight);
  845. let w=parseInt(curNode.scrollWidth);
  846. if(isNaN(h) || isNaN(w))continue;
  847. if(isHori && h<=50)continue;
  848. let a=h*w+h,moreChild=curNode.children[0];
  849. while(moreChild){
  850. comStyle=curWin.getComputedStyle(moreChild);
  851. let ch=parseInt(moreChild.scrollHeight);
  852. let cw=parseInt(moreChild.scrollWidth);
  853. if(h<ch)h=ch;
  854. if(moreChild.innerText!="" && !isNaN(ch) && !isNaN(cw)){
  855. a+=ch*cw;
  856. }
  857. moreChild=moreChild.nextElementSibling;
  858. }
  859. let isMax=false;
  860. if(isHori){
  861. if(maxWidth<w){
  862. isMax=true;
  863. }else if(maxWidth==w && curMaxArea<a){
  864. isMax=true;
  865. }
  866. }else{
  867. isMax=curMaxArea<a;
  868. }
  869. if(curMaxEle==null || isMax){
  870. if(h>0 || !isHori)curHeight=h;
  871. curMaxArea=a;
  872. maxWidth=w;
  873. curMaxEle=curNode;
  874. }
  875. }
  876. if(curMaxEle && (isHori || curHeight>maxHeight || (needCheckNext && curHeight>windowHeight && ele.contains(self.initNext)))){
  877. return checkElement(curMaxEle);
  878. }
  879. if(ele.tagName=="P" || ele.tagName=="BR")ele=ele.parentNode;
  880. if(ele.tagName=="TBODY"){
  881. self.curSiteRule.pageElement=self.geneSelector(ele)+">*";
  882. if(ele.children.length>0 && ele.children[0].querySelector("th")){
  883. self.curSiteRule.pageElement+=":not(:first-child)";
  884. }
  885. debug(self.curSiteRule.pageElement);
  886. return ele.children;
  887. }
  888. self.curSiteRule.pageElement=self.geneSelector(ele);
  889. if(ele.children.length>1){
  890. let hasText=false;
  891. for(let i in ele.childNodes){
  892. let child=ele.childNodes[i];
  893. if(child.nodeType==3 && child.nodeValue.trim()!=''){
  894. hasText=true;
  895. ele=[ele];
  896. break;
  897. }
  898. }
  899. if(!hasText){
  900. let middleChild=ele.children[parseInt(ele.children.length/2)];
  901. if((middleChild.style && middleChild.style.position=="absolute" && middleChild.style.left && middleChild.style.top) || ele.tagName=="UL" || curHeight==0){
  902. ele=[ele];
  903. }else{
  904. self.curSiteRule.pageElement+=">*";
  905. ele=ele.children;
  906. }
  907. }
  908. }else{
  909. ele=[ele];
  910. }
  911. debug(self.curSiteRule.pageElement);
  912. return ele;
  913. }
  914. pageElement=checkElement(body);
  915. if(pageElement)this.saveCurSiteRule();
  916. }
  917. return pageElement;
  918. }
  919.  
  920. getPage(doc){
  921. if(_unsafeWindow.Discourse)return {};
  922. let canSave=false;//發現頁碼選擇器在其他頁對不上,還是別保存了
  923. let url=this.curUrl.replace("#!","").replace("index.php?","?");
  924. let _url=url.replace(/\.s?html?$/i,"");
  925. let pageNum=1,preStr="",afterStr="";
  926. let pageMatch1=url.match(/(.*[a-z\/\-_](?:p|page)?\/?)(\d+)(\.s?html?$|\/?$)/i);
  927. let pageMatch2=url.match(/(.*[\?&]p(?:age)?=)(\d+)($|[#&].*)/i);
  928. if(pageMatch1){
  929. preStr=pageMatch1[1];
  930. pageNum=parseInt(pageMatch1[2]);
  931. afterStr=pageMatch1[3];
  932. }else if(pageMatch2){
  933. preStr=pageMatch2[1];
  934. pageNum=parseInt(pageMatch2[2]);
  935. afterStr=pageMatch2[3];
  936. }
  937. let curPage=doc,i,cur,jsNext;
  938. let next1,next2,next3,next4,nextJs1,nextJs2,nextJs3;
  939. let next=curPage.querySelector(".page-next>a")||
  940. curPage.querySelector("a.next_page")||
  941. curPage.querySelector("#next_page")||
  942. curPage.querySelector(".nextPage")||
  943. curPage.querySelector("a[data-pagination=next]")||
  944. curPage.querySelector("ul.pagination>li.active+li>a")||
  945. curPage.querySelector(".pagination a[rel=next]")||
  946. curPage.querySelector(".pagination-nav__item--next>a")||
  947. curPage.querySelector("a[title='Next page']")||
  948. curPage.querySelector("a.pageright")||
  949. curPage.querySelector("a#rightFix")||
  950. curPage.querySelector("a#next")||
  951. curPage.querySelector(".next>a")||
  952. curPage.querySelector(".next>button")||
  953. curPage.querySelector("a[alt=next]")||
  954. curPage.querySelector("button.next")||
  955. curPage.querySelector("[title=next]")||
  956. getElementByXpath("//a[contains(@class, 'page__next')]",curPage,curPage);
  957. if(!next){
  958. let nexts=curPage.querySelectorAll("a.next");
  959. for(i=0;i<nexts.length;i++){
  960. if(!/^([上前首尾][一1]?[页頁张張]|previous(\s*page)?\s*›?$|前のページ)/i.test(nexts[i].innerText.trim()) &&
  961. nexts[i].style.display!=="none" &&
  962. nexts[i].parentNode.style.display!=="none"){
  963. next=nexts[i];
  964. break;
  965. }
  966. }
  967. }
  968. if(next && (!next.href || /^javascript:/.test(next.href) || next.getAttribute("href")=="#")){
  969. jsNext=next;
  970. next=null;
  971. }
  972. if(!next){
  973. next=curPage.querySelectorAll("[aria-label='Next page']");
  974. if(next && next.length==1){
  975. next=next[0];
  976. if(!next.href || /^javascript:/.test(next.href) || next.getAttribute("href")=="#"){
  977. if(!jsNext)jsNext=next;
  978. next=null;
  979. }
  980. }else{
  981. next=null;
  982. }
  983. }
  984. if(!next){
  985. next=curPage.querySelectorAll("[aria-label='Next']");
  986. if(next && next.length==1){
  987. next=next[0];
  988. if(!next.href || /^javascript:/.test(next.href) || next.getAttribute("href")=="#"){
  989. if(!jsNext)jsNext=next;
  990. next=null;
  991. }
  992. }else{
  993. next=null;
  994. }
  995. }
  996. if(next && /^[下后後][一1]?[章话話篇]/i.test(next.innerText.trim())){
  997. next2=next;
  998. next=null;
  999. }
  1000. if(!next){
  1001. next=curPage.querySelector("a.curr");
  1002. if(next){
  1003. next=next.nextSibling;
  1004. }
  1005. }
  1006. if(!next){
  1007. next=curPage.querySelector("div.wp-pagenavi>span.current+a,div.page-nav>span.current+a,div.article-paging>span+a");
  1008. }
  1009. if(!next){
  1010. let pageDiv=curPage.querySelector("div.pages>ul");
  1011. if(pageDiv){
  1012. cur=pageDiv.querySelector("li>b");
  1013. if(cur)next=cur.parentNode.nextElementSibling;
  1014. if(next)next=next.querySelector("a");
  1015. }
  1016. }
  1017. if(!next){
  1018. cur=curPage.querySelector(".number>ul>li.active");
  1019. if(cur)next=cur.nextElementSibling;
  1020. if(next)next=next.querySelector("a");
  1021. }
  1022. if(!next){
  1023. let aTags=curPage.querySelectorAll("a,button");
  1024. for(i=aTags.length-1;i>=0;i--){
  1025. if(next1 && next2 && next3 && next4)break;
  1026. let aTag=aTags[i];
  1027. if(aTag.innerText=="§")continue;
  1028. if(aTag.innerText.length>50)continue;
  1029. if(aTag.style.display=="none")continue;
  1030. if(aTag.href && /next$/i.test(aTag.href))continue;
  1031. if(aTag.className && /slick|slide/i.test(aTag.className))continue;
  1032. if(aTag.innerText.length<=18){
  1033. if(!next1){
  1034. if(/^[下后後][一1]?[页頁张張]|^next([ _-]?page)?\s*[›>→»]?$|次のページ|^次へ?$/i.test(aTag.innerText.trim())){
  1035. if(!aTag.href || /^javascript:/.test(aTag.href) || aTag.getAttribute("href")=="#"){
  1036. if(!nextJs1)nextJs1=aTag;
  1037. }else{
  1038. next1=aTag;
  1039. }
  1040. }
  1041. }
  1042. if(!next2){
  1043. if(/^[下后後][一1]?[章话話篇]/i.test(aTag.innerText.trim()) || /nextpage/i.test(aTag.className)){
  1044. if(!aTag.href || /^javascript:/.test(aTag.href) || aTag.getAttribute("href")=="#"){
  1045. if(!nextJs2)nextJs2=aTag;
  1046. }else{
  1047. next2=aTag;
  1048. }
  1049. }
  1050. }
  1051. if(!next3){
  1052. if(aTag.innerText=="&gt;" || aTag.innerText=="▶" || aTag.innerText==">" || aTag.innerText=="›" || aTag.innerText=="→" || aTag.innerText=="»"){
  1053. if(!aTag.href || /^javascript:/.test(aTag.href) || aTag.getAttribute("href")=="#"){
  1054. if(!nextJs3)nextJs3=aTag;
  1055. }else{
  1056. next3=aTag;
  1057. }
  1058. }
  1059. }
  1060. }
  1061. if(!aTag.href || /^javascript:/.test(aTag.href) || aTag.getAttribute("href")=="#")continue;
  1062. if(!next4 && aTag.href.length<250){
  1063. let _aHref=aTag.href.replace("?&","?").replace("#!","").replace("index.php?","?");
  1064. let _aHrefTrim=_aHref;
  1065. if(preStr)_aHrefTrim=_aHrefTrim.replace(preStr,"");
  1066. if(afterStr)_aHrefTrim=_aHrefTrim.replace(afterStr,"");
  1067. if(pageNum<999 && _aHrefTrim==pageNum+1){
  1068. next4=aTag;
  1069. }else if(this.curUrl!=aTag.href){
  1070. _aHref=_aHref.replace(/\.s?html?$/i,"");
  1071. if(_aHref.indexOf(_url)!=-1 && /^[\/\?&]?[_-]?(p|page)?=?\/?2(\/|\?|&|$)/i.test(_aHref.replace(_url,""))){
  1072. let curHref=aTag.getAttribute("href");
  1073. let pageOne=curHref.replace(/\/2(\/|\?|&|$)/,"/1$1");
  1074. if(pageOne==curHref)pageOne=null;
  1075. else pageOne=curPage.querySelector(`a[href='${pageOne}']`);
  1076. if(!pageOne || pageOne.className!=curHref.className)next4=aTag;
  1077. }
  1078. }
  1079. }
  1080. }
  1081. if(next3){
  1082. let eles=getAllElementsByXpath(`//a[text()='${next3.innerText}']`,curPage,curPage);
  1083. if(eles.length>1)next3=null;
  1084. }
  1085. }
  1086. if(!next)next=next1||next4||next3||next2||jsNext||nextJs1||nextJs3||nextJs2;
  1087. if(next && next.classList.contains("results-more"))next=null;
  1088. return {next:next,canSave:canSave};
  1089. }
  1090.  
  1091. canonicalUri(src) {
  1092. if(src.charAt(0)=="#")return location.href+src;
  1093. var root_page = /^[^?#]*\//.exec(location.href)[0],
  1094. base_path = location.pathname.replace(/\/[^\/]+\.[^\/]+$/, "/"),
  1095. root_domain = /^\w+\:\/\/\/?[^\/]+/.exec(root_page)[0],
  1096. absolute_regex = /^\w+\:\/\//;
  1097. src=src.replace(/\.\//,"");
  1098. if (/^\/\/\/?/.test(src)){
  1099. src = location.protocol + src;
  1100. }
  1101. else if (!absolute_regex.test(src) && src.charAt(0) != "/"){
  1102. src = (base_path || "") + src;
  1103. }
  1104. return (absolute_regex.test(src) ? src : ((src.charAt(0) == "/" ? root_domain : root_page) + src));
  1105. }
  1106.  
  1107. getLinkByPage(url, pageNum) {
  1108. if(!url)return;
  1109. if(this.curSiteRule.pageNum){
  1110. let result=this.curSiteRule.pageNum;
  1111. let strMatch=result.match(/\{.*?}/);
  1112. if(!strMatch)return null;
  1113. let urlReg=new RegExp("("+result.replace(strMatch[0], ")\\d+(")+")","i");
  1114. let code=strMatch[0].replace(/^{/,"").replace(/}$/,"").replace(/\$p/g,pageNum);
  1115. if(code==pageNum){
  1116. result=url.replace(urlReg,"$1"+code+"$2");
  1117. }else{
  1118. try{
  1119. code=Function('"use strict";return ' + code)();
  1120. result=url.replace(urlReg,"$1"+code+"$2");
  1121. }catch(e){
  1122. debug(e);
  1123. }
  1124. }
  1125. return result==url?url.replace(/([&\/\?](p=|page[=\/_-]?))\d+/i, "$1"+pageNum).replace(/([_-])\d+\./i, "$1"+pageNum+"."):result;
  1126. }else{
  1127. return url.replace(/([&\/\?](p=|page[=\/_-]?))\d+/i, "$1"+pageNum).replace(/([_-])\d+\./i, "$1"+pageNum+".");
  1128. }
  1129. }
  1130.  
  1131. getNextLink(doc) {
  1132. let nextLink=null,page,href;
  1133. let getNextLinkByForm=(form,n)=>{
  1134. let params=[];
  1135. [].forEach.call(form.querySelectorAll("input"), input=>{
  1136. if(n && /^(p|page)$/i.test(input.name)){
  1137. params.push('p='+n);
  1138. }else{
  1139. params.push(input.name+'='+input.value);
  1140. }
  1141. });
  1142. return form.action+'?'+params.join('&');
  1143. };
  1144. if(this.curSiteRule.pageElementByJs){
  1145. this.nextLinkHref="#";
  1146. return true;
  1147. }else if(this.curSiteRule.nextLinkByJs){
  1148. try{
  1149. let targetUrl=Function("doc",'"use strict";' + this.curSiteRule.nextLinkByJs)(doc);
  1150. if(targetUrl)nextLink={href:targetUrl};
  1151. }catch(e){
  1152. debug(e);
  1153. }
  1154. }else if(this.curSiteRule.nextLinkByUrl){
  1155. let targetUrl=this.curUrl.replace(new RegExp(this.curSiteRule.nextLinkByUrl[0],"i"), this.curSiteRule.nextLinkByUrl[1]);
  1156. if(targetUrl != this.curUrl){
  1157. let reps=targetUrl.match(/{.*?}/g);
  1158. if(reps){
  1159. reps.forEach(rep=>{
  1160. let code=rep.replace("{","").replace("}","");
  1161. let result=code.match(/^(\d+)\+1$/);
  1162. if(result){
  1163. result=parseInt(result[1])+1;
  1164. }else{
  1165. try{
  1166. result=Function('"use strict";return ' + code)();
  1167. }catch(e){
  1168. debug(e);
  1169. }
  1170. }
  1171. targetUrl=targetUrl.replace(rep, result);
  1172. });
  1173. }
  1174. }
  1175. nextLink={href:targetUrl};
  1176. }else if(this.curSiteRule.nextLink){
  1177. if(this.curSiteRule.nextLink!="0" && this.curSiteRule.nextLink!=0){
  1178. nextLink=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.nextLink,doc,doc):doc.querySelector(this.curSiteRule.nextLink);
  1179. }
  1180. }else{
  1181. page=this.getPage(doc);
  1182. nextLink=page.next;
  1183. if(nextLink){
  1184. if(nextLink.tagName=="INPUT" && nextLink.parentNode.tagName=="FORM"){
  1185. let form=nextLink.parentNode;
  1186. nextLink.href=getNextLinkByForm(form);
  1187. }
  1188. if(nextLink.parentNode.style.display=="none" || nextLink.style.display=="none" || nextLink.classList.contains("noClick") || nextLink.hasAttribute("disabled")){
  1189. this.nextLinkHref=false;
  1190. return null;
  1191. }else if(doc==document){
  1192. if((!nextLink.href || /^javascript:/.test(nextLink.href)) && !isVisible(nextLink, _unsafeWindow)){
  1193. this.nextLinkHref=false;
  1194. return null;
  1195. }else{
  1196. let nextLinkCs=_unsafeWindow.getComputedStyle(nextLink);
  1197. if(nextLinkCs.cursor=="not-allowed"){
  1198. this.nextLinkHref=false;
  1199. return null;
  1200. }
  1201. this.initNext=nextLink;
  1202. }
  1203. }
  1204. let form=doc.querySelector('#search-form');
  1205. if(!nextLink.href && nextLink.hasAttribute("onclick") && form){
  1206. if(form && /^\d+$/.test(nextLink.innerText)){
  1207. href=getNextLinkByForm(form, nextLink.innerText);
  1208. }
  1209. }
  1210. }
  1211. }
  1212. if(nextLink){
  1213. let needUrl=(this.curSiteRule.action==0 || this.curSiteRule.action==1);
  1214. if(!href)href=nextLink.href;
  1215. if(href && nextLink.getAttribute){
  1216. let _href=nextLink.getAttribute("href");
  1217. if(!_href || _href.charAt(0)=="#"){
  1218. href=_href;
  1219. }
  1220. }
  1221.  
  1222. if((href===""||href===null) && needUrl){
  1223. this.nextLinkHref=false;
  1224. }else if(/^(javascript:void\(0\)|#)/.test(href) && needUrl){
  1225. this.nextLinkHref=false;
  1226. }else{
  1227. this.nextLinkHref=(href && !/^(javascript:|#)/.test(href))?this.canonicalUri(href):"#";
  1228. if(this.nextLinkHref!="#" && (this.nextLinkHref==this.curUrl || this.nextLinkHref==this.curUrl+"#" || this.nextLinkHref==this.oldUrl || this.nextLinkHref==this.oldUrl+"#")){
  1229. this.nextLinkHref=false;
  1230. }else if(doc==document)debug(nextLink);
  1231. }
  1232. }else{
  1233. this.nextLinkHref=false;
  1234. }
  1235. this.preload();
  1236. return nextLink;
  1237. }
  1238.  
  1239. preload(){
  1240. if(!rulesData.preload)return;
  1241. if(!this.nextLinkHref || this.nextLinkHref=="#")return;
  1242. let self=this;
  1243. if(this.curSiteRule && this.curSiteRule.action==1){
  1244. if(!this.preloadIframe){
  1245. this.preloadIframe = document.createElement('iframe');
  1246. let iframe = this.preloadIframe;
  1247. iframe.name = 'pagetual-iframe';
  1248. iframe.width = '100%';
  1249. iframe.height = '0';
  1250. iframe.frameBorder = '0';
  1251. if(ruleParser.curSiteRule.sandbox!=false){
  1252. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1253. }
  1254. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1255. iframe.addEventListener('load', function (e) {
  1256. try{
  1257. let doc=iframe.contentDocument || iframe.contentWindow.document;
  1258. var body = doc.body;
  1259. if (body && body.firstChild) {
  1260. self.lazyImgAction(body.children);
  1261. }
  1262. }catch(e){
  1263. return;
  1264. }
  1265. }, false);
  1266. document.body.appendChild(iframe);
  1267. }
  1268. this.preloadIframe.src = this.nextLinkHref;
  1269. }else{
  1270. _GM_xmlhttpRequest({
  1271. url: this.nextLinkHref,
  1272. method: 'GET',
  1273. overrideMimeType: 'text/html;charset='+document.charset,
  1274. headers: {
  1275. 'Referer': location.href
  1276. },
  1277. timeout: 5000,
  1278. onload: function(res) {
  1279. var doc=null;
  1280. try {
  1281. doc=document.implementation.createHTMLDocument('');
  1282. doc.documentElement.innerHTML=res.response;
  1283. var body = doc.body;
  1284. if (body && body.firstChild) {
  1285. self.lazyImgAction(body.children);
  1286. }
  1287. if(!self.preloadDiv){
  1288. self.preloadDiv = document.createElement('div');
  1289. self.preloadDiv.id = "pagetual-preload";
  1290. self.preloadDiv.style.cssText = 'display:none!important;';
  1291. document.body.appendChild(self.preloadDiv);
  1292. self.checkedImgs={};
  1293. }
  1294. [].forEach.call(doc.images, i=>{
  1295. let iSrc=i.src;
  1296. if(iSrc && !self.checkedImgs[iSrc]){
  1297. self.checkedImgs[iSrc] = true;
  1298. let img = document.createElement('img');
  1299. img.src = iSrc;
  1300. self.preloadDiv.appendChild(img);
  1301. }
  1302. });
  1303. }
  1304. catch (e) {
  1305. return;
  1306. }
  1307. }
  1308. });
  1309. }
  1310. }
  1311.  
  1312. getInsert(refresh) {
  1313. if(refresh){
  1314. this.insert=null;
  1315. }
  1316. if(this.insert && !refresh){
  1317. let parent=this.insert;
  1318. while(parent && parent.nodeName!="BODY"){
  1319. parent=parent.parentNode;
  1320. }
  1321. if(parent && parent.nodeName=="BODY"){
  1322. return this.insert;
  1323. }
  1324. }
  1325. if(this.curSiteRule.insert){
  1326. this.insert=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.insert,document):document.querySelector(this.curSiteRule.insert);
  1327. }else{
  1328. let pageElement=this.getPageElement(document, _unsafeWindow);
  1329. if(pageElement && pageElement.length>0){
  1330. var pELast = pageElement[pageElement.length - 1];
  1331. this.insert = pELast.nextSibling ? pELast.nextSibling : pELast.parentNode.appendChild(document.createTextNode(' '));
  1332. }
  1333. }
  1334. return this.insert;
  1335. }
  1336.  
  1337. pageInit(doc,eles){
  1338. let code=this.curSiteRule.pageInit;
  1339. if(code){
  1340. try{
  1341. Function("doc","eles",'"use strict";' + code)(doc,eles);
  1342. }catch(e){
  1343. debug(e);
  1344. }
  1345. }
  1346. }
  1347.  
  1348. pageAction(doc,eles){
  1349. let code=this.curSiteRule.pageAction;
  1350. if(code){
  1351. try{
  1352. Function("doc","eles",'"use strict";' + code)(doc,eles);
  1353. }catch(e){
  1354. debug(e);
  1355. }
  1356. }
  1357. this.lazyImgAction(eles);
  1358. this.openInNewTab(eles);
  1359. }
  1360.  
  1361. openInNewTab(eles){
  1362. if(rulesData.openInNewTab){
  1363. [].forEach.call(eles, ele=>{
  1364. if(ele.tagName=="A" && ele.href && !/^(mailto:|javascript:|#)/.test(ele.href)){
  1365. ele.setAttribute('target', '_blank');
  1366. }else{
  1367. [].forEach.call(ele.querySelectorAll('a[href]:not([href^="mailto:"]):not([href^="javascript:"]):not([href^="#"])'), a=>{
  1368. a.setAttribute('target', '_blank');
  1369. if (a.getAttribute('onclick') == 'atarget(this)') {
  1370. a.removeAttribute('onclick');
  1371. }
  1372. });
  1373. }
  1374. });
  1375. }
  1376. }
  1377.  
  1378. lazyImgAction(eles){
  1379. let setLazyImg=img=>{
  1380. let realSrc;
  1381. if(img.getAttribute("_src") && !img.src){
  1382. realSrc=img.getAttribute("_src");
  1383. }else if(img.dataset && img.dataset.original){
  1384. realSrc=img.dataset.original;
  1385. }else if(img.dataset && img.dataset.src){
  1386. realSrc=img.dataset.src;
  1387. }else if(img._lazyrias && img._lazyrias.srcset){
  1388. realSrc=img._lazyrias.srcset[img._lazyrias.srcset.length-1];
  1389. }else if(img.dataset && img.dataset.origFile){
  1390. realSrc=img.dataset.origFile;
  1391. }else if(img.srcset){
  1392. var srcs=img.srcset.split(/[xw],/),largeSize=0;
  1393. srcs.forEach(srci=>{
  1394. let srcInfo=srci.trim().split(" "),curSize=parseInt(srcInfo[1]);
  1395. if(srcInfo[1] && curSize>largeSize){
  1396. largeSize=curSize;
  1397. realSrc=srcInfo[0];
  1398. }
  1399. });
  1400. }
  1401. if(realSrc){
  1402. img.src=realSrc;
  1403. img.style.display="block";
  1404. }
  1405. };
  1406. [].forEach.call(eles, ele=>{
  1407. if(ele.tagName=="IMG"){
  1408. setLazyImg(ele);
  1409. }else{
  1410. [].forEach.call(ele.querySelectorAll("img"), img=>{
  1411. setLazyImg(img);
  1412. });
  1413. }
  1414. if(ele.tagName=="A" && ele.classList.contains("lazyload")){
  1415. if(ele.dataset.original){
  1416. ele.style.backgroundImage='url("'+ele.dataset.original+'")';
  1417. }
  1418. }else{
  1419. [].forEach.call(ele.querySelectorAll("a.lazyload"), a=>{
  1420. if(a.dataset.original){
  1421. a.style.backgroundImage='url("'+a.dataset.original+'")';
  1422. }
  1423. });
  1424. }
  1425. });
  1426. let lazyImgSrc=this.curSiteRule.lazyImgSrc;
  1427. if(lazyImgSrc){
  1428. [].forEach.call(eles, ele=>{
  1429. [].forEach.call(ele.querySelectorAll("img"), img=>{
  1430. if(img.getAttribute(lazyImgSrc)){
  1431. img.src=img.getAttribute(lazyImgSrc);
  1432. }
  1433. });
  1434. });
  1435. }
  1436. }
  1437.  
  1438. initPage(callback){
  1439. let self=this;
  1440. curPage=1;
  1441. //if(this.curSiteRule.url && !this.curSiteRule.singleUrl)return;
  1442. this.curSiteRule={};
  1443. this.pageDoc=document;
  1444. this.nextLinkHref=null;
  1445. this.curUrl=location.href;
  1446. this.getRule(()=>{
  1447. if(self.curSiteRule.enable==0){
  1448. debug("Stop as rule disable");
  1449. isPause=true;
  1450. return;
  1451. }
  1452. if(self.curSiteRule && !self.curSiteRule.singleUrl){
  1453. self.hpRules=self.hpRules.filter(item=>{return item&&item.url!=self.curSiteRule.url});
  1454. self.hpRules.unshift(self.curSiteRule);
  1455. if(self.hpRules.length>30){
  1456. self.hpRules.pop();
  1457. }
  1458. storage.setItem("hpRules", self.hpRules);
  1459. }
  1460. let css=self.curSiteRule.css;
  1461. if(css){
  1462. _GM_addStyle(css);
  1463. }
  1464. let autoClick=self.curSiteRule.autoClick;
  1465. if(autoClick){
  1466. let autoClickBtn;
  1467. try{
  1468. autoClickBtn=document.querySelector(autoClick);
  1469. }catch(e){
  1470. autoClickBtn=getElementByXpath(autoClick);
  1471. }
  1472. if(autoClickBtn){
  1473. emuClick(autoClickBtn);
  1474. }
  1475. }
  1476. let code=self.curSiteRule.init;
  1477. if(code){
  1478. try{
  1479. Function('doc','win','iframe','"use strict";' + code)(null,null,null);
  1480. }catch(e){
  1481. debug(e);
  1482. }
  1483. }
  1484. self.getNextLink(document);
  1485. callback();
  1486. });
  1487. }
  1488.  
  1489. insertPage(doc, eles, url, callback, tried){
  1490. this.oldUrl=this.curUrl;
  1491. let oldTitle=this.pageDoc.title;
  1492. this.pageDoc=doc;
  1493. this.curUrl=url;
  1494. let nextLink=this.getNextLink(doc);
  1495. this.nextTitle="";
  1496. if(this.curSiteRule.pageBarText){
  1497. if(this.curSiteRule.pageBarText==1){
  1498. this.nextTitle=doc.title;
  1499. }else{
  1500. try{
  1501. this.nextTitle=Function("doc",'"use strict";' + this.curSiteRule.pageBarText)(doc);
  1502. }catch(e){
  1503. debug(e);
  1504. }
  1505. }
  1506. }
  1507. if(curPage==1 && !tried && !nextLink && this.curSiteRule.singleUrl && this.curSiteRule.pageElement && this.curSiteRule.action!=0){
  1508. this.curSiteRule.action=1;
  1509. this.curUrl=location.href;
  1510. return false;
  1511. }
  1512. if(callback)callback(eles);
  1513. this.getInsert();
  1514. var self=this,newEles=[];
  1515. if(!eles || eles.length==0 || !self.insert || !self.insert.parentNode){
  1516. }else{
  1517. this.pageInit(doc, eles);
  1518. [].forEach.call(eles, ele=>{
  1519. let newEle=ele.cloneNode(true);
  1520. let oldCanvass=ele.querySelectorAll("canvas");
  1521. let newCanvass=newEle.querySelectorAll("canvas");
  1522. for(let i=0;i<oldCanvass.length;i++){
  1523. let oldCanvas=oldCanvass[i];
  1524. let newCanvas=newCanvass[i];
  1525. newCanvas.getContext('2d').drawImage(oldCanvas, 0, 0);
  1526. }
  1527. if(self.curSiteRule.insertPos==2){
  1528. self.insert.appendChild(newEle);
  1529. }else{
  1530. self.insert.parentNode.insertBefore(newEle, self.insert);
  1531. }
  1532. newEles.push(newEle);
  1533. });
  1534. }
  1535. this.pageAction(doc, newEles);
  1536. if(this.oldUrl!=location.href){
  1537. let isJs=/^(javascript|#)/.test(this.oldUrl.replace(location.href,""));
  1538. if(rulesData.enableHistory && !isJs){
  1539. _unsafeWindow.history.replaceState(undefined, oldTitle, this.oldUrl);
  1540. document.title=oldTitle;
  1541. }
  1542. }
  1543. return true;
  1544. }
  1545. }
  1546. var ruleParser = new RuleParser();
  1547.  
  1548. function initConfig(){
  1549. initView();
  1550. _GM_registerMenuCommand(i18n(forceState==1?"enable":"disableSite"), ()=>{
  1551. forceState=(forceState==1?0:1);
  1552. storage.setItem("forceState_"+location.host, forceState);
  1553. showTips(i18n(forceState==1?"disableSiteTips":"enableSiteTips"));
  1554. if(!ruleParser.curSiteRule.url) location.reload();
  1555. });
  1556. _GM_registerMenuCommand(i18n("update"), ()=>{
  1557. updateRules(()=>{
  1558. showTips(i18n("updateSucc"));
  1559. location.reload();
  1560. },(rule,err)=>{
  1561. showTips("Update "+rule.url+" rules fail!");
  1562. });
  1563. showTips(i18n("beginUpdate"));
  1564. });
  1565.  
  1566. var configCon,insertPos;
  1567. if(ruleImportUrlReg.test(location.href)){
  1568. document.addEventListener("click", e=>{
  1569. if(e.target.tagName=="PRE"){
  1570. let nameAttr=e.target.getAttribute("name");
  1571. if(nameAttr=="pagetual" || nameAttr=="user-content-pagetual" || location.href.indexOf("gf.qytechs.cn") != -1){
  1572. let rules=e.target.innerText.trim();
  1573. let isContent=/['"]name['"]/i.test(rules);
  1574. if(!window.confirm("Import?")) return;
  1575. if(isContent){
  1576. let ruleList=JSON.parse(`[${rules}]`);
  1577. for(let i in ruleList){
  1578. let hasRule = false;
  1579. let r = ruleList[i];
  1580. for(let j in ruleParser.customRules){
  1581. if(ruleParser.customRules[j].name == r.name){
  1582. ruleParser.customRules[j] = r;
  1583. hasRule = true;
  1584. break;
  1585. }
  1586. }
  1587. if(!hasRule)ruleParser.customRules.push(r);
  1588. }
  1589. storage.setItem("customRules", ruleParser.customRules);
  1590. showTips(i18n("importSucc"));
  1591. }else{
  1592. rules=rules.split("\n");
  1593. let diff=false;
  1594. for(let c=0;c<rules.length;c++){
  1595. let urlArr=rules[c].split("|"),url,type=1;
  1596. if(urlArr.length==1){
  1597. url=urlArr[0].trim();
  1598. if(!/^http/.test(url)){
  1599. showTips("Wrong url, check again!");
  1600. return;
  1601. }
  1602. }else if(urlArr.length==2){
  1603. type=urlArr[0].trim();
  1604. url=urlArr[1].trim();
  1605. if(!/^http/.test(url)){
  1606. showTips("Wrong url, check again!");
  1607. return;
  1608. }
  1609. }else{
  1610. break;
  1611. }
  1612. let maxId=0,hasUrl=false;
  1613. if(!rulesData.urls){
  1614. rulesData.urls=[];
  1615. maxId=1;
  1616. }else{
  1617. rulesData.urls.forEach(u=>{
  1618. if(maxId<u.id){
  1619. maxId=u.id;
  1620. }
  1621. if(u.url==url){
  1622. hasUrl=true;
  1623. }
  1624. });
  1625. if(hasUrl)break;
  1626. }
  1627. diff=true;
  1628. if(!rulesData.sort)rulesData.sort=[1];
  1629. rulesData.urls.push({id:maxId+1,url:url,type:type});
  1630. rulesData.sort.unshift(maxId+1);
  1631. }
  1632. if(!diff)return;
  1633. storage.setItem("rulesData", rulesData);
  1634.  
  1635. if(rulesData.urls)ruleUrls=ruleUrls.concat(rulesData.urls);
  1636. if(rulesData.sort){
  1637. let urls=[];
  1638. rulesData.sort.forEach(id=>{
  1639. for(let s=0;s<ruleUrls.length;s++){
  1640. if(id==ruleUrls[s].id){
  1641. urls.push(ruleUrls[s]);
  1642. break;
  1643. }
  1644. }
  1645. });
  1646. ruleUrls=urls;
  1647. }
  1648. updateRules(()=>{
  1649. showTips(i18n("updateSucc"));
  1650. },(rule,err)=>{
  1651. showTips("Update "+rule.url+" rules fail!");
  1652. });
  1653. showTips(i18n("beginUpdate"));
  1654. }
  1655. }
  1656. }
  1657. });
  1658. }
  1659. if(location.href==configPage){
  1660. _GM_addStyle(`
  1661. p>span:nth-child(1),p>span:nth-child(2),p>span:nth-child(3){
  1662. cursor: pointer;
  1663. user-select: none;
  1664. }
  1665. p>span:nth-child(1):hover,p>span:nth-child(2):hover,p>span:nth-child(3):hover{
  1666. color:red;
  1667. }
  1668. .updateDate{
  1669. cursor: pointer;
  1670. user-select: none;
  1671. }
  1672. .updateDate:hover{
  1673. color:red;
  1674. }
  1675. `);
  1676. document.querySelector("[name='user-content-click2import']").innerText=i18n("click2ImportRule")
  1677. configCon=document.querySelector(".markdown-body");
  1678. insertPos=configCon.querySelector("hr");
  1679.  
  1680. if(rulesData.urls && rulesData.urls.length>0){
  1681. document.querySelector("pre[name='user-content-pagetual']").style.display="none";
  1682. document.querySelector("p[name='user-content-click2import']").style.display="none";
  1683. }
  1684. }else return false;
  1685. class Rulebar {
  1686. init(ruleUrl){
  1687. this.ruleUrl=ruleUrl;
  1688. this.item=document.createElement("p");
  1689. this.item.title=ruleUrl.type==0?"AutoPagerize Rules":"Pagetual Rules";
  1690. this.item.dataset.id=this.ruleUrl.id;
  1691. let url=document.createElement("span");
  1692. url.innerHTML=ruleUrl.url;
  1693. let up=document.createElement("span");
  1694. up.innerHTML="↑ ";
  1695. up.title=i18n("sortTitle");
  1696. let down=document.createElement("span");
  1697. down.innerHTML="↓ ";
  1698. down.title=i18n("sortTitle");
  1699. let del=document.createElement("span");
  1700. del.innerHTML="× ";
  1701. up.onclick=e=>{
  1702. this.moveUp();
  1703. };
  1704. down.onclick=e=>{
  1705. this.moveDown();
  1706. };
  1707. del.onclick=e=>{
  1708. this.del();
  1709. };
  1710. this.item.appendChild(up);
  1711. this.item.appendChild(down);
  1712. this.item.appendChild(del);
  1713. this.item.appendChild(url);
  1714. configCon.insertBefore(this.item, insertPos);
  1715. }
  1716. saveSort(){
  1717. let sort=[];
  1718. [].forEach.call(this.item.parentNode.querySelectorAll("p[data-id]"), i=>{
  1719. sort.push(i.dataset.id);
  1720. });
  1721. rulesData.sort=sort;
  1722. storage.setItem("rulesData", rulesData);
  1723. }
  1724. moveUp(){
  1725. let preE=this.item.previousElementSibling;
  1726. if(preE.tagName=="P" && preE.children.length>1){
  1727. this.item.parentNode.insertBefore(this.item,preE);
  1728. this.saveSort();
  1729. }
  1730. }
  1731. moveDown(){
  1732. let nextE=this.item.nextElementSibling;
  1733. if(nextE.tagName=="P" && nextE.children.length>1){
  1734. this.item.parentNode.insertBefore(nextE,this.item);
  1735. this.saveSort();
  1736. }
  1737. }
  1738. del(){
  1739. if(this.ruleUrl.id<2){
  1740. showTips(i18n("cantDel"));
  1741. }else if(window.confirm(i18n("confirmDel"))){
  1742. for(let u=0;u<rulesData.urls.length;u++){
  1743. if(this.ruleUrl.id==rulesData.urls[u].id){
  1744. rulesData.urls.splice(u,1);
  1745. break;
  1746. }
  1747. }
  1748. for(let u=0;u<rulesData.sort.length;u++){
  1749. if(this.ruleUrl.id==rulesData.sort[u]){
  1750. rulesData.sort.splice(u,1);
  1751. break;
  1752. }
  1753. }
  1754. storage.setItem("rulesData", rulesData);
  1755. ruleParser.rules=ruleParser.rules.filter(item=>{return item.from!=this.ruleUrl.id});
  1756. storage.setItem("rules", ruleParser.rules);
  1757. this.item.parentNode.removeChild(this.item);
  1758. //location.reload();
  1759. }
  1760. }
  1761. }
  1762. let updateP=document.createElement("p"),i=0;
  1763. let now=new Date().getTime(),inUpdate=false;
  1764.  
  1765.  
  1766. let pastDate=(new Date(updateDate)).toString(),passStr;
  1767. let passTime=(now-updateDate)/1000;
  1768. if(isNaN(passTime)){
  1769. passStr=i18n("firstUpdate");
  1770. }else if(passTime<60){
  1771. passStr=i18n("passSec", parseInt(passTime))+" ← "+i18n("click2update");
  1772. }else if(passTime<60*60){
  1773. passStr=i18n("passMin", parseInt(passTime/60))+" ← "+i18n("click2update");
  1774. }else if(passTime<60*60*24){
  1775. passStr=i18n("passHour", parseInt(passTime/3600))+" ← "+i18n("click2update");
  1776. }else{
  1777. passStr=i18n("passDay", parseInt(passTime/86400))+" ← "+i18n("click2update");
  1778. }
  1779.  
  1780.  
  1781. updateP.className="updateDate";
  1782. updateP.innerHTML=passStr;
  1783. updateP.title=i18n("update")+" - "+pastDate;
  1784. updateP.onclick=e=>{
  1785. updateRules(()=>{
  1786. showTips(i18n("updateSucc"));
  1787. updateP.innerHTML=i18n("passSec", 0);
  1788. updateP.title=i18n("update");
  1789. },(rule,err)=>{
  1790. showTips("Update "+rule.url+" rules fail!");
  1791. });
  1792. showTips(i18n("beginUpdate"));
  1793. };
  1794. configCon.insertBefore(updateP, insertPos);
  1795. if(ruleUrls){
  1796. ruleUrls.forEach(ruleUrl=>{
  1797. var rulebar=new Rulebar();
  1798. rulebar.init(ruleUrl);
  1799. });
  1800. }
  1801. let customUrlsTitle=document.createElement("h2");
  1802. customUrlsTitle.innerHTML=i18n("customUrls");
  1803. configCon.insertBefore(customUrlsTitle, insertPos);
  1804. let customUrlsInput=document.createElement("textarea");
  1805. customUrlsInput.style.width="100%";
  1806. customUrlsInput.placeholder="0 | http://wedata.net/databases/AutoPagerize/items_all.json";
  1807. configCon.insertBefore(customUrlsInput, insertPos);
  1808.  
  1809. let upBtnImgTitle=document.createElement("h2");
  1810. upBtnImgTitle.innerHTML=i18n("upBtnImg");
  1811. upBtnImgTitle.style.width="50%";
  1812. upBtnImgTitle.style.float="left";
  1813. let upBtnImgInput=document.createElement("input");
  1814. upBtnImgInput.style.width="100%";
  1815. upBtnImgInput.placeholder="data:image/png;base64,UpBtn";
  1816. upBtnImgInput.value=rulesData.upBtnImg||'';
  1817. upBtnImgTitle.appendChild(upBtnImgInput);
  1818. configCon.insertBefore(upBtnImgTitle, insertPos);
  1819.  
  1820. let downBtnImgTitle=document.createElement("h2");
  1821. downBtnImgTitle.innerHTML=i18n("downBtnImg");
  1822. downBtnImgTitle.style.width="50%";
  1823. downBtnImgTitle.style.float="left";
  1824. let downBtnImgInput=document.createElement("input");
  1825. downBtnImgInput.style.width="100%";
  1826. downBtnImgInput.placeholder="data:image/png;base64,DownBtn";
  1827. downBtnImgInput.value=rulesData.downBtnImg||'';
  1828. downBtnImgTitle.appendChild(downBtnImgInput);
  1829. configCon.insertBefore(downBtnImgTitle, insertPos);
  1830.  
  1831. let opacityTitle=document.createElement("h2");
  1832. opacityTitle.innerHTML=i18n("opacity");
  1833. let opacityInput=document.createElement("input");
  1834. opacityInput.value=rulesData.opacity*100;
  1835. opacityInput.type="number";
  1836. opacityInput.style.width="50px";
  1837. opacityInput.style.margin="0 0 0 10px";
  1838. opacityTitle.appendChild(opacityInput);
  1839. configCon.insertBefore(opacityTitle, insertPos);
  1840.  
  1841. let configTable=document.createElement("table");
  1842. configTable.appendChild(document.createElement("tbody"));
  1843. configCon.insertBefore(configTable, insertPos);
  1844. function createCheckbox(innerText, val, tag, parentCheck, otherType){
  1845. let title=document.createElement(tag||"h3");
  1846. title.innerHTML=innerText;
  1847. let input=document.createElement("input");
  1848. input.type=otherType||"checkbox";
  1849. input.style.width="50px";
  1850. input.style.height="20px";
  1851. input.value=val;
  1852. input.checked=val;
  1853. let td=document.createElement("td");
  1854. td.appendChild(input);
  1855. if(parentCheck){
  1856. td.appendChild(title);
  1857. let parent=parentCheck.parentNode.nextElementSibling;
  1858. let tr=parent.querySelector("tr");
  1859. if(!tr){
  1860. tr=document.createElement("tr");
  1861. parent.appendChild(tr);
  1862. }
  1863. tr.appendChild(td);
  1864. if(!parentCheck.checked){
  1865. td.style.display="none";
  1866. }
  1867. parentCheck.addEventListener("click", e=>{
  1868. td.style.display=parentCheck.checked?"":"none";
  1869. });
  1870. }else{
  1871. let tr=document.createElement("tr");
  1872. tr.appendChild(td);
  1873. td=document.createElement("td");
  1874. td.appendChild(title);
  1875. tr.appendChild(td);
  1876. configTable.children[0].appendChild(tr);
  1877. }
  1878. return input;
  1879. }
  1880.  
  1881. let enableWhiteListInput=createCheckbox(i18n("autoRun"), rulesData.enableWhiteList!=true);
  1882. let enableDebugInput=createCheckbox(i18n("enableDebug"), rulesData.enableDebug!=false);
  1883. let enableHistoryInput=createCheckbox(i18n("enableHistory"), rulesData.enableHistory===true);
  1884. let openInNewTabInput=createCheckbox(i18n("openInNewTab"), rulesData.openInNewTab!=false);
  1885. let initRunInput=createCheckbox(i18n("initRun"), rulesData.initRun!=false);
  1886. let preloadInput=createCheckbox(i18n("preload"), rulesData.preload!=false);
  1887. let dbClick2StopInput=createCheckbox(i18n("dbClick2Stop"), rulesData.dbClick2Stop);
  1888. let hideBarInput=createCheckbox(i18n("hideBar"), rulesData.hideBar, "h4", dbClick2StopInput);
  1889. let dbClick2StopCtrlInput=createCheckbox(i18n("dbClick2StopCtrl"), rulesData.dbClick2StopCtrl, "h4", dbClick2StopInput);
  1890. let dbClick2StopAltInput=createCheckbox(i18n("dbClick2StopAlt"), rulesData.dbClick2StopAlt, "h4", dbClick2StopInput);
  1891. let dbClick2StopShiftInput=createCheckbox(i18n("dbClick2StopShift"), rulesData.dbClick2StopShift, "h4", dbClick2StopInput);
  1892. let dbClick2StopMetaInput=createCheckbox(i18n("dbClick2StopMeta"), rulesData.dbClick2StopMeta, "h4", dbClick2StopInput);
  1893. let dbClick2StopKeyInput=createCheckbox(i18n("dbClick2StopKey"), rulesData.dbClick2StopKey, "h4", dbClick2StopInput, "text");
  1894. dbClick2StopKeyInput.setAttribute("maxlength", "1");
  1895.  
  1896. let customRulesTitle=document.createElement("h2");
  1897. customRulesTitle.innerHTML=i18n("customRules");
  1898. configCon.insertBefore(customRulesTitle, insertPos);
  1899. let customRulesInput=document.createElement("textarea");
  1900. configCon.insertBefore(customRulesInput, insertPos);
  1901. if(rulesData.editTemp){
  1902. if(!ruleParser.customRules){
  1903. ruleParser.customRules=[];
  1904. }
  1905. for(let i in ruleParser.customRules){
  1906. if(ruleParser.customRules[i].url==rulesData.editTemp.url){
  1907. ruleParser.customRules.splice(i, 1);
  1908. break;
  1909. }
  1910. }
  1911. ruleParser.customRules.unshift(rulesData.editTemp);
  1912. rulesData.editTemp=null;
  1913. storage.setItem("rulesData", rulesData);
  1914. customRulesInput.scrollIntoView();
  1915. }
  1916. customRulesInput.style.width="100%";
  1917. customRulesInput.style.height="500px";
  1918. 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]`;
  1919. customRulesInput.value=getFormatJSON(ruleParser.customRules);
  1920. let blacklistInput=document.createElement("textarea");
  1921. blacklistInput.style.width="100%";
  1922. blacklistInput.style.height="500px";
  1923. blacklistInput.style.display="none";
  1924. blacklistInput.placeholder="http://*.xxx.com/*/y";
  1925. blacklistInput.value=rulesData.blacklist?rulesData.blacklist.join("\n"):"";
  1926. let blacklistBtn=document.createElement("button");
  1927. blacklistBtn.innerText=i18n("editBlacklist");
  1928. blacklistBtn.style.width="100%";
  1929. blacklistBtn.onclick=e=>{
  1930. blacklistInput.style.display=blacklistInput.style.display=="none"?"":"none";
  1931. };
  1932. configCon.insertBefore(blacklistBtn, insertPos);
  1933. configCon.insertBefore(blacklistInput, insertPos);
  1934. let saveBtn=document.createElement("button");
  1935. saveBtn.innerHTML=i18n("save");
  1936. saveBtn.style.width="100%";
  1937. configCon.insertBefore(saveBtn, insertPos);
  1938. saveBtn.onclick=e=>{
  1939. try{
  1940. storage.setItem("hpRules", []);
  1941. if(customRulesInput.value==""){
  1942. storage.setItem("customRules", "");
  1943. }else{
  1944. let customRules=JSON.parse(customRulesInput.value);
  1945. if(Array && Array.isArray && !Array.isArray(customRules)){
  1946. showTips("Rules must be a Array!");
  1947. return;
  1948. }
  1949. debug(customRules);
  1950. storage.setItem("customRules", customRules);
  1951. }
  1952. }catch(e){
  1953. debug(e);
  1954. showTips("JSON error, check again!");
  1955. return;
  1956. }
  1957. rulesData.opacity=opacityInput.value/100;
  1958. rulesData.blacklist=blacklistInput.value?blacklistInput.value.split("\n"):"";
  1959. rulesData.hideBar=hideBarInput.checked;
  1960. rulesData.dbClick2Stop=dbClick2StopInput.checked;
  1961. rulesData.enableWhiteList=!enableWhiteListInput.checked;
  1962. rulesData.enableDebug=enableDebugInput.checked;
  1963. rulesData.enableHistory=enableHistoryInput.checked;
  1964. rulesData.openInNewTab=openInNewTabInput.checked;
  1965. rulesData.initRun=initRunInput.checked;
  1966. rulesData.preload=preloadInput.checked;
  1967. rulesData.upBtnImg=upBtnImgInput.value;
  1968. rulesData.downBtnImg=downBtnImgInput.value;
  1969. rulesData.dbClick2StopCtrl=dbClick2StopCtrlInput.checked;
  1970. rulesData.dbClick2StopAlt=dbClick2StopAltInput.checked;
  1971. rulesData.dbClick2StopShift=dbClick2StopShiftInput.checked;
  1972. rulesData.dbClick2StopMeta=dbClick2StopMetaInput.checked;
  1973. rulesData.dbClick2StopKey=dbClick2StopKeyInput.value;
  1974. storage.setItem("rulesData", rulesData);
  1975. let customUrls=customUrlsInput.value.trim();
  1976. if(customUrls){
  1977. customUrls=customUrls.split(/\n/);
  1978. for(let c=0;c<customUrls.length;c++){
  1979. let urlArr=customUrls[c].split("|"),url,type=1;
  1980. if(urlArr.length==1){
  1981. url=urlArr[0].trim();
  1982. if(!/^http/.test(url)){
  1983. showTips("Wrong url, check again!");
  1984. return;
  1985. }
  1986. }else if(urlArr.length==2){
  1987. type=urlArr[0].trim();
  1988. url=urlArr[1].trim();
  1989. if(!/^http/.test(url)){
  1990. showTips("Wrong url, check again!");
  1991. return;
  1992. }
  1993. }else{
  1994. break;
  1995. }
  1996. let maxId=0,hasUrl=false;
  1997. if(!rulesData.urls){
  1998. rulesData.urls=[];
  1999. maxId=1;
  2000. }else{
  2001. rulesData.urls.forEach(u=>{
  2002. if(maxId<u.id){
  2003. maxId=u.id;
  2004. }
  2005. if(u.url==url){
  2006. hasUrl=true;
  2007. }
  2008. });
  2009. if(hasUrl)break;
  2010. }
  2011. if(!rulesData.sort)rulesData.sort=[1];
  2012. rulesData.urls.push({id:maxId+1,url:url,type:type});
  2013. rulesData.sort.push(maxId+1);
  2014. storage.setItem("rulesData", rulesData);
  2015. }
  2016. }
  2017. showTips("The settings are saved");
  2018. location.reload();
  2019. };
  2020. return true;
  2021. }
  2022.  
  2023. var inUpdate=false;
  2024. function updateRules(success,fail){
  2025. if(inUpdate)return;
  2026. inUpdate=true;
  2027. let ruleIndex=ruleUrls.length-1;
  2028. storage.setItem("hpRules", []);
  2029. function addNextRule(){
  2030. if(ruleIndex<0){
  2031. let now=new Date().getTime();
  2032. storage.setItem("ruleLastUpdate", now);
  2033. storage.setItem("rules", ruleParser.rules);
  2034. inUpdate=false;
  2035. success();
  2036. }else{
  2037. let rule=ruleUrls[ruleIndex--];
  2038. ruleParser.addRuleByUrl(rule.url, rule.type, rule.id, (json,err)=>{
  2039. if(!json){
  2040. fail(rule,err);
  2041. }
  2042. addNextRule();
  2043. })
  2044. }
  2045. }
  2046. addNextRule();
  2047. }
  2048.  
  2049. function objIsArr(obj) {
  2050. return obj &&
  2051. typeof obj === 'object' &&
  2052. typeof obj.length === 'number' &&
  2053. !(obj.propertyIsEnumerable('length'));
  2054. }
  2055.  
  2056. function isVisible(el, win) {
  2057. if(!el.offsetParent)return false;
  2058. var loopable = true,
  2059. visible = el.tagName && win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  2060. while(loopable && visible) {
  2061. el = el.parentNode;
  2062.  
  2063. if(el && el.tagName && el.tagName!="BODY") {
  2064. visible = win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  2065. }else {
  2066. loopable = false;
  2067. }
  2068. }
  2069. return visible;
  2070. }
  2071.  
  2072. function getElementTop(ele) {
  2073. var actualTop = ele.offsetTop;
  2074. var current = ele.offsetParent;
  2075. while (current) {
  2076. actualTop += current.offsetTop;
  2077. current = current.offsetParent;
  2078. }
  2079. return actualTop;
  2080. }
  2081.  
  2082. function getFormatJSON(obj){
  2083. if(!objIsArr(obj))return "";
  2084. let ret="[\n";
  2085. let len=obj.length,i=0,isLast;
  2086. obj.forEach(item=>{
  2087. ret+=" {\n";
  2088. let iLen=Object.keys(item).length,j=0;
  2089. for(let key in item){
  2090. isLast=(++j)==iLen;
  2091. let value=item[key];
  2092. if(objIsArr(value)){
  2093. let vstr="[",v=0,vIsLast=false;
  2094. value.forEach(vi=>{
  2095. vIsLast=(++v)==value.length;
  2096. vstr+="\""+vi.replace(/\\/g,"\\\\")+"\""+(vIsLast?"":",");
  2097. });
  2098. vstr+="]";
  2099. ret+=" \""+key+"\":"+vstr+""+(isLast?"":",")+"\n";
  2100. }else{
  2101. if(typeof value=="string"){
  2102. value=value.replace(/\\/g,"\\\\").replace(/"/g,"\\\"");
  2103. value="\""+value+"\"";
  2104. }
  2105. ret+=" \""+key+"\":"+value+""+(isLast?"":",")+"\n";
  2106. }
  2107. }
  2108. isLast=(++i)==len;
  2109. ret+=" }"+(isLast?"":",")+"\n";
  2110. });
  2111. ret+="]";
  2112. return ret;
  2113. }
  2114.  
  2115. function globMatch(first, second) {
  2116. if (first.length == 0 && second.length == 0){
  2117. return true;
  2118. }
  2119.  
  2120. if (first.length > 1 && first[0] == '*' &&
  2121. second.length == 0){
  2122. return false;
  2123. }
  2124.  
  2125. if ((first.length > 1 && first[0] == '?') ||
  2126. (first.length != 0 && second.length != 0 &&
  2127. first[0] == second[0])){
  2128. return globMatch(first.substring(1),
  2129. second.substring(1));
  2130. }
  2131.  
  2132. if (first.length > 0 && first[0] == '*'){
  2133. return globMatch(first.substring(1), second) ||
  2134. globMatch(first, second.substring(1));
  2135. }
  2136.  
  2137. return false;
  2138. }
  2139.  
  2140. function initRules(callback) {
  2141. /*0 wedata格式,1 pagetual格式*/
  2142. ruleUrls=[
  2143. {
  2144. id:1,
  2145. url:'http://wedata.net/databases/AutoPagerize/items_all.json',
  2146. type:0,
  2147. }
  2148. ];var i=0,j=0;
  2149.  
  2150. ruleParser.initSavedRules(()=>{
  2151. storage.getItem("rulesData", data=>{
  2152. if(data){
  2153. rulesData=data;
  2154. if(data.urls)ruleUrls=ruleUrls.concat(data.urls);
  2155. if(data.sort){
  2156. let urls=[];
  2157. data.sort.forEach(id=>{
  2158. for(let s=0;s<ruleUrls.length;s++){
  2159. if(id==ruleUrls[s].id){
  2160. urls.push(ruleUrls[s]);
  2161. break;
  2162. }
  2163. }
  2164. });
  2165. ruleUrls=urls;
  2166. }
  2167. }
  2168. if(rulesData.upBtnImg){
  2169. upSvg=`<img src="${rulesData.upBtnImg}"/>`;
  2170. }
  2171. if(rulesData.downBtnImg){
  2172. downSvg=`<img src="${rulesData.downBtnImg}"/>`;
  2173. }
  2174. if(typeof(rulesData.opacity)=="undefined"){
  2175. rulesData.opacity=0.3;
  2176. }
  2177. if(typeof(rulesData.hideBar)=="undefined"){
  2178. rulesData.hideBar=false;
  2179. }
  2180. if(typeof(rulesData.dbClick2Stop)=="undefined"){
  2181. rulesData.dbClick2Stop=true;
  2182. }
  2183. if(typeof(rulesData.enableWhiteList)=="undefined"){
  2184. rulesData.enableWhiteList=false;
  2185. }
  2186. if(typeof(rulesData.enableHistory)=="undefined"){
  2187. rulesData.enableHistory=false;
  2188. }
  2189. if(typeof(rulesData.openInNewTab)=="undefined"){
  2190. rulesData.openInNewTab=true;
  2191. }
  2192. if(typeof(rulesData.enableDebug)=="undefined"){
  2193. rulesData.enableDebug=true;
  2194. }
  2195. if(typeof(rulesData.initRun)=="undefined"){
  2196. rulesData.initRun=true;
  2197. }
  2198. if(typeof(rulesData.preload)=="undefined"){
  2199. rulesData.preload=true;
  2200. }
  2201. if(rulesData.blacklist && rulesData.blacklist.length>0){
  2202. for(let b in rulesData.blacklist){
  2203. let curGlob=rulesData.blacklist[b];
  2204. if(globMatch(curGlob, location.href)){
  2205. return;
  2206. }
  2207. }
  2208. }
  2209. enableDebug=rulesData.enableDebug;
  2210. storage.getItem("forceState_"+location.host, v=>{
  2211. storage.getItem("ruleLastUpdate", date=>{
  2212. if(typeof(v)=="undefined"){
  2213. v=(rulesData.enableWhiteList?1:0);
  2214. }
  2215. forceState=v;
  2216. updateDate=date;
  2217. if(initConfig())return;
  2218. if(forceState==1)return;
  2219. let now=new Date().getTime();
  2220. if(!date || now-date>2*24*60*60*1000){
  2221. updateRules(()=>{
  2222. },(rule,err)=>{});
  2223. }
  2224. callback();
  2225. });
  2226. });
  2227. });
  2228. });
  2229. }
  2230.  
  2231. function requestDoc(url, callback){
  2232. _GM_xmlhttpRequest({
  2233. url: url,
  2234. method: 'GET',
  2235. overrideMimeType: 'text/html;charset='+document.charset,
  2236. headers: {
  2237. 'Referer': location.href,
  2238. "Content-Type": "text/html;charset="+document.charset,
  2239. },
  2240. timeout: 5000,
  2241. onload: function(res) {
  2242. var doc=null,response=res.response;
  2243. let preCode=ruleParser.curSiteRule.pageElementPre || ruleParser.curSiteRule.pagePre;
  2244. if(preCode){
  2245. try{
  2246. response=Function("response",'"use strict";' + preCode)(response);
  2247. }catch(e){
  2248. debug(e);
  2249. }
  2250. }
  2251. try {
  2252. doc=document.implementation.createHTMLDocument('');
  2253. doc.documentElement.innerHTML=response;
  2254. }
  2255. catch (e) {
  2256. debug('parse error'+e.toString());
  2257. }
  2258. let pageElement=ruleParser.getPageElement(doc);
  2259. if(inCors && (!pageElement || pageElement.length==0)){
  2260. ruleParser.curSiteRule.pageElement=allOfBody;
  2261. pageElement=ruleParser.getPageElement(doc);
  2262. ruleParser.getInsert(true);
  2263. }
  2264. //只有1的話怕不是圖片哦
  2265. if(pageElement && (pageElement.length>1 || (pageElement.length==1 && pageElement[0].tagName!="IMG") )){
  2266. let result=ruleParser.insertPage(doc, pageElement, url, callback, false);
  2267. ruleParser.curSiteRule.action=0;
  2268. if(!result){
  2269. ruleParser.curSiteRule.action=1;
  2270. requestFromIframe(url, (doc, eles)=>{
  2271. loadPageOver();
  2272. if(eles){
  2273. ruleParser.insertPage(doc, eles, url, callback, true);
  2274. }
  2275. });
  2276. }
  2277. }else if(ruleParser.curSiteRule.singleUrl || curPage==1){
  2278. ruleParser.curSiteRule.action=1;
  2279. requestFromIframe(url, (doc, eles)=>{
  2280. loadPageOver();
  2281. if(eles){
  2282. ruleParser.insertPage(doc, eles, url, callback, true);
  2283. }
  2284. });
  2285. }else{
  2286. isPause=true;
  2287. callback(false);
  2288. }
  2289. },
  2290. onerror: function(e){
  2291. debug(e);
  2292. callback(false);
  2293. },
  2294. ontimeout: function(e){
  2295. debug(e);
  2296. callback(false);
  2297. }
  2298. });
  2299. }
  2300.  
  2301. var failFromIframe=0;
  2302. var inCors=false;
  2303. function requestFromIframe(url, callback){
  2304. url=url.replace(/#[^#]*/,"");
  2305. let orgPage,curPage;
  2306. let iframe = document.createElement('iframe');
  2307. iframe.name = 'pagetual-iframe';
  2308. iframe.width = '100%';
  2309. iframe.height = '0';
  2310. iframe.frameBorder = '0';
  2311. if(ruleParser.curSiteRule.sandbox!=false){
  2312. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  2313. }
  2314. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  2315. let waitTime=100,checkEval;
  2316. if(ruleParser.curSiteRule.wait){
  2317. if(isNaN(ruleParser.curSiteRule.wait)){
  2318. try{
  2319. checkEval=Function("doc",'"use strict";' + ruleParser.curSiteRule.wait);
  2320. }catch(e){
  2321. debug(e);
  2322. }
  2323. }else{
  2324. waitTime=ruleParser.curSiteRule.wait;
  2325. }
  2326. }
  2327. let loadedHandler=e=>{
  2328. if(e.data != 'pagetual-iframe:DOMLoaded' && e.type != 'load')return;
  2329. window.removeEventListener('message', loadedHandler, false);
  2330. iframe.removeEventListener('load', loadedHandler, false);
  2331. let tryTimes=0;
  2332. function checkIframe(){
  2333. try{
  2334. let doc=iframe.contentDocument || iframe.contentWindow.document;
  2335. let eles=ruleParser.getPageElement(doc, iframe.contentWindow);
  2336. if(eles && eles.length>0 && (!checkEval || checkEval(doc))){
  2337. callback(doc, eles);
  2338. }else if(tryTimes++ < 10){
  2339. setTimeout(()=>{
  2340. checkIframe();
  2341. },waitTime);
  2342. return;
  2343. }else{
  2344. if(failFromIframe++ > 2){
  2345. failFromIframe=0;
  2346. debug("Stop as failFromIframe");
  2347. isPause=true;
  2348. callback(false, false);
  2349. }else{
  2350. callback(false, false);
  2351. }
  2352. }
  2353. }catch(e){
  2354. debug("Stop as cors");
  2355. inCors=true;
  2356. //isPause=true;
  2357. if(!ruleParser.curSiteRule.pageElement){
  2358. ruleParser.curSiteRule.pageElement=allOfBody;
  2359. ruleParser.getInsert(true);
  2360. }
  2361. ruleParser.curSiteRule.action=0;
  2362. ruleParser.nextLinkHref=url;
  2363. callback(false, false);
  2364. nextPage();
  2365. }
  2366. document.body.removeChild(iframe);
  2367. }
  2368. setTimeout(()=>{
  2369. checkIframe();
  2370. },waitTime);
  2371. };
  2372. window.addEventListener('message', loadedHandler, false);
  2373. iframe.addEventListener('load', loadedHandler, false);
  2374. iframe.src=url;
  2375. document.body.appendChild(iframe);
  2376. }
  2377.  
  2378. function initPage(){
  2379. ruleParser.initPage(()=>{
  2380. if(ruleParser.nextLinkHref){
  2381. let isJs=/^(javascript|#)/.test(ruleParser.nextLinkHref.replace(location.href,""));
  2382. if(!isJs){
  2383. let inForce=(forceState == 2 || forceState == 3);
  2384. _GM_registerMenuCommand(i18n(inForce?"cancelForceIframe":"forceIframe"), ()=>{
  2385. if(inForce){
  2386. storage.setItem("forceState_"+location.host, "");
  2387. }else{
  2388. let _state=ruleParser.curSiteRule.action>0 || confirm(i18n("forceAllBody"))?2:3;
  2389. storage.setItem("forceState_"+location.host, _state);
  2390. }
  2391. location.reload();
  2392. });
  2393. }
  2394. _GM_registerMenuCommand(i18n("loadNow"), ()=>{
  2395. let loadNum=window.prompt(i18n("loadConfirm"), "1");
  2396. if(loadNum==="" || loadNum===null)return;
  2397. autoLoadNum=Math.abs(parseInt(loadNum));
  2398. nextPage();
  2399. });
  2400. }
  2401. initListener();
  2402. if(rulesData.initRun && ruleParser.curSiteRule.initRun!=0)nextPage();
  2403. });
  2404. }
  2405.  
  2406. var pageBarStyle;
  2407. function initView(){
  2408. _GM_addStyle(`
  2409. .pagetual_pageBar.stop {
  2410. -webkit-filter: invert(100%);
  2411. filter: invert(100%);
  2412. opacity: 1!important;
  2413. }
  2414. .pagetual_pageBar.hide {
  2415. display: none!important;
  2416. }
  2417. .pagetual_pageBar:hover {
  2418. opacity: 1!important;
  2419. }
  2420. .pagetual_pageBar span {
  2421. vertical-align: super;
  2422. }
  2423.  
  2424. .pagetual_pageBar span>svg:hover {
  2425. animation: touhouAni 1s infinite;
  2426. }
  2427. .pagetual_pageBar .pagetual_pageNum{
  2428. color: #55555f;
  2429. }
  2430. .pagetual_pageBar .pagetual_pageNum:hover{
  2431. color: #ff6464;
  2432. }
  2433. .pagetual_tipsWords{
  2434. font-size: 50px;
  2435. font-weight: bold;
  2436. font-family: "黑体", -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto",
  2437. "Oxygen", "Ubuntu", "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji",
  2438. "Segoe UI Emoji", "Segoe UI Symbol";
  2439. color: #ffffff;
  2440. height: 70px;
  2441. line-height: 70px;
  2442. position: fixed;
  2443. left: 50%;
  2444. top: 10%;
  2445. margin-left: -150px;
  2446. padding: 0 10px;
  2447. z-index: 999999999;
  2448. background-color: #000;
  2449. border: 1px solid black;
  2450. border-radius: 10px;
  2451. opacity: 0;
  2452. filter: alpha(opacity=65);
  2453. box-shadow: 5px 5px 20px 0px #000;
  2454. -moz-transition:opacity 0.3s ease-in-out 0s;
  2455. -webkit-transition:opacity 0.3s ease-in-out 0s;
  2456. transition:opacity 0.3s ease-in-out 0s;
  2457. pointer-events: none;
  2458. }
  2459.  
  2460. @keyframes touhouAni{
  2461. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  2462. to {transform: rotate(360deg);}
  2463. }
  2464. @-webkit-keyframes touhouAni{
  2465. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  2466. to {transform: rotate(360deg);}
  2467. }
  2468. .pagetual_loading {
  2469. width: 50px;
  2470. height: 50px;
  2471. margin: 10px auto;
  2472. border-radius: 100%;
  2473. -webkit-animation: pagetual_loading_scaleout 1.0s infinite ease-in-out;
  2474. animation: pagetual_loading_scaleout 1.0s infinite ease-in-out;
  2475. }
  2476. @-webkit-keyframes pagetual_loading_scaleout {
  2477. 0% { -webkit-transform: scale(0.0) }
  2478. 100% {
  2479. -webkit-transform: scale(1.0);
  2480. opacity: 0;
  2481. }
  2482. }
  2483. @keyframes pagetual_loading_scaleout {
  2484. 0% {
  2485. transform: scale(0.0);
  2486. -webkit-transform: scale(0.0);
  2487. } 100% {
  2488. transform: scale(1.0);
  2489. -webkit-transform: scale(1.0);
  2490. opacity: 0;
  2491. }
  2492. }
  2493. `);
  2494. pageBarStyle=`line-height:1;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%);font-size: 30px;visibility: visible; position: initial; width: auto; height: 30px; float: none; clear: both; margin: 5px auto; text-align: center;`;
  2495. }
  2496. var loadingDiv=document.createElement("div");
  2497. 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;";
  2498. 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><div class="pagetual_loading"><svg width="50" height="50" style="position:relative;cursor: pointer;width: 50px;height: 50px;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="#6e6e6e" 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="#6e6e6e" p-id="6366"></path></svg></div>`;
  2499. var loadingCSS=`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;`;
  2500.  
  2501. var upSvg=`<svg width="30" height="30" style="display:initial;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>`;
  2502. var upSvgCSS=`display:initial;position:absolute;cursor: pointer;margin: 0 -45px;width: 30px;height: 30px;vertical-align: middle;fill: currentColor;overflow: hidden;`;
  2503. var downSvg=`<svg width="30" height="30" style="display:initial;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>`;
  2504. var downSvgCSS=`display:initial;position:absolute;cursor: pointer;margin: 0 15px;width: 30px;height: 30px;vertical-align: middle;fill: currentColor;overflow: hidden;transform: rotate(180deg);`;
  2505.  
  2506. 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;`;
  2507. var pageTextStyle=`line-height: 30px;text-decoration: none;user-select: none;visibility: visible;position: initial;width: auto;max-width: 80%; white-space: nowrap; text-overflow: ellipsis;overflow: hidden;height: auto;float: none;clear: both;margin: 0px auto;text-align: center;display: inline-block;font-weight: bold;font-style: normal;font-size: 16px;letter-spacing: initial;vertical-align: top;color: rgb(85, 85, 95);`;
  2508.  
  2509. var tipsWords=document.createElement("div");
  2510. tipsWords.className="pagetual_tipsWords";
  2511.  
  2512. var isPause=false,isLoading=false,curPage=1,forceState=0,bottomGap=1000,autoLoadNum=-1;
  2513.  
  2514. function changeStop(stop, hide){
  2515. isPause=stop;
  2516. [].forEach.call(document.querySelectorAll(".pagetual_pageBar"), bar=>{
  2517. if(isPause){
  2518. bar.classList.add("stop");
  2519. if(hide)bar.classList.add("hide");
  2520. }else{
  2521. bar.classList.remove("stop");
  2522. if(hide)bar.classList.remove("hide");
  2523. }
  2524. });
  2525. }
  2526.  
  2527. function isInViewPort(element) {
  2528. if(!element.parentNode)return false;
  2529. if(_unsafeWindow.getComputedStyle(element).display=="none")return false;
  2530. const viewWidth = window.innerWidth || document.documentElement.clientWidth;
  2531. const viewHeight = window.innerHeight || document.documentElement.clientHeight;
  2532. const {
  2533. top,
  2534. right,
  2535. bottom,
  2536. left,
  2537. } = element.getBoundingClientRect();
  2538.  
  2539. return (
  2540. top >= 0 &&
  2541. left >= 0 &&
  2542. right <= viewWidth + 1 &&
  2543. bottom <= viewHeight * 2
  2544. );
  2545. }
  2546.  
  2547. var urlChanged=false;
  2548. var _wr = function(type) {
  2549. var orig = history[type];
  2550. return function() {
  2551. var rv = orig.apply(this, arguments);
  2552. var e = new Event(type);
  2553. e.arguments = arguments;
  2554. window.dispatchEvent(e);
  2555. return rv;
  2556. };
  2557. };
  2558. history.pushState = _wr('pushState');
  2559. window.addEventListener('pushState', function(e) {
  2560. urlChanged=true;
  2561. isPause=true;
  2562. setTimeout(()=>{
  2563. if(location.href==configPage){
  2564. location.reload();
  2565. }
  2566. },1);
  2567. });
  2568.  
  2569. function initListener(){
  2570. let loadmoreBtn,loading=true,lastScroll=0,checkLoadMoreTimes=0;
  2571. let checkLoadMore=setInterval(()=>{
  2572. loadmoreBtn=getLoadMore(document);
  2573. if(loadmoreBtn && isVisible(loadmoreBtn, _unsafeWindow)){
  2574. loading=false;
  2575. clearInterval(checkLoadMore);
  2576. }else if(checkLoadMoreTimes>10){
  2577. clearInterval(checkLoadMore);
  2578. }
  2579. },300);
  2580. let checkScrollReach=()=>{
  2581. let scrolly=window.scrollY;
  2582. let windowHeight=window.innerHeight || document.documentElement.clientHeight;
  2583. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  2584. if(scrollH-scrolly-windowHeight<bottomGap){
  2585. nextPage();
  2586. }
  2587. };
  2588. let scrollHandler = e=>{
  2589. if(urlChanged){
  2590. ruleParser.initPage(()=>{
  2591. if(ruleParser.nextLinkHref)initView();
  2592. });
  2593. urlChanged=false;
  2594. isPause=false;
  2595. }
  2596. if(isPause)return;
  2597. if(!loading){
  2598. if(!loadmoreBtn || !loadmoreBtn.parentNode){
  2599. loadmoreBtn=getLoadMore(document);
  2600. }
  2601. if(loadmoreBtn){
  2602. if(isInViewPort(loadmoreBtn)){
  2603. emuClick(loadmoreBtn);
  2604. loading=true;
  2605. setTimeout(()=>{loading=false},200);
  2606. }
  2607. }else{
  2608. loading=true;
  2609. setTimeout(()=>{loading=false},200);
  2610. }
  2611. }
  2612. if(!isLoading){
  2613. checkScrollReach();
  2614. }
  2615. if(ruleParser.curSiteRule.lockScroll){
  2616. let curScroll=document.body.scrollTop||document.documentElement.scrollTop;
  2617. if(lastScroll!=0 && isLoading && Math.abs(lastScroll-curScroll)>100){
  2618. document.body.scrollTop=lastScroll;
  2619. document.documentElement.scrollTop=lastScroll;
  2620. }else{
  2621. lastScroll=curScroll;
  2622. }
  2623. }
  2624. };
  2625. if(!ruleParser.curSiteRule.wheel){
  2626. document.addEventListener('scroll', scrollHandler, true);
  2627. }
  2628. document.addEventListener('wheel', scrollHandler, true);
  2629. document.addEventListener('dblclick', e=>{
  2630. if(forceState==1) return;
  2631. if(!rulesData.dbClick2StopKey){
  2632. if((rulesData.dbClick2StopCtrl && !e.ctrlKey) ||
  2633. (rulesData.dbClick2StopAlt && !e.altKey) ||
  2634. (rulesData.dbClick2StopShift && !e.shiftKey) ||
  2635. (rulesData.dbClick2StopMeta && !e.metaKey)){
  2636. return;
  2637. }
  2638. }
  2639. if(e.target.tagName!="BODY"){
  2640. let selStr=document.getSelection().toString().trim();
  2641. if(selStr){
  2642. return;
  2643. }
  2644. }
  2645. if(rulesData.dbClick2Stop && (ruleParser.nextLinkHref || loadmoreBtn)){
  2646. setTimeout(()=>{
  2647. changeStop(!isPause, rulesData.hideBar);
  2648. if(!isPause){
  2649. checkScrollReach();
  2650. }
  2651. showTips(i18n(isPause?"disable":"enable"));
  2652. },10);
  2653. }
  2654. });
  2655. if(rulesData.dbClick2StopKey){
  2656. document.addEventListener('keydown', e=>{
  2657. if((rulesData.dbClick2StopCtrl && !e.ctrlKey) ||
  2658. (rulesData.dbClick2StopAlt && !e.altKey) ||
  2659. (rulesData.dbClick2StopShift && !e.shiftKey) ||
  2660. (rulesData.dbClick2StopMeta && !e.metaKey)){
  2661. return;
  2662. }
  2663. var key = String.fromCharCode(e.keyCode).toLowerCase();
  2664. if(rulesData.dbClick2StopKey.toLowerCase()==key){
  2665. forceState=(forceState==1?0:1);
  2666. showTips(i18n(forceState==1?"disableSiteTips":"enableSiteTips"));
  2667. if(!ruleParser.curSiteRule.url) {
  2668. storage.setItem("forceState_"+location.host, forceState);
  2669. location.reload();
  2670. }
  2671. }
  2672. });
  2673. }
  2674. }
  2675.  
  2676. function showTips(content, wordColor, backColor){
  2677. document.body.appendChild(tipsWords);
  2678. tipsWords.style.opacity=0.8;
  2679. tipsWords.innerText=content;
  2680. tipsWords.style.marginLeft=-tipsWords.offsetWidth/2+"px";
  2681. tipsWords.style.color=wordColor||0xFFFFFF;
  2682. tipsWords.style.backgroundColor=backColor||0x000;
  2683. setTimeout(()=>{tipsWords.style.opacity=0},1000);
  2684. }
  2685.  
  2686. function getLoadMore(doc){
  2687. if(ruleParser.curSiteRule.loadMore==="")return null;
  2688. let btnSel=ruleParser.curSiteRule.loadMore||".LoadMore,.load-more,.button-show-more",loadmoreBtn;
  2689. if(btnSel){
  2690. try{
  2691. loadmoreBtn=doc.querySelector(btnSel);
  2692. }catch(e){
  2693. loadmoreBtn=getElementByXpath(btnSel,doc,doc);
  2694. }
  2695. }
  2696. if(!loadmoreBtn){
  2697. let buttons=doc.querySelectorAll("input,button,a,div[onclick]"),loadmoreReg=/^\s*(加载更多|加載更多|load\s*more|もっと読み込む)\s*$/i;
  2698. for(let i=0;i<buttons.length;i++){
  2699. let button=buttons[i];
  2700. if(button && loadmoreReg.test(button.innerText)){
  2701. loadmoreBtn=button;
  2702. break;
  2703. }
  2704. }
  2705. }
  2706. if(loadmoreBtn && !ruleParser.curSiteRule.loadMore && loadmoreBtn.href && !/^(javascript|#)/.test(loadmoreBtn.href))loadmoreBtn=null;
  2707. return loadmoreBtn;
  2708. }
  2709.  
  2710. var hasPageNum=true;
  2711. function createPageBar(url){
  2712. let insert=ruleParser.getInsert();
  2713. if(!insert || !insert.parentNode)return;
  2714. curPage++;
  2715. let example=ruleParser.curSiteRule.insertPos==2?insert.children[0]:(insert.previousElementSibling||insert);
  2716. if(!example || !example.parentNode)example=insert;
  2717. let inTable=example.parentNode.tagName=="TABLE" ||
  2718. example.tagName=="TR" ||
  2719. example.tagName=="TBODY" ||
  2720. (example.previousElementSibling && example.previousElementSibling.tagName=="TR") ||
  2721. (example.previousElementSibling && example.previousElementSibling.tagName=="TBODY");
  2722. let inLi=example.tagName=="LI" || (example.previousElementSibling && example.previousElementSibling.tagName=="LI");
  2723. if(forceState==2){
  2724. inTable=inLi=false;
  2725. }
  2726. let pageBar=document.createElement(inTable?"tr":(inLi?"li":"div"));
  2727. let upSpan=document.createElement("span");
  2728. let downSpan=document.createElement("span");
  2729. let pageText=document.createElement("a");
  2730. let pageNum;
  2731. pageBar.className="pagetual_pageBar";
  2732. pageBar.id="pagetual_pageBar";
  2733. if(isPause){
  2734. pageBar.classList.add("stop");
  2735. }
  2736. pageBar.style.cssText=pageBarStyle;
  2737. pageBar.title=i18n(isPause?"enable":"disable");
  2738. upSpan.innerHTML=upSvg;
  2739. upSpan.children[0].style.cssText=upSvgCSS;
  2740. upSpan.title=i18n("toTop");
  2741. downSpan.innerHTML=downSvg;
  2742. downSpan.children[0].style.cssText=downSvgCSS;
  2743. downSpan.title=i18n("toBottom");
  2744. upSpan.style.cssText=initStyle;
  2745. downSpan.style.cssText=initStyle;
  2746. pageText.href=url;
  2747. pageText.style.cssText=pageTextStyle;
  2748. pageText.title=i18n("current");
  2749. pageBar.appendChild(upSpan);
  2750. pageBar.appendChild(pageText);
  2751. if(ruleParser.nextTitle){
  2752. pageText.innerHTML=ruleParser.nextTitle+" ";
  2753. pageText.title=ruleParser.nextTitle;
  2754. }
  2755. if(ruleParser.curSiteRule.pageNum || (hasPageNum && /[&\/\?](p=|page[=\/_-]?)\d+|[_-]\d+\./.test(url))){
  2756. pageText.innerHTML+="Page ";
  2757. pageNum=document.createElement("span");
  2758. pageNum.innerText=curPage;
  2759. pageNum.className="pagetual_pageNum";
  2760. pageNum.title=i18n("inputPageNum");
  2761. pageNum.style.cssText=pageTextStyle;
  2762. pageNum.style.cursor="pointer";
  2763. pageNum.style.color="";
  2764. pageNum.style.marginLeft="5px";
  2765. pageNum.addEventListener("click", e=>{
  2766. let pageInput=prompt(i18n("inputPageNum"), "1");
  2767. if(pageInput){
  2768. let pageLink=ruleParser.getLinkByPage(url, pageInput);
  2769. if(pageLink){
  2770. _GM_openInTab(pageLink,{active:true});
  2771. }
  2772. }
  2773. e.preventDefault();
  2774. e.stopPropagation();
  2775. });
  2776. pageBar.appendChild(pageNum);
  2777. }else{
  2778. pageText.innerHTML+="Page "+curPage;
  2779. hasPageNum=false;
  2780. }
  2781. pageBar.appendChild(downSpan);
  2782. let parentStyle=_unsafeWindow.getComputedStyle(example.parentNode);
  2783. let parentWidth=example.parentNode.scrollWidth||parseInt(parentStyle.width);
  2784. pageBar.style.width=parentWidth-parseInt(parentStyle.paddingLeft)-parseInt(parentStyle.paddingRight)-10+"px";
  2785. if(parentStyle.display=="grid" || parentStyle.display=="inline-grid"){
  2786. pageBar.style.gridColumnStart=1;
  2787. pageBar.style.gridColumnEnd=1+parseInt(example.parentNode.offsetWidth/example.offsetWidth);
  2788. }
  2789. if(inTable){
  2790. example=(example.tagName=="TR" || example.tagName=="TBODY")?example:example.previousElementSibling;
  2791. if(example.tagName=="TBODY")example=example.querySelector("tr");
  2792. if(example.previousElementSibling)example=example.previousElementSibling;
  2793. let tdNum=0;
  2794. [].forEach.call(example.children, el=>{
  2795. if(el.tagName=="TD" || el.tagName=="TH"){
  2796. tdNum+=el.colSpan||1;
  2797. }
  2798. });
  2799. pageBar.style.display="table-row";
  2800. pageBar.style.backgroundColor="unset";
  2801. pageBar.style.lineHeight="20px";
  2802. pageBar.style.boxShadow="";
  2803. let td=document.createElement("td");
  2804. td.colSpan=tdNum||1;
  2805. let inTd=document.createElement("div");
  2806. inTd.style.backgroundColor="rgb(240 240 240 / 80%)";
  2807. inTd.style.borderRadius="20px";
  2808. inTd.style.padding="0 0";
  2809. inTd.style.margin="10px";
  2810. inTd.style.lineHeight="20px";
  2811. inTd.style.textAlign="center";
  2812. inTd.style.boxShadow="rgb(0 0 0 / 67%) 0px 0px 10px 0px";
  2813. inTd.appendChild(upSpan);
  2814. inTd.appendChild(pageText);
  2815. if(pageNum)inTd.appendChild(pageNum);
  2816. inTd.appendChild(downSpan);
  2817. td.appendChild(inTd);
  2818. pageBar.appendChild(td);
  2819. }else if(inLi){
  2820. example=example.tagName=="LI"?example:example.previousElementSibling;
  2821. pageBar.style.display="table-row";
  2822. pageBar.style.backgroundColor="unset";
  2823. pageBar.style.lineHeight="20px";
  2824. pageBar.style.boxShadow="";
  2825. let td=document.createElement("td");
  2826. td.colSpan=example.children.length;
  2827. let inTd=document.createElement("div");
  2828. inTd.style.backgroundColor="rgb(240 240 240 / 80%)";
  2829. inTd.style.borderRadius="20px";
  2830. inTd.style.margin="10px"
  2831. inTd.style.padding="0 0";
  2832. inTd.style.textAlign="center";
  2833. inTd.style.minWidth="150px";
  2834. inTd.appendChild(upSpan);
  2835. inTd.appendChild(pageText);
  2836. inTd.style.width=parseInt(pageBar.style.width)-20+"px";
  2837. inTd.style.boxShadow="rgb(0 0 0 / 67%) 0px 0px 10px 0px";
  2838. if(pageNum)inTd.appendChild(pageNum);
  2839. inTd.appendChild(downSpan);
  2840. td.appendChild(inTd);
  2841. pageBar.appendChild(td);
  2842. }
  2843.  
  2844. upSpan.addEventListener("click", e=>{
  2845. document.body.scrollTop=0;
  2846. document.documentElement.scrollTop=0;
  2847. e.preventDefault();
  2848. e.stopPropagation();
  2849. });
  2850. downSpan.addEventListener("click", e=>{
  2851. changeStop(true);
  2852. pageBar.title=i18n(isPause?"enable":"disable");
  2853. document.body.scrollTop=9999999;
  2854. document.documentElement.scrollTop=9999999;
  2855. e.preventDefault();
  2856. e.stopPropagation();
  2857. });
  2858. pageBar.addEventListener("click", e=>{
  2859. changeStop(!isPause);
  2860. pageBar.title=i18n(isPause?"enable":"disable");
  2861. });
  2862. pageText.addEventListener("click", e=>{
  2863. e.stopPropagation();
  2864. });
  2865. if(ruleParser.curSiteRule.insertPos==2){
  2866. insert.appendChild(pageBar);
  2867. }else{
  2868. insert.parentNode.insertBefore(pageBar, insert);
  2869. }
  2870. if(ruleParser.curSiteRule.pageBar){
  2871. try{
  2872. Function("pageBar",'"use strict";' + ruleParser.curSiteRule.pageBar)(pageBar);
  2873. }catch(e){
  2874. debug(e);
  2875. }
  2876. }
  2877.  
  2878. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  2879. let posEle=pageBar.nextElementSibling||pageBar;
  2880. while(posEle && !posEle.offsetParent){
  2881. posEle=posEle.previousElementSibling||posEle.parentNode;
  2882. }
  2883. if(posEle){
  2884. let actualTop = getElementTop(posEle);
  2885. bottomGap=scrollH-actualTop+(window.innerHeight||document.documentElement.clientHeight)*(ruleParser.curSiteRule.rate||1);
  2886. if(bottomGap<100)bottomGap=100;
  2887. }else{
  2888. bottomGap=1000;
  2889. }
  2890. if(rulesData.opacity==0)pageBar.style.display="none";
  2891. return pageBar;
  2892. }
  2893.  
  2894. function emuClick(btn){
  2895. if(!PointerEvent)return btn.click();
  2896. let eventParam={
  2897. isTrusted: true,
  2898. altKey: false,
  2899. azimuthAngle: 0,
  2900. bubbles: true,
  2901. button: 0,
  2902. buttons: 0,
  2903. clientX: 1,
  2904. clientY: 1,
  2905. cancelBubble: false,
  2906. cancelable: true,
  2907. composed: true,
  2908. ctrlKey: false,
  2909. defaultPrevented: false,
  2910. detail: 1,
  2911. eventPhase: 2,
  2912. fromElement: null,
  2913. height: 1,
  2914. isPrimary: false,
  2915. metaKey: false,
  2916. pointerId: 1,
  2917. pointerType: "mouse",
  2918. pressure: 0,
  2919. relatedTarget: null,
  2920. returnValue: true,
  2921. shiftKey: false,
  2922. toElement: null,
  2923. twist: 0,
  2924. which: 1
  2925. };
  2926. var mouseEvent = new PointerEvent("mousedown",eventParam);
  2927. btn.dispatchEvent(mouseEvent);
  2928. mouseEvent = new PointerEvent("mouseup",eventParam);
  2929. btn.dispatchEvent(mouseEvent);
  2930. btn.click();
  2931. }
  2932.  
  2933. var emuIframe,lastActiveUrl=location.href;
  2934. function emuPage(callback){
  2935. let orgPage=null,curPage,iframeDoc,times=0,loadmoreBtn,loadmoreEnd=false,waitTimes=10,changed=false;
  2936. function checkPage(){
  2937. if(isPause)return;
  2938. try{
  2939. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  2940. }catch(e){
  2941. debug("Stop as cors");
  2942. isPause=true;
  2943. callback(false, false);
  2944. return;
  2945. }
  2946.  
  2947. let nextLink=ruleParser.getNextLink(iframeDoc);
  2948. let waitTime=200,checkEval;
  2949. if(ruleParser.curSiteRule.wait){
  2950. if(isNaN(ruleParser.curSiteRule.wait)){
  2951. try{
  2952. checkEval=Function("doc",'"use strict";' + ruleParser.curSiteRule.wait);
  2953. }catch(e){
  2954. debug(e);
  2955. }
  2956. }else{
  2957. waitTime=ruleParser.curSiteRule.wait;
  2958. }
  2959. }
  2960.  
  2961. if(!orgPage){
  2962. if(!loadmoreEnd){
  2963. loadmoreBtn=getLoadMore(iframeDoc);
  2964. if(loadmoreBtn && isVisible(loadmoreBtn, iframeDoc.defaultView)){
  2965. emuClick(loadmoreBtn);
  2966. let intv=setInterval(()=>{
  2967. loadmoreBtn=getLoadMore(iframeDoc);
  2968. if(!loadmoreBtn || !loadmoreBtn.parentNode || !isVisible(loadmoreBtn, iframeDoc.defaultView)){
  2969. clearInterval(intv);
  2970. loadmoreEnd=true;
  2971. setTimeout(()=>{
  2972. checkPage();
  2973. },500);
  2974. }else{
  2975. emuClick(loadmoreBtn);
  2976. }
  2977. },200);
  2978. return;
  2979. }else{
  2980. loadmoreEnd=true;
  2981. }
  2982. }
  2983. let pageEle=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true);
  2984. if(!nextLink || !pageEle || pageEle.length==0 || (checkEval && !checkEval(iframeDoc))){
  2985. if(waitTimes-->0){
  2986. setTimeout(()=>{
  2987. checkPage();
  2988. },waitTime);
  2989. return;
  2990. }
  2991. }
  2992. orgPage=pageEle;
  2993. if(!orgPage || orgPage.length==0){
  2994. debug("Stop as no page when emu");
  2995. isPause=true;
  2996. callback(false, false);
  2997. return;
  2998. }
  2999. if(orgPage && orgPage[0].tagName=="UL")orgPage=orgPage[0].children;
  3000. if(orgPage && nextLink){
  3001. orgPage=orgPage[parseInt(orgPage.length/2)];
  3002. if(!isVisible(nextLink, iframeDoc.defaultView)){
  3003. debug("Stop as next hide when emu");
  3004. isPause=true;
  3005. callback(false, false);
  3006. }else{
  3007. emuClick(nextLink);
  3008. setTimeout(()=>{
  3009. checkPage();
  3010. },500);
  3011. }
  3012. }else{
  3013. debug("Stop as no next when emu");
  3014. isPause=true;
  3015. callback(false, false);
  3016. }
  3017. return;
  3018. }
  3019. if(times++ > 20){
  3020. debug("Stop as timeout when emu");
  3021. isPause=true;
  3022. callback(false, false);
  3023. return;
  3024. }
  3025. let eles=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true),checkItem;
  3026. if(eles && eles.length>0){
  3027. checkItem=eles;
  3028. if(eles[0].tagName=="UL"){
  3029. checkItem=eles[0].children;
  3030. }
  3031. checkItem=checkItem[parseInt(checkItem.length/2)];
  3032. }
  3033. if(!checkItem || (checkEval && !checkEval(iframeDoc))){
  3034. setTimeout(()=>{
  3035. checkPage();
  3036. },waitTime);
  3037. }else{
  3038. if(orgPage!=checkItem){
  3039. changed=true;
  3040. orgPage=checkItem;
  3041. setTimeout(()=>{
  3042. checkPage();
  3043. },waitTime);
  3044. }else if(changed){
  3045. callback(iframeDoc, eles);
  3046. }else{
  3047. setTimeout(()=>{
  3048. checkPage();
  3049. },waitTime);
  3050. }
  3051. }
  3052. }
  3053. if(!emuIframe){
  3054. let loaded=false;
  3055. emuIframe = document.createElement('iframe');
  3056. emuIframe.name = 'pagetual-iframe';
  3057. if(ruleParser.curSiteRule.sandbox!=false){
  3058. emuIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  3059. }
  3060. emuIframe.width = '100%';
  3061. emuIframe.height = '0';
  3062. emuIframe.frameBorder = '0';
  3063. emuIframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  3064. emuIframe.addEventListener("load", e=>{
  3065. setTimeout(()=>{
  3066. try{
  3067. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  3068. }catch(e){
  3069. debug("Stop as cors");
  3070. isPause=true;
  3071. callback(false, false);
  3072. return;
  3073. }
  3074. let code=ruleParser.curSiteRule.init;
  3075. if(code){
  3076. try{
  3077. Function('doc','win','iframe','"use strict";' + code)(iframeDoc, iframeDoc.defaultView, emuIframe);
  3078. }catch(e){
  3079. debug(e);
  3080. }
  3081. }
  3082. if(loaded)return;
  3083. loaded=true;
  3084. checkPage();
  3085. },500);
  3086. });
  3087. emuIframe.src=lastActiveUrl.replace(/#[^#]*/,"");
  3088. document.body.appendChild(emuIframe);
  3089. }else{
  3090. checkPage();
  3091. }
  3092. }
  3093.  
  3094. var scrollToResizeInited = false;
  3095. var resizePool = [];
  3096. function scrollToResize() {
  3097. if (scrollToResizeInited) return;
  3098. scrollToResizeInited = true;
  3099. var scrollingToResize = false;
  3100. document.addEventListener("scroll", e => {
  3101. if (scrollingToResize) return;
  3102. else {
  3103. scrollingToResize = true;
  3104. setTimeout(() => {scrollingToResize = false}, 500);
  3105. }
  3106. resizePool.forEach(resizeArr => {
  3107. let iframe = resizeArr[1]();
  3108. let frameDoc = resizeArr[2]();
  3109. if(ruleParser.curSiteRule.singleUrl){
  3110. iframe.style.height=frameDoc.body.scrollHeight+"px";
  3111. iframe.style.width=frameDoc.body.scrollWidth+"px";
  3112. }else{
  3113. let pageEle = resizeArr[0]();
  3114. if(pageEle){
  3115. let targetElement = pageEle[0];
  3116. if(pageEle.length > 1){
  3117. targetElement = targetElement.parentNode;
  3118. }
  3119. iframe.style.height=targetElement.scrollHeight+"px";
  3120. frameDoc.documentElement.scrollTop = 0;
  3121. frameDoc.documentElement.scrollLeft = 0;
  3122. while(targetElement && targetElement.offsetParent){
  3123. targetElement.offsetParent.scrollTop = targetElement.offsetTop;
  3124. if(targetElement.offsetParent.scrollTop == 0){
  3125. frameDoc.documentElement.scrollTop += targetElement.offsetTop;
  3126. }
  3127. targetElement.offsetParent.scrollLeft = targetElement.offsetLeft;
  3128. if(targetElement.offsetParent.scrollLeft == 0){
  3129. frameDoc.documentElement.scrollLeft += targetElement.offsetLeft;
  3130. }
  3131. targetElement = targetElement.offsetParent;
  3132. }
  3133. }
  3134. }
  3135. });
  3136. });
  3137. }
  3138.  
  3139. function forceIframe(url, callback){
  3140. url=url.replace(/#[^#]*/,"");
  3141. let curIframe = document.createElement('iframe'),iframeDoc;
  3142. let setPosition = ()=>{
  3143. let getIframe = () => {
  3144. return curIframe;
  3145. };
  3146. let getFrameDoc = () => {
  3147. return iframeDoc;
  3148. };
  3149. if(ruleParser.curSiteRule.singleUrl){
  3150. resizePool.push([() => {}, getIframe, getFrameDoc]);
  3151. }else{
  3152. let pageElement = ruleParser.getPageElement(iframeDoc,iframeDoc.defaultView);
  3153. let getPageEle = () => {
  3154. if (!pageElement) {
  3155. pageElement = ruleParser.getPageElement(iframeDoc,iframeDoc.defaultView);
  3156. }
  3157. return pageElement;
  3158. };
  3159. resizePool.push([getPageEle, getIframe, getFrameDoc]);
  3160. }
  3161. };
  3162. curIframe.name = 'pagetual-iframe';
  3163. curIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  3164. curIframe.frameBorder = '0';
  3165. curIframe.scrolling="no";
  3166. 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;';
  3167. curIframe.addEventListener("load", e=>{
  3168. try{
  3169. iframeDoc=curIframe.contentDocument || curIframe.contentWindow.document;
  3170. }catch(e){
  3171. debug("Stop as cors");
  3172. isPause=true;
  3173. callback(false, false);
  3174. return;
  3175. }
  3176. ruleParser.insertPage(iframeDoc, [], url, null, true);
  3177. callback(curIframe, true);
  3178. let css=ruleParser.curSiteRule.css;
  3179. if(css){
  3180. let styleEle=iframeDoc.createElement("style");
  3181. styleEle.innerHTML=css;
  3182. iframeDoc.head.appendChild(styleEle);
  3183. }
  3184. setPosition();
  3185. let code=ruleParser.curSiteRule.init;
  3186. if(code){
  3187. try{
  3188. Function('doc','win','iframe','"use strict";' + code)(iframeDoc,iframeDoc.defaultView,curIframe);
  3189. }catch(e){
  3190. debug(e);
  3191. }
  3192. }
  3193. });
  3194. let inAction=false,checkTimes=0;
  3195. let forceRefresh=e=>{
  3196. if(inAction || !iframeDoc)return;
  3197. inAction=true;
  3198. let foundNext=()=>{
  3199. document.removeEventListener("scroll", forceRefresh);
  3200. }
  3201. setTimeout(()=>{
  3202. inAction=false;
  3203. if(!ruleParser.nextLinkHref){
  3204. checkTimes++;
  3205. ruleParser.getNextLink(iframeDoc);
  3206. if(ruleParser.nextLinkHref){
  3207. foundNext();
  3208. }else if(checkTimes>=10){
  3209. foundNext();
  3210. }
  3211. }else{
  3212. foundNext();
  3213. }
  3214. },50);
  3215. };
  3216. document.addEventListener("scroll", forceRefresh);
  3217. curIframe.src=url;
  3218. let insert=ruleParser.getInsert();
  3219. if(ruleParser.curSiteRule.singleUrl){
  3220. document.body.appendChild(curIframe);
  3221. }else if(ruleParser.curSiteRule.insertPos==2){
  3222. ruleParser.insert.appendChild(curIframe);
  3223. }else{
  3224. ruleParser.insert.parentNode.insertBefore(curIframe, ruleParser.insert);
  3225. }
  3226. scrollToResize();
  3227. return curIframe;
  3228. }
  3229.  
  3230. function loadPageOver(){
  3231. isLoading=false;
  3232. if(loadingDiv.parentNode){
  3233. loadingDiv.parentNode.removeChild(loadingDiv);
  3234. }
  3235. /*setTimeout(()=>{
  3236. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  3237. if(scrollH <= (window.innerHeight || document.documentElement.clientHeight)){
  3238. nextPage();
  3239. }
  3240. },1);*/
  3241. }
  3242.  
  3243. var tryTimes = 0;
  3244.  
  3245. function nextPage(){
  3246. if(isPause || isLoading || forceState==1)return;
  3247. if(ruleParser.curSiteRule.delay){
  3248. try{
  3249. let checkDelay=Function('"use strict";' + ruleParser.curSiteRule.delay)();
  3250. if(!checkDelay)return;
  3251. }catch(e){
  3252. debug(e);
  3253. }
  3254. }
  3255. let nextLink=ruleParser.nextLinkHref;
  3256. if(!nextLink){
  3257. if(curPage==1){
  3258. ruleParser.getNextLink(document);
  3259. nextLink=ruleParser.nextLinkHref;
  3260. }
  3261. if(!nextLink){
  3262. isPause=true;
  3263. if(curPage==1 && (ruleParser.curSiteRule.pinUrl || tryTimes++ <= 10)){
  3264. setTimeout(()=>{isPause=false},500);
  3265. }
  3266. return;
  3267. }
  3268. }
  3269. let pvGallery=document.querySelector("span.pv-gallery-container");
  3270. if(pvGallery && pvGallery.style.display!="none")return;
  3271. let insert=ruleParser.getInsert();
  3272. if(insert){
  3273. let isJs=/^(javascript|#)/.test(nextLink.replace(location.href,""));
  3274. if(!isJs){
  3275. emuIframe=null;
  3276. lastActiveUrl=nextLink;
  3277. }
  3278. if(location.protocol=="https:" && /^http:/.test(nextLink)){
  3279. nextLink=nextLink.replace(/^http/,"https");
  3280. }
  3281. isLoading=true;
  3282. document.body.appendChild(loadingDiv);
  3283. loadingDiv.style.cssText=loadingCSS;
  3284. let sleep=ruleParser.curSiteRule.sleep||0;
  3285. setTimeout(()=>{
  3286. if(ruleParser.curSiteRule.pageElementByJs){
  3287. var over=ele=>{
  3288. loadPageOver();
  3289. if(ele){
  3290. createPageBar(nextLink);
  3291. ruleParser.insertPage(null, ele, nextLink, null, true);
  3292. if(autoLoadNum>=0){
  3293. if(autoLoadNum!=0 && --autoLoadNum==0){
  3294. autoLoadNum=-1;
  3295. }else{
  3296. nextPage();
  3297. }
  3298. }
  3299. }else{
  3300. debug("Stop as no page when get by js");
  3301. isPause=true;
  3302. }
  3303. };
  3304. try{
  3305. Function("over",'"use strict";' + ruleParser.curSiteRule.pageElementByJs)(over);
  3306. }catch(e){
  3307. debug(e);
  3308. }
  3309. }else if((forceState==3||ruleParser.curSiteRule.action==1) && !isJs){
  3310. requestFromIframe(nextLink, (doc, eles)=>{
  3311. loadPageOver();
  3312. if(eles){
  3313. ruleParser.insertPage(doc, eles, nextLink, ()=>{
  3314. createPageBar(nextLink);
  3315. }, true);
  3316. if(autoLoadNum>=0){
  3317. if(autoLoadNum!=0 && --autoLoadNum==0){
  3318. autoLoadNum=-1;
  3319. }else{
  3320. nextPage();
  3321. }
  3322. }
  3323. }
  3324. });
  3325. }else if((forceState==2||ruleParser.curSiteRule.action==2) && !isJs){
  3326. forceIframe(nextLink, (iframe, eles)=>{
  3327. loadPageOver();
  3328. let pageBar=createPageBar(nextLink);
  3329. if(pageBar)iframe.parentNode.insertBefore(pageBar, iframe);
  3330. if(autoLoadNum>=0){
  3331. if(autoLoadNum!=0 && --autoLoadNum==0){
  3332. autoLoadNum=-1;
  3333. }else{
  3334. nextPage();
  3335. }
  3336. }
  3337. });
  3338. }else{
  3339. if(!isJs){
  3340. requestDoc(nextLink, (eles)=>{
  3341. loadPageOver();
  3342. if(eles){
  3343. createPageBar(nextLink);
  3344. if(autoLoadNum>=0){
  3345. if(autoLoadNum!=0 && --autoLoadNum==0){
  3346. autoLoadNum=-1;
  3347. }else{
  3348. nextPage();
  3349. }
  3350. }
  3351. }
  3352. });
  3353. }else{
  3354. emuPage((doc, eles)=>{
  3355. loadPageOver();
  3356. if(eles){
  3357. ruleParser.insertPage(doc, eles, "", ()=>{
  3358. createPageBar(nextLink);
  3359. }, true);
  3360. if(autoLoadNum>=0){
  3361. if(autoLoadNum!=0 && --autoLoadNum==0){
  3362. autoLoadNum=-1;
  3363. }else{
  3364. nextPage();
  3365. }
  3366. }
  3367. }
  3368. });
  3369. }
  3370. }
  3371. },sleep);
  3372. }
  3373. }
  3374.  
  3375. function init(){
  3376. initRules(()=>{
  3377. initPage();
  3378. });
  3379. }
  3380. setTimeout(()=>{
  3381. init();
  3382. },100);
  3383. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址