东方永页机

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

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

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