Greasy Fork 还支持 简体中文。

東方永頁機

自動翻頁脚本 - 自動加載並拼接下一分頁內容,無需規則驅動支持任意網頁

目前為 2022-07-13 提交的版本,檢視 最新版本

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