东方永页机

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

当前为 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.13
  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 origin = location.protocol + '//' + location.host;
  1267. let url = this.basePath || origin;
  1268. if(url.indexOf("http") !== 0) url = origin + url;
  1269. if(src.charAt(0)=="#")return this.curUrl+src;
  1270. if(src.charAt(0)=="?")return this.curUrl.replace(/^([^?#]+).*/, "$1" + src);
  1271. var root_page = /^[^?#]*\//.exec(url)[0],
  1272. root_domain = /^\w+\:\/\/\/?[^\/]+/.exec(root_page)[0],
  1273. absolute_regex = /^\w+\:\/\//;
  1274. this.updateUrl=false;
  1275. while(src.indexOf("../")===0){
  1276. src=src.substr(3);
  1277. root_page=root_page.replace(/\/[^\/]+\/$/, "/");
  1278. this.updateUrl=true;
  1279. }
  1280. src=src.replace(/\.\//,"");
  1281. if (/^\/\/\/?/.test(src)){
  1282. src = location.protocol + src;
  1283. }
  1284. return (absolute_regex.test(src) ? src : ((src.charAt(0) == "/" ? root_domain : root_page) + src));
  1285. }
  1286.  
  1287. getLinkByPage(url, pageNum) {
  1288. if(!url)return;
  1289. if(this.curSiteRule.pageNum){
  1290. let result=this.curSiteRule.pageNum;
  1291. let strMatch=result.match(/\{.*?}/);
  1292. if(!strMatch)return null;
  1293. let urlReg=new RegExp("("+result.replace(strMatch[0], ")\\d+(")+")","i");
  1294. let code=strMatch[0].replace(/^{/,"").replace(/}$/,"").replace(/\$p/g,pageNum);
  1295. if(code==pageNum){
  1296. result=url.replace(urlReg,"$1"+code+"$2");
  1297. }else{
  1298. try{
  1299. code=Function('"use strict";return ' + code)();
  1300. result=url.replace(urlReg,"$1"+code+"$2");
  1301. }catch(e){
  1302. debug(e);
  1303. }
  1304. }
  1305. if(result!=url){
  1306. return result;
  1307. }
  1308. }
  1309. return url.replace(/([&\/\?](p=|page[=\/_-]?))\d+/i, "$1"+pageNum).replace(/([_-])\d+\./i, "$1"+pageNum+".");
  1310. }
  1311.  
  1312. getPageNumFromUrl(url) {
  1313. if(!url)return curPage;
  1314. if(this.curSiteRule.pageNum){
  1315. let result=this.curSiteRule.pageNum;
  1316. let strMatch=result.match(/\{.*?}/);
  1317. if(!strMatch)return null;
  1318. let urlReg=new RegExp(".*"+result.replace(strMatch[0], "(\\d+)")+".*","i");
  1319. let curShowNum=url.replace(urlReg,"$1");
  1320. if (curShowNum!=url){
  1321. let code=strMatch[0].replace(/^{/,"").replace(/}$/,"");
  1322. if(code=="$p"){
  1323. return curShowNum;
  1324. }else{
  1325. try{
  1326. let page1=Function('"use strict";return ' + code.replace("$p", "0"))();
  1327. let page2=Function('"use strict";return ' + code.replace("$p", "1"))();
  1328. let numGap=page2-page1;
  1329. return (curShowNum - page1) / numGap;
  1330. }catch(e){
  1331. debug(e);
  1332. }
  1333. }
  1334. }
  1335. }
  1336. let pageNum=url.replace(/.*[&\/\?](p=|page[=\/_-]?)(\d+).*/i, "$2");
  1337. return pageNum==url?curPage:pageNum;
  1338. }
  1339.  
  1340. getNextLink(doc) {
  1341. let nextLink=null,page,href;
  1342. let getNextLinkByForm=(form,n)=>{
  1343. let params=[];
  1344. [].forEach.call(form.querySelectorAll("input"), input=>{
  1345. if(n && /^(p|page)$/i.test(input.name)){
  1346. params.push('p='+n);
  1347. }else{
  1348. params.push(input.name+'='+input.value);
  1349. }
  1350. });
  1351. return form.action+'?'+params.join('&');
  1352. };
  1353. if(this.curSiteRule.pageElementByJs){
  1354. this.nextLinkHref="#";
  1355. return true;
  1356. }else if(this.curSiteRule.nextLinkByJs){
  1357. try{
  1358. let targetUrl=((typeof _unsafeWindow.pagetualNextLinkByJs=='undefined') ? Function("doc",'"use strict";' + this.curSiteRule.nextLinkByJs) : _unsafeWindow.pagetualNextLinkByJs)(doc);
  1359. if(targetUrl)nextLink={href:targetUrl};
  1360. }catch(e){
  1361. debug(e);
  1362. }
  1363. }else if(this.curSiteRule.nextLinkByUrl){
  1364. let targetUrl=this.curUrl.replace(new RegExp(this.curSiteRule.nextLinkByUrl[0],"i"), this.curSiteRule.nextLinkByUrl[1]);
  1365. if(targetUrl != this.curUrl){
  1366. let reps=targetUrl.match(/{.*?}/g);
  1367. if(reps){
  1368. reps.forEach(rep=>{
  1369. let code=rep.replace("{","").replace("}","").replace(/\(\)/g, "0");
  1370. let result=code.match(/^(\d*)\+1$/);
  1371. if(result){
  1372. result=parseInt(result[1]||1)+1;
  1373. }else{
  1374. try{
  1375. result=Function('"use strict";return ' + code)();
  1376. }catch(e){
  1377. debug(e);
  1378. }
  1379. }
  1380. targetUrl=targetUrl.replace(rep, result);
  1381. });
  1382. }
  1383. }
  1384. nextLink={href:targetUrl};
  1385. }else if(this.curSiteRule.nextLink){
  1386. if(this.curSiteRule.nextLink!="0" && this.curSiteRule.nextLink!=0){
  1387. nextLink=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.nextLink,doc,doc):doc.querySelector(this.curSiteRule.nextLink);
  1388. }
  1389. }else{
  1390. page=this.getPage(doc);
  1391. nextLink=page.next;
  1392. if(nextLink){
  1393. if(nextLink.tagName=="INPUT" && nextLink.parentNode.tagName=="FORM"){
  1394. let form=nextLink.parentNode;
  1395. nextLink.href=getNextLinkByForm(form);
  1396. }
  1397. if(nextLink.parentNode.style.display=="none" || nextLink.style.display=="none" || nextLink.classList.contains("noClick") || nextLink.hasAttribute("disabled")){
  1398. this.nextLinkHref=false;
  1399. return null;
  1400. }else if(doc==document){
  1401. if((!nextLink.href || /^javascript:/.test(nextLink.href)) && !isVisible(nextLink, _unsafeWindow)){
  1402. this.nextLinkHref=false;
  1403. return null;
  1404. }else{
  1405. let nextLinkCs=_unsafeWindow.getComputedStyle(nextLink);
  1406. if(nextLinkCs.cursor=="not-allowed"){
  1407. this.nextLinkHref=false;
  1408. return null;
  1409. }
  1410. this.initNext=nextLink;
  1411. }
  1412. }
  1413. let form=doc.querySelector('#search-form');
  1414. if(!nextLink.href && nextLink.hasAttribute("onclick") && form){
  1415. if(form && /^\d+$/.test(nextLink.innerText)){
  1416. href=getNextLinkByForm(form, nextLink.innerText);
  1417. }
  1418. }
  1419. }
  1420. }
  1421. if(nextLink){
  1422. let needUrl=(this.curSiteRule.action==0 || this.curSiteRule.action==1);
  1423. if(!href)href=nextLink.href;
  1424. if(href && nextLink.getAttribute){
  1425. let _href=nextLink.getAttribute("href");
  1426. if(!_href || _href.charAt(0)=="#" || _href=="?"){
  1427. href="#";
  1428. }else{
  1429. href=_href;
  1430. }
  1431. }
  1432.  
  1433. if((href===""||href===null) && needUrl){
  1434. this.nextLinkHref=false;
  1435. }else if(/^(javascript:void\(0\)|#)/.test(href) && needUrl){
  1436. this.nextLinkHref=false;
  1437. }else{
  1438. this.nextLinkHref=(href && !/^(javascript:|#)/.test(href))?this.canonicalUri(href):"#";
  1439. if(this.nextLinkHref!="#" && (this.nextLinkHref==this.curUrl || this.nextLinkHref==this.curUrl+"#" || this.nextLinkHref==this.oldUrl || this.nextLinkHref==this.oldUrl+"#")){
  1440. this.nextLinkHref=false;
  1441. }else if(doc==document)debug(nextLink);
  1442. }
  1443. }else{
  1444. this.nextLinkHref=false;
  1445. }
  1446. this.preload();
  1447. return nextLink;
  1448. }
  1449.  
  1450. preload(){
  1451. if(!rulesData.preload)return;
  1452. if(!this.nextLinkHref || this.nextLinkHref=="#")return;
  1453. let self=this;
  1454. if(this.curSiteRule && this.curSiteRule.action==1){
  1455. if(!this.preloadIframe){
  1456. this.preloadIframe = document.createElement('iframe');
  1457. let iframe = this.preloadIframe;
  1458. iframe.name = 'pagetual-iframe';
  1459. iframe.width = '100%';
  1460. iframe.height = '0';
  1461. iframe.frameBorder = '0';
  1462. if(ruleParser.curSiteRule.sandbox!=false){
  1463. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1464. }
  1465. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1466. iframe.addEventListener('load', function (e) {
  1467. try{
  1468. let doc=iframe.contentDocument || iframe.contentWindow.document;
  1469. var body = doc.body;
  1470. if (body && body.firstChild) {
  1471. self.lazyImgAction(body.children);
  1472. }
  1473. }catch(e){
  1474. return;
  1475. }
  1476. }, false);
  1477. document.body.appendChild(iframe);
  1478. }
  1479. this.preloadIframe.src = this.nextLinkHref;
  1480. }else{
  1481. _GM_xmlhttpRequest({
  1482. url: this.nextLinkHref,
  1483. method: 'GET',
  1484. overrideMimeType: 'text/html;charset='+document.charset,
  1485. headers: {
  1486. 'Referer': location.href
  1487. },
  1488. timeout: 5000,
  1489. onload: function(res) {
  1490. var doc=null;
  1491. try {
  1492. doc=document.implementation.createHTMLDocument('');
  1493. doc.documentElement.innerHTML=res.response;
  1494. var body = doc.body;
  1495. if (body && body.firstChild) {
  1496. self.lazyImgAction(body.children);
  1497. }
  1498. if(!self.preloadDiv){
  1499. self.preloadDiv = document.createElement('div');
  1500. self.preloadDiv.id = "pagetual-preload";
  1501. self.preloadDiv.style.cssText = 'display:none!important;';
  1502. document.body.appendChild(self.preloadDiv);
  1503. self.checkedImgs={};
  1504. }
  1505. [].forEach.call(doc.images, i=>{
  1506. let iSrc=i.src;
  1507. if(iSrc && !self.checkedImgs[iSrc]){
  1508. self.checkedImgs[iSrc] = true;
  1509. let img = document.createElement('img');
  1510. img.src = iSrc;
  1511. self.preloadDiv.appendChild(img);
  1512. }
  1513. });
  1514. }
  1515. catch (e) {
  1516. return;
  1517. }
  1518. }
  1519. });
  1520. }
  1521. }
  1522.  
  1523. getInsert(refresh) {
  1524. if(refresh){
  1525. this.insert=null;
  1526. }
  1527. if(this.insert && !refresh){
  1528. let parent=this.insert;
  1529. while(parent && parent.nodeName!="BODY"){
  1530. parent=parent.parentNode;
  1531. }
  1532. if(parent && parent.nodeName=="BODY"){
  1533. return this.insert;
  1534. }
  1535. }
  1536. if(this.curSiteRule.insert){
  1537. this.insert=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.insert,document):document.querySelector(this.curSiteRule.insert);
  1538. }else{
  1539. let pageElement=this.getPageElement(document, _unsafeWindow);
  1540. if(pageElement && pageElement.length>0){
  1541. var pELast = pageElement[pageElement.length - 1];
  1542. this.insert = pELast.nextSibling ? pELast.nextSibling : pELast.parentNode.appendChild(document.createTextNode(' '));
  1543. }
  1544. }
  1545. return this.insert;
  1546. }
  1547.  
  1548. pageInit(doc,eles){
  1549. let code=this.curSiteRule.pageInit;
  1550. if(code){
  1551. let initFunc=((typeof _unsafeWindow.pagetualPageInit=='undefined') ? Function("doc", "eles", '"use strict";' + code) : _unsafeWindow.pagetualPageInit);
  1552. let checkInit=(resolve)=>{
  1553. try{
  1554. if(initFunc(doc, eles)===false){
  1555. setTimeout(()=>{
  1556. checkInit(resolve);
  1557. },100);
  1558. } else {
  1559. resolve(true);
  1560. }
  1561. }catch(e){
  1562. resolve(false);
  1563. debug(e);
  1564. }
  1565. };
  1566. return new Promise((resolve) => {
  1567. checkInit(function(e) {
  1568. resolve(e)
  1569. });
  1570. })
  1571. }
  1572. }
  1573.  
  1574. pageAction(doc,eles){
  1575. let code=this.curSiteRule.pageAction;
  1576. if(code){
  1577. try{
  1578. ((typeof _unsafeWindow.pagetualPageAction=='undefined') ? Function("doc", "eles", '"use strict";' + code) : _unsafeWindow.pagetualPageAction)(doc, eles);
  1579. }catch(e){
  1580. debug(e);
  1581. }
  1582. }
  1583. this.lazyImgAction(eles);
  1584. this.openInNewTab(eles);
  1585. }
  1586.  
  1587. openInNewTab(eles){
  1588. if(rulesData.openInNewTab){
  1589. [].forEach.call(eles, ele=>{
  1590. if(ele.tagName=="A" && ele.href && !/^(mailto:|javascript:|#)/.test(ele.href)){
  1591. ele.setAttribute('target', '_blank');
  1592. }else{
  1593. [].forEach.call(ele.querySelectorAll('a[href]:not([href^="mailto:"]):not([href^="javascript:"]):not([href^="#"])'), a=>{
  1594. a.setAttribute('target', '_blank');
  1595. if (a.getAttribute('onclick') == 'atarget(this)') {
  1596. a.removeAttribute('onclick');
  1597. }
  1598. });
  1599. }
  1600. });
  1601. }
  1602. }
  1603.  
  1604. lazyImgAction(eles){
  1605. let setLazyImg=img=>{
  1606. let realSrc;
  1607. if(img.getAttribute("_src") && !img.src){
  1608. realSrc=img.getAttribute("_src");
  1609. }else if(img.dataset && img.dataset.original){
  1610. realSrc=img.dataset.original;
  1611. }else if(img.dataset && img.dataset.lazy){
  1612. realSrc=img.dataset.lazy;
  1613. }else if(img.dataset && img.dataset.src){
  1614. realSrc=img.dataset.src;
  1615. }else if(img._lazyrias && img._lazyrias.srcset){
  1616. realSrc=img._lazyrias.srcset[img._lazyrias.srcset.length-1];
  1617. }else if(img.dataset && img.dataset.origFile){
  1618. realSrc=img.dataset.origFile;
  1619. }else if(img.srcset){
  1620. var srcs=img.srcset.split(/[xw],/),largeSize=0;
  1621. srcs.forEach(srci=>{
  1622. let srcInfo=srci.trim().split(" "),curSize=parseInt(srcInfo[1]);
  1623. if(srcInfo[1] && curSize>largeSize){
  1624. largeSize=curSize;
  1625. realSrc=srcInfo[0];
  1626. }
  1627. });
  1628. }
  1629. if(realSrc){
  1630. img.src=realSrc;
  1631. if(img.style.display=="none"){
  1632. img.style.display="";
  1633. }
  1634. if(img.style.visibility=="hidden"){
  1635. img.style.visibility="";
  1636. }
  1637. if(img.style.opacity==0){
  1638. img.style.opacity="";
  1639. }
  1640. }
  1641. };
  1642. [].forEach.call(eles, ele=>{
  1643. if(ele.tagName=="IMG"){
  1644. setLazyImg(ele);
  1645. }else{
  1646. [].forEach.call(ele.querySelectorAll("img"), img=>{
  1647. setLazyImg(img);
  1648. });
  1649. [].forEach.call(ele.querySelectorAll("div[data-src][data-thumb]"), div=>{
  1650. div.style.setProperty("background-image", "url("+div.dataset.src+")", "important");
  1651. });
  1652. }
  1653. if(ele.tagName=="A" && ele.classList.contains("lazyload")){
  1654. if(ele.dataset.original){
  1655. ele.style.backgroundImage='url("'+ele.dataset.original+'")';
  1656. }
  1657. }else{
  1658. [].forEach.call(ele.querySelectorAll("a.lazyload"), a=>{
  1659. if(a.dataset.original){
  1660. a.style.backgroundImage='url("'+a.dataset.original+'")';
  1661. }
  1662. });
  1663. }
  1664. });
  1665. let lazyImgSrc=this.curSiteRule.lazyImgSrc;
  1666. if(lazyImgSrc){
  1667. [].forEach.call(eles, ele=>{
  1668. [].forEach.call(ele.querySelectorAll("img"), img=>{
  1669. if(img.getAttribute(lazyImgSrc)){
  1670. img.src=img.getAttribute(lazyImgSrc);
  1671. }
  1672. });
  1673. });
  1674. }
  1675. }
  1676.  
  1677. initPage(callback){
  1678. let self=this;
  1679. curPage=1;
  1680. //if(this.curSiteRule.url && !this.curSiteRule.singleUrl)return;
  1681. this.curSiteRule={};
  1682. this.pageDoc=document;
  1683. this.nextLinkHref=null;
  1684. this.curUrl=location.href;
  1685. let base=document.querySelector("base");
  1686. this.basePath=base?base.href:location.href;
  1687. this.getRule(()=>{
  1688. if(self.curSiteRule.enable==0){
  1689. debug("Stop as rule disable");
  1690. isPause=true;
  1691. return;
  1692. }
  1693. //若是再亂匹配就不緩存wedata,或者只在找完本地規則之後再考慮wedata的緩存
  1694. if(self.curSiteRule && !self.curSiteRule.singleUrl && self.curSiteRule.url.length>13){
  1695. self.hpRules=self.hpRules.filter(item=>{return item&&item.url!=self.curSiteRule.url});
  1696. self.hpRules.unshift(self.curSiteRule);
  1697. if(self.hpRules.length>30){
  1698. self.hpRules.pop();
  1699. }
  1700. storage.setItem("hpRules", self.hpRules);
  1701. }
  1702. let css=self.curSiteRule.css || rulesData.customCss;
  1703. if(css && !/^inIframe:/.test(css)){
  1704. _GM_addStyle(css);
  1705. }
  1706. let autoClick=self.curSiteRule.autoClick;
  1707. if(autoClick){
  1708. let autoClickBtn;
  1709. try{
  1710. autoClickBtn=document.querySelector(autoClick);
  1711. }catch(e){
  1712. autoClickBtn=getElementByXpath(autoClick);
  1713. }
  1714. if(autoClickBtn){
  1715. emuClick(autoClickBtn);
  1716. }
  1717. }
  1718. let code=self.curSiteRule.init;
  1719. if(code){
  1720. try{
  1721. ((typeof _unsafeWindow.pagetualInit=='undefined') ? Function('doc','win','iframe','"use strict";' + code) : _unsafeWindow.pagetualInit)(null,null,null);
  1722. }catch(e){
  1723. debug(e);
  1724. }
  1725. }
  1726. self.getNextLink(document);
  1727. callback();
  1728. });
  1729. }
  1730.  
  1731. insertElement(ele) {
  1732. if(this.curSiteRule.insertPos==2){
  1733. this.insert.appendChild(ele);
  1734. }else{
  1735. this.insert.parentNode.insertBefore(ele, this.insert);
  1736. }
  1737. }
  1738.  
  1739. async insertPage(doc, eles, url, callback, tried){
  1740. this.oldUrl=this.curUrl;
  1741. let oldTitle=this.pageDoc.title;
  1742. this.pageDoc=doc;
  1743. this.curUrl=url;
  1744. let nextLink=this.getNextLink(doc);
  1745. this.nextTitle="";
  1746. if(this.curSiteRule.pageBarText){
  1747. if(this.curSiteRule.pageBarText==1 || this.curSiteRule.pageBarText==true){
  1748. this.nextTitle=doc.title;
  1749. }else{
  1750. try{
  1751. this.nextTitle=((typeof _unsafeWindow.pagetualPageBarText=='undefined') ? Function("doc",'"use strict";' + this.curSiteRule.pageBarText) : _unsafeWindow.pagetualPageBarText)(doc);
  1752. }catch(e){
  1753. debug(e);
  1754. }
  1755. }
  1756. }
  1757. if(curPage==1 && !tried && !nextLink && this.curSiteRule.singleUrl && this.curSiteRule.pageElement && this.curSiteRule.action!=0){
  1758. this.curSiteRule.action=1;
  1759. this.curUrl=location.href;
  1760. return false;
  1761. }
  1762. if(callback)callback(eles);
  1763. this.getInsert();
  1764. var self=this,newEles=[];
  1765. if(!eles || eles.length==0 || !self.insert || !self.insert.parentNode){
  1766. }else{
  1767. isLoading=true;
  1768. await this.pageInit(doc, eles);
  1769. [].forEach.call(eles, ele=>{
  1770. let newEle=ele.cloneNode(true);
  1771. let oldCanvass=ele.querySelectorAll("canvas");
  1772. let newCanvass=newEle.querySelectorAll("canvas");
  1773. if(self.updateUrl){
  1774. [].forEach.call(newEle.querySelectorAll("img"), img=>{
  1775. img.src=self.canonicalUri(img.getAttribute("src"));
  1776. });
  1777. [].forEach.call(newEle.querySelectorAll("a"), a=>{
  1778. a.href=self.canonicalUri(a.getAttribute("href"));
  1779. });
  1780. }
  1781. for(let i=0;i<oldCanvass.length;i++){
  1782. let oldCanvas=oldCanvass[i];
  1783. let newCanvas=newCanvass[i];
  1784. newCanvas.getContext('2d').drawImage(oldCanvas, 0, 0);
  1785. }
  1786. self.insertElement(newEle);
  1787. newEles.push(newEle);
  1788. });
  1789. }
  1790. this.pageAction(doc, newEles);
  1791. if(this.oldUrl!=location.href){
  1792. let isJs=/^(javascript|#)/.test(this.oldUrl.replace(location.href,""));
  1793. let enableHistory = this.curSiteRule.history;
  1794. if (enableHistory == 1) {
  1795. enableHistory = true;
  1796. } else if (enableHistory == 0) {
  1797. enableHistory = false;
  1798. } else {
  1799. enableHistory = rulesData.enableHistory;
  1800. }
  1801. if(enableHistory && !isJs){
  1802. _unsafeWindow.history.replaceState(undefined, oldTitle, this.oldUrl);
  1803. document.title=oldTitle;
  1804. }
  1805. }
  1806. isLoading=false;
  1807. return true;
  1808. }
  1809. }
  1810. var ruleParser = new RuleParser();
  1811.  
  1812. class Picker {
  1813. static picker;
  1814. constructor() {
  1815. this.init();
  1816. }
  1817.  
  1818. static getInstance() {
  1819. if (!Picker.picker) {
  1820. Picker.picker = new Picker();
  1821. }
  1822. return Picker.picker;
  1823. }
  1824.  
  1825. init() {
  1826. let self = this;
  1827. this.signList = [];
  1828. let cssText = `
  1829. body.pagetual-picker,
  1830. body.pagetual-picker *:hover,
  1831. body.pagetual-picker a:hover {
  1832. cursor: crosshair !important;
  1833. }
  1834. #pagetual-picker {
  1835. position: fixed;
  1836. top: 0;
  1837. left: calc(50% - 160px);
  1838. background: aliceblue;
  1839. padding: 10px;
  1840. border-radius: 5px;
  1841. text-align: center;
  1842. opacity: 0.95;
  1843. color: #161616;
  1844. z-index: 2147483647;
  1845. font-size: 16px;
  1846. box-shadow: rgb(0 0 0) 0px 0px 10px;
  1847. }
  1848. #pagetual-picker>.title {
  1849. margin: -5px 45px 10px 45px;
  1850. font-size: 20px;
  1851. font-weight: bold;
  1852. cursor: move;
  1853. border-bottom: 1px solid black;
  1854. user-select: none;
  1855. color: orangered;
  1856. }
  1857. #pagetual-picker button {
  1858. background: none;
  1859. border: none;
  1860. vertical-align: top;
  1861. transition: transform .15s ease-in-out;
  1862. float: right;
  1863. cursor: pointer;
  1864. }
  1865. #pagetual-picker button:hover {
  1866. transform: scale(1.2);
  1867. }
  1868. #pagetual-picker>.closePicker {
  1869. position: absolute;
  1870. top: 3px;
  1871. right: 10px;
  1872. }
  1873. #pagetual-picker>.selector{
  1874. display: inline-block;
  1875. width: 290px;
  1876. height: 20px;
  1877. max-width: 65vw;
  1878. padding: 6px 12px;
  1879. font-size: 16px;
  1880. font-weight: 400;
  1881. line-height: 1.5;
  1882. color: #495057;
  1883. background-color: #fff;
  1884. background-clip: padding-box;
  1885. border: 1px solid #ced4da;
  1886. border-radius: 4px;
  1887. transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out;
  1888. box-sizing: content-box;
  1889. }
  1890. #pagetual-picker>.selector:focus {
  1891. color: #495057;
  1892. background-color: #fff;
  1893. border-color: #80bdff;
  1894. outline: 0;
  1895. box-shadow: 0 0 0 3.2px rgb(0 123 255 / 25%);
  1896. }
  1897. #pagetual-picker .xpath {
  1898. line-height: 20px;
  1899. height: 25px;
  1900. width: 25px;
  1901. margin-left: 5px;
  1902. vertical-align: middle;
  1903. appearance: auto;
  1904. }
  1905. #pagetual-picker label {
  1906. font-size: 18px;
  1907. line-height: 25px;
  1908. vertical-align: middle;
  1909. display: inline-block;
  1910. }
  1911. #pagetual-picker .bottom {
  1912. text-align: left;
  1913. margin-top: 10px;
  1914. }
  1915. #pagetual-picker .bottom>button {
  1916. float: right;
  1917. }
  1918. #pagetual-picker svg {
  1919. width: 30px;
  1920. height: 30px;
  1921. vertical-align: middle;
  1922. fill: #161616;
  1923. overflow: hidden;
  1924. }
  1925. #pagetual-picker .allpath {
  1926. font-size: 18px;
  1927. margin: 10px;
  1928. max-width: 350px;
  1929. word-break: break-all;
  1930. cursor: context-menu;
  1931. }
  1932. #pagetual-picker .allpath>span.path {
  1933. cursor: pointer;
  1934. }
  1935. #pagetual-picker .allpath>span.path:hover {
  1936. color: orangered;
  1937. }
  1938. `;
  1939. _GM_addStyle(cssText);
  1940. this.mainSignDiv = this.createSignDiv();
  1941. this.allSignDiv = [];
  1942. let frame = document.createElement("div");
  1943. frame.id = "pagetual-picker";
  1944. frame.innerHTML = createHTML(`
  1945. <div class="title">${i18n("picker")}</div>
  1946. <button title="${i18n("closePicker")}" type="button" class="closePicker">
  1947. <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2754">
  1948. <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">
  1949. </path>
  1950. </svg>
  1951. </button>
  1952. <div class="allpath"></div>
  1953. <textarea class="selector" name="selector" placeholder="${i18n("pickerPlaceholder")}"></textarea>
  1954. <button id="check" title="${i18n("pickerCheck")}" type="button">
  1955. <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1609">
  1956. <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">
  1957. </path>
  1958. </svg>
  1959. </button>
  1960. <div class="bottom">
  1961. <input class="xpath" name="xpath" id="checkbox_id" type="checkbox">
  1962. <label for="checkbox_id">XPath</label>
  1963. <button id="edit" title="${i18n("gotoEdit")}" type="button">
  1964. <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4129" style="color: orangered;fill: orangered;">
  1965. <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">
  1966. </path>
  1967. </svg>
  1968. </button>
  1969. </div>
  1970. `);
  1971. let closeBtn = frame.querySelector(".closePicker");
  1972. let title = frame.querySelector(".title");
  1973. let allpath = frame.querySelector(".allpath");
  1974. let selectorInput = frame.querySelector(".selector");
  1975. let xpath = frame.querySelector(".xpath");
  1976. let checkBtn = frame.querySelector("#check");
  1977. let editBtn = frame.querySelector("#edit");
  1978. closeBtn.addEventListener("click", e => {
  1979. self.close();
  1980. }, true);
  1981. let moving = false;
  1982. let moveHanlder = e => {
  1983. frame.style.left = e.clientX - 160 + "px";
  1984. frame.style.top = e.clientY - 15 + "px";
  1985. e.stopPropagation();
  1986. e.preventDefault();
  1987. };
  1988. let upHanlder = e => {
  1989. moving = false;
  1990. document.removeEventListener("mousemove", moveHanlder, true);
  1991. title.removeEventListener("mouseup", upHanlder, true);
  1992. e.stopPropagation();
  1993. e.preventDefault();
  1994. };
  1995. title.addEventListener("mousedown", e => {
  1996. moving = true;
  1997. document.addEventListener("mousemove", moveHanlder, true);
  1998. title.addEventListener("mouseup", upHanlder, true);
  1999. });
  2000. frame.addEventListener("mouseenter", e => {
  2001. if (moving) return;
  2002. if (self.mainSignDiv.parentNode) self.mainSignDiv.parentNode.removeChild(self.mainSignDiv);
  2003. self.checkInputSelector();
  2004. });
  2005. frame.addEventListener("mouseleave", e => {
  2006. if (moving) return;
  2007. document.body.appendChild(self.mainSignDiv);
  2008. self.clearSigns();
  2009. });
  2010. checkBtn.addEventListener("click", e => {
  2011. self.checkInputSelector();
  2012. });
  2013. xpath.addEventListener("click", e => {
  2014. if (!selectorInput.value) {
  2015. self.setSelectorDiv("");
  2016. return;
  2017. }
  2018. let element = !xpath.checked ? getElementByXpath(selectorInput.value) : document.querySelector(selectorInput.value);
  2019. let selector = self.getSelectorFromEle(element);
  2020. self.setSelectorDiv(selector);
  2021. selectorInput.value = selector;
  2022. });
  2023. editBtn.addEventListener("click", e => {
  2024. let editTemp;
  2025. if(ruleParser.curSiteRule.url && !ruleParser.curSiteRule.singleUrl){
  2026. editTemp=ruleParser.curSiteRule;
  2027. }else{
  2028. editTemp={
  2029. name: document.title,
  2030. url: "^"+location.origin.replace(/\./g,"\\.")
  2031. };
  2032. }
  2033. if (selectorInput.value) {
  2034. editTemp.pageElement = selectorInput.value;
  2035. let preType = editTemp.type === 0;
  2036. if (xpath.checked !== preType) editTemp.type = xpath.checked ? 0 : 1;
  2037. }
  2038. rulesData.editTemp=editTemp;
  2039. storage.setItem("rulesData", rulesData);
  2040. _GM_openInTab(configPage, {active: true});
  2041. });
  2042. this.frame = frame;
  2043. this.xpath = xpath;
  2044. this.allpath = allpath;
  2045. this.selectorInput = selectorInput;
  2046. this.moveHandler = e => {
  2047. if (e.target === document) return;
  2048. self.adjustSignDiv(self.mainSignDiv, self.getTarget(e.target));
  2049. };
  2050. this.clickHandler = e => {
  2051. if (self.inPicker) {
  2052. e.stopPropagation();
  2053. e.preventDefault();
  2054. }
  2055. let target = self.getTarget(e.target);
  2056. let selector = self.getSelectorFromEle(target);
  2057. self.setSelectorDiv(selector);
  2058. selectorInput.value = selector;
  2059. };
  2060. }
  2061.  
  2062. getTarget(ele) {
  2063. while (ele.parentNode && (ele.scrollWidth === 0 || ele.scrollHeight === 0)) {
  2064. ele = ele.parentNode;
  2065. }
  2066. return ele;
  2067. }
  2068.  
  2069. close() {
  2070. this.clearSigns();
  2071. if (this.frame.parentNode) this.frame.parentNode.removeChild(this.frame);
  2072. if (this.mainSignDiv.parentNode) this.mainSignDiv.parentNode.removeChild(this.mainSignDiv);
  2073. document.body.classList.remove("pagetual-picker");
  2074. document.body.removeEventListener("mousemove", this.moveHandler, true);
  2075. document.body.removeEventListener("click", this.clickHandler, true);
  2076. this.inPicker = false;
  2077. }
  2078.  
  2079. setImportant(ele, prop, value) {
  2080. ele.style.setProperty(prop, value, "important");
  2081. }
  2082.  
  2083. createSignDiv() {
  2084. let signDiv = document.createElement("div");
  2085. this.setImportant(signDiv, "position", "absolute");
  2086. this.setImportant(signDiv, "pointer-events", "none");
  2087. this.setImportant(signDiv, "z-index", "2147483647");
  2088. this.setImportant(signDiv, "background", "rgba(120, 170, 210, 0.6)");
  2089. this.setImportant(signDiv, "transition", "all 0.15s ease-out");
  2090. this.setImportant(signDiv, "box-shadow", "rgb(0 0 0) 0px 0px 3px 0px");
  2091. return signDiv;
  2092. }
  2093.  
  2094. adjustSignDiv(div, target) {
  2095. let rect = target.getBoundingClientRect();
  2096. this.setImportant(div, "width", rect.width + "px");
  2097. this.setImportant(div, "height", rect.height + "px");
  2098. this.setImportant(div, "left", rect.left + window.scrollX + "px");
  2099. this.setImportant(div, "top", rect.top + window.scrollY + "px");
  2100. }
  2101.  
  2102. getSelectorFromEle(ele) {
  2103. return this.xpath.checked ? createXPathFromElement(ele) : geneSelector(ele, true);
  2104. }
  2105.  
  2106. setSelectorDiv(selector) {
  2107. let self = this;
  2108. this.allpath.innerHTML = createHTML("");
  2109. if (!selector) return;
  2110. if (this.xpath.checked) {
  2111. let span = document.createElement("span");
  2112. span.innerText = selector;
  2113. span.addEventListener("click", e => {
  2114. self.selectorInput.value = selector;
  2115. self.checkInputSelector();
  2116. }, true);
  2117. this.allpath.appendChild(span);
  2118. } else {
  2119. selector.split(">").forEach((item, index) => self.geneSelectorItem(item, index));
  2120. }
  2121. }
  2122.  
  2123. geneSelectorItem(item, index) {
  2124. let self = this;
  2125. item = item.trim();
  2126. if (!item) return;
  2127. if (index !== 0) {
  2128. let span = document.createElement("span");
  2129. span.innerText = " > ";
  2130. this.allpath.appendChild(span);
  2131. }
  2132. let span = document.createElement("span");
  2133. span.className = "path";
  2134. span.innerText = item;
  2135. span.addEventListener("click", e => {
  2136. let selector = "";
  2137. let target = e.target;
  2138. while (target) {
  2139. selector = target.innerText + selector;
  2140. target = target.previousElementSibling;
  2141. }
  2142. self.selectorInput.value = selector;
  2143. self.checkInputSelector();
  2144. }, true);
  2145. this.allpath.appendChild(span);
  2146. }
  2147.  
  2148. checkInputSelector() {
  2149. let self = this;
  2150. this.clearSigns();
  2151. if (!this.selectorInput.value) return;
  2152. let eles = this.xpath.checked ? getAllElementsByXpath(this.selectorInput.value) : document.querySelectorAll(this.selectorInput.value);
  2153. if (eles && eles.length > 0) {
  2154. eles.forEach(ele => {
  2155. let sign = self.createSignDiv();
  2156. document.body.appendChild(sign);
  2157. self.adjustSignDiv(sign, ele);
  2158. self.signList.push(sign);
  2159. });
  2160. }
  2161. }
  2162.  
  2163. clearSigns() {
  2164. this.signList.forEach(sign => {
  2165. if (sign.parentNode) sign.parentNode.removeChild(sign);
  2166. });
  2167. this.signList = [];
  2168. }
  2169.  
  2170. start() {
  2171. if (this.inPicker) return;
  2172. this.inPicker = true;
  2173. document.documentElement.appendChild(this.frame);
  2174. document.body.appendChild(this.mainSignDiv);
  2175. document.body.classList.add("pagetual-picker");
  2176.  
  2177. document.body.addEventListener("mousemove", this.moveHandler, true);
  2178. document.body.addEventListener("click", this.clickHandler, true);
  2179. this.xpath.checked = ruleParser.curSiteRule.type === 0;
  2180. this.setSelectorDiv(ruleParser.curSiteRule.pageElement || "");
  2181. }
  2182. }
  2183.  
  2184. function initConfig(){
  2185. initView();
  2186. _GM_registerMenuCommand(i18n(forceState==1?"enable":"disableSite"), ()=>{
  2187. forceState=(forceState==1?0:1);
  2188. storage.setItem("forceState_"+location.host, forceState);
  2189. showTips(i18n(forceState==1?"disableSiteTips":"enableSiteTips"));
  2190. if(!ruleParser.curSiteRule.url) location.reload();
  2191. });
  2192. _GM_registerMenuCommand(i18n("update"), ()=>{
  2193. updateRules(()=>{
  2194. showTips(i18n("updateSucc"));
  2195. location.reload();
  2196. },(rule,err)=>{
  2197. showTips("Update "+rule.url+" rules fail!");
  2198. });
  2199. showTips(i18n("beginUpdate"));
  2200. });
  2201. if(guidePage.test(location.href)){
  2202. function createEdit(){
  2203. var options = {
  2204. mode: 'code',
  2205. modes: ['code', 'tree'],
  2206. templates: [
  2207. {
  2208. text: 'New site',
  2209. title: 'Insert a new site',
  2210. className: 'jsoneditor-type-object',
  2211. field: 'SiteTemplate',
  2212. value: {
  2213. 'name': 'Site name',
  2214. 'url': 'Site url'
  2215. }
  2216. }
  2217. ],
  2218. schema: {
  2219. "title": "Sites data",
  2220. "description": "Object containing site config",
  2221. "type": "array",
  2222. "items": {
  2223. "properties": {
  2224. "name": {
  2225. "title": "Site Name",
  2226. "description": "The site's name.",
  2227. "examples": [
  2228. "Google"
  2229. ],
  2230. "type": "string"
  2231. },
  2232. "url": {
  2233. "title": "Site Url",
  2234. "description": "The Regexp of site's url.",
  2235. "examples": [
  2236. "^https:\/\/yande\\.re\/"
  2237. ],
  2238. "type": "string"
  2239. }
  2240. },
  2241. "required": ["name", "url"]
  2242. }
  2243. }
  2244. };
  2245. var container = document.getElementById("jsoneditor");
  2246. container.style.height='800px';
  2247. var editor = new JSONEditor(container, options);
  2248. editor.set(ruleParser.customRules);
  2249. document.querySelector("#saveBtn").onclick=e=>{
  2250. try{
  2251. storage.setItem("hpRules", []);
  2252. let customRules=editor.get();
  2253. if(!customRules){
  2254. storage.setItem("customRules", "");
  2255. }else{
  2256. if(Array && Array.isArray && !Array.isArray(customRules)){
  2257. showTips("Rules must be a Array!");
  2258. return;
  2259. }
  2260. debug(customRules);
  2261. storage.setItem("customRules", customRules);
  2262. }
  2263. }catch(e){
  2264. debug(e);
  2265. showTips("JSON error, check again!");
  2266. return;
  2267. }
  2268. showTips("Edit successfully");
  2269. };
  2270. }
  2271. if(JSONEditor){
  2272. createEdit();
  2273. }else{
  2274. window.onload = e => {
  2275. createEdit();
  2276. }
  2277. }
  2278. return true;
  2279. }
  2280. if(location.href.indexOf("PagetualGuide")!=-1) return true;
  2281.  
  2282. var configCon,insertPos;
  2283. var noRules=!rulesData.urls || rulesData.urls.length===0;
  2284. if(ruleImportUrlReg.test(location.href)){
  2285. if(noRules){
  2286. setTimeout(() => {
  2287. showTips(i18n("firstAlert"));
  2288. }, 3000);
  2289. setTimeout(() => {
  2290. showTips(i18n("firstAlert"));
  2291. }, 6000);
  2292. showTips(i18n("firstAlert"));
  2293. }
  2294. let importBtn = document.createElement("button"), targetPre;
  2295. importBtn.innerText = i18n("import");
  2296. importBtn.style.marginTop = "100px";
  2297. importBtn.style.float = "right";
  2298. importBtn.style.position = "static";
  2299. importBtn.style.display = "block";
  2300. importBtn.style.fontSize = "20px";
  2301. importBtn.addEventListener("click", e => {
  2302. if (targetPre) {
  2303. if (importBtn.parentNode) importBtn.parentNode.removeChild(importBtn);
  2304. try {
  2305. let rules=targetPre.innerText.trim();
  2306. let isContent=/['"]name['"]/i.test(rules);
  2307. if(isContent){
  2308. let ruleList=JSON.parse(`[${rules}]`);
  2309. for(let i in ruleList){
  2310. let hasRule = false;
  2311. let r = ruleList[i];
  2312. for(let j in ruleParser.customRules){
  2313. if(ruleParser.customRules[j].name == r.name){
  2314. ruleParser.customRules[j] = r;
  2315. hasRule = true;
  2316. break;
  2317. }
  2318. }
  2319. if(!hasRule)ruleParser.customRules.push(r);
  2320. }
  2321. storage.setItem("customRules", ruleParser.customRules);
  2322. storage.setItem("hpRules", []);
  2323. showTips(i18n("importSucc"));
  2324. }else{
  2325. rules=rules.split("\n");
  2326. let diff=false;
  2327. for(let c=0;c<rules.length;c++){
  2328. let urlArr=rules[c].split("|"),url,type=1;
  2329. if(urlArr.length==1){
  2330. url=urlArr[0].trim();
  2331. if(!/^http/.test(url)){
  2332. showTips("Wrong url, check again!");
  2333. return;
  2334. }
  2335. }else if(urlArr.length==2){
  2336. type=urlArr[0].trim();
  2337. url=urlArr[1].trim();
  2338. if(!/^http/.test(url)){
  2339. showTips("Wrong url, check again!");
  2340. return;
  2341. }
  2342. }else{
  2343. break;
  2344. }
  2345. let maxId=0,hasUrl=false;
  2346. if(!rulesData.urls){
  2347. rulesData.urls=[];
  2348. maxId=1;
  2349. }else{
  2350. rulesData.urls.forEach(u=>{
  2351. if(maxId<u.id){
  2352. maxId=u.id;
  2353. }
  2354. if(u.url==url){
  2355. hasUrl=true;
  2356. }
  2357. });
  2358. if(hasUrl)break;
  2359. }
  2360. diff=true;
  2361. if(!rulesData.sort)rulesData.sort=[1];
  2362. rulesData.urls.push({id:maxId+1,url:url,type:type});
  2363. rulesData.sort.unshift(maxId+1);
  2364. }
  2365. if(!diff)return;
  2366. storage.setItem("rulesData", rulesData);
  2367.  
  2368. if(rulesData.urls)ruleUrls=ruleUrls.concat(rulesData.urls);
  2369. if(rulesData.sort){
  2370. let urls=[];
  2371. rulesData.sort.forEach(id=>{
  2372. for(let s=0;s<ruleUrls.length;s++){
  2373. if(id==ruleUrls[s].id){
  2374. urls.push(ruleUrls[s]);
  2375. break;
  2376. }
  2377. }
  2378. });
  2379. ruleUrls=urls;
  2380. }
  2381. updateRules(()=>{
  2382. showTips(i18n("updateSucc"));
  2383. location.reload();
  2384. },(rule,err)=>{
  2385. showTips("Update "+rule.url+" rules fail!");
  2386. });
  2387. showTips(i18n("beginUpdate"));
  2388. }
  2389. } catch (e) {
  2390. _GM_notification(e.toString());
  2391. }
  2392. }
  2393. });
  2394. document.addEventListener("mouseover", e => {
  2395. if (e.target.tagName === "PRE") {
  2396. let nameAttr=e.target.getAttribute("name");
  2397. if(nameAttr=="pagetual" || nameAttr=="user-content-pagetual"){
  2398. targetPre = e.target;
  2399. let clientHeight = 35 - e.target.clientHeight;
  2400. if (clientHeight > -20) clientHeight = -20;
  2401. importBtn.style.marginTop = `${clientHeight}px`;
  2402. e.target.appendChild(importBtn);
  2403. }
  2404. }
  2405. });
  2406.  
  2407. if(location.href==configPage){
  2408. _GM_addStyle(`
  2409. p>span:nth-child(1),p>span:nth-child(2),p>span:nth-child(3){
  2410. cursor: pointer;
  2411. user-select: none;
  2412. }
  2413. p>span:nth-child(1):hover,p>span:nth-child(2):hover,p>span:nth-child(3):hover{
  2414. color:red;
  2415. }
  2416. .updateDate{
  2417. cursor: pointer;
  2418. user-select: none;
  2419. }
  2420. .updateDate:hover{
  2421. color:red;
  2422. }
  2423. input[type=number]::-webkit-inner-spin-button,
  2424. input[type=number]::-webkit-outer-spin-button {
  2425. -webkit-appearance: none;
  2426. margin: 0;
  2427. }
  2428. input[type=number] {
  2429. -moz-appearance:textfield;
  2430. }
  2431. `);
  2432. document.querySelector("[name='user-content-click2import']").innerText=i18n("click2ImportRule")
  2433. configCon=document.querySelector(".markdown-body");
  2434. insertPos=configCon.querySelector("hr");
  2435.  
  2436. if(!noRules){
  2437. document.querySelector("pre[name='user-content-pagetual']").style.display="none";
  2438. document.querySelector("p[name='user-content-click2import']").style.display="none";
  2439. }
  2440. }else return true;
  2441. }else return false;
  2442. class Rulebar {
  2443. init(ruleUrl){
  2444. this.ruleUrl=ruleUrl;
  2445. this.item=document.createElement("p");
  2446. this.item.dataset.id=this.ruleUrl.id;
  2447. let url=document.createElement("span");
  2448. url.innerHTML=ruleUrl.url;
  2449. let up=document.createElement("span");
  2450. up.innerHTML="↑ ";
  2451. up.title=i18n("sortTitle");
  2452. let down=document.createElement("span");
  2453. down.innerHTML="↓ ";
  2454. down.title=i18n("sortTitle");
  2455. let del=document.createElement("span");
  2456. del.innerHTML="× ";
  2457. up.onclick=e=>{
  2458. this.moveUp();
  2459. };
  2460. down.onclick=e=>{
  2461. this.moveDown();
  2462. };
  2463. del.onclick=e=>{
  2464. this.del();
  2465. };
  2466. this.item.appendChild(up);
  2467. this.item.appendChild(down);
  2468. this.item.appendChild(del);
  2469. this.item.appendChild(url);
  2470. configCon.insertBefore(this.item, insertPos);
  2471. }
  2472. saveSort(){
  2473. let sort=[];
  2474. [].forEach.call(this.item.parentNode.querySelectorAll("p[data-id]"), i=>{
  2475. sort.push(i.dataset.id);
  2476. });
  2477. rulesData.sort=sort;
  2478. storage.setItem("rulesData", rulesData);
  2479. }
  2480. moveUp(){
  2481. let preE=this.item.previousElementSibling;
  2482. if(preE.tagName=="P" && preE.children.length>1){
  2483. this.item.parentNode.insertBefore(this.item,preE);
  2484. this.saveSort();
  2485. }
  2486. }
  2487. moveDown(){
  2488. let nextE=this.item.nextElementSibling;
  2489. if(nextE.tagName=="P" && nextE.children.length>1){
  2490. this.item.parentNode.insertBefore(nextE,this.item);
  2491. this.saveSort();
  2492. }
  2493. }
  2494. del(){
  2495. if(this.ruleUrl.id<2){
  2496. showTips(i18n("cantDel"));
  2497. }else if(window.confirm(i18n("confirmDel"))){
  2498. for(let u=0;u<rulesData.urls.length;u++){
  2499. if(this.ruleUrl.id==rulesData.urls[u].id){
  2500. rulesData.urls.splice(u,1);
  2501. break;
  2502. }
  2503. }
  2504. for(let u=0;u<ruleUrls.length;u++){
  2505. if(this.ruleUrl.id==ruleUrls[u].id){
  2506. ruleUrls.splice(u,1);
  2507. break;
  2508. }
  2509. }
  2510. for(let u=0;u<rulesData.sort.length;u++){
  2511. if(this.ruleUrl.id==rulesData.sort[u]){
  2512. rulesData.sort.splice(u,1);
  2513. break;
  2514. }
  2515. }
  2516. storage.setItem("rulesData", rulesData);
  2517. ruleParser.rules=ruleParser.rules.filter(item=>{return item.from!=this.ruleUrl.id});
  2518. storage.setItem("rules", ruleParser.rules);
  2519. this.item.parentNode.removeChild(this.item);
  2520. //location.reload();
  2521. }
  2522. }
  2523. }
  2524. let updateP=document.createElement("p"),i=0;
  2525. let now=new Date().getTime(),inUpdate=false;
  2526.  
  2527.  
  2528. let pastDate=(new Date(updateDate)).toString(),passStr;
  2529. let passTime=(now-updateDate)/1000;
  2530. if(isNaN(passTime)){
  2531. passStr=i18n("firstUpdate");
  2532. }else if(passTime<60){
  2533. passStr=i18n("passSec", parseInt(passTime))+" 👆 "+i18n("click2update");
  2534. }else if(passTime<60*60){
  2535. passStr=i18n("passMin", parseInt(passTime/60))+" 👆 "+i18n("click2update");
  2536. }else if(passTime<60*60*24){
  2537. passStr=i18n("passHour", parseInt(passTime/3600))+" 👆 "+i18n("click2update");
  2538. }else{
  2539. passStr=i18n("passDay", parseInt(passTime/86400))+" 👆 "+i18n("click2update");
  2540. }
  2541.  
  2542.  
  2543. updateP.className="updateDate";
  2544. updateP.innerHTML=passStr;
  2545. updateP.title=i18n("update")+" - "+pastDate;
  2546. updateP.onclick=e=>{
  2547. updateRules(()=>{
  2548. showTips(i18n("updateSucc"));
  2549. updateP.innerHTML=i18n("passSec", 0);
  2550. updateP.title=i18n("update");
  2551. },(rule,err)=>{
  2552. showTips("Update "+rule.url+" rules fail!");
  2553. });
  2554. showTips(i18n("beginUpdate"));
  2555. };
  2556. configCon.insertBefore(updateP, insertPos);
  2557. if(ruleUrls){
  2558. ruleUrls.forEach(ruleUrl=>{
  2559. var rulebar=new Rulebar();
  2560. rulebar.init(ruleUrl);
  2561. });
  2562. }
  2563. let customUrlsTitle=document.createElement("h2");
  2564. customUrlsTitle.innerHTML=i18n("customUrls");
  2565. configCon.insertBefore(customUrlsTitle, insertPos);
  2566. let customUrlsInput=document.createElement("textarea");
  2567. customUrlsInput.style.width="100%";
  2568. customUrlsInput.placeholder="http://wedata.net/databases/AutoPagerize/items_all.json";
  2569. configCon.insertBefore(customUrlsInput, insertPos);
  2570.  
  2571. let btns=document.createElement("div");
  2572. btns.style.display="flex";
  2573. configCon.insertBefore(btns, insertPos);
  2574. let upBtnImg=document.createElement("div");
  2575. upBtnImg.style.width="50%";
  2576. let upBtnImgTitle=document.createElement("h2");
  2577. upBtnImgTitle.style.whiteSpace="nowrap";
  2578. upBtnImgTitle.style.overflow="auto";
  2579. upBtnImgTitle.innerHTML=i18n("upBtnImg");
  2580. upBtnImg.appendChild(upBtnImgTitle);
  2581. let upBtnImgInput=document.createElement("input");
  2582. upBtnImgInput.style.width="100%";
  2583. upBtnImgInput.placeholder="data:image/png;base64,UpBtn";
  2584. upBtnImgInput.value=rulesData.upBtnImg||'';
  2585. upBtnImg.appendChild(upBtnImgInput);
  2586. btns.appendChild(upBtnImg);
  2587.  
  2588. let downBtnImg=document.createElement("div");
  2589. downBtnImg.style.width="50%";
  2590. let downBtnImgTitle=document.createElement("h2");
  2591. downBtnImgTitle.style.whiteSpace="nowrap";
  2592. downBtnImgTitle.style.overflow="auto";
  2593. downBtnImgTitle.innerHTML=i18n("downBtnImg");
  2594. downBtnImg.appendChild(downBtnImgTitle);
  2595. let downBtnImgInput=document.createElement("input");
  2596. downBtnImgInput.style.width="100%";
  2597. downBtnImgInput.placeholder="data:image/png;base64,DownBtn";
  2598. downBtnImgInput.value=rulesData.downBtnImg||'';
  2599. downBtnImg.appendChild(downBtnImgInput);
  2600. btns.appendChild(downBtnImg);
  2601.  
  2602. let otherBtns=document.createElement("div");
  2603. otherBtns.style.display="flex";
  2604. configCon.insertBefore(otherBtns, insertPos);
  2605. let loadingText=document.createElement("div");
  2606. loadingText.style.width="100%";
  2607. let loadingTextTitle=document.createElement("h2");
  2608. loadingTextTitle.style.whiteSpace="nowrap";
  2609. loadingTextTitle.style.overflow="auto";
  2610. loadingTextTitle.innerHTML=i18n("loadingTextTitle");
  2611. loadingText.appendChild(loadingTextTitle);
  2612. let loadingTextInput=document.createElement("input");
  2613. loadingTextInput.value=rulesData.loadingText||'';
  2614. loadingTextInput.placeholder=i18n("loadingText");
  2615. loadingTextInput.style.width="100%";
  2616. loadingTextInput.style.margin="0";
  2617. loadingText.appendChild(loadingTextInput);
  2618. otherBtns.appendChild(loadingText);
  2619.  
  2620. let opacity=document.createElement("div");
  2621. let opacityTitle=document.createElement("h2");
  2622. opacityTitle.style.whiteSpace="nowrap";
  2623. opacityTitle.style.overflow="visible";
  2624. opacityTitle.innerHTML=i18n("opacity");
  2625. opacity.appendChild(opacityTitle);
  2626. let opacityInput=document.createElement("input");
  2627. opacityInput.value=rulesData.opacity*100;
  2628. opacityInput.type="number";
  2629. opacityInput.style.width="95px";
  2630. opacityInput.style.margin="0";
  2631. opacityInput.placeholder=i18n("opacityPlaceholder");
  2632. opacity.appendChild(opacityInput);
  2633. otherBtns.appendChild(opacity);
  2634.  
  2635. let pageElementCss=document.createElement("div");
  2636. pageElementCss.style.marginBottom="30px";
  2637. let pageElementCssTitle=document.createElement("h2");
  2638. pageElementCssTitle.innerHTML=i18n("pageElementCss");
  2639. pageElementCss.appendChild(pageElementCssTitle);
  2640. let pageElementCssInput=document.createElement("input");
  2641. pageElementCssInput.value=rulesData.pageElementCss||'';
  2642. pageElementCssInput.style.width="100%";
  2643. pageElementCssInput.style.margin="0";
  2644. pageElementCssInput.placeholder="font-size: xx-large;";
  2645. pageElementCss.appendChild(pageElementCssInput);
  2646. configCon.insertBefore(pageElementCss, insertPos);
  2647.  
  2648. let customCss=document.createElement("div");
  2649. customCss.style.marginBottom="50px";
  2650. let customCssTitle=document.createElement("h2");
  2651. customCssTitle.innerHTML=i18n("customCss");
  2652. customCss.appendChild(customCssTitle);
  2653. let customCssInput=document.createElement("textarea");
  2654. customCssInput.value=rulesData.customCss||'';
  2655. customCssInput.style.width="100%";
  2656. customCssInput.style.margin="0";
  2657. customCssInput.placeholder=".pagetual{\n}";
  2658. customCss.appendChild(customCssInput);
  2659. configCon.insertBefore(customCss, insertPos);
  2660.  
  2661. let configTable=document.createElement("table");
  2662. configTable.style.width="100%";
  2663. let configTbody=document.createElement("tbody");
  2664. configTbody.style.width="100%";
  2665. configTbody.style.display="inline-table";
  2666. configTable.appendChild(configTbody);
  2667. configCon.insertBefore(configTable, insertPos);
  2668. function createCheckbox(innerText, val, tag, parentCheck, otherType){
  2669. if (typeof val == 'undefined') val = "";
  2670. let title=document.createElement(tag||"h3");
  2671. title.innerHTML=innerText;
  2672. let input=document.createElement("input");
  2673. input.type=otherType||"checkbox";
  2674. input.style.width="30px";
  2675. input.style.height="20px";
  2676. input.value=val;
  2677. input.checked=val;
  2678. let td=document.createElement("td");
  2679. td.appendChild(input);
  2680. if(parentCheck){
  2681. td.appendChild(title);
  2682. let parent=parentCheck.parentNode.nextElementSibling;
  2683. let tr=parent.querySelector("tr");
  2684. if(!tr){
  2685. tr=document.createElement("tr");
  2686. parent.appendChild(tr);
  2687. }
  2688. tr.appendChild(td);
  2689. if(!parentCheck.checked){
  2690. td.style.display="none";
  2691. }
  2692. parentCheck.addEventListener("click", e=>{
  2693. td.style.display=parentCheck.checked?"":"none";
  2694. });
  2695. }else{
  2696. let tr=document.createElement("tr");
  2697. tr.appendChild(td);
  2698. td=document.createElement("td");
  2699. td.appendChild(title);
  2700. tr.appendChild(td);
  2701. configTable.children[0].appendChild(tr);
  2702. }
  2703. return input;
  2704. }
  2705.  
  2706. let enableWhiteListInput=createCheckbox(i18n("autoRun"), rulesData.enableWhiteList!=true);
  2707. let enableDebugInput=createCheckbox(i18n("enableDebug"), rulesData.enableDebug!=false);
  2708. let enableHistoryInput=createCheckbox(i18n("enableHistory"), rulesData.enableHistory===true);
  2709. let openInNewTabInput=createCheckbox(i18n("openInNewTab"), rulesData.openInNewTab!=false);
  2710. let initRunInput=createCheckbox(i18n("initRun"), rulesData.initRun!=false);
  2711. let autoLoadNumInput=createCheckbox(i18n("autoLoadNum"), rulesData.autoLoadNum, "h4", initRunInput, "number");
  2712. let preloadInput=createCheckbox(i18n("preload"), rulesData.preload!=false);
  2713. let dbClick2StopInput=createCheckbox(i18n("dbClick2Stop"), rulesData.dbClick2Stop);
  2714. let manualModeInput=createCheckbox(i18n("manualMode"), rulesData.manualMode);
  2715. let hideBarInput=createCheckbox(i18n("hideBar"), rulesData.hideBar, "h4", dbClick2StopInput);
  2716. let dbClick2StopCtrlInput=createCheckbox(i18n("dbClick2StopCtrl"), rulesData.dbClick2StopCtrl, "h4", dbClick2StopInput);
  2717. let dbClick2StopAltInput=createCheckbox(i18n("dbClick2StopAlt"), rulesData.dbClick2StopAlt, "h4", dbClick2StopInput);
  2718. let dbClick2StopShiftInput=createCheckbox(i18n("dbClick2StopShift"), rulesData.dbClick2StopShift, "h4", dbClick2StopInput);
  2719. let dbClick2StopMetaInput=createCheckbox(i18n("dbClick2StopMeta"), rulesData.dbClick2StopMeta, "h4", dbClick2StopInput);
  2720. let dbClick2StopKeyInput=createCheckbox(i18n("dbClick2StopKey"), rulesData.dbClick2StopKey, "h4", dbClick2StopInput, "text");
  2721. dbClick2StopKeyInput.setAttribute("maxlength", "1");
  2722.  
  2723. let customRulesTitle=document.createElement("h2");
  2724. customRulesTitle.innerHTML=i18n("customRules");
  2725. configCon.insertBefore(customRulesTitle, insertPos);
  2726. let customRulesInput=document.createElement("textarea");
  2727. configCon.insertBefore(customRulesInput, insertPos);
  2728. if(rulesData.editTemp){
  2729. if(!ruleParser.customRules){
  2730. ruleParser.customRules=[];
  2731. }
  2732. for(let i in ruleParser.customRules){
  2733. if(ruleParser.customRules[i].url==rulesData.editTemp.url){
  2734. ruleParser.customRules.splice(i, 1);
  2735. break;
  2736. }
  2737. }
  2738. ruleParser.customRules.unshift(rulesData.editTemp);
  2739. rulesData.editTemp=null;
  2740. storage.setItem("rulesData", rulesData);
  2741. customRulesInput.previousElementSibling.scrollIntoView();
  2742. }
  2743. customRulesInput.style.width="100%";
  2744. customRulesInput.style.height="800px";
  2745. 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]`;
  2746. customRulesInput.value=getFormatJSON(ruleParser.customRules);
  2747. let blacklistInput=document.createElement("textarea");
  2748. blacklistInput.style.width="100%";
  2749. blacklistInput.style.height="500px";
  2750. blacklistInput.style.display="none";
  2751. blacklistInput.placeholder="http://*.xxx.com/*/y";
  2752. blacklistInput.value=rulesData.blacklist?rulesData.blacklist.join("\n"):"";
  2753. let blacklistBtn=document.createElement("button");
  2754. blacklistBtn.innerText=i18n("editBlacklist");
  2755. blacklistBtn.style.width="100%";
  2756. blacklistBtn.onclick=e=>{
  2757. blacklistInput.style.display=blacklistInput.style.display=="none"?"":"none";
  2758. };
  2759. configCon.insertBefore(blacklistBtn, insertPos);
  2760. configCon.insertBefore(blacklistInput, insertPos);
  2761. let saveBtn=document.createElement("button");
  2762. saveBtn.innerHTML=i18n("save");
  2763. saveBtn.style.width="100%";
  2764. saveBtn.style.position="fixed";
  2765. saveBtn.style.zIndex="999";
  2766. saveBtn.style.bottom=0;
  2767. saveBtn.style.left=0;
  2768. saveBtn.style.fontSize="x-large";
  2769. configCon.insertBefore(saveBtn, insertPos);
  2770. saveBtn.onclick=e=>{
  2771. try{
  2772. storage.setItem("hpRules", []);
  2773. if(customRulesInput.value==""){
  2774. storage.setItem("customRules", "");
  2775. }else{
  2776. let customRules=JSON.parse(customRulesInput.value);
  2777. if(Array && Array.isArray && !Array.isArray(customRules)){
  2778. showTips("Rules must be a Array!");
  2779. return;
  2780. }
  2781. debug(customRules);
  2782. storage.setItem("customRules", customRules);
  2783. }
  2784. }catch(e){
  2785. debug(e);
  2786. showTips("JSON error, check again!");
  2787. return;
  2788. }
  2789. rulesData.opacity=opacityInput.value/100;
  2790. rulesData.blacklist=blacklistInput.value?blacklistInput.value.split("\n"):"";
  2791. rulesData.hideBar=hideBarInput.checked;
  2792. rulesData.dbClick2Stop=dbClick2StopInput.checked;
  2793. rulesData.enableWhiteList=!enableWhiteListInput.checked;
  2794. rulesData.enableDebug=enableDebugInput.checked;
  2795. rulesData.enableHistory=enableHistoryInput.checked;
  2796. rulesData.openInNewTab=openInNewTabInput.checked;
  2797. rulesData.initRun=initRunInput.checked;
  2798. rulesData.autoLoadNum=autoLoadNumInput.value||'';
  2799. rulesData.preload=preloadInput.checked;
  2800. rulesData.manualMode=manualModeInput.checked;
  2801. rulesData.pageElementCss=pageElementCssInput.value;
  2802. rulesData.customCss=customCssInput.value;
  2803. rulesData.upBtnImg=upBtnImgInput.value;
  2804. rulesData.downBtnImg=downBtnImgInput.value;
  2805. rulesData.loadingText=loadingTextInput.value;
  2806. rulesData.dbClick2StopCtrl=dbClick2StopCtrlInput.checked;
  2807. rulesData.dbClick2StopAlt=dbClick2StopAltInput.checked;
  2808. rulesData.dbClick2StopShift=dbClick2StopShiftInput.checked;
  2809. rulesData.dbClick2StopMeta=dbClick2StopMetaInput.checked;
  2810. rulesData.dbClick2StopKey=dbClick2StopKeyInput.value;
  2811. storage.setItem("rulesData", rulesData);
  2812. let customUrls=customUrlsInput.value.trim();
  2813. if(customUrls){
  2814. customUrls=customUrls.split(/\n/);
  2815. for(let c=0;c<customUrls.length;c++){
  2816. let url;
  2817. if(/^0\s*\|/.test(customUrls[c])){
  2818. url=customUrls[c].replace(/^0\s*\|\s*/, "").trim();
  2819. if(!/^http/.test(url)){
  2820. showTips("Wrong url, check again!");
  2821. return;
  2822. }
  2823. }else{
  2824. url=customUrls[c].trim();
  2825. if(!/^http/.test(url)){
  2826. showTips("Wrong url, check again!");
  2827. return;
  2828. }
  2829. }
  2830. let maxId=1,hasUrl=false;
  2831. if(!rulesData.urls){
  2832. rulesData.urls=[];
  2833. }
  2834. ruleUrls.forEach(u=>{
  2835. if(maxId<u.id){
  2836. maxId=u.id;
  2837. }
  2838. if(u.url==url){
  2839. hasUrl=true;
  2840. }
  2841. });
  2842. if(hasUrl)break;
  2843. if(!rulesData.sort)rulesData.sort=[1];
  2844. rulesData.urls.push({id:maxId+1,url:url});
  2845. rulesData.sort.push(maxId+1);
  2846. storage.setItem("rulesData", rulesData);
  2847. }
  2848. }
  2849. showTips("The settings are saved");
  2850. location.reload();
  2851. };
  2852. return true;
  2853. }
  2854.  
  2855. var inUpdate=false;
  2856. function updateRules(success,fail){
  2857. if(inUpdate)return;
  2858. inUpdate=true;
  2859. let ruleIndex=ruleUrls.length-1;
  2860. storage.setItem("hpRules", []);
  2861. function addNextRule(){
  2862. if(ruleIndex<0){
  2863. let now=new Date().getTime();
  2864. storage.setItem("ruleLastUpdate", now);
  2865. storage.setItem("rules", ruleParser.rules);
  2866. inUpdate=false;
  2867. success();
  2868. }else{
  2869. let rule=ruleUrls[ruleIndex--];
  2870. ruleParser.addRuleByUrl(rule.url, rule.id, (json,err)=>{
  2871. if(!json){
  2872. fail(rule,err);
  2873. }
  2874. addNextRule();
  2875. })
  2876. }
  2877. }
  2878. addNextRule();
  2879. }
  2880.  
  2881. function objIsArr(obj) {
  2882. return obj &&
  2883. typeof obj === 'object' &&
  2884. typeof obj.length === 'number' &&
  2885. !(obj.propertyIsEnumerable('length'));
  2886. }
  2887.  
  2888. function isVisible(el, win) {
  2889. if(!el.offsetParent)return false;
  2890. var loopable = true,
  2891. visible = el.tagName && win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  2892. while(loopable && visible) {
  2893. el = el.parentNode;
  2894.  
  2895. if(el && el.tagName && el.tagName!="BODY") {
  2896. visible = win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  2897. }else {
  2898. loopable = false;
  2899. }
  2900. }
  2901. return visible;
  2902. }
  2903.  
  2904. function getElementTop(ele) {
  2905. var actualTop = ele.offsetTop;
  2906. var current = ele.offsetParent;
  2907. while (current) {
  2908. actualTop += current.offsetTop;
  2909. current = current.offsetParent;
  2910. }
  2911. return actualTop;
  2912. }
  2913.  
  2914. function getFormatJSON(obj){
  2915. if(!objIsArr(obj) || obj.length === 0)return "";
  2916. return JSON.stringify(obj, null, 4);
  2917. let ret="[\n";
  2918. let len=obj.length,i=0,isLast;
  2919. obj.forEach(item=>{
  2920. ret+=" {\n";
  2921. let iLen=Object.keys(item).length,j=0;
  2922. for(let key in item){
  2923. isLast=(++j)==iLen;
  2924. let value=item[key];
  2925. if(objIsArr(value)){
  2926. let vstr="[",v=0,vIsLast=false;
  2927. value.forEach(vi=>{
  2928. vIsLast=(++v)==value.length;
  2929. vstr+="\""+vi.replace(/\\/g,"\\\\")+"\""+(vIsLast?"":",");
  2930. });
  2931. vstr+="]";
  2932. ret+=" \""+key+"\":"+vstr+""+(isLast?"":",")+"\n";
  2933. }else{
  2934. if(typeof value=="string"){
  2935. value=value.replace(/\\/g,"\\\\").replace(/"/g,"\\\"");
  2936. value="\""+value+"\"";
  2937. }
  2938. ret+=" \""+key+"\":"+value+""+(isLast?"":",")+"\n";
  2939. }
  2940. }
  2941. isLast=(++i)==len;
  2942. ret+=" }"+(isLast?"":",")+"\n";
  2943. });
  2944. ret+="]";
  2945. return ret;
  2946. }
  2947.  
  2948. function globMatch(first, second) {
  2949. if (first.length == 0 && second.length == 0){
  2950. return true;
  2951. }
  2952.  
  2953. if (first.length > 1 && first[0] == '*' &&
  2954. second.length == 0){
  2955. return false;
  2956. }
  2957.  
  2958. if ((first.length > 1 && first[0] == '?') ||
  2959. (first.length != 0 && second.length != 0 &&
  2960. first[0] == second[0])){
  2961. return globMatch(first.substring(1),
  2962. second.substring(1));
  2963. }
  2964.  
  2965. if (first.length > 0 && first[0] == '*'){
  2966. return globMatch(first.substring(1), second) ||
  2967. globMatch(first, second.substring(1));
  2968. }
  2969.  
  2970. return false;
  2971. }
  2972.  
  2973. function initRules(callback) {
  2974. /*0 wedata格式,1 pagetual格式*/
  2975. ruleUrls=[
  2976. {
  2977. id:1,
  2978. url:'http://wedata.net/databases/AutoPagerize/items_all.json',
  2979. type:0,
  2980. }
  2981. ];var i=0,j=0;
  2982.  
  2983. ruleParser.initSavedRules(()=>{
  2984. storage.getItem("rulesData", data=>{
  2985. if(data){
  2986. rulesData=data;
  2987. if(data.urls)ruleUrls=ruleUrls.concat(data.urls);
  2988. if(data.sort){
  2989. let urls=[];
  2990. data.sort.forEach(id=>{
  2991. for(let s=0;s<ruleUrls.length;s++){
  2992. if(id==ruleUrls[s].id){
  2993. urls.push(ruleUrls[s]);
  2994. break;
  2995. }
  2996. }
  2997. });
  2998. ruleUrls=urls;
  2999. }
  3000. }
  3001. let upBtnImg=rulesData.upBtnImg,downBtnImg=rulesData.downBtnImg;
  3002. if(upBtnImg && downBtnImg){
  3003. downSvgCSS=downSvgCSS.replace("transform: rotate(180deg);","");
  3004. }else if(upBtnImg && !downBtnImg){
  3005. downBtnImg=upBtnImg;
  3006. }else if(downBtnImg && !upBtnImg){
  3007. upBtnImg=downBtnImg;
  3008. }
  3009. if(upBtnImg){
  3010. upSvg=`<img src="${upBtnImg}"/>`;
  3011. }
  3012. if(downBtnImg){
  3013. downSvg=`<img src="${downBtnImg}"/>`;
  3014. }
  3015. setLoadingDiv(rulesData.loadingText || i18n("loadingText"));
  3016. if(typeof(rulesData.opacity)=="undefined"){
  3017. rulesData.opacity=0.3;
  3018. }
  3019. if(typeof(rulesData.hideBar)=="undefined"){
  3020. rulesData.hideBar=false;
  3021. }
  3022. if(typeof(rulesData.dbClick2Stop)=="undefined"){
  3023. rulesData.dbClick2Stop=true;
  3024. }
  3025. if(typeof(rulesData.enableWhiteList)=="undefined"){
  3026. rulesData.enableWhiteList=false;
  3027. }
  3028. if(typeof(rulesData.enableHistory)=="undefined"){
  3029. rulesData.enableHistory=false;
  3030. }
  3031. if(typeof(rulesData.openInNewTab)=="undefined"){
  3032. rulesData.openInNewTab=true;
  3033. }
  3034. if(typeof(rulesData.enableDebug)=="undefined"){
  3035. rulesData.enableDebug=true;
  3036. }
  3037. if(typeof(rulesData.initRun)=="undefined"){
  3038. rulesData.initRun=true;
  3039. }
  3040. if(typeof(rulesData.preload)=="undefined"){
  3041. rulesData.preload=true;
  3042. }
  3043. if(typeof(rulesData.manualMode)=="undefined"){
  3044. rulesData.manualMode=false;
  3045. }
  3046. if(rulesData.blacklist && rulesData.blacklist.length>0){
  3047. for(let b in rulesData.blacklist){
  3048. let curGlob=rulesData.blacklist[b];
  3049. if(globMatch(curGlob, location.href)){
  3050. return;
  3051. }
  3052. }
  3053. }
  3054. if(rulesData.autoLoadNum){
  3055. autoLoadNum=parseInt(rulesData.autoLoadNum);
  3056. }
  3057. enableDebug=rulesData.enableDebug;
  3058. storage.getItem("forceState_"+location.host, v=>{
  3059. storage.getItem("ruleLastUpdate", date=>{
  3060. if(typeof(v)=="undefined"){
  3061. v=(rulesData.enableWhiteList?1:0);
  3062. }
  3063. forceState=v;
  3064. updateDate=date;
  3065. if(initConfig())return;
  3066. if(forceState==1)return;
  3067. let now=new Date().getTime();
  3068. if(!date || now-date>2*24*60*60*1000){
  3069. updateRules(()=>{
  3070. },(rule,err)=>{});
  3071. storage.setItem("ruleLastUpdate", now);
  3072. }
  3073. callback();
  3074. });
  3075. });
  3076. });
  3077. });
  3078. }
  3079.  
  3080. function requestDoc(url, callback){
  3081. _GM_xmlhttpRequest({
  3082. url: url,
  3083. method: 'GET',
  3084. overrideMimeType: 'text/html;charset='+document.charset,
  3085. headers: {
  3086. 'Referer': location.href,
  3087. "Content-Type": "text/html;charset="+document.charset,
  3088. },
  3089. timeout: 5000,
  3090. onload: function(res) {
  3091. var doc=null,response=res.response;
  3092. let preCode=ruleParser.curSiteRule.pageElementPre || ruleParser.curSiteRule.pagePre;
  3093. if(preCode){
  3094. try{
  3095. if (typeof _unsafeWindow.pagetualPagePre!='undefined') {
  3096. response = _unsafeWindow.pagetualPagePre(response);
  3097. } else if (preCode.length == 2) {
  3098. response = response.replace(new RegExp(preCode[0], "gi"), preCode[1]);
  3099. } else {
  3100. response = Function("response",'"use strict";' + preCode)(response);
  3101. }
  3102. }catch(e){
  3103. debug(e);
  3104. }
  3105. }
  3106. try {
  3107. doc=document.implementation.createHTMLDocument('');
  3108. doc.documentElement.innerHTML=response;
  3109. let base=doc.querySelector("base");
  3110. ruleParser.basePath=base?base.href:url;
  3111. }
  3112. catch (e) {
  3113. debug('parse error'+e.toString());
  3114. }
  3115. let pageElement=ruleParser.getPageElement(doc);
  3116. if(inCors && (!pageElement || pageElement.length==0)){
  3117. ruleParser.curSiteRule.pageElement=allOfBody;
  3118. pageElement=ruleParser.getPageElement(doc);
  3119. ruleParser.getInsert(true);
  3120. }
  3121. //只有1的話怕不是圖片哦
  3122. if(pageElement && (pageElement.length>1 || (pageElement.length==1 && pageElement[0].tagName!="IMG") )){
  3123. ruleParser.insertPage(doc, pageElement, url, callback, false);
  3124. if(ruleParser.curSiteRule.action==1){
  3125. requestFromIframe(url, (doc, eles)=>{
  3126. loadPageOver();
  3127. if(eles){
  3128. ruleParser.insertPage(doc, eles, url, callback, true);
  3129. }
  3130. });
  3131. }else ruleParser.curSiteRule.action=0;
  3132. }else if(ruleParser.curSiteRule.singleUrl || curPage==1){
  3133. ruleParser.curSiteRule.action=1;
  3134. requestFromIframe(url, (doc, eles)=>{
  3135. loadPageOver();
  3136. if(eles){
  3137. ruleParser.insertPage(doc, eles, url, callback, true);
  3138. }
  3139. });
  3140. }else{
  3141. isPause=true;
  3142. callback(false);
  3143. }
  3144. },
  3145. onerror: function(e){
  3146. debug(e);
  3147. callback(false);
  3148. },
  3149. ontimeout: function(e){
  3150. debug(e);
  3151. callback(false);
  3152. }
  3153. });
  3154. }
  3155.  
  3156. function initPage(){
  3157. ruleParser.initPage(()=>{
  3158. if(ruleParser.curSiteRule.autoLoadNum){
  3159. autoLoadNum=ruleParser.curSiteRule.autoLoadNum;
  3160. }
  3161. if(ruleParser.nextLinkHref){
  3162. let isJs=/^(javascript|#)/.test(ruleParser.nextLinkHref.replace(location.href,""));
  3163. if(!isJs){
  3164. let inForce=(forceState == 2 || forceState == 3);
  3165. _GM_registerMenuCommand(i18n(inForce?"cancelForceIframe":"forceIframe"), ()=>{
  3166. if(inForce){
  3167. storage.setItem("forceState_"+location.host, "");
  3168. }else{
  3169. let _state=ruleParser.curSiteRule.action>0 || confirm(i18n("forceAllBody"))?2:3;
  3170. storage.setItem("forceState_"+location.host, _state);
  3171. }
  3172. location.reload();
  3173. });
  3174. }
  3175. _GM_registerMenuCommand(i18n("loadNow"), ()=>{
  3176. let loadNum=window.prompt(i18n("loadConfirm"), "1");
  3177. if(loadNum==="" || loadNum===null)return;
  3178. autoLoadNum=Math.abs(parseInt(loadNum));
  3179. nextPage();
  3180. });
  3181. }
  3182. initListener();
  3183. if(rulesData.initRun && ruleParser.curSiteRule.initRun!=0)nextPage();
  3184. });
  3185. }
  3186.  
  3187. var pageBarStyle;
  3188. function initView(){
  3189. _GM_addStyle(`
  3190. .pagetual_pageBar{
  3191. -moz-transition:opacity 0.3s ease-in-out 0s;
  3192. -webkit-transition:opacity 0.3s ease-in-out 0s;
  3193. transition:opacity 0.3s ease-in-out 0s;
  3194. font-family: Arial,sans-serif !important;
  3195. }
  3196. .pagetual_pageBar.stop {
  3197. -webkit-filter: invert(100%);
  3198. filter: invert(100%);
  3199. opacity: 1!important;
  3200. }
  3201. .pagetual_pageBar.hide {
  3202. display: none!important;
  3203. }
  3204. .pagetual_pageBar:hover {
  3205. opacity: 1!important;
  3206. }
  3207. .pagetual_pageBar span {
  3208. vertical-align: super;
  3209. }
  3210. .pagetual_pageBar a>span {
  3211. margin-top: 0!important;
  3212. opacity: 0;
  3213. -moz-transition:all 0.3s ease-in-out 0s;
  3214. -webkit-transition:all 0.3s ease-in-out 0s;
  3215. transition:all 0.3s ease-in-out 0s;
  3216. }
  3217. .pagetual_pageBar a>span:hover {
  3218. color: red;
  3219. }
  3220. .pagetual_pageBar a:hover>span {
  3221. opacity: 1;
  3222. }
  3223. .pagetual_pageBar a:hover>span.prev {
  3224. margin-top: -30px!important;
  3225. }
  3226. .pagetual_pageBar a:hover>span.next {
  3227. margin-top: 30px!important;
  3228. }
  3229. .pagetual_pageBar span>svg {
  3230. -moz-transition:transform 0.5s ease, opacity 0.3s ease;
  3231. -webkit-transition:transform 0.5s ease, opacity 0.3s ease;
  3232. transition:transform 0.5 ease, opacity 0.3s ease;
  3233. opacity: 0;
  3234. }
  3235. .pagetual_pageBar:hover span>svg {
  3236. opacity: 1;
  3237. }
  3238. .pagetual_pageBar span>svg.upSvg:hover {
  3239. transform: rotate(360deg) scale3d(1.2, 1.2, 1.2);
  3240. }
  3241. .pagetual_pageBar span>svg.downSvg:hover {
  3242. transform: rotate(540deg) scale3d(1.2, 1.2, 1.2)!important;
  3243. }
  3244. .pagetual_pageBar .pagetual_pageNum{
  3245. color: #55555f;
  3246. }
  3247. .pagetual_pageBar .pagetual_pageNum:hover{
  3248. color: #ff6464;
  3249. }
  3250. .pagetual_tipsWords{
  3251. font-size: 50px;
  3252. font-weight: bold;
  3253. font-family: "黑体", -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto",
  3254. "Oxygen", "Ubuntu", "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji",
  3255. "Segoe UI Emoji", "Segoe UI Symbol";
  3256. color: #ffffff;
  3257. min-height: 70px;
  3258. line-height: 70px;
  3259. position: fixed;
  3260. left: 50%;
  3261. top: 10%;
  3262. margin-left: -150px;
  3263. padding: 0 10px;
  3264. z-index: 999999999;
  3265. background-color: #000;
  3266. border: 1px solid black;
  3267. border-radius: 10px;
  3268. opacity: 0;
  3269. filter: alpha(opacity=65);
  3270. box-shadow: 5px 5px 20px 0px #000;
  3271. -moz-transition:opacity 0.3s ease-in-out 0s;
  3272. -webkit-transition:opacity 0.3s ease-in-out 0s;
  3273. transition:opacity 0.3s ease-in-out 0s;
  3274. pointer-events: none;
  3275. }
  3276. .pagetual_loading {
  3277. width: 50px;
  3278. height: 50px;
  3279. margin: 10px auto;
  3280. border-radius: 100%;
  3281. -webkit-animation: pagetual_loading_scaleout 1.0s infinite ease-in-out;
  3282. animation: pagetual_loading_scaleout 1.0s infinite ease-in-out;
  3283. }
  3284. @-webkit-keyframes pagetual_loading_scaleout {
  3285. 0% { -webkit-transform: scale(0.0) }
  3286. 100% {
  3287. -webkit-transform: scale(1.0);
  3288. opacity: 0;
  3289. }
  3290. }
  3291. @keyframes pagetual_loading_scaleout {
  3292. 0% {
  3293. transform: scale(0.0);
  3294. -webkit-transform: scale(0.0);
  3295. } 100% {
  3296. transform: scale(1.0);
  3297. -webkit-transform: scale(1.0);
  3298. opacity: 0;
  3299. }
  3300. }
  3301. .pagetual_loading_text {
  3302. -webkit-animation: pagetual_loading_opacity 2.6s infinite ease-in-out;
  3303. animation: pagetual_loading_opacity 2.6s infinite ease-in-out;
  3304. }
  3305. @-webkit-keyframes pagetual_loading_opacity {
  3306. 0% { opacity: 1 }
  3307. 50% { opacity: 0.2 }
  3308. 100% { opacity: 1 }
  3309. }
  3310. @keyframes pagetual_loading_opacity {
  3311. 0% { opacity: 1 }
  3312. 50% { opacity: 0.2 }
  3313. 100% { opacity: 1 }
  3314. }
  3315. `);
  3316. 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;`;
  3317. }
  3318. var loadingDiv=document.createElement("div");
  3319. 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;";
  3320.  
  3321. 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;`;
  3322. function setLoadingDiv(loadingText){
  3323. 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>`;
  3324. }
  3325.  
  3326. 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>`;
  3327. var upSvgCSS=`display:initial;position:absolute;cursor: pointer;margin: 0 -45px;width: 30px;height: 30px;vertical-align: middle;fill: currentColor;overflow: hidden;`;
  3328. 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>`;
  3329. 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);`;
  3330.  
  3331. 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;`;
  3332. 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;`;
  3333.  
  3334. var tipsWords=document.createElement("div");
  3335. tipsWords.className="pagetual_tipsWords";
  3336.  
  3337. var isPause=false,isLoading=false,curPage=1,forceState=0,bottomGap=1000,autoLoadNum=-1;
  3338.  
  3339. function changeStop(stop, hide){
  3340. isPause=stop;
  3341. [].forEach.call(document.querySelectorAll(".pagetual_pageBar"), bar=>{
  3342. if(isPause){
  3343. bar.classList.add("stop");
  3344. if(hide)bar.classList.add("hide");
  3345. }else{
  3346. bar.classList.remove("stop");
  3347. if(hide)bar.classList.remove("hide");
  3348. }
  3349. });
  3350. }
  3351.  
  3352. function isInViewPort(element) {
  3353. if(!element.parentNode)return false;
  3354. if(_unsafeWindow.getComputedStyle(element).display=="none")return false;
  3355. const viewWidth = window.innerWidth || document.documentElement.clientWidth;
  3356. const viewHeight = window.innerHeight || document.documentElement.clientHeight;
  3357. const {
  3358. top,
  3359. right,
  3360. bottom,
  3361. left,
  3362. } = element.getBoundingClientRect();
  3363.  
  3364. return (
  3365. top >= 0 &&
  3366. left >= 0 &&
  3367. right <= viewWidth + 1 &&
  3368. bottom <= viewHeight * 2
  3369. );
  3370. }
  3371.  
  3372. var urlChanged=false;
  3373. var _wr = function(type) {
  3374. var orig = history[type];
  3375. return function() {
  3376. var rv = orig.apply(this, arguments);
  3377. var e = new Event(type);
  3378. e.arguments = arguments;
  3379. window.dispatchEvent(e);
  3380. return rv;
  3381. };
  3382. };
  3383. history.pushState = _wr('pushState');
  3384. window.addEventListener('pushState', function(e) {
  3385. urlChanged=true;
  3386. isPause=true;
  3387. setTimeout(()=>{
  3388. if(location.href==configPage || guidePage.test(location.href)){
  3389. location.reload();
  3390. }else if(!ruleParser.ruleMatch(ruleParser.curSiteRule)){
  3391. initPage();
  3392. }
  3393. },1);
  3394. });
  3395.  
  3396. function initListener(){
  3397. let loadmoreBtn,loading=true,lastScroll=0,checkLoadMoreTimes=0;
  3398. let checkLoadMore=setInterval(()=>{
  3399. loadmoreBtn=getLoadMore(document);
  3400. if(loadmoreBtn && isVisible(loadmoreBtn, _unsafeWindow)){
  3401. loading=false;
  3402. clearInterval(checkLoadMore);
  3403. }else if(checkLoadMoreTimes++>30){
  3404. clearInterval(checkLoadMore);
  3405. }
  3406. },300);
  3407. let checkScrollReach=()=>{
  3408. let scrolly=window.scrollY;
  3409. let windowHeight=window.innerHeight || document.documentElement.clientHeight;
  3410. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  3411. if(scrollH-scrolly-windowHeight<bottomGap){
  3412. nextPage();
  3413. }
  3414. };
  3415. let scrollHandler = e=>{
  3416. if(urlChanged){
  3417. ruleParser.initPage(()=>{
  3418. if(ruleParser.nextLinkHref)initView();
  3419. });
  3420. urlChanged=false;
  3421. isPause=false;
  3422. }
  3423. if(isPause)return;
  3424. if(!loading){
  3425. if(!loadmoreBtn || !loadmoreBtn.parentNode){
  3426. loadmoreBtn=getLoadMore(document);
  3427. }
  3428. if(loadmoreBtn){
  3429. if(isInViewPort(loadmoreBtn)){
  3430. emuClick(loadmoreBtn);
  3431. loading=true;
  3432. setTimeout(()=>{loading=false},200);
  3433. }
  3434. }else{
  3435. loading=true;
  3436. setTimeout(()=>{loading=false},200);
  3437. }
  3438. }
  3439. if(!isLoading){
  3440. checkScrollReach();
  3441. }
  3442. if(ruleParser.curSiteRule.lockScroll){
  3443. let curScroll=document.body.scrollTop||document.documentElement.scrollTop;
  3444. if(isLoading && Math.abs(lastScroll-curScroll)>350){
  3445. document.body.scrollTop=lastScroll;
  3446. document.documentElement.scrollTop=lastScroll;
  3447. }else{
  3448. lastScroll=curScroll;
  3449. }
  3450. }
  3451. };
  3452. document.addEventListener('dblclick', e=>{
  3453. if(forceState==1 || e.target.tagName=='INPUT' || e.target.tagName=='TEXTAREA') return;
  3454. if(!rulesData.dbClick2StopKey){
  3455. if((rulesData.dbClick2StopCtrl && !e.ctrlKey) ||
  3456. (rulesData.dbClick2StopAlt && !e.altKey) ||
  3457. (rulesData.dbClick2StopShift && !e.shiftKey) ||
  3458. (rulesData.dbClick2StopMeta && !e.metaKey)){
  3459. return;
  3460. }
  3461. }
  3462. if(e.target.tagName!="BODY"){
  3463. let selStr=document.getSelection().toString();
  3464. if(selStr && selStr.trim()){
  3465. return;
  3466. }
  3467. }
  3468. if(rulesData.dbClick2Stop && (ruleParser.nextLinkHref || loadmoreBtn)){
  3469. setTimeout(()=>{
  3470. changeStop(!isPause, rulesData.hideBar);
  3471. if(!isPause){
  3472. checkScrollReach();
  3473. }
  3474. showTips(i18n(isPause?"disable":"enable"));
  3475. },10);
  3476. }
  3477. });
  3478. if(rulesData.dbClick2StopKey){
  3479. document.addEventListener('keydown', e=>{
  3480. if((rulesData.dbClick2StopCtrl && !e.ctrlKey) ||
  3481. (rulesData.dbClick2StopAlt && !e.altKey) ||
  3482. (rulesData.dbClick2StopShift && !e.shiftKey) ||
  3483. (rulesData.dbClick2StopMeta && !e.metaKey)){
  3484. return;
  3485. }
  3486. if (document.activeElement &&
  3487. (document.activeElement.tagName == 'INPUT' ||
  3488. document.activeElement.tagName == 'TEXTAREA')) {
  3489. return;
  3490. }
  3491. var key = String.fromCharCode(e.keyCode).toLowerCase();
  3492. if(rulesData.dbClick2StopKey.toLowerCase()==key){
  3493. forceState=(forceState==1?0:1);
  3494. showTips(i18n(forceState==1?"disableSiteTips":"enableSiteTips"));
  3495. if(!ruleParser.curSiteRule.url) {
  3496. storage.setItem("forceState_"+location.host, forceState);
  3497. location.reload();
  3498. }
  3499. }
  3500. });
  3501. }
  3502. let clickNext=() => {
  3503. let nextLink=ruleParser.nextLinkHref;
  3504. if(!nextLink)return;
  3505. let isJs=/^(javascript|#)/.test(nextLink.replace(location.href,""));
  3506. if(isJs){
  3507. let nextBtn=ruleParser.getNextLink(document);
  3508. if(nextBtn)emuClick(nextBtn);
  3509. }else{
  3510. window.location.href = nextLink;
  3511. }
  3512. };
  3513. if(typeof ruleParser.curSiteRule.manualMode=='undefined' ? rulesData.manualMode : ruleParser.curSiteRule.manualMode){
  3514. document.addEventListener('keydown', e=>{
  3515. if (document.activeElement &&
  3516. (document.activeElement.tagName == 'INPUT' ||
  3517. document.activeElement.tagName == 'TEXTAREA' ||
  3518. document.activeElement.contentEditable == 'true')) {
  3519. return;
  3520. }
  3521. if(e.keyCode==39){
  3522. clickNext();
  3523. }
  3524. });
  3525. document.addEventListener('pagetual.next', function() {
  3526. clickNext();
  3527. }, false);
  3528. return;
  3529. }
  3530. if(!ruleParser.curSiteRule.wheel){
  3531. document.addEventListener('scroll', scrollHandler, true);
  3532. }
  3533. document.addEventListener('wheel', scrollHandler, true);
  3534. }
  3535.  
  3536. function showTips(content, wordColor, backColor){
  3537. document.body.appendChild(tipsWords);
  3538. tipsWords.style.opacity=0.8;
  3539. tipsWords.innerText=content;
  3540. tipsWords.style.marginLeft=-tipsWords.offsetWidth/2+"px";
  3541. tipsWords.style.color=wordColor||0xFFFFFF;
  3542. tipsWords.style.backgroundColor=backColor||0x000;
  3543. setTimeout(()=>{tipsWords.style.opacity=0},1000);
  3544. }
  3545.  
  3546. function getLoadMore(doc){
  3547. if(ruleParser.curSiteRule.loadMore==="")return null;
  3548. let btnSel=ruleParser.curSiteRule.loadMore||".LoadMore,.load-more,.button-show-more,button[data-testid='more-results-button']",loadmoreBtn;
  3549. if(btnSel){
  3550. try{
  3551. loadmoreBtn=doc.querySelector(btnSel);
  3552. }catch(e){
  3553. loadmoreBtn=getElementByXpath(btnSel,doc,doc);
  3554. }
  3555. }
  3556. if(!loadmoreBtn){
  3557. let buttons=doc.querySelectorAll("input,button,a,div[onclick]"),loadmoreReg=/^\s*(加载更多|加載更多|load\s*more|もっと読み込む)\s*$/i;
  3558. for(let i=0;i<buttons.length;i++){
  3559. let button=buttons[i];
  3560. if(button.innerText.length > 20)continue;
  3561. if(button && loadmoreReg.test(button.innerText)){
  3562. loadmoreBtn=button;
  3563. break;
  3564. }
  3565. }
  3566. }
  3567. if(loadmoreBtn && !ruleParser.curSiteRule.loadMore){
  3568. let href=loadmoreBtn.getAttribute("href");
  3569. if (href && href!="/" && !/^(javascript|#)/.test(href)){
  3570. loadmoreBtn=null;
  3571. }
  3572. }
  3573. return loadmoreBtn;
  3574. }
  3575.  
  3576. function scrollToPageBar(bar){
  3577. let yOffset = -15;
  3578. if (typeof ruleParser.curSiteRule.pageBarTop !== 'undefined') {
  3579. yOffset = -ruleParser.curSiteRule.pageBarTop;
  3580. }
  3581. const y = bar.getBoundingClientRect().top + window.pageYOffset + yOffset;
  3582. window.scrollTo({ top: y, behavior: 'smooth'});
  3583. }
  3584.  
  3585. var hasPageNum=true;
  3586. function createPageBar(url){
  3587. let insert=ruleParser.getInsert();
  3588. if(!insert || !insert.parentNode)return;
  3589. curPage++;
  3590. let example=ruleParser.curSiteRule.insertPos==2?insert.children[0]:(insert.parentNode.children[parseInt(insert.parentNode.children.length/2)]||insert);
  3591. if (example.className=="pagetual_pageBar") {
  3592. example=example.previousElementSibling;
  3593. }
  3594. if(!example || !example.parentNode)example=insert;
  3595. let exampleStyle = _unsafeWindow.getComputedStyle(example);
  3596. let inTable=example.parentNode.tagName=="TABLE" ||
  3597. example.tagName=="TR" ||
  3598. example.tagName=="TBODY" ||
  3599. exampleStyle.display=="table-row" ||
  3600. (example.previousElementSibling && example.previousElementSibling.tagName=="TR") ||
  3601. (example.previousElementSibling && example.previousElementSibling.tagName=="TBODY");
  3602. let inLi=example.tagName=="LI" || (example.previousElementSibling && example.previousElementSibling.tagName=="LI");
  3603. if(forceState==2){
  3604. inTable=inLi=false;
  3605. }
  3606. let pageBar=document.createElement(inTable?"tr":(inLi?"li":"div"));
  3607. let upSpan=document.createElement("span");
  3608. let downSpan=document.createElement("span");
  3609. let pageText=document.createElement("a");
  3610. let pageNum;
  3611. pageBar.className="pagetual_pageBar";
  3612. pageBar.id="pagetual_pageBar"+curPage;
  3613. if(isPause){
  3614. pageBar.classList.add("stop");
  3615. }
  3616. pageBar.style.cssText=pageBarStyle;
  3617. pageBar.title=i18n(isPause?"enable":"disable");
  3618. upSpan.innerHTML=upSvg;
  3619. upSpan.children[0].style.cssText=upSvgCSS;
  3620. upSpan.title=i18n("toTop");
  3621. downSpan.innerHTML=downSvg;
  3622. downSpan.children[0].style.cssText=downSvgCSS;
  3623. downSpan.title=i18n("toBottom");
  3624. upSpan.style.cssText=initStyle;
  3625. downSpan.style.cssText=initStyle;
  3626. pageText.href=url;
  3627. pageText.style.cssText=pageTextStyle;
  3628. pageText.title=i18n("current");
  3629. pageBar.appendChild(upSpan);
  3630. pageBar.appendChild(pageText);
  3631. if(ruleParser.nextTitle){
  3632. pageText.innerHTML=ruleParser.nextTitle+" ";
  3633. pageText.title=ruleParser.nextTitle;
  3634. }
  3635. if(ruleParser.curSiteRule.pageNum || (hasPageNum && /[&\/\?](p=|page[=\/_-]?)\d+|[_-]\d+\./.test(url))){
  3636. pageText.innerHTML+="Page ";
  3637. pageNum=document.createElement("span");
  3638. pageNum.innerHTML=ruleParser.getPageNumFromUrl(url);
  3639. pageNum.className="pagetual_pageNum";
  3640. pageNum.title=i18n("inputPageNum");
  3641. pageNum.style.cssText=pageTextStyle;
  3642. pageNum.style.cursor="pointer";
  3643. pageNum.style.color="";
  3644. pageNum.style.marginLeft="5px";
  3645. pageNum.addEventListener("click", e=>{
  3646. let pageInput=prompt(i18n("inputPageNum"), "1");
  3647. if(pageInput){
  3648. let pageLink=ruleParser.getLinkByPage(url, pageInput);
  3649. if(pageLink){
  3650. _GM_openInTab(pageLink,{active:true});
  3651. }
  3652. }
  3653. e.preventDefault();
  3654. e.stopPropagation();
  3655. });
  3656. pageBar.appendChild(pageNum);
  3657. }else{
  3658. pageText.innerHTML+="Page "+curPage;
  3659. hasPageNum=false;
  3660. }
  3661. let preBtn=document.createElement("span");
  3662. preBtn.innerHTML="∧";
  3663. preBtn.title="Prev page";
  3664. preBtn.className="prev";
  3665. 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";
  3666. let nextBtn=document.createElement("span");
  3667. nextBtn.innerHTML="∨";
  3668. nextBtn.title="Next page";
  3669. nextBtn.className="next";
  3670. 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";
  3671. let localPage=curPage;
  3672. preBtn.addEventListener("click", e=>{
  3673. e.stopPropagation();
  3674. e.preventDefault();
  3675. let prePageBar = document.querySelector("#pagetual_pageBar"+(localPage-1));
  3676. if (prePageBar) {
  3677. scrollToPageBar(prePageBar);
  3678. } else {
  3679. window.scrollTo({ top: 0, behavior: 'smooth'});
  3680. }
  3681. });
  3682. nextBtn.addEventListener("click", e=>{
  3683. e.stopPropagation();
  3684. e.preventDefault();
  3685. let prePageBar=document.querySelector("#pagetual_pageBar"+(localPage+1));
  3686. if (prePageBar) {
  3687. scrollToPageBar(prePageBar);
  3688. } else {
  3689. window.scrollTo({ top: 9999999, behavior: 'smooth'});
  3690. }
  3691. });
  3692. pageText.insertBefore(preBtn, pageText.firstChild);
  3693. pageText.insertBefore(nextBtn, pageText.firstChild);
  3694. pageBar.appendChild(downSpan);
  3695. let parentStyle=_unsafeWindow.getComputedStyle(example.parentNode);
  3696. let parentWidth=example.parentNode.offsetWidth||parseInt(parentStyle.width);
  3697. pageBar.style.width=parentWidth-parseInt(parentStyle.paddingLeft)-parseInt(parentStyle.paddingRight)-10+"px";
  3698. if(parentStyle.display=="grid" || parentStyle.display=="inline-grid"){
  3699. pageBar.style.gridColumnStart=1;
  3700. pageBar.style.gridColumnEnd=1+parseInt(example.parentNode.offsetWidth/example.offsetWidth);
  3701. }
  3702. if(inTable){
  3703. example=(example.tagName=="TR" || example.tagName=="TBODY")?example:example.previousElementSibling;
  3704. if(example.tagName=="TBODY")example=example.querySelector("tr");
  3705. let preTr=example;
  3706. while(preTr && preTr.children.length==0)preTr=preTr.previousElementSibling;
  3707. if(preTr)example=preTr;
  3708. let tdNum=0;
  3709. if (exampleStyle.display=="table-row") {
  3710. [].forEach.call(example.children, el=>{
  3711. tdNum+=el.colSpan||1;
  3712. });
  3713. } else {
  3714. [].forEach.call(example.children, el=>{
  3715. if(el.tagName=="TD" || el.tagName=="TH"){
  3716. tdNum+=el.colSpan||1;
  3717. }
  3718. });
  3719. }
  3720. pageBar.style.display="table-row";
  3721. pageBar.style.backgroundColor="unset";
  3722. pageBar.style.lineHeight="20px";
  3723. pageBar.style.boxShadow="";
  3724. let td=document.createElement("td");
  3725. td.colSpan=tdNum||1;
  3726. let inTd=document.createElement("div");
  3727. inTd.style.backgroundColor="rgb(240 240 240 / 80%)";
  3728. inTd.style.borderRadius="20px";
  3729. inTd.style.padding="0 0";
  3730. inTd.style.margin="10px";
  3731. inTd.style.lineHeight="20px";
  3732. inTd.style.textAlign="center";
  3733. inTd.style.boxShadow="rgb(0 0 0 / 67%) 0px 0px 10px 0px";
  3734. inTd.appendChild(upSpan);
  3735. inTd.appendChild(pageText);
  3736. if(pageNum)inTd.appendChild(pageNum);
  3737. inTd.appendChild(downSpan);
  3738. td.appendChild(inTd);
  3739. pageBar.appendChild(td);
  3740. }else if(inLi){
  3741. example=example.tagName=="LI"?example:example.previousElementSibling;
  3742. pageBar.style.display="table-row";
  3743. pageBar.style.backgroundColor="unset";
  3744. pageBar.style.lineHeight="20px";
  3745. pageBar.style.boxShadow="";
  3746. let td=document.createElement("td");
  3747. td.colSpan=example.children.length;
  3748. let inTd=document.createElement("div");
  3749. inTd.style.backgroundColor="rgb(240 240 240 / 80%)";
  3750. inTd.style.borderRadius="20px";
  3751. inTd.style.margin="10px"
  3752. inTd.style.padding="0 0";
  3753. inTd.style.textAlign="center";
  3754. inTd.style.minWidth="150px";
  3755. inTd.appendChild(upSpan);
  3756. inTd.appendChild(pageText);
  3757. inTd.style.width=parseInt(pageBar.style.width)-20+"px";
  3758. inTd.style.boxShadow="rgb(0 0 0 / 67%) 0px 0px 10px 0px";
  3759. if(pageNum)inTd.appendChild(pageNum);
  3760. inTd.appendChild(downSpan);
  3761. td.appendChild(inTd);
  3762. pageBar.appendChild(td);
  3763. }
  3764.  
  3765. upSpan.addEventListener("click", e=>{
  3766. document.body.scrollTop=0;
  3767. document.documentElement.scrollTop=0;
  3768. e.preventDefault();
  3769. e.stopPropagation();
  3770. });
  3771. downSpan.addEventListener("click", e=>{
  3772. changeStop(true);
  3773. pageBar.title=i18n(isPause?"enable":"disable");
  3774. document.body.scrollTop=9999999;
  3775. document.documentElement.scrollTop=9999999;
  3776. e.preventDefault();
  3777. e.stopPropagation();
  3778. });
  3779. pageBar.addEventListener("click", e=>{
  3780. changeStop(!isPause);
  3781. pageBar.title=i18n(isPause?"enable":"disable");
  3782. });
  3783. pageText.addEventListener("click", e=>{
  3784. e.stopPropagation();
  3785. if (e.ctrlKey || e.altKey || e.shiftKey || e.metaKey) return;
  3786. if (e.which == 1) {
  3787. e.preventDefault();
  3788. scrollToPageBar(pageBar);
  3789. }
  3790. });
  3791. ruleParser.insertElement(pageBar);
  3792. if(ruleParser.curSiteRule.pageBar && ruleParser.curSiteRule.pageBar !== 0){
  3793. try{
  3794. ((typeof _unsafeWindow.pagetualPageBar=='undefined') ? Function("pageBar",'"use strict";' + ruleParser.curSiteRule.pageBar) : _unsafeWindow.pagetualPageBar)(pageBar);
  3795. }catch(e){
  3796. debug(e);
  3797. }
  3798. }
  3799.  
  3800. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  3801. let posEle=pageBar.nextElementSibling||pageBar;
  3802. while(posEle && !posEle.offsetParent){
  3803. posEle=posEle.previousElementSibling||posEle.parentNode;
  3804. }
  3805. if(posEle){
  3806. let actualTop = getElementTop(posEle);
  3807. bottomGap=scrollH-actualTop+(window.innerHeight||document.documentElement.clientHeight)*(ruleParser.curSiteRule.rate||1);
  3808. if(bottomGap<100)bottomGap=100;
  3809. }else{
  3810. bottomGap=1000;
  3811. }
  3812. if(rulesData.opacity==0 || ruleParser.curSiteRule.pageBar === 0)pageBar.style.display="none";
  3813. return pageBar;
  3814. }
  3815.  
  3816. function emuClick(btn){
  3817. let orgHref=btn.getAttribute('href');
  3818. if(orgHref){
  3819. btn.setAttribute('href', orgHref.replace(/#$/,""));
  3820. }
  3821. if(!PointerEvent)return btn.click();
  3822. let eventParam={
  3823. isTrusted: true,
  3824. altKey: false,
  3825. azimuthAngle: 0,
  3826. bubbles: true,
  3827. button: 0,
  3828. buttons: 0,
  3829. clientX: 1,
  3830. clientY: 1,
  3831. cancelBubble: false,
  3832. cancelable: true,
  3833. composed: true,
  3834. ctrlKey: false,
  3835. defaultPrevented: false,
  3836. detail: 1,
  3837. eventPhase: 2,
  3838. fromElement: null,
  3839. height: 1,
  3840. isPrimary: false,
  3841. metaKey: false,
  3842. pointerId: 1,
  3843. pointerType: "mouse",
  3844. pressure: 0,
  3845. relatedTarget: null,
  3846. returnValue: true,
  3847. shiftKey: false,
  3848. toElement: null,
  3849. twist: 0,
  3850. which: 1
  3851. };
  3852. var mouseEvent = new PointerEvent("mousedown",eventParam);
  3853. btn.dispatchEvent(mouseEvent);
  3854. mouseEvent = new PointerEvent("mouseup",eventParam);
  3855. btn.dispatchEvent(mouseEvent);
  3856. btn.click();
  3857. if(orgHref){
  3858. setTimeout(()=>btn.setAttribute('href', orgHref),0);
  3859. }
  3860. }
  3861.  
  3862. var failFromIframe=0;
  3863. var inCors=false;
  3864. function requestFromIframe(url, callback){
  3865. url=url.replace(/#[^#]*/,"");
  3866. let orgPage,curPage;
  3867. let iframe = document.createElement('iframe');
  3868. iframe.name = 'pagetual-iframe';
  3869. iframe.width = '100%';
  3870. iframe.height = '0';
  3871. iframe.frameBorder = '0';
  3872. if(ruleParser.curSiteRule.sandbox!=false){
  3873. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  3874. }
  3875. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  3876. let waitTime=100,checkEval;
  3877. if(ruleParser.curSiteRule.waitElement){
  3878. checkEval = doc => {
  3879. return ruleParser.waitElement(doc);
  3880. };
  3881. }else if(ruleParser.curSiteRule.wait){
  3882. if(isNaN(ruleParser.curSiteRule.wait)){
  3883. try{
  3884. checkEval=(typeof _unsafeWindow.pagetualWait=='undefined') ? Function("doc",'"use strict";' + ruleParser.curSiteRule.wait) : _unsafeWindow.pagetualWait;
  3885. }catch(e){
  3886. debug(e);
  3887. }
  3888. }else{
  3889. waitTime=ruleParser.curSiteRule.wait;
  3890. }
  3891. }
  3892. let loadedHandler=e=>{
  3893. if(e.data != 'pagetual-iframe:DOMLoaded' && e.type != 'load')return;
  3894. window.removeEventListener('message', loadedHandler, false);
  3895. iframe.removeEventListener('load', loadedHandler, false);
  3896. let tryTimes=0;
  3897. function checkIframe(){
  3898. try{
  3899. let doc=iframe.contentDocument || iframe.contentWindow.document;
  3900. let base=doc.querySelector("base");
  3901. ruleParser.basePath=base?base.href:url;
  3902. let eles=ruleParser.getPageElement(doc, iframe.contentWindow);
  3903. if(checkEval && !checkEval(doc)){
  3904. setTimeout(()=>{
  3905. checkIframe();
  3906. },waitTime);
  3907. return;
  3908. }else if(eles && eles.length>0){
  3909. callback(doc, eles);
  3910. }else if(tryTimes++ < 100){
  3911. setTimeout(()=>{
  3912. checkIframe();
  3913. },waitTime);
  3914. return;
  3915. }else{
  3916. if(failFromIframe++ > 2){
  3917. failFromIframe=0;
  3918. debug("Stop as failFromIframe");
  3919. isPause=true;
  3920. callback(false, false);
  3921. }else{
  3922. callback(false, false);
  3923. }
  3924. }
  3925. }catch(e){
  3926. debug("Stop as cors");
  3927. inCors=true;
  3928. //isPause=true;
  3929. if(!ruleParser.curSiteRule.pageElement){
  3930. ruleParser.curSiteRule.pageElement=allOfBody;
  3931. ruleParser.getInsert(true);
  3932. }
  3933. ruleParser.curSiteRule.action=0;
  3934. ruleParser.nextLinkHref=url;
  3935. callback(false, false);
  3936. nextPage();
  3937. }
  3938. document.body.removeChild(iframe);
  3939. }
  3940. setTimeout(()=>{
  3941. checkIframe();
  3942. },waitTime);
  3943. };
  3944. window.addEventListener('message', loadedHandler, false);
  3945. iframe.addEventListener('load', loadedHandler, false);
  3946. iframe.src=url;
  3947. document.body.appendChild(iframe);
  3948. }
  3949.  
  3950. var emuIframe,lastActiveUrl;
  3951. function emuPage(callback){
  3952. let orgPage=null,orgContent=null,preContent=null,curPage,iframeDoc,times=0,loadmoreBtn,loadmoreEnd=false,waitTimes=10,changed=false;
  3953. function returnFalse(log){
  3954. debug(log);
  3955. isPause=true;
  3956. callback(false, false);
  3957. if(emuIframe && emuIframe.parentNode){
  3958. emuIframe.parentNode.removeChild(emuIframe);
  3959. emuIframe=null;
  3960. }
  3961. }
  3962. function checkPage(){
  3963. if(isPause)return;
  3964. try{
  3965. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  3966. }catch(e){
  3967. returnFalse("Stop as cors");
  3968. return;
  3969. }
  3970.  
  3971. let waitTime=200,checkEval;
  3972. let nextLink=ruleParser.getNextLink(iframeDoc);
  3973. if(!nextLink){
  3974. if(waitTimes-->0){
  3975. setTimeout(()=>{
  3976. checkPage();
  3977. },waitTime);
  3978. return;
  3979. }
  3980. }
  3981. if(ruleParser.curSiteRule.waitElement){
  3982. checkEval = doc => {
  3983. return ruleParser.waitElement(doc);
  3984. };
  3985. }else if(ruleParser.curSiteRule.wait){
  3986. if(isNaN(ruleParser.curSiteRule.wait)){
  3987. try{
  3988. checkEval=(typeof _unsafeWindow.pagetualWait=='undefined') ? Function("doc",'"use strict";' + ruleParser.curSiteRule.wait) : _unsafeWindow.pagetualWait;
  3989. }catch(e){
  3990. debug(e);
  3991. }
  3992. }else{
  3993. waitTime=ruleParser.curSiteRule.wait;
  3994. }
  3995. }
  3996.  
  3997. if(!orgPage){
  3998. if(!loadmoreEnd){
  3999. loadmoreBtn=getLoadMore(iframeDoc);
  4000. if(loadmoreBtn && isVisible(loadmoreBtn, iframeDoc.defaultView)){
  4001. emuClick(loadmoreBtn);
  4002. let intv=setInterval(()=>{
  4003. loadmoreBtn=getLoadMore(iframeDoc);
  4004. if(!loadmoreBtn || !loadmoreBtn.parentNode || !isVisible(loadmoreBtn, iframeDoc.defaultView)){
  4005. clearInterval(intv);
  4006. loadmoreEnd=true;
  4007. setTimeout(()=>{
  4008. checkPage();
  4009. },500);
  4010. }else{
  4011. emuClick(loadmoreBtn);
  4012. }
  4013. },200);
  4014. return;
  4015. }else{
  4016. loadmoreEnd=true;
  4017. }
  4018. }
  4019. let pageEle=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true);
  4020. if(checkEval && !checkEval(iframeDoc)){
  4021. setTimeout(()=>{
  4022. checkPage();
  4023. },waitTime);
  4024. return;
  4025. }else if(!pageEle || pageEle.length==0){
  4026. if(waitTimes-->0){
  4027. setTimeout(()=>{
  4028. checkPage();
  4029. },waitTime);
  4030. return;
  4031. }
  4032. }
  4033. orgPage=pageEle;
  4034. if(!orgPage || orgPage.length==0){
  4035. returnFalse("Stop as no page when emu");
  4036. return;
  4037. }
  4038. if(orgPage[0].tagName=="UL")orgPage=orgPage[0].children;
  4039. if(nextLink){
  4040. orgPage=orgPage[parseInt(orgPage.length/2)];
  4041. if(orgPage.tagName=="IMG" && orgPage.src){
  4042. orgContent=orgPage.src;
  4043. }else{
  4044. orgContent=orgPage.innerText.trim() || orgPage.innerHTML;
  4045. }
  4046. preContent=orgContent;
  4047. if(!isVisible(nextLink, iframeDoc.defaultView)){
  4048. returnFalse("Stop as next hide when emu");
  4049. }else{
  4050. emuClick(nextLink);
  4051. setTimeout(()=>{
  4052. checkPage();
  4053. },500);
  4054. }
  4055. }else{
  4056. returnFalse("Stop as no next when emu");
  4057. }
  4058. return;
  4059. }
  4060. if(times++ > 100){
  4061. returnFalse("Stop as timeout when emu");
  4062. return;
  4063. }
  4064. let eles=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true),checkItem;
  4065. if(eles && eles.length>0){
  4066. checkItem=eles;
  4067. if(eles[0].tagName=="UL")checkItem=eles[0].children;
  4068. checkItem=checkItem[parseInt(checkItem.length/2)];
  4069. }
  4070. if(!checkItem || (checkEval && !checkEval(iframeDoc))){
  4071. setTimeout(()=>{
  4072. checkPage();
  4073. },waitTime);
  4074. }else{
  4075. let checkInner;
  4076. if(checkItem.tagName=="IMG" && checkItem.src){
  4077. checkInner=checkItem.src;
  4078. }else{
  4079. checkInner=checkItem.innerText.trim() || checkItem.innerHTML;
  4080. }
  4081. if(orgPage!=checkItem || checkInner!=preContent){
  4082. changed=true;
  4083. orgPage=checkItem;
  4084. preContent=checkInner;
  4085. setTimeout(()=>{
  4086. checkPage();
  4087. },waitTime);
  4088. }else if(changed){
  4089. if (orgContent == preContent) {
  4090. returnFalse("Stop as same content");
  4091. } else {
  4092. callback(iframeDoc, eles);
  4093. }
  4094. }else{
  4095. setTimeout(()=>{
  4096. checkPage();
  4097. },waitTime);
  4098. }
  4099. }
  4100. }
  4101. if(!emuIframe){
  4102. let loaded=false;
  4103. emuIframe = document.createElement('iframe');
  4104. emuIframe.name = 'pagetual-iframe';
  4105. if(ruleParser.curSiteRule.sandbox!=false){
  4106. emuIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  4107. }
  4108. emuIframe.width = '100%';
  4109. emuIframe.height = '0';
  4110. emuIframe.frameBorder = '0';
  4111. emuIframe.style.cssText = 'position:fixed;left:0;top:50%;margin:0!important;padding:0!important;visibility:hidden!important;';
  4112. emuIframe.addEventListener("load", e=>{
  4113. setTimeout(()=>{
  4114. try{
  4115. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  4116. }catch(e){
  4117. returnFalse("Stop as cors");
  4118. return;
  4119. }
  4120. let code=ruleParser.curSiteRule.init;
  4121. if(code){
  4122. try{
  4123. Function('doc','win','iframe','"use strict";' + code)(iframeDoc, iframeDoc.defaultView, emuIframe);
  4124. }catch(e){
  4125. debug(e);
  4126. }
  4127. }
  4128. if(loaded)return;
  4129. loaded=true;
  4130. checkPage();
  4131. },500);
  4132. });
  4133. if (!lastActiveUrl) lastActiveUrl=location.href;
  4134. emuIframe.src=lastActiveUrl.replace(/#[^#]*/,"");
  4135. document.body.appendChild(emuIframe);
  4136. }else{
  4137. checkPage();
  4138. }
  4139. }
  4140.  
  4141. var scrollToResizeInited = false;
  4142. var resizePool = [];
  4143. var scrollingToResize = false;
  4144.  
  4145. function scrollToResize(e) {
  4146. if (scrollingToResize) return;
  4147. else {
  4148. scrollingToResize = true;
  4149. let fitWidth = ruleParser.curSiteRule.fitWidth !== false;
  4150. let resizeHandler = () => {
  4151. resizePool.forEach(resizeArr => {
  4152. let iframe = resizeArr[1]();
  4153. let frameDoc = resizeArr[2]();
  4154. if(ruleParser.curSiteRule.singleUrl){
  4155. iframe.style.height=frameDoc.body.scrollHeight+"px";
  4156. iframe.style.width=frameDoc.body.scrollWidth+"px";
  4157. }else{
  4158. let pageEle = resizeArr[0]();
  4159. if(pageEle){
  4160. let targetElement = pageEle[0];
  4161. if(pageEle.length > 1){
  4162. targetElement = targetElement.parentNode;
  4163. }
  4164. if(parseInt(iframe.style.height)==targetElement.scrollHeight) return;
  4165. iframe.style.height=targetElement.scrollHeight+"px";
  4166. frameDoc.documentElement.scrollTop = 0;
  4167. frameDoc.documentElement.scrollLeft = 0;
  4168. while(targetElement && targetElement.offsetParent){
  4169. targetElement.offsetParent.scrollTop = targetElement.offsetTop;
  4170. if(targetElement.offsetParent.scrollTop == 0){
  4171. frameDoc.documentElement.scrollTop += targetElement.offsetTop;
  4172. }
  4173. if(fitWidth){
  4174. targetElement.offsetParent.scrollLeft = targetElement.offsetLeft;
  4175. if(targetElement.offsetParent.scrollLeft == 0){
  4176. frameDoc.documentElement.scrollLeft += targetElement.offsetLeft;
  4177. }
  4178. }
  4179. targetElement = targetElement.offsetParent;
  4180. }
  4181. if(!fitWidth && iframe.style.marginLeft == '0px'){
  4182. iframe.style.width = "100vw";
  4183. iframe.style.marginLeft = -iframe.getBoundingClientRect().left + "px";
  4184. }
  4185. }
  4186. }
  4187. });
  4188. };
  4189. setTimeout(() => {
  4190. resizeHandler();
  4191. scrollingToResize = false
  4192. }, 200);
  4193. resizeHandler();
  4194. }
  4195. }
  4196.  
  4197. function forceIframe(url, callback){
  4198. url=url.replace(/#[^#]*/,"");
  4199. let curIframe = document.createElement('iframe'),iframeDoc,isloaded=false,inAction=true;
  4200. let loadedHandler = ()=>{
  4201. inAction=false;
  4202. if(isloaded)return;
  4203. isloaded=true;
  4204. ruleParser.insertPage(iframeDoc, [], url, null, true);
  4205. callback(curIframe, true);
  4206. let getIframe = () => {
  4207. return curIframe;
  4208. };
  4209. let getFrameDoc = () => {
  4210. return iframeDoc;
  4211. };
  4212. if(ruleParser.curSiteRule.singleUrl){
  4213. resizePool.push([() => {}, getIframe, getFrameDoc]);
  4214. }else{
  4215. let pageElement = ruleParser.getPageElement(iframeDoc,iframeDoc.defaultView);
  4216. let getPageEle = () => {
  4217. if (!pageElement || pageElement.length===0) {
  4218. pageElement = ruleParser.getPageElement(iframeDoc,iframeDoc.defaultView);
  4219. }
  4220. return pageElement;
  4221. };
  4222. resizePool.push([getPageEle, getIframe, getFrameDoc]);
  4223. }
  4224. scrollToResize();
  4225. };
  4226. curIframe.name = 'pagetual-iframe';
  4227. curIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  4228. curIframe.frameBorder = '0';
  4229. curIframe.scrolling="no";
  4230. 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;';
  4231. curIframe.addEventListener("load", e=>{
  4232. try{
  4233. iframeDoc=curIframe.contentDocument || curIframe.contentWindow.document;
  4234. }catch(e){
  4235. debug("Stop as cors");
  4236. isPause=true;
  4237. callback(false, false);
  4238. return;
  4239. }
  4240. let css=ruleParser.curSiteRule.css || rulesData.customCss;
  4241. if(css){
  4242. css = css.replace(/^inIframe:/, "");
  4243. let styleEle=iframeDoc.createElement("style");
  4244. styleEle.innerHTML=css;
  4245. iframeDoc.head.appendChild(styleEle);
  4246. }
  4247. loadedHandler();
  4248. let code=ruleParser.curSiteRule.init;
  4249. if(code){
  4250. try{
  4251. Function('doc','win','iframe','"use strict";' + code)(iframeDoc,iframeDoc.defaultView,curIframe);
  4252. }catch(e){
  4253. debug(e);
  4254. }
  4255. }
  4256. });
  4257. let checkTimes=0,findPageEle=false;
  4258. let forceRefresh=e=>{
  4259. if(inAction || !iframeDoc)return;
  4260. inAction=true;
  4261. let foundNext=()=>{
  4262. document.removeEventListener("scroll", forceRefresh);
  4263. }
  4264. setTimeout(()=>{
  4265. inAction=false;
  4266. if(!ruleParser.nextLinkHref){
  4267. checkTimes++;
  4268. ruleParser.getNextLink(iframeDoc);
  4269. if(ruleParser.nextLinkHref){
  4270. foundNext();
  4271. }else if(checkTimes>=10){
  4272. foundNext();
  4273. }else if(checkTimes>=3 && !findPageEle){
  4274. let pageElement = ruleParser.getPageElement(iframeDoc,iframeDoc.defaultView);
  4275. if(!pageElement){
  4276. inAction=true;
  4277. curIframe.contentWindow.location.reload();
  4278. }else{
  4279. findPageEle=true;
  4280. }
  4281. }
  4282. }else{
  4283. foundNext();
  4284. }
  4285. },50);
  4286. };
  4287. document.addEventListener("scroll", forceRefresh);
  4288. curIframe.src=url;
  4289. let insert=ruleParser.getInsert();
  4290. if(ruleParser.curSiteRule.singleUrl || forceState==2){
  4291. document.body.appendChild(loadingDiv);
  4292. document.body.appendChild(curIframe);
  4293. }else{
  4294. ruleParser.insertElement(curIframe);
  4295. }
  4296.  
  4297. if (!scrollToResizeInited) {
  4298. scrollToResizeInited = true;
  4299. document.addEventListener("scroll", scrollToResize);
  4300. }
  4301. return curIframe;
  4302. }
  4303.  
  4304. function loadPageOver(){
  4305. isLoading=false;
  4306. if(loadingDiv.parentNode){
  4307. loadingDiv.parentNode.removeChild(loadingDiv);
  4308. }
  4309. /*setTimeout(()=>{
  4310. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  4311. if(scrollH <= (window.innerHeight || document.documentElement.clientHeight)){
  4312. nextPage();
  4313. }
  4314. },1);*/
  4315. }
  4316.  
  4317. var tryTimes = 0;
  4318.  
  4319. function nextPage(){
  4320. if(typeof ruleParser.curSiteRule.manualMode=='undefined' ? rulesData.manualMode : ruleParser.curSiteRule.manualMode)return;
  4321. if(isPause || isLoading || forceState==1)return;
  4322. if(ruleParser.curSiteRule.delay){
  4323. try{
  4324. let checkDelay=((typeof _unsafeWindow.pagetualDelay=='undefined') ? Function('"use strict";' + ruleParser.curSiteRule.delay) : _unsafeWindow.pagetualDelay)();
  4325. if(!checkDelay)return;
  4326. }catch(e){
  4327. debug(e);
  4328. }
  4329. }
  4330. if(ruleParser.curSiteRule.pageElementCss || ruleParser.curSiteRule.pageElementStyle || rulesData.pageElementCss){
  4331. ruleParser.getPageElement(document, _unsafeWindow);
  4332. }
  4333. let nextLink=ruleParser.nextLinkHref;
  4334. if(!nextLink){
  4335. if(curPage==1){
  4336. ruleParser.getNextLink(document);
  4337. nextLink=ruleParser.nextLinkHref;
  4338. }
  4339. if(!nextLink){
  4340. isLoading=true;
  4341. if(curPage==1 && (ruleParser.curSiteRule.pinUrl || tryTimes++ <= 10)){
  4342. setTimeout(()=>{isLoading=false},500);
  4343. }
  4344. return;
  4345. }
  4346. }
  4347. let pvGallery=document.querySelector("span.pv-gallery-container");
  4348. if(pvGallery && pvGallery.style.display!="none")return;
  4349. let insert=ruleParser.getInsert();
  4350. if(insert){
  4351. let isJs=/^(javascript|#)/.test(nextLink.replace(location.href,""));
  4352. if(!isJs){
  4353. emuIframe=null;
  4354. lastActiveUrl=nextLink;
  4355. }
  4356. if(location.protocol=="https:" && /^http:/.test(nextLink)){
  4357. nextLink=nextLink.replace(/^http/,"https");
  4358. }
  4359. isLoading=true;
  4360. ruleParser.insertElement(loadingDiv);
  4361. let parent=loadingDiv.parentNode;
  4362. if(parent.tagName=="TBODY"){
  4363. parent=parent.parentNode;
  4364. }
  4365. if(parent.tagName=="TABLE"){
  4366. parent.parentNode.appendChild(loadingDiv);
  4367. }
  4368. loadingDiv.style.cssText=loadingCSS;
  4369. let sleep=ruleParser.curSiteRule.sleep||0;
  4370. setTimeout(()=>{
  4371. if(ruleParser.curSiteRule.pageElementByJs){
  4372. var over=ele=>{
  4373. loadPageOver();
  4374. if(ele){
  4375. createPageBar(nextLink);
  4376. ruleParser.insertPage(null, ele, nextLink, null, true);
  4377. if(autoLoadNum>=0){
  4378. if(autoLoadNum!=0 && --autoLoadNum==0){
  4379. autoLoadNum=-1;
  4380. }else{
  4381. nextPage();
  4382. }
  4383. }
  4384. }else{
  4385. debug("Stop as no page when get by js");
  4386. isPause=true;
  4387. }
  4388. };
  4389. try{
  4390. ((typeof _unsafeWindow.pagetualPageElementByJs=='undefined') ? Function("over",'"use strict";' + ruleParser.curSiteRule.pageElementByJs) : _unsafeWindow.pagetualPageElementByJs)(over);
  4391. }catch(e){
  4392. debug(e);
  4393. }
  4394. }else if((forceState==3||ruleParser.curSiteRule.action==1) && !isJs){
  4395. requestFromIframe(nextLink, (doc, eles)=>{
  4396. loadPageOver();
  4397. if(eles){
  4398. ruleParser.insertPage(doc, eles, nextLink, ()=>{
  4399. createPageBar(nextLink);
  4400. }, true);
  4401. if(autoLoadNum>=0){
  4402. if(autoLoadNum!=0 && --autoLoadNum==0){
  4403. autoLoadNum=-1;
  4404. }else{
  4405. nextPage();
  4406. }
  4407. }
  4408. }
  4409. });
  4410. }else if((forceState==2||ruleParser.curSiteRule.action==2) && !isJs){
  4411. forceIframe(nextLink, (iframe, eles)=>{
  4412. loadPageOver();
  4413. let pageBar=createPageBar(nextLink);
  4414. if(pageBar)iframe.parentNode.insertBefore(pageBar, iframe);
  4415. if(autoLoadNum>=0){
  4416. if(autoLoadNum!=0 && --autoLoadNum==0){
  4417. autoLoadNum=-1;
  4418. }else{
  4419. nextPage();
  4420. }
  4421. }
  4422. });
  4423. }else{
  4424. if(!isJs){
  4425. requestDoc(nextLink, (eles)=>{
  4426. loadPageOver();
  4427. if(eles){
  4428. createPageBar(nextLink);
  4429. if(autoLoadNum>=0){
  4430. if(autoLoadNum!=0 && --autoLoadNum==0){
  4431. autoLoadNum=-1;
  4432. }else{
  4433. nextPage();
  4434. }
  4435. }
  4436. }
  4437. });
  4438. }else{
  4439. emuPage((doc, eles)=>{
  4440. loadPageOver();
  4441. if(eles){
  4442. ruleParser.insertPage(doc, eles, "", ()=>{
  4443. createPageBar(nextLink);
  4444. }, true);
  4445. if(autoLoadNum>=0){
  4446. if(autoLoadNum!=0 && --autoLoadNum==0){
  4447. autoLoadNum=-1;
  4448. }else{
  4449. setTimeout(() => nextPage(), 1);
  4450. }
  4451. }
  4452. }
  4453. });
  4454. }
  4455. }
  4456. },sleep);
  4457. }
  4458. }
  4459.  
  4460. function init(){
  4461. initRules(()=>{
  4462. initPage();
  4463. });
  4464. }
  4465.  
  4466. function visibilitychangeHandler(){
  4467. document.removeEventListener('visibilitychange', visibilitychangeHandler);
  4468. init();
  4469. }
  4470.  
  4471. setTimeout(()=>{
  4472. if (document.hidden) {
  4473. document.addEventListener('visibilitychange', visibilitychangeHandler);
  4474. } else {
  4475. init();
  4476. }
  4477. },100);
  4478. })();

QingJ © 2025

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