东方永页机

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

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

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

QingJ © 2025

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