东方永页机

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

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

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