东方永页机

终极自动翻页 - 加载并拼接下一分页内容至当前页尾,智能适配任意网页

当前为 2023-04-15 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Pagetual
  3. // @name:zh-CN 东方永页机
  4. // @name:zh-TW 東方永頁機
  5. // @name:ja 東方永頁機
  6. // @name:ru Pagetual
  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.35.20
  14. // @description Perpetual pages - Most powerful auto-pager script. Auto loading next paginated web pages and inserting into current page. Support thousands of web sites without any rule.
  15. // @description:zh-CN 终极自动翻页 - 加载并拼接下一分页内容至当前页尾,智能适配任意网页
  16. // @description:zh-TW 終極自動翻頁 - 加載並拼接下一分頁內容至當前頁尾,智能適配任意網頁
  17. // @description:ja Webページを自動で読み込み継ぎ足し表示を行うブラウザ拡張です、次のページ付けされた Web ページの自動読み込みと現在のページへの挿入 ルールなしで何千もの Web サイトをサポートします。
  18. // @description:ru Автоматическая подгрузка следующих страниц и вставка их содержимого в текущую страницу. Поддерживает тысячи сайтов даже с настройками по умолчанию.
  19. // @description:de Automatisches Laden der nächsten paginierten Webseiten und Einfügen in die aktuelle Seite. Unterstützen Sie Tausende von Websites ohne Regeln.
  20. // @description:es Carga automática de las siguientes páginas web paginadas e inserción en la página actual. Admite miles de sitios web sin ninguna regla.
  21. // @description:fr Chargement automatique des pages Web paginées suivantes et insertion dans la page en cours. Prend en charge des milliers de sites Web sans aucune règle.
  22. // @description:it Caricamento automatico delle pagine Web impaginate successive e inserimento nella pagina corrente. Supporta migliaia di siti web senza alcuna regola.
  23. // @description:ko 페이지가 매겨진 다음 웹 페이지를 자동으로 로드하고 현재 페이지에 삽입합니다. 규칙 없이 수천 개의 웹 사이트를 지원합니다.
  24. // @author hoothin
  25. // @license MPL License
  26. // @match *://*/*
  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_setClipboard
  38. // @grant GM.xmlHttpRequest
  39. // @grant GM.registerMenuCommand
  40. // @grant GM.notification
  41. // @grant GM.getValue
  42. // @grant GM.setValue
  43. // @grant GM.addStyle
  44. // @grant GM.openInTab
  45. // @grant GM.deleteValue
  46. // @grant GM.info
  47. // @grant GM.setClipboard
  48. // @supportURL https://github.com/hoothin/UserScripts/issues
  49. // @connect wedata.net
  50. // @connect githubusercontent.com
  51. // @connect ghproxy.com
  52. // @connect hoothin.github.io
  53. // @run-at document-idle
  54. // @connect *
  55. // ==/UserScript==
  56.  
  57. (function() {
  58. 'use strict';
  59.  
  60. if (window.name === 'pagetual-iframe' || (window.frameElement && window.frameElement.name === 'pagetual-iframe')) {
  61. var domloaded = function (){
  62. window.scroll(window.scrollX, 999999);
  63. window.parent.postMessage('pagetual-iframe:DOMLoaded', '*');
  64. };
  65. if (window.opera) {
  66. document.addEventListener('DOMContentLoaded', domloaded, false);
  67. } else {
  68. domloaded();
  69. }
  70. if (getComputedStyle(document.documentElement).display == 'none') document.documentElement.style.display = 'block';
  71. if (document.body && getComputedStyle(document.body).display == 'none') document.body.style.display = 'block';
  72. return;
  73. }
  74.  
  75. if (window.top != window.self) {
  76. try {
  77. if (window.self.innerWidth < 100 || window.self.innerHeight < 100) {
  78. return;
  79. }
  80. } catch(e) {
  81. return;
  82. }
  83. }
  84.  
  85. const noRuleTest = false;
  86. const lang = navigator.appName == "Netscape" ? navigator.language : navigator.userLanguage;
  87. let config = {};
  88. switch (lang) {
  89. case "zh-CN":
  90. case "zh-SG":
  91. config = {
  92. enableDebug: "调试模式,输出信息至控制台",
  93. disable: "暂时禁用",
  94. disableSite: "站点禁用开关",
  95. disableSiteTips: "已在此站禁用",
  96. enableSiteTips: "已在此站启用",
  97. enable: "启用自动翻页",
  98. toTop: "回到顶部",
  99. toBottom: "前往页尾",
  100. current: "当前页",
  101. forceIframe: "强制拼接",
  102. cancelForceIframe: "取消强制拼接",
  103. configure: "打开配置页面",
  104. firstUpdate: "点击此处初始化规则",
  105. update: "更新在线规则",
  106. click2update: "点击立即更新规则",
  107. loadNow: "立即翻页",
  108. loadConfirm: "要翻几页?(0为不间断)",
  109. noNext: "没有找到下一页,请新建规则",
  110. passSec: "更新于 #t# 秒前",
  111. passMin: "更新于 #t# 分钟前",
  112. passHour: "更新于 #t# 小时前",
  113. passDay: "更新于 #t# 天前",
  114. cantDel: "无法删除内置规则",
  115. confirmDel: "是否确认要删除此规则?",
  116. updateSucc: "更新成功",
  117. beginUpdate: "正在更新,请耐心等待,不要关闭页面",
  118. customUrls: "导入 Pagetual 或 AutoPagerize 规则 url,一行一条",
  119. customRules: "输入【东方永页机】格式的自定义规则 <a href='#t#'>贡献规则</a>",
  120. save: "保存设置",
  121. loadingText: "少女祈祷中...",
  122. opacity: "不透明值",
  123. opacityPlaceholder: "0: 隐藏分隔条",
  124. hideBar: "隐藏分页隔条",
  125. hideBarButNoStop: "隐藏但不停止",
  126. dbClick2Stop: "空白处双击暂停翻页",
  127. sortTitle: "排序在下次更新规则后生效",
  128. autoRun: "自动启用,否则为白名单模式",
  129. autoLoadNum: "自动加载指定页数",
  130. turnRate: "距离页尾X倍页面高度时就开始翻页",
  131. inputPageNum: "输入页码跳转",
  132. enableHistory: "翻页后写入历史记录",
  133. enableHistoryAfterInsert: "拼接后立即写入历史记录,否则浏览完毕后再行写入",
  134. contentVisibility: "自动切换 contentVisibility,提升渲染性能",
  135. initRun: "打开页面后立即尝试翻页,否则滚动至页尾再翻页",
  136. preload: "翻页前预读下一页,加速浏览",
  137. click2ImportRule: "点击下方添加特殊规则库,并静待更新成功:",
  138. forceAllBody: "是否拼接整个页面?",
  139. openInNewTab: "使拼接页面的内容在新页面打开",
  140. importSucc: "导入成功",
  141. import: "导入",
  142. editCurrent: "编辑此站规则",
  143. editBlacklist: "编辑黑名单网址,一行一条,支持? *通配符",
  144. upBtnImg: "回到页首图标",
  145. downBtnImg: "前往页尾图标",
  146. sideControllerIcon: "侧边栏图标",
  147. loadingTextTitle: "加载中文字",
  148. dbClick2StopCtrl: "Ctrl 键",
  149. dbClick2StopAlt: "Alt 键",
  150. dbClick2StopShift: "Shift 键",
  151. dbClick2StopMeta: "Meta 键",
  152. dbClick2StopKey: "快捷键",
  153. pageElementCss: "页面主体框架的样式",
  154. customCss: "自定义 css",
  155. firstAlert: "你还未导入规则库,请选择合适的规则库导入哦",
  156. picker: "东方永页机主体元素抓取器",
  157. closePicker: "关闭东方永页机抓取器",
  158. pickerPlaceholder: "没想法建议留空",
  159. pickerCheck: "检查你编辑的选择器并复制",
  160. switchSelector: "点击切换元素",
  161. gotoEdit: "使用当前的选择器前往编辑规则",
  162. manualMode: "禁用拼接,手动用右方向键翻页,可使用左方向键返回",
  163. clickMode: "禁用拼接,滚动至页尾时自动点击下一页",
  164. pageBarMenu: "点击分隔条中间弹出菜单",
  165. nextSwitch: "切换其他页码",
  166. arrowToScroll: "左方向键滚动至上一页,右方向键滚动至下一页",
  167. sideController: "在侧边显示翻页控制栏",
  168. hideLoadingIcon: "隐藏加载动画",
  169. hideBarArrow: "隐藏分隔条定位箭头",
  170. duplicate: "检测到永页机重复安装,请删除其他脚本管理器中的永页机!",
  171. forceStateIframe: "以 iframe 嵌入整页",
  172. forceStateDynamic: "通过 iframe 加载动态内容后取出",
  173. forceStateDisable: "在此站禁用",
  174. page: "Page ",
  175. prevPage: "上一页",
  176. nextPage: "下一页",
  177. errorRulesMustBeArray: "规则必须为数组形式!",
  178. errorJson: "JSON 格式有错,请重新检查!",
  179. editSuccess: "编辑成功",
  180. errorWrongUrl: "URL 错误, 请重新检查!",
  181. errorAlreadyExists: "已经存在!",
  182. settingsSaved: "设置已保存,刷新后生效",
  183. iframe: "强制拼接",
  184. dynamic: "动态加载",
  185. reloadPage: "编辑完成,是否立即刷新页面?",
  186. copied: "已复制",
  187. noValidContent: "没有检测到有效内容,点击查看",
  188. outOfDate: "脚本已过时,请及时更新到最新版本!"
  189. };
  190. break;
  191. case "zh-TW":
  192. case "zh-HK":
  193. config = {
  194. enableDebug: "調試模式,輸出信息至控制台",
  195. disable: "暫時禁用",
  196. disableSite: "站點禁用開關",
  197. disableSiteTips: "已在此站禁用",
  198. enableSiteTips: "已在此站啟用",
  199. enable: "啟用自動翻頁",
  200. toTop: "回到頂部",
  201. toBottom: "前往頁尾",
  202. current: "當前頁",
  203. forceIframe: "強制拼接",
  204. cancelForceIframe: "取消强制拼接",
  205. configure: "打開配置頁面",
  206. firstUpdate: "點擊此處初始化規則",
  207. update: "更新在綫規則",
  208. click2update: "點擊立即更新規則",
  209. loadNow: "立即翻頁",
  210. loadConfirm: "要翻几頁?(0為不間斷)",
  211. noNext: "沒有找到下一頁,請新建規則",
  212. passSec: "更新于 #t# 秒前",
  213. passMin: "更新于 #t# 分鐘前",
  214. passHour: "更新于 #t# 小時前",
  215. passDay: "更新于 #t# 天前",
  216. cantDel: "無法刪除内置規則",
  217. confirmDel: "是否確認要刪除此規則?",
  218. updateSucc: "更新成功",
  219. beginUpdate: "正在更新,請稍候",
  220. customUrls: "導入 Pagetual 或 AutoPagerize 規則 url,一行一條",
  221. customRules: "輸入【東方永頁機】格式的自定義規則 <a href='#t#'>貢獻規則</a>",
  222. save: "存儲設置",
  223. loadingText: "少女祈禱中...",
  224. opacity: "不透明值",
  225. opacityPlaceholder: "0: 隱藏分隔條",
  226. hideBar: "隱藏分頁隔條",
  227. hideBarButNoStop: "隱藏但不停止",
  228. dbClick2Stop: "空白處雙擊暫停翻頁",
  229. sortTitle: "排序在下次更新規則後生效",
  230. autoRun: "自動啓用,否則為白名單模式",
  231. autoLoadNum: "自動加載指定頁數",
  232. turnRate: "距離頁尾X倍頁面高度時就開始翻頁",
  233. inputPageNum: "輸入頁碼跳轉",
  234. enableHistory: "翻頁后寫入歷史記錄",
  235. enableHistoryAfterInsert: "拼接後立即寫入歷史記錄,否則瀏覽完畢後再行寫入",
  236. contentVisibility: "自動切換 contentVisibility,提升渲染性能",
  237. initRun: "打開頁面后立即嘗試翻頁,否則滾動至頁尾再翻頁",
  238. preload: "翻頁前預讀下一頁,加速瀏覽",
  239. click2ImportRule: "點擊下方添加特殊規則庫,并靜待更新成功:",
  240. forceAllBody: "是否拼接整個頁面?",
  241. openInNewTab: "使拼接頁面的内容在新頁面打開",
  242. importSucc: "導入成功",
  243. import: "導入",
  244. editCurrent: "編輯此站規則",
  245. editBlacklist: "編輯黑名單網址,一行一條,支持? *通配符",
  246. upBtnImg: "回到頁首圖標",
  247. downBtnImg: "前往頁尾圖標",
  248. sideControllerIcon: "側邊欄圖標",
  249. loadingTextTitle: "加載中文字",
  250. dbClick2StopCtrl: "Ctrl 鍵",
  251. dbClick2StopAlt: "Alt 鍵",
  252. dbClick2StopShift: "Shift 鍵",
  253. dbClick2StopMeta: "Meta 鍵",
  254. dbClick2StopKey: "快捷鍵",
  255. pageElementCss: "頁面主體框架的樣式",
  256. customCss: "自定義 css",
  257. firstAlert: "你還未導入規則庫,請選擇合適的規則庫導入哦",
  258. picker: "東方永頁機主體元素抓取器",
  259. closePicker: "關閉東方永頁機抓取器",
  260. pickerPlaceholder: "沒想法建議留空",
  261. pickerCheck: "檢查你編輯的選擇器並複製",
  262. switchSelector: "點擊切換元素",
  263. gotoEdit: "使用當前的選擇器前往編輯規則",
  264. manualMode: "禁用拼接,手動用右方向鍵翻頁,左方向鍵返回",
  265. clickMode: "禁用拼接,滾動至頁尾時自動點擊下一頁",
  266. pageBarMenu: "點擊分隔條中間彈出菜單",
  267. nextSwitch: "切換其他頁碼",
  268. arrowToScroll: "左方向鍵滾動至上一頁,右方向鍵滾動至下一頁",
  269. sideController: "在側邊顯示翻頁控制欄",
  270. hideLoadingIcon: "隱藏加載動畫",
  271. hideBarArrow: "隱藏分隔條定位箭頭",
  272. duplicate: "檢測到永頁機重複安裝,請刪除其他腳本管理器中的永頁機!",
  273. forceStateIframe: "以 iframe 嵌入整頁",
  274. forceStateDynamic: "通過 iframe 加載動態內容後取出",
  275. forceStateDisable: "在此站禁用",
  276. page: "Page ",
  277. prevPage: "上一頁",
  278. nextPage: "下一頁",
  279. errorRulesMustBeArray: "規則必須為陣列形式!",
  280. errorJson: "JSON 格式有錯,請重新檢查!",
  281. editSuccess: "編輯成功",
  282. errorWrongUrl: "URL 錯誤, 請重新檢查!",
  283. errorAlreadyExists: "已經存在!",
  284. settingsSaved: "設置已保存,刷新後生效",
  285. iframe: "強制拼接",
  286. dynamic: "動態加載",
  287. reloadPage: "編輯完成,是否立即刷新頁面?",
  288. copied: "已復制",
  289. noValidContent: "沒有檢測到有效内容,點擊查看",
  290. outOfDate: "脚本已過時,請及時更新到最新版本!"
  291. };
  292. break;
  293. case "ja":
  294. config = {
  295. enableDebug: "デバッグモード",
  296. disable: "一時的に無効",
  297. disableSite: "無効状態の切り替え",
  298. disableSiteTips: "このサイトで既に無効になっています",
  299. enableSiteTips: "このサイトで既に有効になっています",
  300. enable: "ページめくりを有効にする",
  301. toTop: "トップに戻る",
  302. toBottom: "ページの下部に移動",
  303. current: "現在のページ",
  304. forceIframe: "強制ステッチ",
  305. cancelForceIframe: "強制ステッチをキャンセル",
  306. configure: "設定ページを開く",
  307. firstUpdate: "ここをクリックしてルールを初期化します",
  308. update: "更新ルール",
  309. click2update: "今すぐルールを更新してください",
  310. loadNow: "今すぐページをめくる",
  311. loadConfirm: "数ページめくりたいですか?(0は途切れない)",
  312. noNext: "次のページが見つかりません、新しいルールを作成してください",
  313. passSec: "#t#秒前に更新",
  314. passMin: "#t#分前に更新",
  315. passHour: "#t#時間前に更新",
  316. passDay: "#t#日前に更新",
  317. cantDel: "組み込みルールを削除できません",
  318. confirmDel: "このルールを削除してもよろしいですか?",
  319. updateSucc: "更新に成功しました",
  320. beginUpdate: "更新中、お待ちください",
  321. customUrls: "インポートルールのURL、1行に1つ",
  322. customRules: "【東方永頁機】の形式でカスタムルールを入力してください <a href='#t#'>寄稿ルール</a>",
  323. save: "設定を保存",
  324. loadingText: "少女祈祷中...",
  325. opacity: "不透明値",
  326. opacityPlaceholder: "0: 隠す",
  327. hideBar: "ページ区切り文字を非表示にします",
  328. hideBarButNoStop: "非表示にするが停止しない",
  329. dbClick2Stop: "空白部分をダブルクリックしてページめくりを一時停止します",
  330. sortTitle: "並べ替えは、次のルールの更新後に有効になります",
  331. autoRun: "自動的に有効",
  332. autoLoadNum: "指定したページ数を自動的に読み込みます",
  333. turnRate: "ページの端からページの高さの X 倍になったらページをめくる",
  334. inputPageNum: "ジャンプするページ番号を入力",
  335. enableHistory: "ページめくり後の履歴を書く",
  336. enableHistoryAfterInsert: "スプライシングの直後に履歴レコードを書き込みます。それ以外の場合は、閲覧後に書き込みます",
  337. contentVisibility: "contentVisibility を自動的に切り替えてレンダリング パフォーマンスを向上させる",
  338. initRun: "Webページを開いた直後にページをめくる",
  339. preload: "事前に次のページを読む",
  340. click2ImportRule: "以下をクリックして、ルールベースを追加します:",
  341. forceAllBody: "フルページ埋め込み?",
  342. openInNewTab: "スプライスされたページのコンテンツを新しいページで開きます",
  343. importSucc: "インポート完了",
  344. import: "インポート",
  345. editCurrent: "現在のルールの編集",
  346. editBlacklist: "ブラックリストのURLを編集し、1行ずつ、サポート? *ワイルドカード",
  347. upBtnImg: "トップアイコンに戻る",
  348. downBtnImg: "フッターアイコンに移動",
  349. sideControllerIcon: "サイドバー アイコン",
  350. loadingTextTitle: "テキストをロード",
  351. dbClick2StopCtrl: "Ctrlキー",
  352. dbClick2StopAlt: "Altキー",
  353. dbClick2StopShift: "Shiftキー",
  354. dbClick2StopMeta: "Metaキー",
  355. dbClick2StopKey: "Shortcutキー",
  356. pageElementCss: "ページ本文フレームの STYLE",
  357. customCss: "カスタム css",
  358. firstAlert: "ルールベースをインポートしていないため、インポートする適切なルールベースを選択してください",
  359. picker: "Pagetualページ要素ピッカー",
  360. closePicker: "Pagetualピッカーを閉じる",
  361. pickerPlaceholder: "わからない場合は空のままにしてください",
  362. pickerCheck: "セレクターをチェックしてコピー",
  363. switchSelector: "クリックして要素を切り替えます",
  364. gotoEdit: "現在のセレクターでルールを編集する",
  365. manualMode: "スプライシングを無効にします。手動で右の矢印キーを使用してページをめくります",
  366. clickMode: "スティッチングを無効にします。ページの最後までスクロールすると、次のページが自動的にクリックされます",
  367. pageBarMenu: "ページバーの中央をクリックしてメニューをポップアップ表示",
  368. nextSwitch: "次のページに切り替え",
  369. arrowToScroll: "左矢印キーで前へ、右矢印キーで次へ",
  370. sideController: "サイドバーにページング コントロール バーを表示する",
  371. hideLoadingIcon: "読み込み中のアニメーションを隠す",
  372. hideBarArrow: "分割線の位置矢印を隠す",
  373. duplicate: "Pagetual の重複インストールが検出されました。他のスクリプト マネージャで永続的なページ マシンを削除してください!",
  374. forceStateIframe: "iframe にページ全体を埋め込む",
  375. forceStateDynamic: "iframe 経由で動的コンテンツを読み込む",
  376. forceStateDisable: "このステーションでのページめくりを無効にする",
  377. page: "Page ",
  378. prevPage: "Prev page",
  379. nextPage: "Next page",
  380. errorRulesMustBeArray: "Rules must be a Array!",
  381. errorJson: "JSON error, check again!",
  382. editSuccess: "Edit successfully",
  383. errorWrongUrl: "Wrong url, check again!",
  384. errorAlreadyExists: "Already exists!",
  385. settingsSaved: "The settings are saved, refresh to view",
  386. iframe: "Iframe",
  387. dynamic: "Dynamic",
  388. reloadPage: "Edit completed, reload page now?",
  389. copied: "Copied",
  390. noValidContent: "有効なコンテンツが検出されませんでした。クリックして表示",
  391. outOfDate: "スクリプトが古くなっています。最新バージョンに更新してください。"
  392. };
  393. break;
  394. case "ru":
  395. case "ru-RU":
  396. config = {
  397. enableDebug: "Включить отладку",
  398. disable: "Выключено",
  399. disableSite: "Включить/выключить на сайте",
  400. disableSiteTips: "Выключено для этого сайта",
  401. enableSiteTips: "Включено для этого сайта",
  402. enable: "Включено",
  403. toTop: "Наверх",
  404. toBottom: "Вниз",
  405. current: "Текущая страница",
  406. forceIframe: "Подгрузить ещё страницу",
  407. cancelForceIframe: "Отменить подгрузку",
  408. configure: "Настройки",
  409. firstUpdate: "Нажмите здесь, чтобы инициализировать правила",
  410. update: "Обновить правила",
  411. click2update: "Нажмите, чтобы обновить правила",
  412. loadNow: "Загрузить следующую страницу",
  413. loadConfirm: "Сколько страниц вы хотите загрузить? (0 означает бесконечность)",
  414. noNext: "Ссылка на следующую страницу не найдена. Пожалуйста, создайте новое правило",
  415. passSec: "Обновлено #t# секунд назад",
  416. passMin: "Обновлено #t# минут назад",
  417. passHour: "Обновлено #t# часов назад",
  418. passDay: "Обновлено #t# дней назад",
  419. cantDel: "Нельзя удалить правила по умолчанию",
  420. confirmDel: "Вы уверены, что хотите удалить эту ссылку?",
  421. updateSucc: "Правила обновлены",
  422. beginUpdate: "Обновление. Пожалуйста, немного подождите",
  423. customUrls: "Ссылки с правилами для импорта. Одна ссылка на строку",
  424. customRules: "Введите пользовательские правила в формате Pagetual. <a href='#t#'>Улучшить встроенные правила</a>",
  425. save: "Сохранить настройки",
  426. loadingText: "Следующая страница подгружается…",
  427. opacity: "Прозрачность",
  428. opacityPlaceholder: "0 - скрыть",
  429. hideBar: "Скрыть разделитель страниц",
  430. hideBarButNoStop: "Скрыть, но не останавливать",
  431. dbClick2Stop: "Двойной клик на странице для выключения",
  432. sortTitle: "Правило сортировки применится после следующего обновления правил",
  433. autoRun: "Автозапуск (режим черного списка)",
  434. autoLoadNum: "Количество страниц для предзагрузки",
  435. turnRate: "Подгрузить страницу, когда она будет в X раз больше высоты страницы от конца страницы",
  436. inputPageNum: "Введите номер страницы для перехода",
  437. enableHistory: "Записать историю после переключения страниц",
  438. enableHistoryAfterInsert: "Записать запись истории сразу после вставки, иначе записать после просмотра",
  439. contentVisibility: "Автоматически переключать contentVisibility для повышения производительности рендеринга",
  440. initRun: "Подгружать страницы сразу после открытия",
  441. preload: "Предзагрузка следующей страницы",
  442. click2ImportRule: "Нажмите, чтобы импортировать базовые правила: ",
  443. forceAllBody: "Присоединить страницу целиком?",
  444. openInNewTab: "Открыть дополнительные ссылки в новой вкладке",
  445. importSucc: "Импорт завершен",
  446. import: "Импорт",
  447. editCurrent: "Изменить правило для текущего сайта",
  448. editBlacklist: "Изменить черный список. Одна ссылка на строку. Поддерживаются метасимволы: ? и *",
  449. upBtnImg: "Иконка перехода к началу",
  450. downBtnImg: "Иконка перехода к концу",
  451. sideControllerIcon: "Значок боковой панели",
  452. loadingTextTitle: "Текст во время загрузки",
  453. dbClick2StopCtrl: "Ctrl",
  454. dbClick2StopAlt: "Alt",
  455. dbClick2StopShift: "Shift",
  456. dbClick2StopMeta: "Meta",
  457. dbClick2StopKey: "Клавиша",
  458. pageElementCss: "Пользовательский стиль для основных элементов страницы",
  459. customCss: "Полный пользовательский CSS",
  460. firstAlert: "Вы не импортировали базовое правило. Пожалуйста, выберите соответствующее правило для импорта",
  461. picker: "Pagetual: выбор элемента страницы",
  462. closePicker: "Закрыть окно Pagetual",
  463. pickerPlaceholder: "Если не знаете, что тут писать — оставьте поле пустым",
  464. pickerCheck: "Проверить и скопировать селектор",
  465. switchSelector: "Нажмите для выбора элемента",
  466. gotoEdit: "Перейти к редактированию правила с текущим селектором",
  467. manualMode: "Отключить автоматическую загрузку страниц. Загружать вручную с помощью стрелки вправо (или вызова события 'pagetual.next')",
  468. clickMode: "Отключить \"сшивание\" страниц. При прокрутке до конца автоматически переходить на следующую страницу",
  469. pageBarMenu: "Открывать меню кликом на середину панели страниц",
  470. nextSwitch: "Переключить ссылку на следующую страницу",
  471. arrowToScroll: "Листать страницы клавишами со стрелками влево и вправо",
  472. sideController: "Показать справа панель перемещения по вкладке",
  473. hideLoadingIcon: "Скрыть анимацию загрузки",
  474. hideBarArrow: "Скрыть кнопки перемещения на разделителе",
  475. duplicate: "Похоже, Pagetual установлен несколько раз. Пожалуйста, удалите Pagetual из других менеджеров скриптов!",
  476. forceStateIframe: "Вставить полную страницу как iframe",
  477. forceStateDynamic: "Загружать динамический контент через iframe",
  478. forceStateDisable: "Отключить перелистывание страниц на этой станции",
  479. page: "Страница ",
  480. prevPage: "Предыдущая страница",
  481. nextPage: "Следующая страница",
  482. errorRulesMustBeArray: "Правила должны быть массивом!",
  483. errorJson: "Ошибка разбора JSON. Пожалуйста, исправьте его",
  484. editSuccess: "Редактирование успешно",
  485. errorWrongUrl: "Ссылка некорректна. Пожалуйста, исправьте её",
  486. errorAlreadyExists: "Уже существует!",
  487. settingsSaved: "Настройки сохранены. Обновите страницы",
  488. iframe: "iframe",
  489. dynamic: "Динамически",
  490. reloadPage: "Редактирование завершено. Обновить страницу?",
  491. copied: "Скопировано",
  492. noValidContent: "Действительный контент не обнаружен, нажмите для просмотра",
  493. outOfDate: "Скрипт устарел, своевременно обновляйте до последней версии!"
  494. };
  495. break;
  496. default:
  497. config = {
  498. enableDebug: "Enable debug output",
  499. disable: "Disable",
  500. disableSite: "Toggle disabled state",
  501. disableSiteTips: "Disabled on this site",
  502. enableSiteTips: "Enabled on this site",
  503. enable: "Enable",
  504. toTop: "To Top",
  505. toBottom: "To Bottom",
  506. current: "Current Page",
  507. forceIframe: "Force to join next page",
  508. cancelForceIframe: "Cancel Force join",
  509. configure: "Configure",
  510. firstUpdate: "Click here to initialize the rules",
  511. update: "Update online rules",
  512. click2update: "Click to update rules from url now",
  513. loadNow: "Load next page manually",
  514. loadConfirm: "How much pages do you want to load? (0 means infinite)",
  515. noNext: "No next link found, please create a new rule",
  516. passSec: "Updated #t# seconds ago",
  517. passMin: "Updated #t# minutes ago",
  518. passHour: "Updated #t# hours ago",
  519. passDay: "Updated #t# days ago",
  520. cantDel: "Can't delete buildin rules",
  521. confirmDel: "Are you sure you want to delete this rule?",
  522. updateSucc: "Update succeeded",
  523. beginUpdate: "Begin update, wait a minute please",
  524. customUrls: "Import Pagetual or AutoPagerize rule url, One url per line",
  525. customRules: "Input custom rules with [Pagetual] format. <a href='#t#'>Contribute rules</a>",
  526. save: "Save",
  527. loadingText: "Shojo Now Loading...",
  528. opacity: "Opacity",
  529. opacityPlaceholder: "0: hide spacer",
  530. hideBar: "Hide the paging spacer",
  531. hideBarButNoStop: "Hide but not stop",
  532. dbClick2Stop: "Double-click on the blank space to pause",
  533. sortTitle: "Sorting takes effect after the next rule update",
  534. autoRun: "Auto run (black list mode)",
  535. autoLoadNum: "Amount for preload pages",
  536. turnRate: "Turn the next page when it's less than X times page height from the footer",
  537. inputPageNum: "Enter page number to jump",
  538. enableHistory: "Write history after page turning",
  539. enableHistoryAfterInsert: "Write history immediately after splicing, otherwise write after browsing",
  540. contentVisibility: "Automatically switch contentVisibility to improve rendering performance",
  541. initRun: "Turn pages immediately after opening",
  542. preload: "Preload next page for speeding up",
  543. click2ImportRule: "Click to import base rules link, then wait until the update is complete: ",
  544. forceAllBody: "Join full body of page?",
  545. openInNewTab: "Open urls of additions in new tab",
  546. importSucc: "Import completed",
  547. import: "Import",
  548. editCurrent: "Edit rule for current",
  549. editBlacklist: "Edit the blacklist urls, line by line, Support ? * for wildcard",
  550. upBtnImg: "Icon of back to top",
  551. downBtnImg: "Icon of go to footer",
  552. sideControllerIcon: "Icon of sidebar",
  553. loadingTextTitle: "Loading text",
  554. dbClick2StopCtrl: "Ctrl key",
  555. dbClick2StopAlt: "Alt key",
  556. dbClick2StopShift: "Shift key",
  557. dbClick2StopMeta: "Meta key",
  558. dbClick2StopKey: "Shortcut key",
  559. pageElementCss: "Custom style for main page elements",
  560. customCss: "Custom complete css",
  561. firstAlert: "You have not imported the base rule, please select the appropriate rule to import",
  562. picker: "Pagetual page element picker",
  563. closePicker: "Close Pagetual picker",
  564. pickerPlaceholder: "Leave empty if you have no idea",
  565. pickerCheck: "Check selector and copy",
  566. switchSelector: "Click to switch element",
  567. gotoEdit: "Go to edit rule with current selector",
  568. manualMode: "Disable splicing, manually turn pages with the right arrow keys (or dispatch event 'pagetual.next')",
  569. clickMode: "Disable splicing, automatically click the next page when scrolling to the end of the page",
  570. pageBarMenu: "Click the middle of the page bar to open the menu",
  571. nextSwitch: "Switch next link",
  572. arrowToScroll: "Press left arrow key to scroll prev and right arrow key to scroll next",
  573. sideController: "Display the paging control bar in the sidebar",
  574. hideLoadingIcon: "Hide loading animation",
  575. hideBarArrow: "Hide arrow for page bar",
  576. duplicate: "Duplicate Pagetual have been installed, check your script manager!",
  577. forceStateIframe: "Embed full page as iframe",
  578. forceStateDynamic: "Load dynamic content via iframe",
  579. forceStateDisable: "Disable page turning on this site",
  580. page: "Page ",
  581. prevPage: "Prev page",
  582. nextPage: "Next page",
  583. errorRulesMustBeArray: "Rules must be a Array!",
  584. errorJson: "JSON error, check again!",
  585. editSuccess: "Edit successfully",
  586. errorWrongUrl: "Wrong url, check again!",
  587. errorAlreadyExists: "Already exists!",
  588. settingsSaved: "The settings are saved, refresh to view",
  589. iframe: "Iframe",
  590. dynamic: "Dynamic",
  591. reloadPage: "Edit completed, reload page now?",
  592. copied: "Copied",
  593. noValidContent: "No valid content detected, click to view",
  594. outOfDate: "The script is outdated, update to the latest version in time!"
  595. };
  596. break;
  597. }
  598. var enableDebug = true;
  599. function i18n(name, param) {
  600. return config[name] ? config[name].replace("#t#", param) : name;
  601. };
  602.  
  603. function debug(str, title) {
  604. if (enableDebug) {
  605. console.log(
  606. `%cPagetual v.${_GM_info.script.version}】 ${title ? title : 'debug'}:`,
  607. 'color: yellow;font-size: large;font-weight: bold;background-color: darkblue;',
  608. str
  609. );
  610. }
  611. };
  612.  
  613. var _GM_xmlhttpRequest, _GM_registerMenuCommand, _GM_notification, _GM_addStyle, _GM_openInTab, _GM_info, _GM_setClipboard;
  614. if (typeof GM_xmlhttpRequest != 'undefined') {
  615. _GM_xmlhttpRequest = GM_xmlhttpRequest;
  616. } else if (typeof GM != 'undefined' && typeof GM.xmlHttpRequest != 'undefined') {
  617. _GM_xmlhttpRequest = GM.xmlHttpRequest;
  618. } else {
  619. _GM_xmlhttpRequest = (f) => {fetch(f.url).then(response => response.text()).then(data => {let res = {response:data}; f.onload(res)}).catch(e => f.onerror(e))};
  620. }
  621. if (typeof GM_registerMenuCommand != 'undefined') {
  622. _GM_registerMenuCommand = GM_registerMenuCommand;
  623. } else if (typeof GM != 'undefined' && typeof GM.registerMenuCommand != 'undefined') {
  624. _GM_registerMenuCommand = GM.registerMenuCommand;
  625. } else {
  626. _GM_registerMenuCommand = (s, f) => {};
  627. }
  628. if (typeof GM_info != 'undefined') {
  629. _GM_info = GM_info;
  630. } else if (typeof GM != 'undefined' && typeof GM.info != 'undefined') {
  631. _GM_info = GM.info;
  632. } else {
  633. _GM_info = {script: {}};
  634. }
  635. if (typeof GM_notification != 'undefined') {
  636. _GM_notification = GM_notification;
  637. } else if (typeof GM != 'undefined' && typeof GM.notification != 'undefined') {
  638. _GM_notification = GM.notification;
  639. } else {
  640. _GM_notification = (s) => {showTips(s)};
  641. }
  642. if (typeof GM_openInTab != 'undefined') {
  643. _GM_openInTab = GM_openInTab;
  644. } else if (typeof GM != 'undefined' && typeof GM.openInTab != 'undefined') {
  645. _GM_openInTab = GM.openInTab;
  646. } else {
  647. _GM_openInTab = (s,t) => {window.open(s)};
  648. }
  649. if (typeof GM_addStyle != 'undefined') {
  650. _GM_addStyle = GM_addStyle;
  651. } else if (typeof GM != 'undefined' && typeof GM.addStyle != 'undefined') {
  652. _GM_addStyle = GM.addStyle;
  653. } else {
  654. _GM_addStyle = cssStr => {
  655. let styleEle = document.createElement("style");
  656. styleEle.innerHTML = cssStr;
  657. document.head.appendChild(styleEle);
  658. return styleEle;
  659. };
  660. }
  661. if (typeof GM_setClipboard != 'undefined') {
  662. _GM_setClipboard = GM_setClipboard;
  663. } else if (typeof GM != 'undefined' && typeof GM.setClipboard != 'undefined') {
  664. _GM_setClipboard = GM.setClipboard;
  665. } else {
  666. _GM_setClipboard = (s, i) => {};
  667. }
  668. var _unsafeWindow = (typeof unsafeWindow == 'undefined') ? window : unsafeWindow;//兼容 ios userscripts 的寫法
  669. var storage = {
  670. supportGM: typeof GM_getValue == 'function' && typeof GM_getValue('a', 'b') != 'undefined',
  671. supportGMPromise: typeof GM != 'undefined' && typeof GM.getValue == 'function' && typeof GM.getValue('a', 'b') != 'undefined' && typeof GM.getValue('a', 'b').then == 'function',
  672. supportCrossSave: function() {
  673. return this.supportGM || this.supportGMPromise;
  674. },
  675. mxAppStorage: (function() {
  676. try {
  677. return window.external.mxGetRuntime().storage;
  678. } catch(e) {
  679. }
  680. })(),
  681. operaUJSStorage: (function() {
  682. try {
  683. return window.opera.scriptStorage;
  684. } catch(e) {
  685. }
  686. })(),
  687. setItem: function(key, value) {
  688. if (this.supportGMPromise) {
  689. GM.setValue(key, value);
  690. if (value === "" && typeof GM != 'undefined' && typeof GM.deleteValue != 'undefined') {
  691. GM.deleteValue(key);
  692. }
  693. } else if (this.supportGM) {
  694. GM_setValue(key, value);
  695. if (value === "" && typeof GM_deleteValue != 'undefined') {
  696. GM_deleteValue(key);
  697. }
  698. } else if (this.operaUJSStorage) {
  699. this.operaUJSStorage.setItem(key, value);
  700. } else if (this.mxAppStorage) {
  701. this.mxAppStorage.setConfig(key, value);
  702. } else if (window.localStorage) {
  703. window.localStorage.setItem(key, value);
  704. }
  705. },
  706. getItem: function(key, cb) {
  707. var value;
  708. if (this.supportGMPromise) {
  709. value = GM.getValue(key).then(v => {cb(v)});
  710. return;
  711. } else if (this.supportGM) {
  712. value = GM_getValue(key);
  713. } else if (this.operaUJSStorage) {
  714. value = this.operaUJSStorage.getItem(key);
  715. } else if (this.mxAppStorage) {
  716. value = this.mxAppStorage.getConfig(key);
  717. } else if (window.localStorage) {
  718. value = window.localStorage.getItem(key);
  719. };
  720. cb(value);
  721. }
  722. };
  723. var rulesData = {}, ruleUrls, updateDate;
  724. const configPage = ["https://github.com/hoothin/UserScripts/tree/master/Pagetual",
  725. "https://hoothin.github.io/UserScripts/Pagetual/"];
  726. const guidePage = /^https?:\/\/.*pagetual.*rule\.html/i;
  727. const ruleImportUrlReg = /greasyfork\.org\/.*scripts\/438684[^\/]*(\/discussions|\/?$|\/feedback)|github\.com\/hoothin\/UserScripts\/(tree\/master\/Pagetual|issues)/i;
  728. const allOfBody = "body>*";
  729. const mainSel = "article,.article,[role=main],main,.main,#main";
  730. const nextTextReg1 = new RegExp("\u005e\u7ffb\u003f\u005b\u4e0b\u540e\u5f8c\u6b21\u005d\u005b\u4e00\u30fc\u0031\u005d\u003f\u005b\u9875\u9801\u5f20\u5f35\u005d\u007c\u005e\u0028\u006e\u0065\u0078\u0074\u005b\u0020\u005f\u002d\u005d\u003f\u0070\u0061\u0067\u0065\u007c\u006f\u006c\u0064\u0065\u0072\u0029\u005c\u0073\u002a\u005b\u203a\u003e\u2192\u00bb\u005d\u003f\u0024\u007c\u6b21\u306e\u30da\u30fc\u30b8\u007c\u005e\u6b21\u3078\u003f\u0024\u007cВперед", "i");
  731. const nextTextReg2 = new RegExp("\u005e\u005b\u4e0b\u540e\u5f8c\u6b21\u005d\u005b\u4e00\u30fc\u0031\u005d\u003f\u005b\u7ae0\u8bdd\u8a71\u8282\u7bc0\u4e2a\u500b\u5e45\u005d", "i");
  732. const lazyImgAttr = ["data-lazy-src", "data-lazy", "data-url", "data-orig-file", "zoomfile", "file", "original", "load-src", "imgsrc", "real_src", "src2", "origin-src", "data-lazyload", "data-lazyload-src", "data-lazy-load-src", "data-ks-lazyload", "data-ks-lazyload-custom", "data-src", "data-defer-src", "data-actualsrc", "data-cover", "data-original", "data-thumb", "data-imageurl", "data-placeholder", "lazysrc"];
  733. _GM_registerMenuCommand(i18n("configure"), () => {
  734. _GM_openInTab(configPage[0], {active: true});
  735. });
  736. _GM_registerMenuCommand(i18n("editCurrent"), () => {
  737. Picker.getInstance().start();
  738. });
  739.  
  740. function getBody(doc) {
  741. return doc.body || doc.querySelector('body') || doc;
  742. }
  743.  
  744. function getElementByXpath(xpath, contextNode, doc) {
  745. doc = doc || document;
  746. contextNode = contextNode || doc;
  747. try {
  748. var result = doc.evaluate(xpath, contextNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
  749. return result.singleNodeValue && result.singleNodeValue.nodeType === 1 && result.singleNodeValue;
  750. } catch (err) {
  751. debug(`Invalid xpath: ${xpath}`);
  752. }
  753. return null;
  754. }
  755.  
  756. function getAllElementsByXpath(xpath, contextNode, doc) {
  757. doc = doc || document;
  758. contextNode = contextNode || doc;
  759. var result = [];
  760. try {
  761. var query = doc.evaluate(xpath, contextNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  762. for (var i = 0; i < query.snapshotLength; i++) {
  763. var node = query.snapshotItem(i);
  764. if (node.nodeType === 1) result.push(node);
  765. }
  766. } catch (err) {
  767. debug(`Invalid xpath: ${xpath}`);
  768. }
  769. return result;
  770. }
  771.  
  772. function isXPath(xpath) {
  773. if (!xpath) return false;
  774. return /^\(*(descendant::|\.\/|\/|id\()/.test(xpath);
  775. }
  776.  
  777. function getAllElements(sel, doc) {
  778. try {
  779. if (!isXPath(sel)) {
  780. return doc.querySelectorAll(sel);
  781. }
  782. } catch(e) {
  783. debug(e, 'Error selector');
  784. }
  785. return getAllElementsByXpath(sel, doc, doc);
  786. }
  787.  
  788. function getElement(sel, doc) {
  789. try {
  790. if (!isXPath(sel)) {
  791. return doc.querySelector(sel);
  792. }
  793. } catch(e) {
  794. debug(e, 'Error selector');
  795. }
  796. return getElementByXpath(sel, doc, doc);
  797. }
  798.  
  799. function geneSelector(ele, addID) {
  800. let selector = ele.nodeName.toLowerCase();
  801. //Google id class都是隨機。百度更過分,style script順序都是隨機的
  802. if (selector != "html" && selector != "body") {
  803. let hasId = false;
  804. if (addID && ele.id && /^[a-z_][\w\-_]*$/i.test(ele.id)) {
  805. hasId = true;
  806. selector = '#' + ele.id;
  807. } else {
  808. let className = "";
  809. if (ele.className) {
  810. let classList = ele.classList, i = 0;
  811. for (let i = 0; i < classList.length; i++) {
  812. let c = classList[i];
  813. if (/^[\w\-_]+$/.test(c) && !/\d{3,}/.test(c)) {
  814. className += '.' + c;
  815. }
  816. }
  817. selector += className;
  818. }
  819. let parent = ele.parentElement;
  820. if (parent) {
  821. selector = geneSelector(parent, addID) + ' > ' + selector;
  822. if (!className && !hasId && parent.children.length > 1) {
  823. let i, j = 0;
  824. for (i = 0; i < parent.children.length; i++) {
  825. if (parent.children[i].nodeName == ele.nodeName) {
  826. j++;
  827. if (parent.children[i] == ele) {
  828. break;
  829. }
  830. }
  831. }
  832. selector += (/^HTML$/i.test(parent.nodeName) ? "" : `:nth-of-type(${j})`);
  833. }
  834. }
  835. }
  836. }
  837. return selector;
  838. }
  839.  
  840. function createXPathFromElement(elm) {
  841. let allNodes = document.getElementsByTagName('*'), segs;
  842. for (segs = []; elm && elm.nodeType == 1; elm = elm.parentNode) {
  843. if (/^(BODY|HTML)$/i.test(elm.nodeName)) {
  844. segs.unshift(elm.localName.toLowerCase());
  845. continue;
  846. }
  847. if (elm.hasAttribute && elm.hasAttribute('id')) {
  848. var uniqueIdCount = 0;
  849. for (var n = 0; n < allNodes.length; n++) {
  850. if (allNodes[n].hasAttribute('id') && allNodes[n].id == elm.id) uniqueIdCount++;
  851. if (uniqueIdCount > 1) break;
  852. }
  853. if ( uniqueIdCount == 1) {
  854. segs.unshift('id("' + elm.getAttribute('id') + '")');
  855. return segs.join('/');
  856. } else {
  857. segs.unshift(elm.localName.toLowerCase() + '[@id="' + elm.getAttribute('id') + '"]');
  858. }
  859. } else if (elm.hasAttribute && elm.hasAttribute('class')) {
  860. segs.unshift(elm.localName.toLowerCase() + '[@class="' + elm.getAttribute('class') + '"]');
  861. } else {
  862. let i, sib;
  863. for (i = 1, sib = elm.previousSibling; sib; sib = sib.previousSibling) {
  864. if (sib.localName == elm.localName) i++;
  865. }
  866. segs.unshift(elm.localName.toLowerCase() + '[' + i + ']');
  867. }
  868. }
  869. return segs.length ? '/' + segs.join('/') : null;
  870. }
  871.  
  872. var escapeHTMLPolicy;
  873. if (_unsafeWindow.trustedTypes && _unsafeWindow.trustedTypes.createPolicy) {
  874. escapeHTMLPolicy = _unsafeWindow.trustedTypes.createPolicy('pagetual_default', {
  875. createHTML: (string, sink) => string
  876. });
  877. }
  878.  
  879. function createHTML(html){
  880. return escapeHTMLPolicy?escapeHTMLPolicy.createHTML(html):html;
  881. }
  882.  
  883. const AsyncFunction = Object.getPrototypeOf(async function(){}).constructor;
  884.  
  885. async function sleep(time) {
  886. await new Promise((resolve) => {
  887. setTimeout(() => {
  888. resolve();
  889. }, time);
  890. })
  891. }
  892.  
  893. class RuleParser {
  894. constructor() {
  895. this.hpRules = [];
  896. this.smartRules = [];
  897. this.customRules = [];
  898. this.rules = [];
  899. this.pageDoc = document;
  900. this.nextLinkHref = null;
  901. this.nextTitle = "";
  902. this.oldUrl = "";
  903. this.curUrl = location.href;
  904. this.curSiteRule = {};
  905. }
  906.  
  907. initSavedRules(callback) {
  908. var self = this;
  909. storage.getItem("smartRules", smartRules => {
  910. if (smartRules) self.smartRules = smartRules;
  911. storage.getItem("hpRules", hpRules => {
  912. if (hpRules) self.hpRules = hpRules;
  913. storage.getItem("customRules", customRules => {
  914. if (customRules) self.customRules = customRules;
  915. storage.getItem("rules", rules => {
  916. if (rules) self.rules = rules;
  917. callback();
  918. });
  919. });
  920. });
  921. });
  922. }
  923.  
  924. saveCurSiteRule() {
  925. /*if(!this.curSiteRule || !this.curSiteRule.url || this.curSiteRule.singleUrl || this.curSiteRule.url.length<13)return;
  926. this.hpRules=this.hpRules.filter(item=>{return item&&item.url!=this.curSiteRule.url});
  927. this.hpRules.unshift(this.curSiteRule);
  928. if(this.hpRules.length>30){
  929. this.hpRules.pop();
  930. }
  931. storage.setItem("hpRules", this.hpRules);*/
  932. }
  933.  
  934. requestJSON(url, callback) {
  935. _GM_xmlhttpRequest({
  936. url: url,
  937. method: 'GET',
  938. timeout: 20000,
  939. onload: function(res) {
  940. let json = null;
  941. try {
  942. json = JSON.parse(res.response || res.responseText);
  943. } catch(e) {
  944. debug(e, 'Error json');
  945. }
  946. callback(json);
  947. },
  948. onerror: function(e) {
  949. callback(null, e);
  950. },
  951. ontimeout: function(e) {
  952. callback(null, e);
  953. }
  954. });
  955. }
  956.  
  957. formatRule(item, from) {
  958. if (item.data && item.data.url) {
  959. let result = {
  960. name: item.name,
  961. from: from,
  962. action: item.data.forceIframe=="true"?1:undefined,
  963. url: item.data.url,
  964. pageElement: item.data.pageElement,
  965. nextLink: item.data.nextLink,
  966. insert: item.data.insertBefore||undefined,
  967. updatedAt: item.updated_at
  968. };
  969. let _css = (item.data.Stylus || '') + (item.data.CSS || '');
  970. if (_css) result.css = _css;
  971. if (item.data.bookmarklet) result.pageAction = item.data.bookmarklet;
  972. return result;
  973. } else {
  974. item.from = from;
  975. return item;
  976. }
  977. return null;
  978. }
  979.  
  980. addRuleByUrl(url, from, callback) {
  981. if (url.indexOf("?") == -1) {
  982. url = url + "?" + Date.now();
  983. } else {
  984. url = url + "&" + Date.now();
  985. }
  986. this.requestJSON(url, (json,err) => {
  987. if (!json) {
  988. debug(err, "Update " + url + " rules fail!");
  989. }
  990. this.addRules(json, from);
  991. callback(json, err);
  992. });
  993. }
  994.  
  995. addRules(rules, from) {
  996. if (rules && rules.length > 0) {
  997. let first = -1;
  998. this.rules = this.rules.filter((item, i) => {
  999. if (item.from == from) {
  1000. if (first == -1) first = i;
  1001. return false;
  1002. } else return true;
  1003. });
  1004. if (first == -1) first = 0;
  1005. rules.forEach(item => {
  1006. let rule = this.formatRule(item, from);
  1007. if (rule) {
  1008. this.rules.splice(first, 0, rule)
  1009. }
  1010. });
  1011. }
  1012. }
  1013.  
  1014. ruleMatchPre(r) {
  1015. if (r.include) {
  1016. let include;
  1017. if (Array && Array.isArray && Array.isArray(r.include)) {
  1018. include = r.include.every((sel, i) => {
  1019. let ele = getElement(sel, document);
  1020. return !!ele;
  1021. });
  1022. } else include = getElement(r.include, document);
  1023. if (!include) return false;
  1024. }
  1025. if (r.exclude) {
  1026. let exclude;
  1027. if (Array && Array.isArray && Array.isArray(r.exclude)) {
  1028. exclude = !r.exclude.every((sel, i) => {
  1029. let ele = getElement(sel, document);
  1030. return !ele;
  1031. });
  1032. } else exclude = getElement(r.exclude, document);
  1033. if (exclude) return false;
  1034. }
  1035. return true;
  1036. }
  1037.  
  1038. ruleMatchReady(r) {
  1039. let findIndex = 0;
  1040. if (r.nextLink && r.nextLink != 0) {
  1041. let nextLinkSel = r.nextLink, nextLink;
  1042. if (Array && Array.isArray && Array.isArray(nextLinkSel)) {
  1043. nextLink = !nextLinkSel.every((sel, i) => {
  1044. let ele = getElement(sel, document);
  1045. if (ele) findIndex = i;
  1046. return !ele;
  1047. });
  1048. } else nextLink = getElement(nextLinkSel, document);
  1049. if (!nextLink) return false;
  1050. }
  1051. if (r.pageElement) {
  1052. let pageElementSel = r.pageElement, pageElement;
  1053. if (Array && Array.isArray && Array.isArray(pageElementSel)) {
  1054. pageElementSel = pageElementSel[findIndex];
  1055. }
  1056. pageElement = getElement(pageElementSel, document);
  1057. if (!pageElement) return false;
  1058. }
  1059. if (r.insert) {
  1060. let insertSel = r.insert, insert;
  1061. if (Array && Array.isArray && Array.isArray(insertSel)) {
  1062. insertSel = insertSel[findIndex];
  1063. }
  1064. insert = getElement(insertSel, document);
  1065. if (!insert) return false;
  1066. }
  1067. //if (findIndex !== 0) nextIndex = findIndex;
  1068. return true;
  1069. }
  1070.  
  1071. ruleMatch(r) {
  1072. return this.ruleMatchPre(r) && this.ruleMatchReady(r);
  1073. }
  1074.  
  1075. scrollToShow(sel, doc) {
  1076. let exclude = getElement(sel, doc);
  1077. if (exclude) {
  1078. var actualTop = exclude.offsetTop;
  1079. var current = exclude.offsetParent;
  1080. while (current !== null) {
  1081. actualTop += current.offsetTop;
  1082. current = current.offsetParent;
  1083. }
  1084. getBody(doc).scrollTop = 0;
  1085. doc.documentElement.scrollTop = 0;
  1086. let maxHeight = Math.max(getBody(doc).scrollHeight, doc.documentElement.scrollHeight);
  1087. getBody(doc).scrollTop = actualTop - 10;
  1088. doc.documentElement.scrollTop = actualTop - 10;
  1089. setTimeout(() => {
  1090. while (actualTop < maxHeight) {
  1091. actualTop += 200;
  1092. getBody(doc).scrollTop = actualTop;
  1093. doc.documentElement.scrollTop = actualTop;
  1094. }
  1095. }, 0);
  1096. return false;
  1097. }
  1098. return true;
  1099. }
  1100.  
  1101. waitElement(doc, selArr) {
  1102. if (!selArr) selArr = this.curSiteRule.waitElement;
  1103. let includeSel = selArr[0].trim(), excludeSel;
  1104. if (selArr.length == 2) {
  1105. excludeSel = selArr[1].trim().replace(/^!/, '');
  1106. } else if (includeSel.indexOf('!') == 0) {
  1107. excludeSel = includeSel.replace(/^!/, '');
  1108. includeSel = '';
  1109. }
  1110. if (includeSel) {
  1111. let include = getElement(includeSel, doc);
  1112. if (!include) {
  1113. return false;
  1114. }
  1115. }
  1116. if (doc === document) return true;
  1117. if (excludeSel) {
  1118. if (!this.scrollToShow(excludeSel, doc)) {
  1119. if (!loadingDiv.offsetParent && this.insert.parentNode) {
  1120. this.insertElement(loadingDiv);
  1121. }
  1122. return false;
  1123. }
  1124. }
  1125. return true;
  1126. }
  1127.  
  1128. getRule(callback) {
  1129. if(noRuleTest) {
  1130. this.curSiteRule = {};
  1131. this.curSiteRule.url = location.origin + location.pathname;
  1132. this.curSiteRule.singleUrl = true;
  1133. callback();
  1134. return;
  1135. }
  1136. if (this.curSiteRule && this.curSiteRule.url && !this.curSiteRule.singleUrl) {
  1137. if (this.ruleMatch(this.curSiteRule)) {
  1138. return callback();
  1139. }
  1140. }
  1141. this.curSiteRule = {};
  1142. var self = this;
  1143. var href = location.href.slice(0, 500);
  1144.  
  1145. function setRule(r) {
  1146. if (self.preSiteRule && self.ruleMatch(self.preSiteRule)) {
  1147. self.curSiteRule = self.preSiteRule;
  1148. return callback();
  1149. }
  1150. if (!r.singleUrl) {
  1151. self.curSiteRule = r;
  1152. self.preSiteRule = r;
  1153. if (r.enable !== 0) debug(r, 'Match rule');
  1154. } else if (!self.curSiteRule || !self.curSiteRule.singleUrl) self.curSiteRule = r;
  1155. callback();
  1156. }
  1157.  
  1158. function checkRule(r) {
  1159. if (r.from == 1 && r.url.length <= 13) return false;
  1160. let urlReg = new RegExp(r.url, "i");
  1161. if (urlReg.test(href)) {
  1162. if (!self.ruleMatchPre(r)) return false;
  1163. if (r.waitElement) {
  1164. let waitTime = 500;
  1165. let checkReady = () => {
  1166. setTimeout(() => {
  1167. if (!self.waitElement(document, r.waitElement)) {
  1168. checkReady();
  1169. } else {
  1170. setRule(r);
  1171. }
  1172. }, parseInt(waitTime));
  1173. };
  1174. checkReady();
  1175. return true;
  1176. } else if (r.wait) {
  1177. let waitTime = 500, checkEval, maxCheckTimes = 50;
  1178. if (isNaN(r.wait)) {
  1179. try {
  1180. checkEval = (typeof _unsafeWindow.pagetualWait == 'undefined') ? Function("doc",'"use strict";' + r.wait) : _unsafeWindow.pagetualWait;
  1181. } catch(e) {
  1182. debug(e, 'Error when checkeval');
  1183. }
  1184. } else {
  1185. waitTime = r.wait;
  1186. }
  1187. let checkReady = () => {
  1188. if (maxCheckTimes-- <= 0) {
  1189. debug("Wait for rule ready but failed");
  1190. setRule(r);
  1191. return;
  1192. }
  1193. setTimeout(() => {
  1194. if (!self.ruleMatchReady(r) || (checkEval && !checkEval(document))) {
  1195. checkReady();
  1196. } else {
  1197. setRule(r);
  1198. }
  1199. }, parseInt(waitTime));
  1200. };
  1201. checkReady();
  1202. return true;
  1203. }
  1204. if (r.pinUrl) {
  1205. setRule(r);
  1206. return true;
  1207. }
  1208. if (!self.ruleMatchReady(r)) {
  1209. return false;
  1210. }
  1211. setRule(r);
  1212. return true;
  1213. }
  1214. return false;
  1215. }
  1216.  
  1217. for (let i in this.hpRules) {
  1218. let rule = this.hpRules[i];
  1219. if (!rule || !rule.url) continue;
  1220. if (rule.singleUrl) {
  1221. continue;
  1222. }
  1223. if (checkRule(rule)) return;
  1224. }
  1225. for (let i in this.customRules) {
  1226. let rule = this.customRules[i];
  1227. if (!rule || !rule.url) continue;
  1228. if (checkRule(rule)) return;
  1229. }
  1230. for (let i in this.smartRules) {
  1231. let rule = this.smartRules[i];
  1232. if (!rule || !rule.url) continue;
  1233. if (rule.singleUrl) {
  1234. let singleUrl = location.origin + location.pathname;
  1235. if (singleUrl == rule.url) {
  1236. setRule(rule);
  1237. callback = () => {
  1238. if (self.curSiteRule && !self.curSiteRule.singleUrl) {
  1239. self.smartRules = self.smartRules.filter(item => {return item && item.url != singleUrl});
  1240. storage.setItem("smartRules", self.smartRules);
  1241. if (self.curSiteRule.url.length > 13) {
  1242. self.hpRules = self.hpRules.filter(item => {return item && item.url != self.curSiteRule.url});
  1243. self.hpRules.unshift(self.curSiteRule);
  1244. if (self.hpRules.length > 30) {
  1245. self.hpRules.pop();
  1246. }
  1247. storage.setItem("hpRules", self.hpRules);
  1248. }
  1249. }
  1250. };
  1251. break;
  1252. }
  1253. continue;
  1254. }
  1255. }
  1256. let r = 0;
  1257. function searchByTime() {
  1258. setTimeout(() => {
  1259. let end = r + 50;
  1260. end = end > self.rules.length ? self.rules.length : end;
  1261. for (; r < end; r++) {
  1262. let rule = self.rules[r];
  1263. if (rule.from == 2) {
  1264. delete rule.autoLoadNum;
  1265. delete rule.history;
  1266. delete rule.sideController;
  1267. if (rule.pageBar == 0) delete rule.pageBar;
  1268. }
  1269. if (checkRule(rule)) return;
  1270. }
  1271. if (end >= self.rules.length) {
  1272. setRule({url: location.origin + location.pathname, singleUrl: true});
  1273. return;
  1274. } else {
  1275. searchByTime();
  1276. }
  1277. }, 1);
  1278. }
  1279. searchByTime();
  1280. }
  1281.  
  1282. replaceElement(doc) {
  1283. if (!doc || doc === document) return;
  1284. let replaceElementSel = this.curSiteRule.replaceElement;
  1285. if (replaceElementSel) {
  1286. if (!Array.isArray(replaceElementSel)) {
  1287. replaceElementSel = [replaceElementSel];
  1288. }
  1289. replaceElementSel.forEach(sel => {
  1290. let pageEles = getAllElements(sel, document);
  1291. let replaceEles = getAllElements(sel, doc);
  1292. for (let i = 0; i < pageEles.length; i++) {
  1293. let replaceEle = replaceEles[i];
  1294. let pageEle = pageEles[i];
  1295. if (replaceEle) {
  1296. pageEle.parentNode.replaceChild(replaceEle.cloneNode(true), pageEle);
  1297. } else break;
  1298. }
  1299. });
  1300. }
  1301. }
  1302.  
  1303. refreshByClick() {
  1304. let refreshByClickSel = this.curSiteRule.refreshByClick;
  1305. if (refreshByClickSel) {
  1306. let self = this;
  1307. document.addEventListener("click", e => {
  1308. if (!self.refreshing) {
  1309. self.refreshing = true;
  1310. setTimeout(() => {
  1311. self.refreshing = false;
  1312. let checkEles = getAllElements(refreshByClickSel, document);
  1313. for (let i = 0; i < checkEles.length; i++) {
  1314. if (checkEles[i] === e.target) {
  1315. urlChanged = true;
  1316. isPause = true;
  1317. if (!ruleParser.nextLinkHref) isLoading = false;
  1318. break;
  1319. }
  1320. }
  1321. }, 300);
  1322. }
  1323. });
  1324. }
  1325. }
  1326.  
  1327. getValidHeight(ele) {
  1328. if (!ele.offsetParent) return 0;
  1329. let h = ele.scrollHeight;
  1330. let moreChild = ele.children[0], minOffsetTop = h;
  1331. while (moreChild) {
  1332. if (moreChild.offsetParent && moreChild.offsetTop < minOffsetTop) {
  1333. minOffsetTop = moreChild.offsetTop;
  1334. }
  1335. moreChild = moreChild.nextElementSibling;
  1336. }
  1337. if (minOffsetTop != h && minOffsetTop > 0) {
  1338. h -= minOffsetTop;
  1339. }
  1340. return h;
  1341. }
  1342.  
  1343. getPageElement(doc, curWin, dontFind) {
  1344. if (doc == document && this.docPageElement) {
  1345. let parent = this.docPageElement && this.docPageElement[0];
  1346. while (parent && !/^BODY$/i.test(parent.nodeName)) {
  1347. parent = parent.parentNode;
  1348. }
  1349. if (parent && /^BODY$/i.test(parent.nodeName)) {
  1350. return this.docPageElement;
  1351. }
  1352. }
  1353. let pageElement = null;
  1354. let self = this;
  1355. let body = getBody(doc);
  1356. if (this.curSiteRule.pageElement) {
  1357. let pageElementSel = this.curSiteRule.pageElement;
  1358. if (Array && Array.isArray && Array.isArray(pageElementSel)) {
  1359. pageElementSel = pageElementSel[nextIndex < pageElementSel.length ? nextIndex : 0];
  1360. }
  1361. pageElement = getAllElements(pageElementSel, doc);
  1362. }
  1363. if (pageElement && pageElement.length === 1 && pageElement[0].style.display === 'none') {
  1364. pageElement = [body];
  1365. }
  1366. if (this.curSiteRule.singleUrl && pageElement && pageElement.length > 0 && /^TR$/i.test(pageElement[0].nodeName)) {
  1367. let mainTr = this.insert.parentNode.querySelector('tr'), mainTdNum = 0, newTdNum = 0;
  1368. [].forEach.call(mainTr.children, el => {
  1369. if (/^(TD|TH)$/i.test(el.nodeName)) {
  1370. mainTdNum += el.colSpan || 1;
  1371. }
  1372. });
  1373. [].forEach.call(pageElement[0].children, el => {
  1374. if (/^(TD|TH)$/i.test(el.nodeName)) {
  1375. newTdNum += el.colSpan || 1;
  1376. }
  1377. });
  1378. if (mainTdNum != newTdNum) {
  1379. this.curSiteRule.pageElement = allOfBody;
  1380. pageElement = [body];
  1381. this.getInsert(true);
  1382. }
  1383. }
  1384. if ((this.curSiteRule.singleUrl || !this.curSiteRule.pageElement) && (!pageElement || pageElement.length == 0) && curWin && !dontFind) {
  1385. if (!body) return null;
  1386. let bodyHeight = parseInt(body.offsetHeight || body.scrollHeight);
  1387. let curHeight = bodyHeight, curWidth = 0;
  1388. let windowHeight = window.innerHeight || document.documentElement.clientHeight;
  1389. let needCheckNext = (doc == document && this.initNext);
  1390. function checkElement(ele) {
  1391. if (/^(PRE|CODE)$/i.test(ele.nodeName)) {
  1392. self.curSiteRule.pageElement = geneSelector(ele.parentNode);
  1393. debug(self.curSiteRule.pageElement, 'Page element');
  1394. return [ele.parentNode];
  1395. }
  1396. if (ele.children && ele.children.length == 1) {
  1397. let hasText = false;
  1398. for (let i in ele.childNodes) {
  1399. let child = ele.childNodes[i];
  1400. if (child.nodeType == 3 && child.nodeValue.trim() !== '') {
  1401. hasText = true;
  1402. break;
  1403. }
  1404. }
  1405. if (!hasText) {
  1406. ele = ele.children[0];
  1407. curHeight = self.getValidHeight(ele);
  1408. curWidth = parseInt(ele.offsetWidth || ele.scrollWidth);
  1409. }
  1410. }
  1411. if (/^PICTURE$/i.test(ele.nodeName)) {
  1412. self.curSiteRule.pageElement = geneSelector(ele.parentNode) + ">" + ele.nodeName.toLowerCase();
  1413. debug(self.curSiteRule.pageElement, 'Page element');
  1414. return [ele];
  1415. }
  1416. if (curHeight / bodyHeight <= 0.25) {
  1417. let article = doc.querySelectorAll(mainSel);
  1418. if (article && article.length > 0) {
  1419. if (article.length == 1) {
  1420. article = article[0];
  1421. self.curSiteRule.pageElement = article.nodeName.toLowerCase() + (article.id ? "#" + article.id : "") + (article.className ? "." + article.className : "") + ">*";
  1422. debug(self.curSiteRule.pageElement, 'Page element');
  1423. return article.children;
  1424. } else {
  1425. self.curSiteRule.pageElement = mainSel;
  1426. debug(self.curSiteRule.pageElement, 'Page element');
  1427. return article;
  1428. }
  1429. }
  1430. self.curSiteRule.pageElement = allOfBody;
  1431. debug(self.curSiteRule.pageElement, 'Page element');
  1432. return [body];
  1433. }
  1434. if (/^FORM$/i.test(ele.nodeName) && ele.parentNode != getBody(document)) {
  1435. self.curSiteRule.pageElement = geneSelector(ele) + ">*";
  1436. debug(self.curSiteRule.pageElement, 'Page element');
  1437. return ele.children;
  1438. }
  1439. if (ele.children.length == 0 && !self.curSiteRule.pageElement) {
  1440. if (/^P$/i.test(ele.parentNode.nodeName)) ele = ele.parentNode;
  1441. self.curSiteRule.pageElement = geneSelector(ele.parentNode) + ">" + ele.nodeName.toLowerCase();
  1442. debug(self.curSiteRule.pageElement, 'Page element');
  1443. return getAllElements(self.curSiteRule.pageElement, doc);
  1444. }
  1445. let i, minHeight = curHeight * 0.52, curMaxEle = null, curMaxArea = 0, minWidth = curWidth * 0.38;
  1446. let isHori, preOffsetTop = -1;
  1447. let articleNum = 0;
  1448. for (i = 0; i < ele.children.length; i++) {
  1449. let curNode = ele.children[i];
  1450. if (/^(CANVAS|NAV)$/i.test(curNode.nodeName)) continue;
  1451. if (!curNode.offsetParent) continue;
  1452. if (!/^IMG$/i.test(curNode.nodeName) && curNode.querySelector('img') == null && /^\s*$/.test(curNode.innerText)) continue;
  1453. if (needCheckNext && !curNode.contains(self.initNext) && getElementTop(curNode) > windowHeight) {
  1454. continue;
  1455. }
  1456. if (/^ARTICLE$/i.test(curNode.nodeName)) articleNum++;
  1457. let h = self.getValidHeight(curNode);
  1458. let w = curNode.scrollWidth;
  1459. if (isNaN(h) || isNaN(w)) continue;
  1460. isHori = preOffsetTop == curNode.offsetTop ? true : (preOffsetTop == -1 ? (curNode.nextElementSibling && curNode.nextElementSibling.offsetTop == curNode.offsetTop) : false);
  1461. if (isHori && h <= 50) continue;
  1462. let a = h * w, moreChild = curNode.children[0];
  1463. while (moreChild) {
  1464. let ch = self.getValidHeight(moreChild);
  1465. let cw = moreChild.scrollWidth;
  1466. if (h < ch) {
  1467. h = ch;
  1468. }
  1469. if (moreChild.innerText != "" && ch && cw) {
  1470. a += ch * cw;
  1471. }
  1472. moreChild = moreChild.nextElementSibling;
  1473. }
  1474. let isMax = false;
  1475. if (isHori) {
  1476. if (curMaxEle) {
  1477. if (curWidth < w) {
  1478. isMax = true;
  1479. } else if (curWidth < w + 300 && curMaxArea < a) {
  1480. isMax = true;
  1481. }
  1482. }
  1483. } else {
  1484. if (curMaxEle && curMaxEle.offsetParent == curNode.offsetParent && curMaxEle.offsetTop == curNode.offsetTop) {
  1485. if (curMaxArea * 2 > a) continue;
  1486. }
  1487. isMax = curMaxArea < a;
  1488. }
  1489. if (curMaxEle == null || isMax) {
  1490. if (isHori) {
  1491. if (curMaxEle && w < minWidth) {
  1492. continue;
  1493. }
  1494. } else {
  1495. if (h < minHeight) {
  1496. if (!needCheckNext || h < windowHeight || !ele.contains(self.initNext)) {
  1497. continue;
  1498. }
  1499. }
  1500. }
  1501. curHeight = h;
  1502. curMaxArea = a;
  1503. curWidth = w;
  1504. curMaxEle = curNode;
  1505. preOffsetTop = curNode.offsetTop;
  1506. }
  1507. }
  1508. if (curMaxEle) {
  1509. let sameClassNum = 0;
  1510. if (curMaxEle.className) {
  1511. for(i = 0; i < ele.children.length; i++) {
  1512. let curNode = ele.children[i];
  1513. if (curMaxEle != curNode && curNode.style.display !== 'none' && curMaxEle.className == curNode.className && curMaxEle.nodeName == curNode.nodeName){
  1514. sameClassNum++;
  1515. }
  1516. }
  1517. }
  1518. if (sameClassNum < 5) {
  1519. return checkElement(curMaxEle);
  1520. }
  1521. }
  1522. if (ele.parentNode.children.length == 1 && curWin.getComputedStyle(ele.parentNode).float == 'none') ele = ele.parentNode;
  1523. else if (/^(P|BR|TD)$/i.test(ele.nodeName)) ele = ele.parentNode;
  1524. else if (/^TBODY$/i.test(ele.nodeName)) {
  1525. self.curSiteRule.pageElement = geneSelector(ele) + ">*";
  1526. if (ele.children.length > 0 && ele.children[0].querySelector("th")) {
  1527. self.curSiteRule.pageElement += ":not(:first-child)";
  1528. }
  1529. debug(self.curSiteRule.pageElement, 'Page element');
  1530. return ele.children;
  1531. }
  1532. let imgs = ele.querySelectorAll('img');
  1533. if (imgs.length == 1) {
  1534. let img = imgs[0];
  1535. if (img.offsetWidth > ele.offsetWidth / 3 * 2 && img.offsetHeight > ele.offsetHeight / 2) {
  1536. ele = img;
  1537. }
  1538. }
  1539. self.curSiteRule.pageElement = geneSelector(ele);
  1540. let pf = false;
  1541. if (ele.parentNode) {
  1542. let paDisplay = curWin.getComputedStyle(ele.parentNode).display;
  1543. pf = paDisplay.indexOf('flex') !== -1 || paDisplay.indexOf('grid') !== -1;
  1544. }
  1545. if (ele.children.length > 1) {
  1546. if (articleNum > 1) {
  1547. self.curSiteRule.pageElement += ">article";
  1548. ele = ele.children;
  1549. } else {
  1550. let hasText = false;
  1551. for (let i in ele.childNodes) {
  1552. let child = ele.childNodes[i];
  1553. if (child.nodeType == 3 && child.nodeValue.trim() !== '') {
  1554. hasText = true;
  1555. ele = [ele];
  1556. break;
  1557. }
  1558. }
  1559. if (!hasText) {
  1560. let gridArea = curWin.getComputedStyle(ele).gridArea;
  1561. if (gridArea && gridArea != "auto / auto / auto / auto") {
  1562. self.curSiteRule.pageElement += ">*";
  1563. ele = ele.children;
  1564. } else {
  1565. let middleChild = ele.children[parseInt(ele.children.length / 2)];
  1566. if (curWin.getComputedStyle(ele).display === 'flex' || (rulesData.opacity != 0 && !pf)) {
  1567. ele = [ele];
  1568. } else if ((middleChild.style && middleChild.style.position === "absolute" && middleChild.style.left && middleChild.style.top) || /^UL$/i.test(ele.nodeName) || curHeight == 0) {
  1569. ele = [ele];
  1570. } else {
  1571. self.curSiteRule.pageElement += ">*";
  1572. ele = ele.children;
  1573. }
  1574. }
  1575. }
  1576. }
  1577. } else if (pf) {
  1578. self.curSiteRule.pageElement += ">*";
  1579. ele = ele.children;
  1580. } else {
  1581. ele = [ele];
  1582. }
  1583. debug(self.curSiteRule.pageElement, 'Page element');
  1584. return ele;
  1585. }
  1586. pageElement = checkElement(body);
  1587. if (pageElement && pageElement.length > 0 && self.initNext) {
  1588. let lastBottom = getElementBottom(pageElement[pageElement.length - 1]);
  1589. if (lastBottom && getElementTop(self.initNext) - lastBottom > 1000) {
  1590. debug("Stop as too long between next & page element");
  1591. isPause = true;
  1592. pageElement = [];
  1593. } else {
  1594. if (pageElement.length == 1 && /^IMG$/i.test(pageElement[0].nodeName)) {
  1595. self.curSiteRule.pageBar = 0;
  1596. }
  1597. }
  1598. }
  1599. //if(pageElement)this.saveCurSiteRule();
  1600. }
  1601.  
  1602. if (doc !== document) {
  1603. this.setPageElementCss(pageElement);
  1604. this.lazyImgAction(pageElement);
  1605. } else if (!this.docPageElement) {
  1606. this.setPageElementCss(pageElement, true);
  1607. this.docPageElement = pageElement;
  1608. if (this.nextLinkHref) {
  1609. this.openInNewTab(pageElement);
  1610. }
  1611. }
  1612. if (this.curSiteRule.singleUrl && pageElement && pageElement.length > 0) {
  1613. let targetEle = pageElement.length > 1 ? pageElement[0].parentNode : pageElement[0];
  1614. let video = targetEle.querySelector("video") || targetEle.querySelector("iframe[id*=play],[id*=play]>iframe,iframe[src*=player],iframe[src*=m3u8]") || targetEle.querySelector("canvas");
  1615. if (video && doc == document) {
  1616. if (video && video.offsetParent && video.name != 'pagetual-iframe') {
  1617. let scrollWidth = video.scrollWidth || video.offsetWidth;
  1618. let scrollHeight = video.scrollHeight || video.offsetHeight;
  1619. if (scrollWidth > 420 && scrollHeight > 420) {
  1620. debug("Disable when large media found");
  1621. } else if (scrollWidth > 100 && scrollHeight > 100) {
  1622. let winWidth = window.innerWidth || document.documentElement.clientWidth;
  1623. let winHeight = window.innerHeight || document.documentElement.clientHeight;
  1624. if (scrollWidth > winWidth>>1 || scrollHeight > winHeight>>1) {
  1625. debug("Disable when large media found under mobile");
  1626. } else {
  1627. video = null;
  1628. }
  1629. } else {
  1630. video = null;
  1631. }
  1632. } else {
  1633. video = null;
  1634. }
  1635. }
  1636. if (video) {
  1637. isPause = true;
  1638. this.clearAddElement();
  1639. return null;
  1640. }
  1641. }
  1642. return pageElement;
  1643. }
  1644.  
  1645. changeVisibility() {
  1646. let contentVisibility = this.curSiteRule.contentVisibility || rulesData.contentVisibility;
  1647. if (!contentVisibility) return;
  1648. if (!this.changingVisibility) {
  1649. clearTimeout(this.changeVisibilityTimer);
  1650. this.changeVisibilityTimer = setTimeout(() => {
  1651. this.changingVisibility = true;
  1652. this.changeVisibility();
  1653. }, 300);
  1654. return;
  1655. }
  1656. this.changingVisibility = false;
  1657. if (!this.visibilityItems || !this.visibilityItems.length || this.visibleIndex < 0) return;
  1658. let tempIndex = this.visibleIndex, findVisible = false, lastVisible = 0;
  1659. let viewPortHeight = window.innerHeight || document.documentElement.clientHeight || getBody(document).clientHeight;
  1660. let checkItem = this.visibilityItems[tempIndex];
  1661. while(checkItem) {
  1662. if (checkItem.offsetParent) {
  1663. if (!checkItem.style.containIntrinsicSize) return;
  1664. let clientRect = checkItem.getBoundingClientRect();
  1665. let top = clientRect && clientRect.top;
  1666. let bottom = clientRect && clientRect.bottom;
  1667. if (bottom > 0 && top < viewPortHeight) {
  1668. if (!findVisible) {
  1669. findVisible = true;
  1670. lastVisible = tempIndex;
  1671. }
  1672. checkItem.style.contentVisibility = "visible";
  1673. } else {
  1674. if (top < viewPortHeight && checkItem.style.contentVisibility == "auto") {
  1675. break;
  1676. } else checkItem.style.contentVisibility = "auto";
  1677. }
  1678. }
  1679. if (tempIndex == 0) break;
  1680. tempIndex--;
  1681. checkItem = this.visibilityItems[tempIndex];
  1682. }
  1683. tempIndex = this.visibleIndex + 1;
  1684. if (findVisible) {
  1685. this.visibleIndex = lastVisible;
  1686. }
  1687. checkItem = this.visibilityItems[tempIndex];
  1688. while(checkItem) {
  1689. if (checkItem.offsetParent) {
  1690. if (!checkItem.style.containIntrinsicSize) return;
  1691. let clientRect = checkItem.getBoundingClientRect();
  1692. let top = clientRect && clientRect.top;
  1693. let bottom = clientRect && clientRect.bottom;
  1694. if (bottom > 0 && top < viewPortHeight) {
  1695. findVisible = true;
  1696. lastVisible = tempIndex;
  1697. checkItem.style.contentVisibility = "visible";
  1698. } else {
  1699. if (findVisible && checkItem.style.contentVisibility == "auto") {
  1700. break;
  1701. } else checkItem.style.contentVisibility = "auto";
  1702. }
  1703. }
  1704. if (tempIndex == this.visibilityItems.length - 1) break;
  1705. tempIndex++;
  1706. checkItem = this.visibilityItems[tempIndex];
  1707. }
  1708. if (findVisible) {
  1709. this.visibleIndex = lastVisible;
  1710. }
  1711. }
  1712.  
  1713. setPageElementCss(pageElement, init) {
  1714. let self = this;
  1715. if (pageElement && pageElement.length > 0) {
  1716. let pageElementCss = this.curSiteRule.pageElementCss || rulesData.pageElementCss;
  1717. if (!pageElementCss && init && !this.nextLinkHref) return;
  1718. let contentVisibility = this.curSiteRule.contentVisibility || rulesData.contentVisibility;
  1719. if (!contentVisibility && !pageElementCss) return;
  1720. [].forEach.call(pageElement, (ele, i) => {
  1721. if (!/LINK|META|STYLE|SCRIPT/i.test(ele.nodeName)) {
  1722. if (pageElementCss) {
  1723. if (pageElementCss !== '0' && !ele.dataset.pagetualPageElement) {
  1724. ele.style.cssText = (ele.style.cssText || '') + pageElementCss;
  1725. ele.dataset.pagetualPageElement = 1;
  1726. }
  1727. }
  1728. if (contentVisibility) {
  1729. ele.style.containIntrinsicSize = `auto ${ele.offsetHeight || self.preVisibleHeight || 100}px`;
  1730. if (ele.style.containIntrinsicSize) {
  1731. if (ele.offsetHeight) self.preVisibleHeight = ele.offsetHeight;
  1732. if (init) {
  1733. ele.style.contentVisibility = "visible";
  1734. self.visibilityItems.push(ele);
  1735. self.visibleIndex++;
  1736. } else {
  1737. ele.style.contentVisibility = emuIframe ? "visible" : "auto";
  1738. }
  1739. }
  1740. }
  1741. }
  1742. });
  1743. }
  1744. }
  1745.  
  1746. clearAddElement() {
  1747. if (this.addedElePool && this.addedElePool.length) {
  1748. this.addedElePool.forEach(ele => {
  1749. if (ele.parentNode) ele.parentNode.removeChild(ele);
  1750. });
  1751. }
  1752. this.addedElePool = [];
  1753. SideController.getInstance().remove();
  1754. }
  1755.  
  1756. async getPage(doc) {
  1757. if (document.documentElement.className.indexOf('discourse') != -1) return {};
  1758. let body = getBody(doc);
  1759. let canSave = false;//發現頁碼選擇器在其他頁對不上,還是別保存了
  1760. let url = this.curUrl.slice(0, 250).replace("index.php?", "?");
  1761. let _url = url.replace(/\.s?html?$/i, "").toLowerCase();
  1762. let pageNum = 1, preStr = "", afterStr = "";
  1763. let pageTwoReg = /^[\/\?&]?[_-]?(p|page)?=?\/?2(\/|\?|&|$)/i;
  1764. let pageMatch1 = url.match(/(.*[\?&]p(?:age)?=)(\d+)($|[#&].*)/i);
  1765. let doubtTextReg = /^\s*(»|>>)\s*$/;
  1766. if (pageMatch1) {
  1767. preStr = pageMatch1[1];
  1768. pageNum = parseInt(pageMatch1[2]);
  1769. afterStr = pageMatch1[3];
  1770. } else {
  1771. let pageMatch2 = url.match(/(.*[a-z\/\-_](?:p|page)?\/?)(\d+)(\.s?html?$|\/?$)/i);
  1772. if (pageMatch2) {
  1773. preStr = pageMatch2[1];
  1774. pageNum = parseInt(pageMatch2[2]);
  1775. afterStr = pageMatch2[3];
  1776. if (/^\/?$/.test(afterStr) && !/(p(age)?|_|\-|\/)$/.test(preStr)) {
  1777. preStr = "";
  1778. afterStr = "";
  1779. }
  1780. }
  1781. }
  1782. if (pageNum > 999) {
  1783. pageNum = 1;
  1784. preStr = "";
  1785. afterStr = "";
  1786. }
  1787. let curPage = doc, i, cur, jsNext;
  1788. let next1, next2, next3, next4, nextJs1, nextJs2, nextJs3;
  1789. let next = body.querySelector(".page-next>a") ||
  1790. body.querySelector("a.next_page") ||
  1791. body.querySelector("#next_page") ||
  1792. body.querySelector(".nextPage") ||
  1793. body.querySelector(".pagination-next>a") ||
  1794. body.querySelector("a[data-pagination=next]") ||
  1795. body.querySelector("ul.pagination>li.active+li>a") ||
  1796. body.querySelector("[class^=pag] .current+a") ||
  1797. body.querySelector(".pagination a[rel=next]") ||
  1798. body.querySelector(".pagination-nav__item--next>a") ||
  1799. body.querySelector("a.pageright") ||
  1800. body.querySelector(".page-numbers.current+a");
  1801. if (!next) {
  1802. await sleep(1);
  1803. next = body.querySelector("input[value='next']") ||
  1804. body.querySelector("input[value='Next page']") ||
  1805. body.querySelector("input[value='下一页']") ||
  1806. body.querySelector("input[value='下一頁']") ||
  1807. body.querySelector("a#pb_next") ||
  1808. body.querySelector("a#rightFix") ||
  1809. body.querySelector("a#btnPreGn") ||
  1810. body.querySelector("a.page-next") ||
  1811. body.querySelector("a.pages-next") ||
  1812. body.querySelector("a.page.right");
  1813. }
  1814. if (!next) {
  1815. await sleep(1);
  1816. next = body.querySelector("a#next") ||
  1817. body.querySelector(".next>a") ||
  1818. body.querySelector(".next>button") ||
  1819. body.querySelector("a[alt=next]") ||
  1820. body.querySelector(".pg_area>em+a") ||
  1821. body.querySelector("button.next:not([disabled])") ||
  1822. body.querySelector(".btn_next:not([disabled])") ||
  1823. body.querySelector(".btn-next:not([disabled])") ||
  1824. body.querySelector("[title=next]") ||
  1825. body.querySelector("a#linkNext") ||
  1826. body.querySelector("a[class*=page__next]");
  1827. }
  1828. if (!next) {
  1829. await sleep(1);
  1830. let nexts = body.querySelectorAll("a.next");
  1831. for (i = 0; i < nexts.length; i++) {
  1832. if (nexts[i].style.display !== "none" &&
  1833. nexts[i].parentNode.style.display !== "none" &&
  1834. !/^\s*([上前首尾]|previous)/i.test(nexts[i].innerText.trim())) {
  1835. next = nexts[i];
  1836. break;
  1837. }
  1838. }
  1839. }
  1840. if (next && (!next.href || /^(javascript|#)/.test(next.href.replace(location.href, "")))) {
  1841. jsNext = next;
  1842. next = null;
  1843. }
  1844. if (!next) {
  1845. next = body.querySelectorAll("[aria-label='Next page']");
  1846. if (next && next.length == 1) {
  1847. next = next[0];
  1848. if (!next.href || /^(javascript|#)/.test(next.href.replace(location.href, ""))) {
  1849. if (!jsNext) jsNext = next;
  1850. next = null;
  1851. }
  1852. } else {
  1853. next = null;
  1854. }
  1855. }
  1856. if (jsNext) {
  1857. if (jsNext.className) {
  1858. if (/slick|slide|gallery/i.test(jsNext.className)) jsNext = null;
  1859. else if (jsNext.classList && jsNext.classList.contains('disabled')) jsNext = null;
  1860. }
  1861. if (jsNext) {
  1862. let ariaLabel = jsNext.getAttribute("aria-label");
  1863. if (ariaLabel && /slick|slide|gallery/i.test(ariaLabel)) jsNext = null;
  1864. }
  1865. }
  1866. if (next && nextTextReg2.test(next.innerText.trim())) {
  1867. next2 = next;
  1868. next = null;
  1869. }
  1870. if (!next) {
  1871. next = body.querySelector("a.curr+a") ||
  1872. body.querySelector("div.wp-pagenavi>span.current+a,div.page-nav>span.current+a,div.article-paging>span+a") ||
  1873. body.querySelector(".number>ul>li.active+li>a");;
  1874. }
  1875. if (!next) {
  1876. let pageDiv = body.querySelector("div.pages>ul");
  1877. if (pageDiv) {
  1878. cur = pageDiv.querySelector("li>b");
  1879. if (cur) next = cur.parentNode.nextElementSibling;
  1880. if (next) next = next.querySelector("a");
  1881. }
  1882. }
  1883. if (!next) {
  1884. next = body.querySelector(".pages>a[href='javascript:;']+a");
  1885. if (next && (next.href == "javascript:;" || next.getAttribute("href") == "#")) next = null;
  1886. }
  1887. if (!next) {
  1888. await sleep(1);
  1889. let pageDiv = body.querySelector(".pagination");
  1890. if (pageDiv) {
  1891. cur = pageDiv.querySelector("[class*=current]");
  1892. if (cur) next = cur.parentNode.nextElementSibling;
  1893. if (next) next = next.querySelector("a");
  1894. }
  1895. }
  1896. if (!next) {
  1897. let aTags = body.querySelectorAll("a,button,[type='button']");
  1898. for (i = aTags.length - 1; i >= 0; i--) {
  1899. if (next1) break;
  1900. if (i % 500 == 0) {
  1901. await sleep(1);
  1902. }
  1903. let aTag = aTags[i];
  1904. if (aTag.style.display == "none") continue;
  1905. if (aTag.innerText) {
  1906. if (aTag.innerText.trim().length > 80) continue;
  1907. if (aTag.innerText == "§") continue;
  1908. }
  1909. let availableHref = aTag.href && aTag.href.length < 250 && /^http/.test(aTag.href);
  1910. if (availableHref && /next$/i.test(aTag.href)) continue;
  1911. if (aTag.className) {
  1912. if (/slick|slide|gallery/i.test(aTag.className)) continue;
  1913. if (aTag.classList && aTag.classList.contains('disabled')) continue;
  1914. }
  1915. let ariaLabel = aTag.getAttribute("aria-label");
  1916. if (ariaLabel && /slick|slide|gallery/i.test(ariaLabel)) continue;
  1917. if (aTag.parentNode) {
  1918. if (aTag.parentNode.className && /slick|slide|gallery/i.test(aTag.parentNode.className)) continue;
  1919. if (aTag.parentNode.classList && aTag.parentNode.classList.contains('disabled')) continue;
  1920. if (/^BLOCKQUOTE$/i.test(aTag.parentNode.nodeName)) continue;
  1921. }
  1922. let isJs = !aTag.href || /^(javascript|#)/.test(aTag.href.replace(location.href, ""));
  1923. let innerText = (aTag.innerText || aTag.value || aTag.title || '');
  1924. if (innerText && innerText.length < 250) {
  1925. innerText = innerText.trim().replace(/\n.*/, '').replace(/ /g, '');
  1926. if (isJs && /^(»|>>|>|›|→|❯)$/.test(innerText)) continue;
  1927. if (innerText && innerText.length <= 25) {
  1928. if (!next1) {
  1929. if (nextTextReg1.test(innerText)) {
  1930. if (isJs) {
  1931. if (!nextJs1) nextJs1 = aTag;
  1932. } else {
  1933. next1 = aTag;
  1934. }
  1935. }
  1936. }
  1937. if (!next4) {
  1938. if (!next2) {
  1939. if (nextTextReg2.test(innerText) || /nextpage|pager\-older/i.test(aTag.className) || /^(»|>>)$/.test(innerText)) {
  1940. if (isJs) {
  1941. if (!nextJs2) nextJs2 = aTag;
  1942. } else {
  1943. next2 = aTag;
  1944. }
  1945. }
  1946. }
  1947. if (!next3) {
  1948. if (/^(next\s*(»|>>|>|›|→|❯)?|&gt;|▶|>|›|→|❯)$/i.test(innerText)) {
  1949. if (isJs) {
  1950. if (!nextJs3) nextJs3 = aTag;
  1951. } else {
  1952. next3 = aTag;
  1953. }
  1954. }
  1955. }
  1956. }
  1957. }
  1958. }
  1959. if (isJs) continue;
  1960. if (!next4) {
  1961. let prevEle = aTag.previousElementSibling;
  1962. if (prevEle && (/^(B|SPAN|STRONG)$/i.test(prevEle.nodeName))) {
  1963. if (/^\d+$/.test(aTag.innerText.trim()) && /^\d+$/.test(prevEle.innerText.trim()) && parseInt(aTag.innerText) == parseInt(prevEle.innerText) + 1) {
  1964. next4 = aTag;
  1965. }
  1966. }
  1967. }
  1968. if (!next4 && availableHref) {
  1969. if (aTag.href.indexOf(location.hostname) === -1) continue;
  1970. let _aHref = aTag.href.replace("?&", "?").replace("index.php?", "?").toLowerCase();
  1971. if (preStr || afterStr) {
  1972. let _aHrefTrim = _aHref;
  1973. if (preStr) _aHrefTrim = _aHrefTrim.replace(preStr, "");
  1974. if (afterStr) _aHrefTrim = _aHrefTrim.replace(afterStr, "");
  1975. if (_aHrefTrim == pageNum + 1) {
  1976. next4 = aTag;
  1977. }
  1978. } else if (this.curUrl != aTag.href) {
  1979. _aHref = _aHref.replace(/\.s?html?$/i, "");
  1980. if (_aHref.indexOf(_url) != -1) {
  1981. let pageTwoMatch = _aHref.replace(_url, "").match(pageTwoReg);
  1982. if (pageTwoMatch) {
  1983. afterStr = pageTwoMatch[2];
  1984. next4 = aTag;
  1985. }
  1986. }
  1987. }
  1988. if (next4) {
  1989. let curHref = next4.getAttribute("href");
  1990. let curPageReg = new RegExp("(.*)" + (pageNum + 1) + afterStr.replace(/([\.\?])/g, '\\$1'));
  1991. let otherPageHref = curHref.replace(curPageReg, `$1${pageNum}${afterStr}`);
  1992. let otherPageEle = body.querySelector(`a[href='${otherPageHref}']`);
  1993. if (!otherPageEle) {
  1994. otherPageHref = curHref.replace(curPageReg, `$1${pageNum + 2}${afterStr}`);
  1995. otherPageEle = body.querySelector(`a[href='${otherPageHref}']`);
  1996. }
  1997. if (otherPageEle && !/^\d+$/.test(otherPageEle.innerText.trim())) next4 = null;
  1998. }
  1999. }
  2000. }
  2001. if (next2 && doubtTextReg.test(next2.innerText)) {
  2002. next2 = this.verifyNext(next2, doc);
  2003. }
  2004. if (nextJs2 && doubtTextReg.test(nextJs2.innerText)) {
  2005. nextJs2 = this.verifyNext(nextJs2, doc);
  2006. }
  2007. if (next3) {
  2008. next3 = this.verifyNext(next3, doc);
  2009. }
  2010. if (nextJs3) {
  2011. nextJs3 = this.verifyNext(nextJs3, doc);
  2012. }
  2013. }
  2014. if (!next) next = next1 || next4 || next3 || next2;
  2015. if (!next) {
  2016. next = jsNext || nextJs1 || nextJs3 || nextJs2;
  2017. if (next && next.parentNode.className.indexOf('tab') != -1) next = null;
  2018. }
  2019. if (next && next.classList && next.classList.contains("results-more")) next=null;
  2020. if (next && next.hasAttribute && next.hasAttribute("disabled")) next=null;
  2021. return {next:next, canSave:canSave};
  2022. }
  2023.  
  2024. verifyNext(next, doc) {
  2025. if (!next) return null;
  2026. if (next.previousElementSibling && /^BR$/i.test(next.previousElementSibling.nodeName)) return null;
  2027. let eles = getAllElements(`//${next.nodeName}[text()='${next.innerText}']`, doc);
  2028. if (eles.length >= 2 && eles[0].href != eles[1].href) {
  2029. next = null;
  2030. } else if (doc == document) {
  2031. let left = getElementLeft(next);
  2032. if (left < 20 || (document.documentElement.scrollWidth > 500 && left < 250)) {
  2033. next = null;
  2034. } else {
  2035. let top = getElementTop(next);
  2036. if (top < 20) {
  2037. next = null;
  2038. } else {
  2039. let bottom = top + next.offsetHeight || 0;
  2040. let scrollH = Math.max(document.documentElement.scrollHeight, getBody(document).scrollHeight);
  2041. if (scrollH - bottom < 10) next = null;
  2042. }
  2043. }
  2044. }
  2045. return next;
  2046. }
  2047.  
  2048. canonicalUri(src) {
  2049. if (!src) {
  2050. return "";
  2051. }
  2052. if (src.charAt(0) == "#") return this.curUrl + src;
  2053. if (src.charAt(0) == "?") return this.curUrl.replace(/^([^\?#]+).*/, "$1" + src);
  2054. let origin = location.protocol + '//' + location.host;
  2055. let url = this.basePath || origin;
  2056. url = url.replace(/(\?|#).*/, "");
  2057. if (/https?:\/\/[^\/]+$/.test(url)) url = url + '/';
  2058. if (url.indexOf("http") !== 0) url = origin + url;
  2059. var root_page = /^[^\?#]*\//.exec(url)[0],
  2060. root_domain = /^\w+\:\/\/\/?[^\/]+/.exec(root_page)[0],
  2061. absolute_regex = /^\w+\:\/\//;
  2062. this.updateUrl = false;
  2063. while (src.indexOf("../") === 0) {
  2064. src = src.substr(3);
  2065. root_page = root_page.replace(/\/[^\/]+\/$/, "/");
  2066. this.updateUrl = true;
  2067. }
  2068. src = src.replace(/\.\//, "");
  2069. if (/^\/\/\/?/.test(src)) {
  2070. src = location.protocol + src;
  2071. }
  2072. return (absolute_regex.test(src) ? src : ((src.charAt(0) == "/" ? root_domain : root_page) + src));
  2073. }
  2074.  
  2075. getLinkByPage(url, pageNum) {
  2076. if (!url) return;
  2077. if (this.curSiteRule.pageNum) {
  2078. let result = this.curSiteRule.pageNum;
  2079. let strMatch = result.match(/\{.*?}/);
  2080. if (!strMatch) return null;
  2081. let urlReg = new RegExp("(" + result.replace(strMatch[0], ")\\d+(") + ")", "i");
  2082. let code = strMatch[0].replace(/^{/, "").replace(/}$/, "").replace(/\$p/g, pageNum);
  2083. if (code == pageNum) {
  2084. result = url.replace(urlReg, "$1" + code + "$2");
  2085. } else {
  2086. try {
  2087. code = Function('"use strict";return ' + code)();
  2088. result = url.replace(urlReg, "$1" + code + "$2");
  2089. } catch(e) {
  2090. debug(e);
  2091. }
  2092. }
  2093. if (result != url) {
  2094. return result;
  2095. }
  2096. }
  2097. return url.replace(/([&\/\?](p=|page[=\/_-]?))\d+/i, "$1" + pageNum).replace(/([_-])\d+\./i, "$1" + pageNum + ".");
  2098. }
  2099.  
  2100. getPageNumFromUrl(url) {
  2101. if (!url) return curPage;
  2102. if (this.curSiteRule.pageNum) {
  2103. let result = this.curSiteRule.pageNum;
  2104. let strMatch = result.match(/\{.*?}/);
  2105. if (!strMatch) return null;
  2106. let urlReg = new RegExp(".*" + result.replace(strMatch[0], "(\\d+)") + ".*", "i");
  2107. let curShowNum = url.replace(urlReg, "$1");
  2108. if (curShowNum != url) {
  2109. let code = strMatch[0].replace(/^{/, "").replace(/}$/, "");
  2110. if (code == "$p") {
  2111. return curShowNum;
  2112. } else {
  2113. try {
  2114. let page1 = Function('"use strict";return ' + code.replace("$p", "0"))();
  2115. let page2 = Function('"use strict";return ' + code.replace("$p", "1"))();
  2116. let numGap = page2 - page1;
  2117. return (curShowNum - page1) / numGap;
  2118. } catch(e) {
  2119. debug(e);
  2120. }
  2121. }
  2122. } else {
  2123. return curPage;
  2124. }
  2125. }
  2126. let pageNum = url.replace(/.*[&\/\?](p=|page[=\/_-]?)(\d+).*/i, "$2");
  2127. return pageNum == url ? curPage : (pageNum.length > 4 ? curPage : pageNum);
  2128. }
  2129.  
  2130. async getNextLink(doc) {
  2131. let nextLink = null, page, href;
  2132. let getNextLinkByForm = (form, submitBtn, n) => {
  2133. let params = [];
  2134. let formData = new FormData(form);
  2135. if (submitBtn && submitBtn.getAttribute) {
  2136. let btnValue, btnName;
  2137. btnName = submitBtn.getAttribute("name");
  2138. btnValue = submitBtn.getAttribute("value");
  2139. if (btnName && btnValue) params = [btnName + "=" + btnValue];
  2140. }
  2141. for (let [key, value] of formData) {
  2142. if (n && /^(p|page)$/i.test(key)) {
  2143. params.push(key + '=' + n);
  2144. } else {
  2145. params.push(key + '=' + encodeURIComponent(value));
  2146. }
  2147. }
  2148. params = params.join('&');
  2149. return form.action + (form.action.indexOf('?') == -1 ? '?' : '&') + params + (form.method == 'post' ? '#p{' + params + '}' : '');
  2150. };
  2151. if (this.curSiteRule.pageElementByJs) {
  2152. this.nextLinkHref = "#";
  2153. return true;
  2154. } else if (this.curSiteRule.nextLinkByJs) {
  2155. try {
  2156. let over = _url => {
  2157. };
  2158. let targetUrl = await ((typeof _unsafeWindow.pagetualNextLinkByJs == 'undefined') ? new AsyncFunction("doc", '"use strict";' + this.curSiteRule.nextLinkByJs) : _unsafeWindow.pagetualNextLinkByJs)(doc);
  2159. if (targetUrl) nextLink = {href: targetUrl};
  2160. } catch(e) {
  2161. debug(e);
  2162. }
  2163. } else if (this.curSiteRule.nextLinkByUrl) {
  2164. let targetUrl = this.curUrl.replace(new RegExp(this.curSiteRule.nextLinkByUrl[0], "i"), this.curSiteRule.nextLinkByUrl[1]);
  2165. if (targetUrl != this.curUrl) {
  2166. let includeSel = this.curSiteRule.nextLinkByUrl[2];
  2167. let excludeSel = this.curSiteRule.nextLinkByUrl[3];
  2168. if (includeSel) {
  2169. includeSel = includeSel.trim();
  2170. if (!getElement(includeSel, doc)) {
  2171. this.nextLinkHref=false;
  2172. return null;
  2173. }
  2174. }
  2175. if (excludeSel) {
  2176. excludeSel = excludeSel.trim();
  2177. if (getElement(excludeSel, doc)) {
  2178. this.nextLinkHref=false;
  2179. return null;
  2180. }
  2181. }
  2182. let reps = targetUrl.match(/{.*?}/g);
  2183. if (reps) {
  2184. reps.forEach(rep => {
  2185. let code = rep.replace("{", "").replace("}", "").replace(/\(\)/g, "0");
  2186. let result = code.match(/^(\d*)\+1$/);
  2187. if (result) {
  2188. result = parseInt(result[1] || 1) + 1;
  2189. } else {
  2190. try {
  2191. result = Function('"use strict";return ' + code)();
  2192. } catch(e) {
  2193. debug(e);
  2194. }
  2195. }
  2196. targetUrl = targetUrl.replace(rep, result);
  2197. });
  2198. }
  2199. }
  2200. nextLink = {href: targetUrl};
  2201. } else if (this.curSiteRule.nextLink) {
  2202. let nextLinkSel = this.curSiteRule.nextLink;
  2203. if (nextLinkSel != 0) {
  2204. if (Array && Array.isArray && Array.isArray(nextLinkSel)) {
  2205. nextLink = getElement(nextLinkSel[nextIndex], doc);
  2206. if (!nextLink && curPage == 1 && nextIndex != 0) {
  2207. nextIndex = 0;
  2208. nextLink = getElement(nextLinkSel[nextIndex], doc);
  2209. }
  2210. } else nextLink = getElement(nextLinkSel, doc);
  2211. }
  2212. if (nextLink && (this.curSiteRule.action == 0 || this.curSiteRule.action == 1 || this.curSiteRule.action == 2)) {
  2213. let form = doc.querySelector('#search-form');
  2214. if (!nextLink.href && nextLink.hasAttribute && nextLink.hasAttribute("onclick") && form) {
  2215. if (/^\d+$/.test(nextLink.innerText)) {
  2216. nextLink.href = getNextLinkByForm(form, nextLink, nextLink.innerText);
  2217. }
  2218. } else if (/^INPUT$/i.test(nextLink.nodeName) || nextLink.type == "submit") {
  2219. form = nextLink.parentNode;
  2220. while (form) {
  2221. if (/^FORM$/i.test(form.nodeName)) break;
  2222. else form = form.parentNode;
  2223. }
  2224. if (form) {
  2225. nextLink.href = getNextLinkByForm(form, nextLink);
  2226. }
  2227. }
  2228. if (nextLink.href && this.curSiteRule.action != 0) {
  2229. nextLink.href = nextLink.href.replace(/#p{.*/, "");
  2230. }
  2231. }
  2232. } else {
  2233. page = await this.getPage(doc);
  2234. nextLink = page.next;
  2235. if (nextLink) {
  2236. if (/^INPUT$/i.test(nextLink.nodeName) || nextLink.type == "submit") {
  2237. let form = nextLink.parentNode;
  2238. while (form) {
  2239. if (/^FORM$/i.test(form.nodeName)) break;
  2240. else form = form.parentNode;
  2241. }
  2242. if (form) {
  2243. nextLink.href = getNextLinkByForm(form, nextLink);
  2244. }
  2245. }
  2246. let parent = nextLink;
  2247. while (parent && !/^BODY$/i.test(parent.nodeName)) {
  2248. if (parent.hasAttribute && parent.hasAttribute("disabled")) {
  2249. this.nextLinkHref = false;
  2250. return null;
  2251. }
  2252. if (parent.className && parent.classList) {
  2253. if (parent.classList.contains("noClick") || parent.classList.contains("no-pages") || parent.classList.contains("disabled")) {
  2254. this.nextLinkHref = false;
  2255. return null;
  2256. }
  2257. }
  2258. if (parent.style && parent.style.display === "none") {
  2259. this.nextLinkHref = false;
  2260. return null;
  2261. }
  2262. parent = parent.parentNode;
  2263. }
  2264. if (doc == document) {
  2265. if ((!nextLink.href || /^(javascript|#)/.test(nextLink.href.replace(location.href, ""))) && !isVisible(nextLink, _unsafeWindow)) {
  2266. this.nextLinkHref = false;
  2267. return null;
  2268. } else {
  2269. let nextLinkCs = _unsafeWindow.getComputedStyle(nextLink);
  2270. if (nextLinkCs.cursor == "not-allowed") {
  2271. this.nextLinkHref = false;
  2272. return null;
  2273. }
  2274. this.initNext = nextLink;
  2275. }
  2276. }
  2277. let form = doc.querySelector('#search-form');
  2278. if (!nextLink.href && nextLink.hasAttribute("onclick") && form) {
  2279. if (form && /^\d+$/.test(nextLink.innerText)) {
  2280. href = getNextLinkByForm(form, nextLink, nextLink.innerText);
  2281. }
  2282. }
  2283. }
  2284. }
  2285. if (nextLink) {
  2286. if (!this.checkStopSign(nextLink, doc)) return null;
  2287. if (this.curSiteRule.action == 3) {
  2288. if (doc == document) debug(nextLink, 'Next link');
  2289. this.nextLinkHref = '#';
  2290. } else {
  2291. let needUrl = (this.curSiteRule.action == 0 || this.curSiteRule.action == 1 || this.curSiteRule.action == 2);
  2292. if (!href) href = nextLink.href;
  2293. if (href && nextLink.getAttribute) {
  2294. let _href = nextLink.getAttribute("href");
  2295. if (_href) {
  2296. if (_href.charAt(0) == "#" || _href == "?"){
  2297. href = "#";
  2298. } else {
  2299. href = _href;
  2300. }
  2301. }
  2302. }
  2303.  
  2304. if (needUrl && (href === "" || href === null)) {
  2305. this.nextLinkHref = false;
  2306. } else if (needUrl && /^(javascript:|#)/.test(href)) {
  2307. this.nextLinkHref = false;
  2308. } else {
  2309. this.nextLinkHref = (href && !/^(javascript:|#)/.test(href)) ? this.canonicalUri(href) : "#";
  2310. let compareUrl = this.nextLinkHref.replace(/#p{.*/, "");
  2311. if (compareUrl != "#" && (compareUrl == this.initUrl || compareUrl == this.curUrl || compareUrl == this.curUrl + "#" || compareUrl == this.oldUrl || compareUrl == this.oldUrl + "#")) {
  2312. this.nextLinkHref = false;
  2313. } else if (doc == document) debug(nextLink, 'Next link');
  2314. }
  2315. }
  2316. } else {
  2317. this.nextLinkHref = false;
  2318. }
  2319. this.preload();
  2320. return nextLink;
  2321. }
  2322.  
  2323. checkStopSign(nextLink, doc) {
  2324. if (this.curSiteRule.stopSign) {
  2325. if (Array && Array.isArray && Array.isArray(this.curSiteRule.stopSign)) {
  2326. let includeSel = this.curSiteRule.stopSign[0];
  2327. let excludeSel = this.curSiteRule.stopSign[1];
  2328. let curSign = this.curSiteRule.stopSign[2];
  2329. let maxSign = this.curSiteRule.stopSign[3];
  2330. if (Array && Array.isArray && Array.isArray(includeSel) && !curSign) {
  2331. curSign = includeSel;
  2332. includeSel = false;
  2333. }
  2334. if (Array && Array.isArray && Array.isArray(excludeSel) && !maxSign) {
  2335. maxSign = excludeSel;
  2336. excludeSel = false;
  2337. }
  2338. if (includeSel) {
  2339. includeSel = includeSel.trim();
  2340. if (!getElement(includeSel, doc)) {
  2341. isPause = true;
  2342. this.nextLinkHref = false;
  2343. return false;
  2344. }
  2345. }
  2346. if (excludeSel) {
  2347. excludeSel = excludeSel.trim();
  2348. if (getElement(excludeSel, doc)) {
  2349. isPause = true;
  2350. this.nextLinkHref = false;
  2351. return false;
  2352. }
  2353. }
  2354. if (curSign && maxSign) {
  2355. let currentEle = getElement(curSign[0], doc);
  2356. let maxEle = getElement(maxSign[0], doc);
  2357. if (currentEle && maxEle) {
  2358. let currentSignNum, maxSignNum;
  2359. if (/\(.*\)/.test(curSign[1])) {
  2360. currentSignNum = currentEle.innerText.match(new RegExp(curSign[1]));
  2361. if (currentSignNum) currentSignNum = currentSignNum[1];
  2362. } else if (currentEle.getAttribute) {
  2363. currentSignNum = currentEle.getAttribute(curSign[1]);
  2364. }
  2365. if (/\(.*\)/.test(maxSign[1])) {
  2366. maxSignNum = maxEle.innerText.match(new RegExp(maxSign[1]));
  2367. if (maxSignNum) maxSignNum = maxSignNum[1];
  2368. } else if (maxEle.getAttribute) {
  2369. maxSignNum = maxEle.getAttribute(maxSign[1]);
  2370. }
  2371. if (currentSignNum && maxSignNum && currentSignNum == maxSignNum) {
  2372. isPause = true;
  2373. this.nextLinkHref = false;
  2374. return false;
  2375. }
  2376. }
  2377. }
  2378. } else {
  2379. try {
  2380. let stopSign = ((typeof _unsafeWindow.stopSign == 'undefined') ? Function("doc", "nextLink", '"use strict";' + this.curSiteRule.stopSign) : _unsafeWindow.stopSign)(doc, nextLink);
  2381. if (stopSign) {
  2382. isPause = true;
  2383. this.nextLinkHref = false;
  2384. return false;
  2385. }
  2386. } catch(e) {
  2387. debug(e);
  2388. }
  2389. }
  2390. }
  2391. return true;
  2392. }
  2393.  
  2394. preload() {
  2395. if (!rulesData.preload) return;
  2396. if (!this.nextLinkHref || this.nextLinkHref == "#") return;
  2397. let self = this, url = this.nextLinkHref;
  2398. let postParams = url.match(/#p{(.*)}$/);
  2399. if (postParams) {
  2400. postParams = postParams[1];
  2401. url = url.replace(/#p{.*/, "");
  2402. }
  2403. _GM_xmlhttpRequest({
  2404. url: url,
  2405. method: postParams ? 'POST' : 'GET',
  2406. data: postParams,
  2407. overrideMimeType: 'text/html;charset=' + (document.characterSet || document.charset || document.inputEncoding),
  2408. headers: {
  2409. 'Referer': location.href,
  2410. 'User-Agent': navigator.userAgent,
  2411. "Content-Type": (postParams ? "application/x-www-form-urlencoded" : "text/html") + ";charset=" + (document.characterSet || document.charset || document.inputEncoding),
  2412. },
  2413. timeout: 10000,
  2414. onload: function(res) {
  2415. var doc = null;
  2416. try {
  2417. doc = document.implementation.createHTMLDocument('');
  2418. doc.documentElement.innerHTML = res.response;
  2419. var body = getBody(doc);
  2420. if (body && body.firstChild) {
  2421. self.lazyImgAction(body.children);
  2422. }
  2423. if (!self.preloadDiv) {
  2424. self.preloadDiv = document.createElement('div');
  2425. self.preloadDiv.id = "pagetual-preload";
  2426. self.preloadDiv.style.cssText = 'display:none!important;';
  2427. getBody(document).appendChild(self.preloadDiv);
  2428. self.checkedImgs = {};
  2429. }
  2430. [].forEach.call(doc.images, i => {
  2431. let iSrc = i.src;
  2432. if (iSrc && !self.checkedImgs[iSrc]) {
  2433. self.checkedImgs[iSrc] = true;
  2434. let img = document.createElement('img');
  2435. img.src = iSrc;
  2436. self.preloadDiv.appendChild(img);
  2437. }
  2438. });
  2439. let code = self.curSiteRule.preloadImages;
  2440. if (code) {
  2441. let imgSrcArr = new Function("doc", '"use strict";' + code)(doc);
  2442. if (imgSrcArr && imgSrcArr.length) {
  2443. imgSrcArr.forEach(imgSrc => {
  2444. if (imgSrc && !self.checkedImgs[imgSrc]) {
  2445. self.checkedImgs[imgSrc] = true;
  2446. let img = document.createElement('img');
  2447. img.src = imgSrc;
  2448. self.preloadDiv.appendChild(img);
  2449. }
  2450. });
  2451. }
  2452. }
  2453. }
  2454. catch(e) {
  2455. debug(e);
  2456. return;
  2457. }
  2458. }
  2459. });
  2460. }
  2461.  
  2462. getInsert(refresh) {
  2463. if (refresh) {
  2464. this.insert = null;
  2465. }
  2466. if (this.insert && document.documentElement.contains(this.insert)) {
  2467. return this.insert;
  2468. }
  2469. if (this.curSiteRule.insert) {
  2470. let insertSel = this.curSiteRule.insert;
  2471. if (Array && Array.isArray && Array.isArray(insertSel)) {
  2472. insertSel = insertSel[nextIndex < insertSel.length ? nextIndex : 0];
  2473. }
  2474. this.insert = getElement(insertSel, document);
  2475. } else {
  2476. if (refresh) this.docPageElement = null;
  2477. let pageElement = this.getPageElement(document, _unsafeWindow);
  2478. if (this.curSiteRule.singleUrl && this.nextLinkHref == "#" && this.curSiteRule.pageElement === 'body') {
  2479. debug("Stop as jsNext & whole body");
  2480. isPause = true;
  2481. return null;
  2482. }
  2483. if (pageElement && pageElement.length > 0) {
  2484. var pELast = pageElement[pageElement.length - 1];
  2485. this.insert = pELast.nextSibling ? pELast.nextSibling : pELast.parentNode.appendChild(document.createTextNode(' '));
  2486. }
  2487. }
  2488. return this.insert;
  2489. }
  2490.  
  2491. pageInit(doc,eles){
  2492. let code=this.curSiteRule.pageInit;
  2493. if(code){
  2494. let initFunc=((typeof _unsafeWindow.pagetualPageInit=='undefined') ? Function("doc", "eles", '"use strict";' + code) : _unsafeWindow.pagetualPageInit);
  2495. let checkInit=(resolve)=>{
  2496. try{
  2497. if(initFunc(doc, eles)===false){
  2498. setTimeout(()=>{
  2499. checkInit(resolve);
  2500. },100);
  2501. } else {
  2502. resolve(true);
  2503. }
  2504. }catch(e){
  2505. resolve(false);
  2506. debug(e);
  2507. }
  2508. };
  2509. return new Promise((resolve) => {
  2510. checkInit(function(e) {
  2511. resolve(e)
  2512. });
  2513. })
  2514. }
  2515. }
  2516.  
  2517. pageAction(doc,eles) {
  2518. let code = this.curSiteRule.pageAction;
  2519. if (code) {
  2520. try {
  2521. ((typeof _unsafeWindow.pagetualPageAction == 'undefined') ? Function("doc", "eles", '"use strict";' + code) : _unsafeWindow.pagetualPageAction)(doc, eles);
  2522. } catch(e) {
  2523. debug(e);
  2524. }
  2525. }
  2526. this.openInNewTab(eles);
  2527. this.replaceElement(doc);
  2528. }
  2529.  
  2530. openInNewTab(eles) {
  2531. if (openInNewTab) {
  2532. [].forEach.call(eles, ele => {
  2533. if (/^A$/i.test(ele.nodeName) && ele.href && !/^(mailto:|javascript:)|#/.test(ele.href)) {
  2534. ele.setAttribute('target', openInNewTab == 1 ? '_blank' : '_self');
  2535. } else {
  2536. [].forEach.call(ele.querySelectorAll('a[href]:not([href^="mailto:"]):not([href^="javascript:"]):not([href^="#"])'), a => {
  2537. if (openInNewTab == 1) {
  2538. a.setAttribute('target', '_blank');
  2539. if (a.getAttribute('onclick') == 'atarget(this)') {
  2540. a.removeAttribute('onclick');
  2541. }
  2542. } else a.setAttribute('target', '_self');
  2543. });
  2544. }
  2545. });
  2546. }
  2547. }
  2548.  
  2549. lazyImgAction(eles) {
  2550. if (!eles || eles.length == 0) return;
  2551. let lazyImgSrc = this.curSiteRule.lazyImgSrc;
  2552. if (lazyImgSrc === 0 || lazyImgSrc === '0') return;
  2553. let setLazyImg = img => {
  2554. let realSrc;
  2555. if (lazyImgSrc) {
  2556. if (!Array.isArray(lazyImgSrc)) {
  2557. lazyImgSrc = [lazyImgSrc];
  2558. }
  2559. realSrc = img.getAttribute(lazyImgSrc[0]);
  2560. if (lazyImgSrc.length == 2) {
  2561. let removeProps = lazyImgSrc[1].split(",");
  2562. removeProps.forEach(prop => {
  2563. img.removeAttribute(prop.trim());
  2564. });
  2565. }
  2566. }
  2567. if (!realSrc) {
  2568. if (img.getAttribute("_src") && !img.src) {
  2569. realSrc = img.getAttribute("_src");
  2570. } else {
  2571. for (let i in lazyImgAttr) {
  2572. let attrName = lazyImgAttr[i];
  2573. let attrValue = img.getAttribute(attrName);
  2574. if (attrValue) {
  2575. realSrc = attrValue;
  2576. break;
  2577. }
  2578. }
  2579. }
  2580. if (!realSrc && img._lazyrias && img._lazyrias.srcset) {
  2581. realSrc = img._lazyrias.srcset[img._lazyrias.srcset.length - 1];
  2582. }
  2583. if (realSrc) {
  2584. img.removeAttribute("srcset");
  2585. } else if (img.srcset) {
  2586. var srcs = img.srcset.split(/[xw],/i), largeSize = 0;
  2587. srcs.forEach(srci => {
  2588. let srcInfo = srci.trim().split(" "), curSize = parseInt(srcInfo[1]);
  2589. if (srcInfo[1] && curSize > largeSize) {
  2590. largeSize = curSize;
  2591. realSrc = srcInfo[0];
  2592. }
  2593. });
  2594. }
  2595. }
  2596. if (realSrc) {
  2597. img.src = realSrc;
  2598. if (img.style.display == "none") {
  2599. img.style.display = "";
  2600. }
  2601. if (img.style.visibility == "hidden") {
  2602. img.style.visibility = "";
  2603. }
  2604. if (img.style.opacity == 0) {
  2605. img.style.opacity = "";
  2606. }
  2607. }
  2608. };
  2609. [].forEach.call(eles, ele => {
  2610. if (/^IMG$/i.test(ele.nodeName)) {
  2611. setLazyImg(ele);
  2612. } else {
  2613. [].forEach.call(ele.querySelectorAll("img,picture>source"), img => {
  2614. setLazyImg(img);
  2615. });
  2616. [].forEach.call(ele.querySelectorAll("div[data-src][data-thumb]"), div => {
  2617. div.style.setProperty("background-image", "url(" + div.dataset.src + ")", "important");
  2618. });
  2619. }
  2620. if (/^A$/i.test(ele.nodeName) && ele.classList.contains("lazyload")) {
  2621. if (ele.dataset.original) {
  2622. ele.style.backgroundImage = 'url("' + ele.dataset.original + '")';
  2623. }
  2624. } else {
  2625. [].forEach.call(ele.querySelectorAll("a.lazyload"), a => {
  2626. if (a.dataset.original) {
  2627. a.style.backgroundImage = 'url("' + a.dataset.original + '")';
  2628. }
  2629. });
  2630. }
  2631. });
  2632. }
  2633.  
  2634. initPage(callback) {
  2635. let self = this;
  2636. if (self.initing) return;
  2637. self.initing = true;
  2638. setTimeout(() => {
  2639. self.initing = false;
  2640. }, 100);
  2641. curPage = 1;
  2642. urlChanged = false;
  2643. this.clearAddElement();
  2644. this.insert = null;
  2645. this.visibilityItems = [];
  2646. this.visibleIndex = -1;
  2647. this.pageDoc = document;
  2648. this.nextLinkHref = null;
  2649. this.curUrl = location.href;
  2650. this.oldUrl = "";
  2651. this.initUrl = location.href;
  2652. this.historyUrl = "";
  2653. let base = document.querySelector("base");
  2654. this.basePath = base ? base.href : location.href;
  2655. this.getRule(async () => {
  2656. isPause = false;
  2657. if (self.curSiteRule.enable == 0) {
  2658. debug("Stop as rule disable");
  2659. isPause = true;
  2660. return;
  2661. }
  2662. //若是再亂匹配就不緩存wedata,或者只在找完本地規則之後再考慮wedata的緩存
  2663. if (self.curSiteRule.singleUrl) {
  2664. delete self.curSiteRule.pageElement;
  2665. self.smartRules = self.smartRules.filter(item => {return item && item.url != self.curSiteRule.url});
  2666. self.smartRules.unshift(self.curSiteRule);
  2667. if (self.smartRules.length > 100) {
  2668. self.smartRules.pop();
  2669. }
  2670. storage.setItem("smartRules", self.smartRules);
  2671. } else if (self.curSiteRule && self.curSiteRule.url.length > 13) {
  2672. self.hpRules = self.hpRules.filter(item => {return item && item.url != self.curSiteRule.url});
  2673. self.hpRules.unshift(self.curSiteRule);
  2674. if (self.hpRules.length > 30) {
  2675. self.hpRules.pop();
  2676. }
  2677. storage.setItem("hpRules", self.hpRules);
  2678. }
  2679. let css = self.curSiteRule.css || rulesData.customCss;
  2680. if (css && !/^inIframe:/.test(css)) {
  2681. _GM_addStyle(css);
  2682. }
  2683. if (typeof self.curSiteRule.openInNewTab !== 'undefined') {
  2684. openInNewTab = self.curSiteRule.openInNewTab ? 1 : 2;
  2685. }
  2686. let autoClick = self.curSiteRule.autoClick;
  2687. if (autoClick) {
  2688. let autoClickBtn;
  2689. autoClickBtn = getElement(autoClick, document);
  2690. if (autoClickBtn) {
  2691. emuClick(autoClickBtn);
  2692. }
  2693. }
  2694. let code = self.curSiteRule.init;
  2695. if (code) {
  2696. try {
  2697. ((typeof _unsafeWindow.pagetualInit == 'undefined') ? Function('doc','win','iframe','"use strict";' + code) : _unsafeWindow.pagetualInit)(null, null, null);
  2698. } catch(e) {
  2699. debug(e);
  2700. }
  2701. }
  2702. await self.getNextLink(document);
  2703. self.refreshByClick();
  2704.  
  2705. let pageElementCss = self.curSiteRule.pageElementCss || rulesData.pageElementCss;
  2706. if (pageElementCss && pageElementCss !== '0') {
  2707. self.getPageElement(document, _unsafeWindow);
  2708. }
  2709. callback();
  2710. let initRun = typeof self.curSiteRule.initRun == 'undefined' ? rulesData.initRun : self.curSiteRule.initRun;
  2711. if (initRun && initRun != false && self.nextLinkHref) nextPage();
  2712. });
  2713. }
  2714.  
  2715. insertElement(ele) {
  2716. if (!this.insert || !this.insert.parentNode) {
  2717. this.getInsert();
  2718. }
  2719. if (this.insert) {
  2720. this.addedElePool.push(ele);
  2721. if (this.curSiteRule.insertPos == 2) {
  2722. this.insert.appendChild(ele);
  2723. } else {
  2724. this.insert.parentNode.insertBefore(ele, this.insert);
  2725. }
  2726. }
  2727. }
  2728.  
  2729. async insertPage(doc, eles, url, callback, tried) {
  2730. this.oldUrl = this.curUrl;
  2731. let oldTitle = this.pageDoc.title;
  2732. this.pageDoc = doc;
  2733. this.curUrl = url;
  2734. let nextLink = await this.getNextLink(doc);
  2735. this.nextTitle = "";
  2736. if (this.curSiteRule.pageBarText) {
  2737. if (this.curSiteRule.pageBarText == 1 || this.curSiteRule.pageBarText == true) {
  2738. this.nextTitle = doc.title;
  2739. } else {
  2740. try {
  2741. this.nextTitle = ((typeof _unsafeWindow.pagetualPageBarText == 'undefined') ? Function("doc",'"use strict";' + this.curSiteRule.pageBarText) : _unsafeWindow.pagetualPageBarText)(doc);
  2742. } catch(e) {
  2743. debug(e);
  2744. }
  2745. }
  2746. }
  2747. if (curPage == 1 && !tried && !nextLink && this.curSiteRule.singleUrl && this.curSiteRule.pageElement && this.curSiteRule.action != 0) {
  2748. this.curSiteRule.action = 1;
  2749. this.curUrl = location.href;
  2750. return false;
  2751. }
  2752. let curScroll = getBody(document).scrollTop || document.documentElement.scrollTop;
  2753. if (callback) callback(eles);
  2754. this.getInsert();
  2755. var self = this, newEles = [];
  2756. if (!eles || eles.length == 0 || !self.insert || !self.insert.parentNode) {
  2757. } else {
  2758. isLoading = true;
  2759. await this.pageInit(doc, eles);
  2760. [].forEach.call(eles, ele => {
  2761. let newEle = ele.cloneNode(true);
  2762. let oldCanvass = ele.querySelectorAll("canvas");
  2763. let newCanvass = newEle.querySelectorAll("canvas");
  2764. if (self.updateUrl) {
  2765. [].forEach.call(newEle.querySelectorAll("img"), img => {
  2766. if (img.getAttribute("src")) img.src = self.canonicalUri(img.getAttribute("src"));
  2767. });
  2768. [].forEach.call(newEle.querySelectorAll("a"), a => {
  2769. if (a.getAttribute("href")) a.href = self.canonicalUri(a.getAttribute("href"));
  2770. });
  2771. }
  2772. for (let i = 0; i < oldCanvass.length; i++) {
  2773. let oldCanvas = oldCanvass[i];
  2774. let newCanvas = newCanvass[i];
  2775. newCanvas.getContext('2d').drawImage(oldCanvas, 0, 0);
  2776. }
  2777. if (!/^(STYLE|SCRIPT)$/.test(newEle.nodeName)) self.visibilityItems.push(newEle);
  2778. self.insertElement(newEle);
  2779. newEles.push(newEle);
  2780. });
  2781. getBody(document).scrollTop = curScroll;
  2782. document.documentElement.scrollTop = curScroll;
  2783. }
  2784. this.pageAction(doc, newEles);
  2785. let enableHistory = this.curSiteRule.history;
  2786. let enableHistoryAfterInsert = false;
  2787. if (enableHistory == 1) {
  2788. enableHistory = true;
  2789. } else if (enableHistory == 2) {
  2790. enableHistory = true;
  2791. enableHistoryAfterInsert = true;
  2792. } else if (enableHistory == 0) {
  2793. enableHistory = false;
  2794. } else {
  2795. enableHistory = rulesData.enableHistory;
  2796. enableHistoryAfterInsert = rulesData.enableHistoryAfterInsert;
  2797. }
  2798. if (enableHistory) {
  2799. this.historyUrl = enableHistoryAfterInsert ? this.curUrl : this.oldUrl;
  2800. if(this.historyUrl != location.href) {
  2801. let isJs = /^(javascript|#)/.test(this.historyUrl.replace(location.href, ""));
  2802. if (!isJs) {
  2803. let historyTitle = enableHistoryAfterInsert ? doc.title : oldTitle;
  2804. _unsafeWindow.history.replaceState(undefined, historyTitle, this.historyUrl);
  2805. document.title = historyTitle;
  2806. }
  2807. }
  2808. }
  2809. isLoading = false;
  2810. return true;
  2811. }
  2812. }
  2813. var ruleParser = new RuleParser();
  2814.  
  2815. class SideController {
  2816. static controller;
  2817. constructor() {
  2818. this.inited = false;
  2819. }
  2820.  
  2821. static getInstance() {
  2822. if (!SideController.controller) {
  2823. SideController.controller = new SideController();
  2824. }
  2825. return SideController.controller;
  2826. }
  2827.  
  2828. static setup() {
  2829. if (ruleParser.curSiteRule.sideController === false) return;
  2830. if (!rulesData.sideController && !ruleParser.curSiteRule.sideController) return;
  2831. SideController.getInstance().addToStage();
  2832. }
  2833.  
  2834. init() {
  2835. if (this.inited) return;
  2836. this.inited = true;
  2837. let self = this;
  2838. this.cssText = `
  2839. #pagetual-sideController {
  2840. position: fixed;
  2841. top: calc(50% - 83px);
  2842. left: calc(99% - 40px);
  2843. width: 40px;
  2844. border-radius: 20px;
  2845. box-shadow: rgb(0 0 0) 0px 0px 10px;
  2846. text-align: center;
  2847. background: #ffffffd0!important;
  2848. user-select: none;
  2849. z-index: 2147483646!important;
  2850. padding: 0!important;
  2851. opacity: 0.5;
  2852. transition: opacity .5s ease, background .5s, box-shadow .5s;
  2853. }
  2854. #pagetual-sideController:hover {
  2855. opacity: 1;
  2856. }
  2857. #pagetual-sideController * {
  2858. font-weight: bold;
  2859. font-family: arial;
  2860. font-style: normal;
  2861. font-size: 20px!important;
  2862. color: black!important;
  2863. line-height: normal;
  2864. float: none;
  2865. }
  2866. #pagetual-sideController.stop {
  2867. -webkit-filter: invert(100%);
  2868. filter: invert(100%);
  2869. }
  2870. .pagetual-sideController-btn {
  2871. padding: 5px 0;
  2872. cursor: pointer;
  2873. transition: transform .15s ease-in-out, opacity .3s ease;
  2874. }
  2875. #pagetual-sideController .pagetual-sideController-btn:hover {
  2876. transform: scale(1.5);
  2877. color: red!important;
  2878. }
  2879. #pagetual-sideController.minSize {
  2880. box-shadow: rgb(0 0 0 / 0%) 0px 0px 0px;
  2881. background: #00000000!important;
  2882. }
  2883. #pagetual-sideController.minSize .pagetual-sideController-btn {
  2884. opacity: 0;
  2885. }
  2886. #pagetual-sideController #pagetual-sideController-move > svg {
  2887. transition: transform .3s ease;
  2888. }
  2889. #pagetual-sideController #pagetual-sideController-move > svg:hover {
  2890. transform: scale(1.2);
  2891. }
  2892. #pagetual-sideController.minSize #pagetual-sideController-move > svg {
  2893. background: white;
  2894. }
  2895. #pagetual-sideController #pagetual-sideController-move > img,
  2896. #pagetual-sideController #pagetual-sideController-move > span {
  2897. width: 35px;
  2898. height: 35px;
  2899. cursor: pointer;
  2900. }
  2901. #pagetual-sideController.minSize #pagetual-sideController-move > img,
  2902. #pagetual-sideController.minSize #pagetual-sideController-move > span {
  2903. border-radius: 50px;
  2904. text-shadow: rgb(255 255 255) 0px 0px 10px;
  2905. }
  2906. #pagetual-sideController #pagetual-sideController-pagenum {
  2907. font-size: 10px!important;
  2908. line-height: 13px;
  2909. text-align: center;
  2910. position: absolute;
  2911. right: -2px;
  2912. top: 60px;
  2913. border: 1px solid #00000099;
  2914. display: inline-block;
  2915. width: 13px;
  2916. height: 13px;
  2917. box-sizing: content-box;
  2918. border-radius: 50%;
  2919. background: white;
  2920. opacity: 0;
  2921. transition: opacity .5s ease;
  2922. pointer-events: none;
  2923. }
  2924. #pagetual-sideController.minSize #pagetual-sideController-pagenum {
  2925. opacity: 0.8;
  2926. }
  2927. `;
  2928. this.styleEle = _GM_addStyle(this.cssText);
  2929. let frame = document.createElement("div");
  2930. frame.id = "pagetual-sideController";
  2931. frame.innerHTML = createHTML(`
  2932. <div id="pagetual-sideController-top" class="pagetual-sideController-btn">⊼</div>
  2933. <div>
  2934. <div id="pagetual-sideController-pre" class="pagetual-sideController-btn">∧</div>
  2935. <div id="pagetual-sideController-move"><svg width="30" height="30" style="border-radius: 15px;display: initial;position: relative;cursor: pointer;margin: 0;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"><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"></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"></path></svg><div id="pagetual-sideController-pagenum"></div></div>
  2936. <div id="pagetual-sideController-next" class="pagetual-sideController-btn">∨</div>
  2937. </div>
  2938. <div id="pagetual-sideController-bottom" class="pagetual-sideController-btn">⊻</div>
  2939. `);
  2940. let top = frame.querySelector("#pagetual-sideController-top");
  2941. let pre = frame.querySelector("#pagetual-sideController-pre");
  2942. let move = frame.querySelector("#pagetual-sideController-move");
  2943. let next = frame.querySelector("#pagetual-sideController-next");
  2944. let bottom = frame.querySelector("#pagetual-sideController-bottom");
  2945. let pagenum = frame.querySelector("#pagetual-sideController-pagenum");
  2946. if (sideControllerIcon) move.innerHTML = sideControllerIcon;
  2947.  
  2948. frame.addEventListener("dblclick", e => {
  2949. e.preventDefault();
  2950. e.stopPropagation();
  2951. }, true);
  2952.  
  2953. frame.addEventListener("mouseenter", e => {
  2954. clearTimeout(self.hideTimer);
  2955. frame.classList.remove("minSize");
  2956. });
  2957.  
  2958. frame.addEventListener("mouseleave", e => {
  2959. clearTimeout(self.hideTimer);
  2960. self.hideTimer = setTimeout(() => {
  2961. frame.classList.add("minSize");
  2962. }, 2000);
  2963. });
  2964.  
  2965. pre.addEventListener("click", e => {
  2966. let prePageBar = getPageBar().preBar;
  2967. if (prePageBar) {
  2968. scrollToPageBar(prePageBar);
  2969. } else {
  2970. let scrollTop = getBody(document).scrollTop || document.documentElement.scrollTop;
  2971. window.scrollTo({ top: scrollTop - (window.innerHeight || document.documentElement.clientHeight), behavior: 'smooth'});
  2972. }
  2973. }, true);
  2974.  
  2975. next.addEventListener("click", e => {
  2976. let pageBarObj = getPageBar();
  2977. let nextPageBar = pageBarObj.nextBar;
  2978. if (nextPageBar) {
  2979. scrollToPageBar(nextPageBar);
  2980. } else {
  2981. if (pageBarObj.preBar) {
  2982. let scrollH = Math.max(document.documentElement.scrollHeight, getBody(document).scrollHeight);
  2983. window.scrollTo({ top: (scrollH || 9999999), behavior: 'smooth'});
  2984. } else {
  2985. let scrollTop = getBody(document).scrollTop || document.documentElement.scrollTop;
  2986. window.scrollTo({ top: scrollTop + (window.innerHeight || document.documentElement.clientHeight), behavior: 'smooth'});
  2987. }
  2988. }
  2989. }, true);
  2990.  
  2991. top.addEventListener("click", e => {
  2992. getBody(document).scrollTop=0;
  2993. document.documentElement.scrollTop=0;
  2994. e.preventDefault();
  2995. e.stopPropagation();
  2996. }, true);
  2997.  
  2998. bottom.addEventListener("click", e => {
  2999. changeStop(true);
  3000. let scrollH = Math.max(document.documentElement.scrollHeight, getBody(document).scrollHeight);
  3001. getBody(document).scrollTop = scrollH || 9999999;
  3002. document.documentElement.scrollTop = scrollH || 9999999;
  3003. e.preventDefault();
  3004. e.stopPropagation();
  3005. }, true);
  3006.  
  3007. let initX, initY, moving = false;
  3008. move.addEventListener("click", e => {
  3009. if (!moving) {
  3010. changeStop(!isPause);
  3011. }
  3012. }, true);
  3013.  
  3014. move.oncontextmenu = e => {
  3015. e.preventDefault();
  3016. Picker.getInstance().start();
  3017. };
  3018.  
  3019. let mouseMoveHandler = e => {
  3020. if (moving) {
  3021. let windowHeight=window.innerHeight || document.documentElement.clientHeight;
  3022. let windowWidth=window.innerWidth || document.documentElement.clientWidth;
  3023. initX = (e.clientX - 10 + 40) / windowWidth * 100;
  3024. initY = (e.clientY - 83 + 83) / windowHeight * 100;
  3025. this.frame.style.top = `calc(${initY}% - 83px)`;
  3026. this.frame.style.left = `calc(${initX}% - 40px)`;
  3027. } else if (Math.abs(e.clientX - initX) + Math.abs(e.clientY - initY) > 20) {
  3028. moving = true;
  3029. }
  3030. };
  3031. let mouseUpHandler = e => {
  3032. document.removeEventListener("mousemove", mouseMoveHandler, true);
  3033. document.removeEventListener("mouseup", mouseUpHandler, true);
  3034. if (moving) {
  3035. rulesData.sideControllerPos = {x: parseInt(initX), y: parseInt(initY)};
  3036. storage.setItem("rulesData", rulesData);
  3037. }
  3038. };
  3039.  
  3040. move.addEventListener("mousedown", e => {
  3041. initX = e.clientX;
  3042. initY = e.clientY;
  3043. moving = false;
  3044. document.addEventListener("mousemove", mouseMoveHandler, true);
  3045. document.addEventListener("mouseup", mouseUpHandler, true);
  3046. }, true);
  3047.  
  3048. this.frame = frame;
  3049. this.pagenum = pagenum;
  3050. if (rulesData.sideControllerPos) {
  3051. this.frame.style.top = `calc(${rulesData.sideControllerPos.y}% - 83px)`;
  3052. this.frame.style.left = `calc(${rulesData.sideControllerPos.x}% - 40px)`;
  3053. }
  3054. }
  3055.  
  3056. addToStage() {
  3057. this.init();
  3058. if (!this.styleEle || !this.styleEle.parentNode) {
  3059. this.styleEle = _GM_addStyle(this.cssText);
  3060. }
  3061. if (!isPause) {
  3062. this.frame.classList.remove("stop");
  3063. }
  3064. this.pagenum.innerText = curPage;
  3065. this.frame.title = i18n("page") + curPage;
  3066. if (this.frame.parentNode) return;
  3067. getBody(document).appendChild(this.frame);
  3068. clearTimeout(this.hideTimer);
  3069. this.hideTimer = setTimeout(() => {
  3070. this.frame.classList.add("minSize");
  3071. }, 2000);
  3072. }
  3073.  
  3074. remove() {
  3075. if (this.frame && this.frame.parentNode) this.frame.parentNode.removeChild(this.frame);
  3076. }
  3077. }
  3078.  
  3079. class NextSwitch {
  3080. static nextSwitch;
  3081. constructor() {
  3082. this.init();
  3083. }
  3084.  
  3085. static getInstance() {
  3086. if (!NextSwitch.nextSwitch) {
  3087. NextSwitch.nextSwitch = new NextSwitch();
  3088. }
  3089. return NextSwitch.nextSwitch;
  3090. }
  3091.  
  3092. init() {
  3093. let self = this;
  3094. this.cssText = `
  3095. #pagetual-nextSwitch {
  3096. position: fixed;
  3097. top: 10px;
  3098. left: calc(50% - 160px);
  3099. background: aliceblue;
  3100. padding: 10px;
  3101. border-radius: 5px;
  3102. text-align: center;
  3103. opacity: 0.95;
  3104. color: #161616;
  3105. z-index: 2147483647;
  3106. font-size: 16px;
  3107. box-shadow: rgb(0 0 0) 0px 0px 10px;
  3108. }
  3109. #pagetual-nextSwitch>.title {
  3110. margin: -5px 45px 10px 45px;
  3111. font-size: 20px;
  3112. font-weight: bold;
  3113. border-bottom: 1px solid black;
  3114. user-select: none;
  3115. color: orangered;
  3116. }
  3117. #pagetual-nextSwitch>.group {
  3118. display: flex;
  3119. flex-direction: column;
  3120. }
  3121. #pagetual-nextSwitch>.group>span {
  3122. color: #161616;
  3123. cursor: pointer;
  3124. margin: 3px;
  3125. font-size: larger;
  3126. }
  3127. #pagetual-nextSwitch>.group>span:hover {
  3128. color: red;
  3129. }
  3130. #pagetual-nextSwitch>.group>span.current {
  3131. border: 2px dotted red;
  3132. border-radius: 10px;
  3133. }
  3134. #pagetual-nextSwitch>.closeSwitch {
  3135. position: absolute;
  3136. top: 3px;
  3137. right: 10px;
  3138. background: none;
  3139. border: none;
  3140. vertical-align: top;
  3141. transition: transform .15s ease-in-out;
  3142. float: right;
  3143. cursor: pointer;
  3144. }
  3145. #pagetual-nextSwitch svg {
  3146. width: 30px;
  3147. height: 30px;
  3148. vertical-align: middle;
  3149. fill: #161616;
  3150. overflow: hidden;
  3151. }
  3152. #pagetual-nextSwitch button:hover {
  3153. transform: scale(1.2);
  3154. }
  3155. `;
  3156. this.styleEle = _GM_addStyle(this.cssText);
  3157. let frame = document.createElement("div");
  3158. frame.id = "pagetual-nextSwitch";
  3159. frame.innerHTML = createHTML(`
  3160. <div class="title">${i18n("nextSwitch")}</div>
  3161. <button type="button" class="closeSwitch">
  3162. <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2754">
  3163. <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">
  3164. </path>
  3165. </svg>
  3166. </button>
  3167. <div class="group"></div>
  3168. `);
  3169. let group = frame.querySelector(".group");
  3170. let closeBtn = frame.querySelector(".closeSwitch");
  3171. closeBtn.addEventListener("click", e => {
  3172. self.close();
  3173. }, true);
  3174. this.frame = frame;
  3175. let currentSpan;
  3176. ruleParser.curSiteRule.nextLink.forEach((link, i) => {
  3177. let span = document.createElement("span");
  3178. let target = getElement(link, document);
  3179. let index = "<b>" + (i + 1) + "</b>: ";
  3180. if (target) {
  3181. let targetInner = target.innerText.trim();
  3182. span.innerHTML = index + (targetInner || link);
  3183. } else {
  3184. span.innerHTML = index + "Not Found";
  3185. }
  3186. span.title = link;
  3187. span.addEventListener("click", e => {
  3188. if (currentSpan) currentSpan.classList.remove("current");
  3189. span.classList.add("current");
  3190. currentSpan = span;
  3191. nextIndex = i;
  3192. storage.setItem("nextSwitch_" + location.host, nextIndex === 0 ? "" : nextIndex);
  3193. ruleParser.curUrl += "#pagetual";
  3194. ruleParser.oldUrl = ruleParser.curUrl;
  3195. autoLoadNum = -1;
  3196. if (!ruleParser.nextLinkHref) {
  3197. isLoading = false;
  3198. }
  3199. ruleParser.getNextLink(ruleParser.pageDoc || document);
  3200. self.close();
  3201. }, true);
  3202. if (i == nextIndex) {
  3203. span.classList.add("current");
  3204. currentSpan = span;
  3205. }
  3206. group.appendChild(span);
  3207. });
  3208. }
  3209.  
  3210. start() {
  3211. if (!this.styleEle || !this.styleEle.parentNode) {
  3212. this.styleEle = _GM_addStyle(this.cssText);
  3213. }
  3214. document.documentElement.appendChild(this.frame);
  3215. }
  3216.  
  3217. close() {
  3218. if (this.frame.parentNode) this.frame.parentNode.removeChild(this.frame);
  3219. }
  3220. }
  3221.  
  3222. class Picker {
  3223. static picker;
  3224. constructor() {
  3225. this.init();
  3226. }
  3227.  
  3228. static getInstance() {
  3229. if (!Picker.picker) {
  3230. Picker.picker = new Picker();
  3231. }
  3232. return Picker.picker;
  3233. }
  3234.  
  3235. init() {
  3236. let self = this;
  3237. this.signList = [];
  3238. this.cssText = `
  3239. body.pagetual-picker,
  3240. body.pagetual-picker *:hover,
  3241. body.pagetual-picker a:hover {
  3242. cursor: crosshair !important;
  3243. }
  3244. #pagetual-picker {
  3245. position: fixed;
  3246. top: 10px;
  3247. left: calc(50% - 178px);
  3248. background: aliceblue;
  3249. padding: 10px;
  3250. border-radius: 5px;
  3251. text-align: center;
  3252. opacity: 0.95;
  3253. color: #161616;
  3254. z-index: 2147483646;
  3255. font-size: 16px;
  3256. box-shadow: rgb(0 0 0) 0px 0px 10px;
  3257. }
  3258. #pagetual-picker * {
  3259. margin: 0;
  3260. padding: 0;
  3261. font-family: Times New Roman;
  3262. overflow: initial;
  3263. }
  3264. #pagetual-picker>.title {
  3265. margin: -5px 45px 10px 45px;
  3266. font-size: 20px;
  3267. font-weight: bold;
  3268. cursor: pointer;
  3269. border-bottom: 1px solid black;
  3270. user-select: none;
  3271. color: orangered;
  3272. height: initial;
  3273. width: initial;
  3274. position: initial;
  3275. }
  3276. #pagetual-picker button {
  3277. background: none;
  3278. border: none;
  3279. vertical-align: top;
  3280. transition: transform .15s ease-in-out;
  3281. float: right;
  3282. cursor: pointer;
  3283. overflow: hidden;
  3284. }
  3285. #pagetual-picker button:hover {
  3286. transform: scale(1.2);
  3287. }
  3288. #pagetual-picker>.closePicker {
  3289. position: absolute;
  3290. top: 3px;
  3291. right: 10px;
  3292. }
  3293. #pagetual-picker>.logoIcon {
  3294. position: absolute;
  3295. top: 3px;
  3296. left: 10px;
  3297. }
  3298. #pagetual-picker>.logoIcon.showSign>svg>path {
  3299. fill: gray;
  3300. }
  3301. #pagetual-picker textarea{
  3302. display: inline-block;
  3303. width: 290px;
  3304. height: 20px;
  3305. max-width: calc(65vw - 50px);
  3306. min-height: unset;
  3307. padding: 6px 12px;
  3308. font-size: 16px;
  3309. font-weight: 400;
  3310. line-height: 1.5;
  3311. color: #495057;
  3312. background-color: #fff;
  3313. background-clip: padding-box;
  3314. border: 1px solid #ced4da;
  3315. border-radius: 4px;
  3316. transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out;
  3317. box-sizing: content-box;
  3318. margin-right: 5px;
  3319. resize: both;
  3320. box-shadow: 0 1px 5px 1px #ddd;
  3321. }
  3322. #pagetual-picker textarea:focus {
  3323. color: black;
  3324. background-color: #fff;
  3325. border-color: #80bdff;
  3326. outline: 0;
  3327. box-shadow: 0 0 0 3.2px rgb(0 123 255 / 25%);
  3328. }
  3329. #pagetual-picker [type=checkbox],
  3330. #pagetual-picker [type=radio] {
  3331. line-height: 20px;
  3332. height: 25px;
  3333. width: 25px;
  3334. margin-left: 5px;
  3335. vertical-align: middle;
  3336. appearance: auto;
  3337. display: inline-block;
  3338. position: initial;
  3339. }
  3340. #pagetual-picker label {
  3341. font-size: 18px;
  3342. line-height: 25px;
  3343. vertical-align: middle;
  3344. display: inline-block;
  3345. color: black;
  3346. position: initial;
  3347. }
  3348. #pagetual-picker .bottom {
  3349. text-align: left;
  3350. margin: 10px 0;
  3351. width: 100%;
  3352. }
  3353. #pagetual-picker .bottom>button {
  3354. float: right;
  3355. }
  3356. #pagetual-picker svg {
  3357. width: 30px;
  3358. height: 30px;
  3359. vertical-align: middle;
  3360. fill: #161616;
  3361. overflow: hidden;
  3362. }
  3363. #pagetual-picker svg * {
  3364. pointer-events: none;
  3365. }
  3366. #pagetual-picker .allpath {
  3367. font-size: 18px;
  3368. margin: 10px auto;
  3369. max-width: 330px;
  3370. word-break: break-all;
  3371. cursor: context-menu;
  3372. overflow: hidden;
  3373. max-height: 42px;
  3374. -moz-transition:max-height 1s ease-in;
  3375. -webkit-transition:max-height 1s ease-in;
  3376. transition:max-height 1s ease-in;
  3377. color: black;
  3378. }
  3379. #pagetual-picker .allpath:hover {
  3380. max-height: calc(100vh - 130px);
  3381. overflow: auto;
  3382. }
  3383. #pagetual-picker .allpath>span.path {
  3384. cursor: pointer;
  3385. }
  3386. #pagetual-picker .allpath>span.path:hover {
  3387. color: orangered;
  3388. }
  3389. #pagetual-picker .moreConfig {
  3390. display: flex;
  3391. justify-content: space-between;
  3392. border-top: 1px solid;
  3393. padding-top: 10px;
  3394. width: 100%;
  3395. }
  3396. #pagetual-picker .command {
  3397. width: 100%;
  3398. color: black!important;
  3399. text-align: center;
  3400. font-size: large;
  3401. margin-top: 10px;
  3402. }
  3403. #pagetual-picker .command:hover {
  3404. color: orangered;
  3405. }
  3406. #pagetual-picker #showDetail {
  3407. float: initial;
  3408. margin-top: 10px;
  3409. }
  3410. #pagetual-picker #showDetail.showDetail {
  3411. float: right;
  3412. }
  3413. #pagetual-picker #showDetail>svg {
  3414. -moz-transition:transform 0.3s ease;
  3415. -webkit-transition:transform 0.3s ease;
  3416. transition:transform 0.3 ease;
  3417. }
  3418. #pagetual-picker #showDetail.showDetail>svg {
  3419. transform: rotate(180deg);
  3420. }
  3421. #pagetual-picker .tempRule {
  3422. margin-top: 10px;
  3423. height: 300px;
  3424. }
  3425. #pagetual-picker #saveDetail {
  3426. display: none;
  3427. position: absolute;
  3428. bottom: 10px;
  3429. right: 8px;
  3430. }
  3431. #pagetual-picker .showDetail~#saveDetail {
  3432. display: inline-block;
  3433. }
  3434. #pagetual-picker #saveDetail svg {
  3435. width: 35px;
  3436. height: 35px;
  3437. }
  3438. `;
  3439. this.styleEle = _GM_addStyle(this.cssText);
  3440. this.mainSignDiv = this.createSignDiv();
  3441. this.allSignDiv = [];
  3442. let frame = document.createElement("div");
  3443. frame.id = "pagetual-picker";
  3444. frame.innerHTML = createHTML(`
  3445. <button title="Pagetual" type="button" class="logoIcon">
  3446. <svg width="30" height="30" class="upSvg pagetual" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><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"></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"></path></svg>
  3447. </button>
  3448. <div class="title">${i18n("picker")}</div>
  3449. <button title="${i18n("closePicker")}" type="button" class="closePicker">
  3450. <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><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" fill="#604b4a"></path></svg>
  3451. </button>
  3452. <div class="allpath" title="${i18n("switchSelector")}"></div>
  3453. <div>
  3454. <textarea class="selector" spellcheck="false" name="selector" placeholder="${i18n("pickerPlaceholder")}"></textarea>
  3455. <button id="check" title="${i18n("pickerCheck")}" type="button">
  3456. <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><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" fill="#604b4a"></path></svg>
  3457. </button>
  3458. </div>
  3459. <div class="bottom">
  3460. <input name="xpath" id="checkbox_id" type="checkbox" />
  3461. <label for="checkbox_id">XPath</label>
  3462. <button id="edit" title="${i18n("gotoEdit")}" type="button">
  3463. <svg viewBox="0 0 1024 1024" style="color: orangered;fill: orangered;" version="1.1" xmlns="http://www.w3.org/2000/svg">
  3464. <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">
  3465. </path>
  3466. </svg>
  3467. </button>
  3468. </div>
  3469. <div class="moreConfig">
  3470. <div title="${i18n('forceStateIframe')}">
  3471. <input name="forceState" id="forceStateIframe" type="radio" />
  3472. <label for="forceStateIframe">${i18n('iframe')}</label>
  3473. </div>
  3474. <div title="${i18n('forceStateDynamic')}">
  3475. <input name="forceState" id="forceStateDynamic" type="radio" />
  3476. <label for="forceStateDynamic">${i18n('dynamic')}</label>
  3477. </div>
  3478. <div title="${i18n('forceStateDisable')}">
  3479. <input name="forceState" id="forceStateDisable" type="radio" />
  3480. <label for="forceStateDisable">${i18n('disable')}</label>
  3481. </div>
  3482. </div>
  3483. <button id="nextSwitch" class="command" title="${i18n("nextSwitch")}" type="button">${i18n("nextSwitch")}</button>
  3484. <button id="loadNow" class="command" title="${i18n("loadNow")}" type="button">${i18n("loadNow")}</button>
  3485. <div>
  3486. <textarea style="display: none;" class="tempRule" spellcheck="false" placeholder="{Rule object}" title="Rule for current site"></textarea>
  3487. <button id="showDetail" title="" type="button">
  3488. <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M511.1 63.7c-247.4 0-448 200.6-448 448s200.6 448 448 448 448-200.6 448-448-200.6-448-448-448z m281.2 374.5L535.6 694.9c-12.5 12.5-32.8 12.5-45.3 0l-255.8-256c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0l210.7 210.7c12.5 12.5 32.8 12.5 45.3 0l211.4-211.4c12.5-12.5 32.8-12.5 45.3 0 12.3 12.5 12.3 32.8-0.2 45.3z" fill="orangered"></path></svg>
  3489. </button>
  3490. <button id="saveDetail" title="" type="button">
  3491. <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M704 128H192c-35.2 0-64 28.8-64 64v640c0 35.2 28.8 64 64 64h640c35.2 0 64-28.8 64-64V320L704 128zM256 256h320v128H256V256z m256 512c-70.4 0-128-57.6-128-128s57.6-128 128-128 128 57.6 128 128-57.6 128-128 128z" fill="orangered"></path></svg>
  3492. </button>
  3493. </div>
  3494. `);
  3495. let forceStateIframe = frame.querySelector("#forceStateIframe");//forceState 1 禁用 2 强嵌 3 动态
  3496. let forceStateDynamic = frame.querySelector("#forceStateDynamic");
  3497. let forceStateDisable = frame.querySelector("#forceStateDisable");
  3498. let clickRadio = e => {
  3499. let radio = e.currentTarget.querySelector('input');
  3500. if (radio.checked) {
  3501. forceState = "";
  3502. } else {
  3503. switch (radio.id) {
  3504. case "forceStateIframe":
  3505. forceState = 2;
  3506. break;
  3507. case "forceStateDynamic":
  3508. forceState = 3;
  3509. break;
  3510. case "forceStateDisable":
  3511. forceState = 1;
  3512. break;
  3513. default:
  3514. return;
  3515. }
  3516. }
  3517. storage.setItem("forceState_"+location.host, forceState);
  3518. self.close();
  3519. location.reload();
  3520. };
  3521. forceStateIframe.parentNode.addEventListener("mousedown", clickRadio);
  3522. forceStateDynamic.parentNode.addEventListener("mousedown", clickRadio);
  3523. forceStateDisable.parentNode.addEventListener("mousedown", clickRadio);
  3524. if (forceState == 1) forceStateDisable.checked = true;
  3525. else if (forceState == 2) forceStateIframe.checked = true;
  3526. else if (forceState == 3) forceStateDynamic.checked = true;
  3527. let closeBtn = frame.querySelector(".closePicker");
  3528. let logoBtn = frame.querySelector(".logoIcon");
  3529. let title = frame.querySelector(".title");
  3530. let allpath = frame.querySelector(".allpath");
  3531. let selectorInput = frame.querySelector(".selector");
  3532. let xpath = frame.querySelector("#checkbox_id");
  3533. let checkBtn = frame.querySelector("#check");
  3534. let editBtn = frame.querySelector("#edit");
  3535. let nextSwitch = frame.querySelector("#nextSwitch");
  3536. let loadNow = frame.querySelector("#loadNow");
  3537. let tempRule = frame.querySelector(".tempRule");
  3538. let showDetailBtn = frame.querySelector("#showDetail");
  3539. let saveDetailBtn = frame.querySelector("#saveDetail");
  3540. showDetailBtn.addEventListener("click", e => {
  3541. if (tempRule.style.display == "none") {
  3542. tempRule.style.display = "";
  3543. showDetailBtn.classList.add("showDetail");
  3544. } else {
  3545. tempRule.style.display = "none";
  3546. showDetailBtn.classList.remove("showDetail");
  3547. }
  3548. }, true);
  3549. saveDetailBtn.addEventListener("click", e => {
  3550. let editTemp = self.getTempRule();
  3551. if(!ruleParser.customRules) {
  3552. ruleParser.customRules = [];
  3553. }
  3554. for (let i in ruleParser.customRules) {
  3555. if (ruleParser.customRules[i].url == editTemp.url) {
  3556. ruleParser.customRules.splice(i, 1);
  3557. break;
  3558. }
  3559. }
  3560. if (tempRule.value) {
  3561. ruleParser.customRules.unshift(editTemp);
  3562. }
  3563. storage.setItem("customRules", ruleParser.customRules);
  3564. if (ruleParser.hpRules && ruleParser.curSiteRule && !ruleParser.curSiteRule.singleUrl) {
  3565. ruleParser.hpRules = ruleParser.hpRules.filter(item => {return item && item.url != ruleParser.curSiteRule.url});
  3566. storage.setItem("hpRules", ruleParser.hpRules);
  3567. }
  3568. if (window.confirm(i18n("reloadPage"))) {
  3569. setTimeout(() => {location.reload()}, 100);
  3570. }
  3571. }, true);
  3572. nextSwitch.addEventListener("click", e => {
  3573. self.close();
  3574. NextSwitch.getInstance().start();
  3575. }, true);
  3576. loadNow.addEventListener("click", e => {
  3577. self.close();
  3578. let loadNum=window.prompt(i18n("loadConfirm"), "1");
  3579. if(loadNum==="" || loadNum===null)return;
  3580. autoLoadNum=Math.abs(parseInt(loadNum));
  3581. nextPage();
  3582. }, true);
  3583. closeBtn.addEventListener("click", e => {
  3584. self.close();
  3585. }, true);
  3586. this.showSign = true;
  3587. logoBtn.addEventListener("click", e => {
  3588. logoBtn.classList.toggle("showSign");
  3589. self.showSign = !self.showSign;
  3590. getBody(document).classList.toggle("pagetual-picker");
  3591. }, true);
  3592. let moving = false;
  3593. let initX = 0, initY = 0, initPos = {x: 0, y: 0};
  3594. let moveHanlder = e => {
  3595. if (moving) {
  3596. frame.style.left = e.clientX - initX + "px";
  3597. frame.style.top = e.clientY - initY + "px";
  3598. e.stopPropagation();
  3599. e.preventDefault();
  3600. } else if(Math.abs(e.clientX - initPos.x) + Math.abs(e.clientY - initPos.y) > 20) {
  3601. moving = true;
  3602. }
  3603. };
  3604. let upHanlder = e => {
  3605. if (moving) {
  3606. moving = false;
  3607. } else {
  3608. _GM_openInTab(configPage[0], {active: true});
  3609. }
  3610. document.removeEventListener("mousemove", moveHanlder, true);
  3611. title.removeEventListener("mouseup", upHanlder, true);
  3612. e.stopPropagation();
  3613. e.preventDefault();
  3614. };
  3615. title.addEventListener("mousedown", e => {
  3616. initPos = {x: e.clientX, y: e.clientY};
  3617. initX = e.clientX - parseInt(getComputedStyle(frame).left);
  3618. initY = e.clientY - parseInt(getComputedStyle(frame).top);
  3619. document.addEventListener("mousemove", moveHanlder, true);
  3620. title.addEventListener("mouseup", upHanlder, true);
  3621. });
  3622. frame.addEventListener("mouseenter", e => {
  3623. if (!self.showSign || moving) return;
  3624. if (self.mainSignDiv.parentNode) self.mainSignDiv.parentNode.removeChild(self.mainSignDiv);
  3625. self.checkInputSelector();
  3626. });
  3627. frame.addEventListener("mouseleave", e => {
  3628. if (!self.showSign) {
  3629. if (self.mainSignDiv.parentNode) self.mainSignDiv.parentNode.removeChild(self.mainSignDiv);
  3630. self.clearSigns();
  3631. return;
  3632. }
  3633. if (moving) return;
  3634. getBody(document).appendChild(self.mainSignDiv);
  3635. self.clearSigns();
  3636. });
  3637. checkBtn.addEventListener("click", e => {
  3638. self.checkInputSelector();
  3639. if (this.selectorInput.value) _GM_setClipboard(this.selectorInput.value);
  3640. showTips(i18n("copied"));
  3641. });
  3642. xpath.addEventListener("click", e => {
  3643. if (!selectorInput.value) {
  3644. self.setSelectorDiv("");
  3645. return;
  3646. }
  3647. let element = getElement(selectorInput.value, document);
  3648. let selector = self.getSelectorFromEle(element);
  3649. self.setSelectorDiv(selector);
  3650. selectorInput.value = selector;
  3651. });
  3652. editBtn.addEventListener("click", e => {
  3653. rulesData.editTemp = self.getTempRule();
  3654. storage.setItem("rulesData", rulesData);
  3655. _GM_openInTab(configPage[0], {active: true});
  3656. });
  3657. editBtn.oncontextmenu = e => {
  3658. e.preventDefault();
  3659. _GM_openInTab(configPage[0], {active: true});
  3660. };
  3661. this.frame = frame;
  3662. this.xpath = xpath;
  3663. this.allpath = allpath;
  3664. this.selectorInput = selectorInput;
  3665. this.nextSwitch = nextSwitch;
  3666. this.loadNow = loadNow;
  3667. this.tempRule = tempRule;
  3668. this.logoBtn = logoBtn;
  3669. this.moveHandler = e => {
  3670. if (!self.showSign || e.target === document) return;
  3671. self.adjustSignDiv(self.mainSignDiv, self.getTarget(e.target));
  3672. };
  3673. this.clickHandler = e => {
  3674. if (!self.showSign) return;
  3675. if (self.inPicker) {
  3676. e.stopPropagation();
  3677. e.preventDefault();
  3678. }
  3679. let target = self.getTarget(e.target);
  3680. let selector = self.getSelectorFromEle(target);
  3681. selectorInput.value = selector;
  3682. self.setSelectorDiv(selector);
  3683. };
  3684. }
  3685.  
  3686. getTempRule() {
  3687. if (this.tempRule.value) {
  3688. try {
  3689. this.editTemp = JSON.parse(this.tempRule.value);
  3690. } catch (e) {
  3691. this.editTemp = null;
  3692. }
  3693. }
  3694. if (!this.editTemp) {
  3695. if (ruleParser.curSiteRule.url && !ruleParser.curSiteRule.singleUrl) {
  3696. this.editTemp = ruleParser.curSiteRule;
  3697. } else {
  3698. this.editTemp = {
  3699. name: document.title,
  3700. url: "^" + (location.origin + location.pathname).replace(/[^\/]*$/, "").replace(/^https?/, "https?").replace(/\./g, "\\.")
  3701. };
  3702. }
  3703. delete this.editTemp.from;
  3704. delete this.editTemp.type;
  3705. delete this.editTemp.updatedAt;
  3706. }
  3707. let selectorInput = this.frame.querySelector(".selector");
  3708. if (selectorInput.value && this.tempRule.style.display == "none") {
  3709. this.editTemp.pageElement = selectorInput.value;
  3710. }
  3711. return this.editTemp;
  3712. }
  3713.  
  3714. getTarget(ele) {
  3715. while (ele.parentNode && (ele.offsetWidth === 0 || ele.offsetHeight === 0)) {
  3716. ele = ele.parentNode;
  3717. }
  3718. return ele;
  3719. }
  3720.  
  3721. close() {
  3722. this.clearSigns();
  3723. if (this.frame.parentNode) this.frame.parentNode.removeChild(this.frame);
  3724. if (this.mainSignDiv.parentNode) this.mainSignDiv.parentNode.removeChild(this.mainSignDiv);
  3725. getBody(document).classList.remove("pagetual-picker");
  3726. getBody(document).removeEventListener("mousemove", this.moveHandler, true);
  3727. getBody(document).removeEventListener("click", this.clickHandler, true);
  3728. this.inPicker = false;
  3729. }
  3730.  
  3731. setImportant(ele, prop, value) {
  3732. ele.style.setProperty(prop, value, "important");
  3733. }
  3734.  
  3735. createSignDiv() {
  3736. let signDiv = document.createElement("div");
  3737. this.setImportant(signDiv, "position", "absolute");
  3738. this.setImportant(signDiv, "pointer-events", "none");
  3739. this.setImportant(signDiv, "z-index", "2147483646");
  3740. this.setImportant(signDiv, "background", "rgba(120, 170, 210, 0.6)");
  3741. this.setImportant(signDiv, "transition", "all 0.15s ease-out");
  3742. this.setImportant(signDiv, "box-shadow", "rgb(0 0 0) 0px 0px 3px 0px");
  3743. return signDiv;
  3744. }
  3745.  
  3746. adjustSignDiv(div, target) {
  3747. let rect = target.getBoundingClientRect();
  3748. this.setImportant(div, "width", rect.width + "px");
  3749. this.setImportant(div, "height", rect.height + "px");
  3750. this.setImportant(div, "left", rect.left + window.scrollX + "px");
  3751. this.setImportant(div, "top", rect.top + window.scrollY + "px");
  3752. }
  3753.  
  3754. getSelectorFromEle(ele) {
  3755. return this.xpath.checked ? createXPathFromElement(ele) : geneSelector(ele, true);
  3756. }
  3757.  
  3758. fillTempRuleTextarea() {
  3759. if (this.tempRule.style.display == "none") this.tempRule.value = JSON.stringify(this.getTempRule(), null, 4);
  3760. }
  3761.  
  3762. setSelectorDiv(selector) {
  3763. this.fillTempRuleTextarea();
  3764. let self = this;
  3765. this.allpath.innerHTML = createHTML("");
  3766. if (!selector) return;
  3767. if (this.xpath.checked) {
  3768. let span = document.createElement("span");
  3769. span.innerText = selector;
  3770. span.addEventListener("click", e => {
  3771. self.selectorInput.value = selector;
  3772. self.checkInputSelector();
  3773. }, true);
  3774. this.allpath.appendChild(span);
  3775. } else {
  3776. selector.split(">").forEach((item, index) => self.geneSelectorItem(item, index));
  3777. }
  3778. }
  3779.  
  3780. geneSelectorItem(item, index) {
  3781. let self = this;
  3782. item = item.trim();
  3783. if (!item) return;
  3784. if (index !== 0) {
  3785. let span = document.createElement("span");
  3786. span.innerText = " > ";
  3787. this.allpath.appendChild(span);
  3788. }
  3789. let span = document.createElement("span");
  3790. span.className = "path";
  3791. span.innerText = item;
  3792. span.addEventListener("click", e => {
  3793. let selector = "";
  3794. let target = e.target;
  3795. while (target) {
  3796. selector = target.innerText + selector;
  3797. target = target.previousElementSibling;
  3798. }
  3799. self.selectorInput.value = selector;
  3800. self.checkInputSelector();
  3801. }, true);
  3802. this.allpath.appendChild(span);
  3803. }
  3804.  
  3805. checkInputSelector() {
  3806. let self = this;
  3807. this.clearSigns();
  3808. if (!this.selectorInput.value) return;
  3809. let eles = getAllElements(this.selectorInput.value, document);
  3810. if (eles && eles.length > 0) {
  3811. eles.forEach(ele => {
  3812. let sign = self.createSignDiv();
  3813. getBody(document).appendChild(sign);
  3814. self.adjustSignDiv(sign, ele);
  3815. self.signList.push(sign);
  3816. });
  3817. this.fillTempRuleTextarea();
  3818. }
  3819. }
  3820.  
  3821. clearSigns() {
  3822. this.signList.forEach(sign => {
  3823. if (sign.parentNode) sign.parentNode.removeChild(sign);
  3824. });
  3825. this.signList = [];
  3826. }
  3827.  
  3828. start() {
  3829. if (this.inPicker) return;
  3830. this.inPicker = true;
  3831. if (!this.styleEle || !this.styleEle.parentNode) {
  3832. this.styleEle = _GM_addStyle(this.cssText);
  3833. }
  3834. document.documentElement.appendChild(this.frame);
  3835. getBody(document).appendChild(this.mainSignDiv);
  3836. getBody(document).classList.add("pagetual-picker");
  3837.  
  3838. this.logoBtn.classList.remove("showSign");
  3839. this.showSign = true;
  3840.  
  3841. getBody(document).addEventListener("mousemove", this.moveHandler, true);
  3842. getBody(document).addEventListener("click", this.clickHandler, true);
  3843. this.xpath.checked = isXPath(ruleParser.curSiteRule.pageElement);
  3844.  
  3845. this.loadNow.style.display = ruleParser.nextLinkHref ? "block" : "none";
  3846. if (ruleParser.curSiteRule.nextLink && Array && Array.isArray && Array.isArray(ruleParser.curSiteRule.nextLink)) {
  3847. this.nextSwitch.style.display = "block";
  3848. } else {
  3849. this.nextSwitch.style.display = "none";
  3850. }
  3851.  
  3852. let pageElementSel = ruleParser.curSiteRule.pageElement || "";
  3853. if (Array && Array.isArray && Array.isArray(pageElementSel)) {
  3854. pageElementSel = pageElementSel[nextIndex < pageElementSel.length ? nextIndex : 0];
  3855. }
  3856. this.setSelectorDiv(pageElementSel);
  3857. }
  3858. }
  3859.  
  3860. function createEdit() {
  3861. var options = {
  3862. mode: 'code',
  3863. modes: ['code', 'tree'],
  3864. templates: [
  3865. {
  3866. text: 'New site',
  3867. title: 'Insert a new site',
  3868. className: 'jsoneditor-type-object',
  3869. field: 'SiteTemplate',
  3870. value: {
  3871. 'name': 'Site name',
  3872. 'url': 'Site url'
  3873. }
  3874. }
  3875. ],
  3876. schema: {
  3877. "title": "Sites data",
  3878. "description": "Object containing site config",
  3879. "type": "array",
  3880. "items": {
  3881. "type": 'object',
  3882. "properties": {
  3883. "name": {
  3884. "title": "Site Name",
  3885. "description": "The site's name.",
  3886. "examples": [
  3887. "Google"
  3888. ],
  3889. "type": "string"
  3890. },
  3891. "url": {
  3892. "title": "Site Url",
  3893. "description": "The Regexp of site's url.",
  3894. "examples": [
  3895. "^https:\/\/yande\\.re\/"
  3896. ],
  3897. "type": "string"
  3898. }
  3899. },
  3900. "required": ["name", "url"]
  3901. }
  3902. }
  3903. };
  3904. var container = document.getElementById("jsoneditor");
  3905. container.style.height = '800px';
  3906. container.innerHTML = "";
  3907. var editor = new JSONEditor(container, options);
  3908. editor.set(ruleParser.customRules);
  3909. document.querySelector("#saveBtn").onclick = e => {
  3910. try {
  3911. storage.setItem("hpRules", []);
  3912. storage.setItem("smartRules", []);
  3913. let customRules = editor.get();
  3914. if (!customRules) {
  3915. storage.setItem("customRules", "");
  3916. } else {
  3917. if (Array && Array.isArray && !Array.isArray(customRules)) {
  3918. showTips(i18n("errorRulesMustBeArray"));
  3919. return;
  3920. }
  3921. debug(customRules);
  3922. storage.setItem("customRules", customRules);
  3923. }
  3924. } catch(e) {
  3925. debug(e);
  3926. showTips(i18n("errorJson"));
  3927. return;
  3928. }
  3929. showTips(i18n("editSuccess"));
  3930. };
  3931. }
  3932.  
  3933. function initConfig() {
  3934. listenUrl();
  3935. let href = location.href.slice(0, 250);
  3936. try {
  3937. if (_unsafeWindow.initedPagetual) {
  3938. if (ruleImportUrlReg.test(href)) {
  3939. showTips(i18n('duplicate'));
  3940. }
  3941. return true;
  3942. }
  3943. _unsafeWindow.initedPagetual = true;
  3944. } catch(e) {showTips(e)}
  3945. _GM_registerMenuCommand(i18n(forceState == 1 ? "enable" : "disableSite"), () => {
  3946. forceState = (forceState == 1 ? 0 : 1);
  3947. storage.setItem("forceState_" + location.host, forceState);
  3948. showTips(i18n(forceState == 1 ? "disableSiteTips" : "enableSiteTips"));
  3949. if (!ruleParser.curSiteRule.url) location.reload();
  3950. });
  3951. _GM_registerMenuCommand(i18n("update"), () => {
  3952. showTips(i18n("beginUpdate"));
  3953. updateRules(() => {
  3954. showTips(i18n("updateSucc"));
  3955. location.reload();
  3956. },(rule, err) => {
  3957. showTips(`Update ${rule.url} rules fail!`);
  3958. debug(err);
  3959. });
  3960. });
  3961. if (guidePage.test(href)) {
  3962. if (typeof JSONEditor !== 'undefined') {
  3963. createEdit();
  3964. } else {
  3965. window.onload = e => {
  3966. createEdit();
  3967. }
  3968. }
  3969. return true;
  3970. }
  3971. if (href.indexOf("PagetualGuide") != -1) return true;
  3972. if (location.hostname === "pagetual.hoothin.com") return true;
  3973.  
  3974. var configCon, insertPos;
  3975. var noRules = !rulesData.urls || rulesData.urls.length === 0;
  3976.  
  3977. let inConfig = false;
  3978. for (let i = 0; i < configPage.length; i++) {
  3979. if (configPage[i] == location.href) {
  3980. inConfig = true;
  3981. break;
  3982. }
  3983. }
  3984. if (ruleImportUrlReg.test(href) || inConfig) {
  3985. let importing = false;
  3986. if (noRules) {
  3987. setTimeout(() => {
  3988. if (!importing) showTips(i18n("firstAlert"));
  3989. }, 3000);
  3990. setTimeout(() => {
  3991. if (!importing) showTips(i18n("firstAlert"));
  3992. }, 6000);
  3993. showTips(i18n("firstAlert"));
  3994. }
  3995. let defaultOption = document.querySelector('#discussion_rating_4');
  3996. if (defaultOption) defaultOption.checked = true;
  3997. let createImportBtn = (pre) => {
  3998. let importBtn = document.createElement("button");
  3999. importBtn.id = "pagetualImport";
  4000. importBtn.innerText = i18n("import");
  4001. importBtn.style.marginTop = "100px";
  4002. importBtn.style.float = "right";
  4003. importBtn.style.position = "relative";
  4004. importBtn.style.display = "block";
  4005. importBtn.style.fontSize = "20px";
  4006. importBtn.addEventListener("click", e => {
  4007. let parentNode = importBtn.parentNode;
  4008. if (!parentNode) return;
  4009. parentNode.removeChild(importBtn);
  4010. try {
  4011. let rules = parentNode.innerText.trim();
  4012. let isContent = /['"]name['"]/i.test(rules);
  4013. if (isContent) {
  4014. let ruleList = JSON.parse(`[${rules}]`);
  4015. for (let i in ruleList) {
  4016. let hasRule = false;
  4017. let r = ruleList[i];
  4018. for (let j in ruleParser.customRules) {
  4019. if (ruleParser.customRules[j].name == r.name) {
  4020. ruleParser.customRules[j] = r;
  4021. hasRule = true;
  4022. break;
  4023. }
  4024. }
  4025. if (!hasRule) ruleParser.customRules.push(r);
  4026. ruleParser.hpRules.unshift(r);
  4027. }
  4028. storage.setItem("customRules", ruleParser.customRules);
  4029. storage.setItem("hpRules", ruleParser.hpRules);
  4030. storage.setItem("smartRules", []);
  4031. showTips(i18n("importSucc"));
  4032. } else {
  4033. rules = rules.split("\n");
  4034. let diff = false;
  4035. for (let c = 0; c < rules.length; c++) {
  4036. let urlArr = rules[c].split("|"), url, type = 1;
  4037. if (urlArr.length == 1) {
  4038. url = urlArr[0].trim();
  4039. if (!/^http/.test(url)) {
  4040. showTips(i18n("errorWrongUrl"));
  4041. return;
  4042. }
  4043. } else if (urlArr.length == 2) {
  4044. type = urlArr[0].trim();
  4045. url = urlArr[1].trim();
  4046. if (!/^http/.test(url)) {
  4047. showTips(i18n("errorWrongUrl"));
  4048. return;
  4049. }
  4050. } else {
  4051. break;
  4052. }
  4053. let maxId = 1, hasUrl = false;
  4054. if (!rulesData.urls) {
  4055. rulesData.urls = [];
  4056. maxId = 1;
  4057. } else {
  4058. rulesData.urls.forEach(u => {
  4059. if (maxId < u.id) {
  4060. maxId = u.id;
  4061. }
  4062. if (u.url == url) {
  4063. hasUrl = true;
  4064. }
  4065. });
  4066. if (hasUrl) break;
  4067. }
  4068. diff = true;
  4069. if (!rulesData.sort) rulesData.sort = [1];
  4070. rulesData.urls.push({id: maxId + 1, url: url, type: type});
  4071. rulesData.sort.unshift(maxId + 1);
  4072. }
  4073. if (!diff) {
  4074. showTips(i18n("errorAlreadyExists"));
  4075. return;
  4076. }
  4077. storage.setItem("rulesData", rulesData);
  4078.  
  4079. if (rulesData.urls) ruleUrls = ruleUrls.concat(rulesData.urls);
  4080. if (rulesData.sort) {
  4081. let urls = [];
  4082. rulesData.sort.forEach(id => {
  4083. for (let s = 0; s < ruleUrls.length; s++) {
  4084. if (id == ruleUrls[s].id) {
  4085. urls.push(ruleUrls[s]);
  4086. break;
  4087. }
  4088. }
  4089. });
  4090. ruleUrls = urls;
  4091. }
  4092. showTips(i18n("beginUpdate"));
  4093. updateRules(() => {
  4094. showTips(i18n("updateSucc"));
  4095. location.reload();
  4096. }, (rule, err) => {
  4097. showTips(`Update ${rule.url} rules fail!`);
  4098. debug(err);
  4099. });
  4100. importing = true;
  4101. }
  4102. } catch (e) {
  4103. _GM_notification(e.toString());
  4104. }
  4105. });
  4106. if (pre) {
  4107. let clientHeight = 35 - pre.clientHeight;
  4108. if (clientHeight > -20) clientHeight = -20;
  4109. importBtn.style.marginTop = `${clientHeight}px`;
  4110. pre.appendChild(importBtn);
  4111. }
  4112. return importBtn;
  4113. };
  4114. [].forEach.call(document.querySelectorAll('pre[name=pagetual],pre[name=user-content-pagetual]'), pre => {
  4115. let importBtn = createImportBtn(pre);
  4116. });
  4117. document.addEventListener("mouseover", e => {
  4118. if (/^PRE$/i.test(e.target.nodeName)) {
  4119. let nameAttr = e.target.getAttribute("name");
  4120. if (nameAttr == "pagetual" || nameAttr == "user-content-pagetual") {
  4121. if (e.target.querySelector('#pagetualImport')) return;
  4122. let importBtn = createImportBtn(e.target);
  4123. }
  4124. }
  4125. });
  4126.  
  4127. if (inConfig) {
  4128. if (_GM_info.script && _GM_info.script.version && _GM_info.script.version !== '1.0.0') {
  4129. let versionEle = document.querySelector('.markdown-body>h1[id],article>h1');
  4130. let latestVer = versionEle.innerText.match(/\d[\d\.]+/)[0];
  4131. if (latestVer != _GM_info.script.version) {
  4132. showTips(i18n('outOfDate'));
  4133. }
  4134. }
  4135. _GM_addStyle(`
  4136. p>span:nth-child(1),p>span:nth-child(2),p>span:nth-child(3){
  4137. cursor: pointer;
  4138. user-select: none;
  4139. }
  4140. p>span:nth-child(1):hover,p>span:nth-child(2):hover,p>span:nth-child(3):hover{
  4141. color:red;
  4142. }
  4143. .updateDate{
  4144. cursor: pointer;
  4145. user-select: none;
  4146. }
  4147. .updateDate:hover{
  4148. color:red;
  4149. }
  4150. input[type=number]::-webkit-inner-spin-button,
  4151. input[type=number]::-webkit-outer-spin-button {
  4152. -webkit-appearance: none;
  4153. margin: 0;
  4154. }
  4155. input[type=number] {
  4156. -moz-appearance:textfield;
  4157. }
  4158. #readme>.is-stuck {
  4159. position: static!important;
  4160. }
  4161. .markdown-body table td>h3 {
  4162. margin: 16px!important;
  4163. }
  4164. `);
  4165. document.querySelector("[name='user-content-click2import'],[name='click2import']").innerText = i18n("click2ImportRule")
  4166. configCon = document.querySelector(".markdown-body");
  4167. insertPos = configCon.querySelector("hr");
  4168.  
  4169. if (!noRules) {
  4170. document.querySelector("pre[name='user-content-pagetual'],pre[name='pagetual']").style.display = "none";
  4171. document.querySelector("p[name='user-content-click2import'],p[name='click2import']").style.display = "none";
  4172. }
  4173. let otherconfig = document.querySelector("a[name='user-content-otherconfig'],a[name='otherconfig']");
  4174. if (otherconfig) otherconfig.parentNode.removeChild(otherconfig);
  4175. } else return true;
  4176. } else return false;
  4177. class Rulebar {
  4178. init(ruleUrl) {
  4179. this.ruleUrl = ruleUrl;
  4180. this.item = document.createElement("p");
  4181. this.item.dataset.id = this.ruleUrl.id;
  4182. let url = document.createElement("span");
  4183. url.innerHTML = ruleUrl.url;
  4184. let up = document.createElement("span");
  4185. up.innerHTML = "↑ ";
  4186. up.title = i18n("sortTitle");
  4187. let down = document.createElement("span");
  4188. down.innerHTML = "↓ ";
  4189. down.title = i18n("sortTitle");
  4190. let del = document.createElement("span");
  4191. del.innerHTML = "× ";
  4192. up.onclick = e => {
  4193. this.moveUp();
  4194. };
  4195. down.onclick = e => {
  4196. this.moveDown();
  4197. };
  4198. del.onclick = e => {
  4199. this.del();
  4200. };
  4201. this.item.appendChild(up);
  4202. this.item.appendChild(down);
  4203. this.item.appendChild(del);
  4204. this.item.appendChild(url);
  4205. configCon.insertBefore(this.item, insertPos);
  4206. }
  4207. saveSort() {
  4208. let sort = [];
  4209. [].forEach.call(this.item.parentNode.querySelectorAll("p[data-id]"), i => {
  4210. sort.push(i.dataset.id);
  4211. });
  4212. rulesData.sort = sort;
  4213. let urls = [];
  4214. sort.forEach(id => {
  4215. for (let s = 0; s < ruleUrls.length; s++) {
  4216. if (id == ruleUrls[s].id) {
  4217. urls.push(ruleUrls[s]);
  4218. break;
  4219. }
  4220. }
  4221. });
  4222. ruleUrls = urls;
  4223. storage.setItem("rulesData", rulesData);
  4224. }
  4225. moveUp() {
  4226. let preE = this.item.previousElementSibling;
  4227. if (/^P$/i.test(preE.nodeName) && preE.children.length > 1) {
  4228. this.item.parentNode.insertBefore(this.item, preE);
  4229. this.saveSort();
  4230. }
  4231. }
  4232. moveDown() {
  4233. let nextE = this.item.nextElementSibling;
  4234. if (/^P$/i.test(nextE.nodeName) && nextE.children.length > 1) {
  4235. this.item.parentNode.insertBefore(nextE, this.item);
  4236. this.saveSort();
  4237. }
  4238. }
  4239. del() {
  4240. if (this.ruleUrl.id < 2) {
  4241. showTips(i18n("cantDel"));
  4242. } else if (window.confirm(i18n("confirmDel"))) {
  4243. for (let u = 0; u < rulesData.urls.length; u++) {
  4244. if (this.ruleUrl.id == rulesData.urls[u].id) {
  4245. rulesData.urls.splice(u, 1);
  4246. break;
  4247. }
  4248. }
  4249. for (let u = 0; u < ruleUrls.length; u++) {
  4250. if (this.ruleUrl.id == ruleUrls[u].id) {
  4251. ruleUrls.splice(u, 1);
  4252. break;
  4253. }
  4254. }
  4255. for (let u = 0; u < rulesData.sort.length; u++) {
  4256. if (this.ruleUrl.id == rulesData.sort[u]) {
  4257. rulesData.sort.splice(u, 1);
  4258. break;
  4259. }
  4260. }
  4261. storage.setItem("rulesData", rulesData);
  4262. ruleParser.rules = ruleParser.rules.filter(item => {return item.from != this.ruleUrl.id});
  4263. storage.setItem("rules", ruleParser.rules);
  4264. this.item.parentNode.removeChild(this.item);
  4265. //location.reload();
  4266. }
  4267. }
  4268. }
  4269. let updateP = document.createElement("p"), i = 0;
  4270. let now = new Date().getTime(), inUpdate = false;
  4271.  
  4272.  
  4273. let pastDate = (new Date(updateDate)).toString(), passStr;
  4274. let passTime = (now - updateDate) / 1000;
  4275. if (isNaN(passTime)) {
  4276. passStr = i18n("firstUpdate");
  4277. } else if (passTime < 60) {
  4278. passStr = i18n("passSec", parseInt(passTime)) + " 👆 " + i18n("click2update");
  4279. } else if (passTime < 60 * 60) {
  4280. passStr = i18n("passMin", parseInt(passTime / 60)) + " 👆 " + i18n("click2update");
  4281. } else if (passTime < 60 * 60 * 24) {
  4282. passStr = i18n("passHour", parseInt(passTime / 3600)) + " 👆 " + i18n("click2update");
  4283. } else {
  4284. passStr = i18n("passDay", parseInt(passTime / 86400)) + " 👆 " + i18n("click2update");
  4285. }
  4286.  
  4287.  
  4288. updateP.className = "updateDate";
  4289. updateP.innerHTML = passStr;
  4290. updateP.title = i18n("update") + " - " + pastDate;
  4291. updateP.onclick = e => {
  4292. ruleParser.rules = [];
  4293. showTips(i18n("beginUpdate"));
  4294. updateRules(() => {
  4295. showTips(i18n("updateSucc"));
  4296. updateP.innerHTML = i18n("passSec", 0);
  4297. updateP.title = i18n("update");
  4298. }, (rule, err) => {
  4299. showTips(`Update ${rule.url} rules fail!`);
  4300. debug(err);
  4301. });
  4302. };
  4303. configCon.insertBefore(updateP, insertPos);
  4304. if (ruleUrls) {
  4305. ruleUrls.forEach(ruleUrl => {
  4306. var rulebar = new Rulebar();
  4307. rulebar.init(ruleUrl);
  4308. });
  4309. }
  4310. let customUrlsTitle = document.createElement("h2");
  4311. customUrlsTitle.innerHTML = i18n("customUrls");
  4312. configCon.insertBefore(customUrlsTitle, insertPos);
  4313. let customUrlsInput = document.createElement("textarea");
  4314. customUrlsInput.style.width = "100%";
  4315. customUrlsInput.placeholder = "http://wedata.net/databases/AutoPagerize/items_all.json";
  4316. customUrlsInput.spellcheck = false;
  4317. configCon.insertBefore(customUrlsInput, insertPos);
  4318.  
  4319. let btns = document.createElement("div");
  4320. btns.style.display = "flex";
  4321. configCon.insertBefore(btns, insertPos);
  4322. let upBtnImg = document.createElement("div");
  4323. upBtnImg.style.width = "33%";
  4324. let upBtnImgTitle = document.createElement("h2");
  4325. upBtnImgTitle.style.whiteSpace = "nowrap";
  4326. upBtnImgTitle.style.overflow = "auto";
  4327. upBtnImgTitle.innerHTML = i18n("upBtnImg");
  4328. upBtnImg.appendChild(upBtnImgTitle);
  4329. let upBtnImgInput = document.createElement("input");
  4330. upBtnImgInput.style.width = "100%";
  4331. upBtnImgInput.placeholder = "data:image/png;base64,UpBtn";
  4332. upBtnImgInput.value = rulesData.upBtnImg || '';
  4333. upBtnImgInput.spellcheck = false;
  4334. upBtnImg.appendChild(upBtnImgInput);
  4335. btns.appendChild(upBtnImg);
  4336.  
  4337. let downBtnImg = document.createElement("div");
  4338. downBtnImg.style.width = "33%";
  4339. let downBtnImgTitle = document.createElement("h2");
  4340. downBtnImgTitle.style.whiteSpace = "nowrap";
  4341. downBtnImgTitle.style.overflow = "auto";
  4342. downBtnImgTitle.innerHTML = i18n("downBtnImg");
  4343. downBtnImg.appendChild(downBtnImgTitle);
  4344. let downBtnImgInput = document.createElement("input");
  4345. downBtnImgInput.style.width = "100%";
  4346. downBtnImgInput.placeholder = "data:image/png;base64,DownBtn";
  4347. downBtnImgInput.value = rulesData.downBtnImg || '';
  4348. downBtnImgInput.spellcheck = false;
  4349. downBtnImg.appendChild(downBtnImgInput);
  4350. btns.appendChild(downBtnImg);
  4351.  
  4352. let sideControllerIconDiv = document.createElement("div");
  4353. sideControllerIconDiv.style.width = "33%";
  4354. let sideControllerIconTitle = document.createElement("h2");
  4355. sideControllerIconTitle.style.whiteSpace = "nowrap";
  4356. sideControllerIconTitle.style.overflow = "auto";
  4357. sideControllerIconTitle.innerHTML = i18n("sideControllerIcon");
  4358. sideControllerIconDiv.appendChild(sideControllerIconTitle);
  4359. let sideControllerIconInput = document.createElement("input");
  4360. sideControllerIconInput.style.width = "100%";
  4361. sideControllerIconInput.placeholder = "⚪";
  4362. sideControllerIconInput.value = rulesData.sideControllerIcon || '';
  4363. sideControllerIconInput.spellcheck = false;
  4364. sideControllerIconDiv.appendChild(sideControllerIconInput);
  4365. btns.appendChild(sideControllerIconDiv);
  4366.  
  4367. let otherBtns = document.createElement("div");
  4368. otherBtns.style.display = "flex";
  4369. configCon.insertBefore(otherBtns, insertPos);
  4370. let loadingText = document.createElement("div");
  4371. loadingText.style.width = "100%";
  4372. let loadingTextTitle = document.createElement("h2");
  4373. loadingTextTitle.style.whiteSpace = "nowrap";
  4374. loadingTextTitle.style.overflow = "auto";
  4375. loadingTextTitle.innerHTML = i18n("loadingTextTitle");
  4376. loadingText.appendChild(loadingTextTitle);
  4377. let loadingTextInput = document.createElement("input");
  4378. loadingTextInput.value = rulesData.loadingText||'';
  4379. loadingTextInput.placeholder = i18n("loadingText");
  4380. loadingTextInput.style.width = "100%";
  4381. loadingTextInput.style.margin = "0";
  4382. loadingTextInput.spellcheck = false;
  4383. loadingText.appendChild(loadingTextInput);
  4384. otherBtns.appendChild(loadingText);
  4385.  
  4386. let opacity = document.createElement("div");
  4387. let opacityTitle = document.createElement("h2");
  4388. opacityTitle.style.whiteSpace = "nowrap";
  4389. opacityTitle.style.overflow = "visible";
  4390. opacityTitle.innerHTML = i18n("opacity");
  4391. opacity.appendChild(opacityTitle);
  4392. let opacityInput = document.createElement("input");
  4393. opacityInput.value = rulesData.opacity * 100;
  4394. opacityInput.type = "number";
  4395. opacityInput.style.width = "110px";
  4396. opacityInput.style.margin = "0";
  4397. opacityInput.placeholder = i18n("opacityPlaceholder");
  4398. opacityInput.spellcheck = false;
  4399. opacity.appendChild(opacityInput);
  4400. otherBtns.appendChild(opacity);
  4401.  
  4402. let pageElementCss = document.createElement("div");
  4403. pageElementCss.style.marginBottom = "30px";
  4404. let pageElementCssTitle = document.createElement("h2");
  4405. pageElementCssTitle.innerHTML = i18n("pageElementCss");
  4406. pageElementCss.appendChild(pageElementCssTitle);
  4407. let pageElementCssInput = document.createElement("input");
  4408. pageElementCssInput.value = rulesData.pageElementCss || '';
  4409. pageElementCssInput.style.width = "100%";
  4410. pageElementCssInput.style.margin = "0";
  4411. pageElementCssInput.placeholder = "font-size: xx-large;";
  4412. pageElementCssInput.spellcheck = false;
  4413. pageElementCss.appendChild(pageElementCssInput);
  4414. configCon.insertBefore(pageElementCss, insertPos);
  4415.  
  4416. let customCss = document.createElement("div");
  4417. customCss.style.marginBottom = "50px";
  4418. let customCssTitle = document.createElement("h2");
  4419. customCssTitle.innerHTML = i18n("customCss");
  4420. customCss.appendChild(customCssTitle);
  4421. let customCssInput = document.createElement("textarea");
  4422. customCssInput.value = rulesData.customCss || '';
  4423. customCssInput.style.width = "100%";
  4424. customCssInput.style.margin = "0";
  4425. customCssInput.placeholder = ".pagetual{\n}";
  4426. customCssInput.spellcheck = false;
  4427. customCss.appendChild(customCssInput);
  4428. configCon.insertBefore(customCss, insertPos);
  4429.  
  4430. let configTable = document.createElement("table");
  4431. configTable.style.width = "100%";
  4432. let configTbody = document.createElement("tbody");
  4433. configTbody.style.width = "100%";
  4434. configTbody.style.display = "inline-table";
  4435. configTable.appendChild(configTbody);
  4436. configCon.insertBefore(configTable, insertPos);
  4437. function createCheckbox(innerText, val, tag, parentCheck, otherType) {
  4438. if (typeof val == 'undefined') val = "";
  4439. let title = document.createElement(tag || "h3");
  4440. title.innerHTML = innerText;
  4441. title.style.overflowWrap = "normal";
  4442. let input = document.createElement("input");
  4443. if (otherType === 'key') {
  4444. input.type = 'text';
  4445. input.setAttribute('readOnly', 'readonly');
  4446. input.addEventListener("keydown", e => {
  4447. if (e.key === 'Escape' || e.key === 'Backspace') input.value = '';
  4448. else input.value = e.key;
  4449. e.stopPropagation();
  4450. e.preventDefault();
  4451. });
  4452. } else {
  4453. input.type = otherType || "checkbox";
  4454. }
  4455. input.style.width = "30px";
  4456. input.style.height = "20px";
  4457. input.style.float = "left";
  4458. input.style.margin = "5px";
  4459. input.value = val;
  4460. input.checked = val;
  4461. let td = document.createElement("td");
  4462. td.appendChild(input);
  4463. if (parentCheck) {
  4464. title.style.margin = "0";
  4465. td.appendChild(title);
  4466. let parent = parentCheck.parentNode.nextElementSibling;
  4467. let tr = parent.querySelector("tr");
  4468. if (!tr) {
  4469. tr = document.createElement("tr");
  4470. parent.appendChild(tr);
  4471. }
  4472. tr.appendChild(td);
  4473. if (!parentCheck.checked) {
  4474. td.style.display = "none";
  4475. }
  4476. parentCheck.addEventListener("click", e => {
  4477. td.style.display = parentCheck.checked ? "" : "none";
  4478. });
  4479. } else {
  4480. let tr = document.createElement("tr");
  4481. tr.appendChild(td);
  4482. td = document.createElement("td");
  4483. td.appendChild(title);
  4484. tr.appendChild(td);
  4485. configTable.children[0].appendChild(tr);
  4486. }
  4487. return input;
  4488. }
  4489.  
  4490. let enableWhiteListInput = createCheckbox(i18n("autoRun"), rulesData.enableWhiteList != true);
  4491. let sideControllerInput = createCheckbox(i18n("sideController"), rulesData.sideController);
  4492. let enableDebugInput = createCheckbox(i18n("enableDebug"), rulesData.enableDebug != false);
  4493. let enableHistoryInput = createCheckbox(i18n("enableHistory"), rulesData.enableHistory === true);
  4494. let enableHistoryAfterInsertInput = createCheckbox(i18n("enableHistoryAfterInsert"), rulesData.enableHistoryAfterInsert === true);
  4495. let openInNewTabInput = createCheckbox(i18n("openInNewTab"), rulesData.openInNewTab != false);
  4496. let hidePageBarInput = createCheckbox(i18n("hideBar"), rulesData.opacity == 0);
  4497. let hidePageBarArrowInput = createCheckbox(i18n("hideBarArrow"), rulesData.hideBarArrow);
  4498. let hideLoadingIconInput = createCheckbox(i18n("hideLoadingIcon"), rulesData.hideLoadingIcon != false);
  4499. let initRunInput = createCheckbox(i18n("initRun"), rulesData.initRun != false);
  4500. let autoLoadNumInput = createCheckbox(i18n("autoLoadNum"), rulesData.autoLoadNum, "h4", initRunInput, "number");
  4501. let preloadInput = createCheckbox(i18n("preload"), rulesData.preload != false);
  4502. let rateInput = createCheckbox(i18n("turnRate"), rulesData.rate, "h4", preloadInput, "number");
  4503. let dbClick2StopInput = createCheckbox(i18n("dbClick2Stop"), rulesData.dbClick2Stop);
  4504. let manualModeInput = createCheckbox(i18n("manualMode"), rulesData.manualMode);
  4505. let clickModeInput = createCheckbox(i18n("clickMode"), rulesData.clickMode);
  4506. let pageBarMenuInput = createCheckbox(i18n("pageBarMenu"), rulesData.pageBarMenu != false);
  4507. let arrowToScrollInput = createCheckbox(i18n("arrowToScroll"), rulesData.arrowToScroll);
  4508. let contentVisibilityInput = createCheckbox(i18n("contentVisibility"), rulesData.contentVisibility);
  4509.  
  4510. let hideBarInput = createCheckbox(i18n("hideBar"), rulesData.hideBar && !rulesData.hideBarButNoStop, "h4", dbClick2StopInput, 'radio');
  4511. hideBarInput.name = 'hideBar';
  4512. let hideBarButNoStopInput = createCheckbox(i18n("hideBarButNoStop"), rulesData.hideBarButNoStop, "h4", dbClick2StopInput, 'radio');
  4513. hideBarButNoStopInput.name = 'hideBar';
  4514. hideBarInput.addEventListener('mouseup', e => {
  4515. if (hideBarInput.checked) {
  4516. setTimeout(() => {hideBarInput.checked = false}, 0);
  4517. }
  4518. });
  4519. hideBarButNoStopInput.addEventListener('mouseup', e => {
  4520. if (hideBarButNoStopInput.checked) {
  4521. setTimeout(() => {hideBarButNoStopInput.checked = false}, 0);
  4522. }
  4523. });
  4524. hidePageBarInput.addEventListener('click', e => {
  4525. opacityInput.value = hidePageBarInput.checked ? 0 : 30;
  4526. });
  4527.  
  4528. let dbClick2StopCtrlInput = createCheckbox(i18n("dbClick2StopCtrl"), rulesData.dbClick2StopCtrl, "h4", dbClick2StopInput);
  4529. let dbClick2StopAltInput = createCheckbox(i18n("dbClick2StopAlt"), rulesData.dbClick2StopAlt, "h4", dbClick2StopInput);
  4530. let dbClick2StopShiftInput = createCheckbox(i18n("dbClick2StopShift"), rulesData.dbClick2StopShift, "h4", dbClick2StopInput);
  4531. let dbClick2StopMetaInput = createCheckbox(i18n("dbClick2StopMeta"), rulesData.dbClick2StopMeta, "h4", dbClick2StopInput);
  4532. let dbClick2StopKeyInput = createCheckbox(i18n("dbClick2StopKey"), rulesData.dbClick2StopKey, "h4", dbClick2StopInput, "key");
  4533.  
  4534. let customRulesTitle = document.createElement("h2");
  4535. customRulesTitle.innerHTML = i18n("customRules", location.href.replace('tree', 'edit').replace(/\/$/, '') + '/pagetualRules.json');
  4536. configCon.insertBefore(customRulesTitle, insertPos);
  4537. let customRulesInput = document.createElement("textarea");
  4538. customRulesInput.spellcheck = false;
  4539. configCon.insertBefore(customRulesInput, insertPos);
  4540. if (rulesData.editTemp) {
  4541. if (!ruleParser.customRules) {
  4542. ruleParser.customRules = [];
  4543. }
  4544. for (let i in ruleParser.customRules) {
  4545. if (ruleParser.customRules[i].url == rulesData.editTemp.url) {
  4546. ruleParser.customRules.splice(i, 1);
  4547. break;
  4548. }
  4549. }
  4550. ruleParser.customRules.unshift(rulesData.editTemp);
  4551. rulesData.editTemp = null;
  4552. storage.setItem("rulesData", rulesData);
  4553. customRulesInput.previousElementSibling.scrollIntoView();
  4554. }
  4555. customRulesInput.style.width = "100%";
  4556. customRulesInput.style.height = "800px";
  4557. 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]`;
  4558. let preCustom = getFormatJSON(ruleParser.customRules);
  4559. customRulesInput.value = preCustom;
  4560. let blacklistInput = document.createElement("textarea");
  4561. blacklistInput.style.width = "100%";
  4562. blacklistInput.style.height = "500px";
  4563. blacklistInput.style.display = "none";
  4564. blacklistInput.spellcheck = false;
  4565. blacklistInput.placeholder = "http://*.xxx.com/*/y";
  4566. blacklistInput.value = rulesData.blacklist ? rulesData.blacklist.join("\n") : "";
  4567. let blacklistBtn = document.createElement("button");
  4568. blacklistBtn.innerText = i18n("editBlacklist");
  4569. blacklistBtn.style.width = "100%";
  4570. blacklistBtn.onclick = e => {
  4571. blacklistInput.style.display = blacklistInput.style.display == "none" ? "" : "none";
  4572. };
  4573. configCon.insertBefore(blacklistBtn, insertPos);
  4574. configCon.insertBefore(blacklistInput, insertPos);
  4575. let saveBtn = document.createElement("button");
  4576. saveBtn.innerHTML = i18n("save");
  4577. saveBtn.style.width = "100%";
  4578. saveBtn.style.position = "fixed";
  4579. saveBtn.style.zIndex = "999";
  4580. saveBtn.style.bottom = 0;
  4581. saveBtn.style.left = 0;
  4582. saveBtn.style.fontSize = "x-large";
  4583. configCon.insertBefore(saveBtn, insertPos);
  4584. saveBtn.onclick = e => {
  4585. try {
  4586. if (customRulesInput.value != preCustom) {
  4587. storage.setItem("hpRules", []);
  4588. storage.setItem("smartRules", []);
  4589. }
  4590. if (customRulesInput.value == "") {
  4591. storage.setItem("customRules", "");
  4592. } else {
  4593. let customRules = JSON.parse(customRulesInput.value);
  4594. if (Array && Array.isArray && !Array.isArray(customRules)) {
  4595. showTips(i18n("errorRulesMustBeArray"));
  4596. return;
  4597. }
  4598. debug(customRules);
  4599. storage.setItem("customRules", customRules);
  4600. customRulesInput.value = JSON.stringify(customRules, null, 4);
  4601. }
  4602. } catch(e) {
  4603. debug(e);
  4604. showTips(i18n("errorJson"));
  4605. return;
  4606. }
  4607. rulesData.opacity = opacityInput.value / 100;
  4608. rulesData.blacklist = blacklistInput.value ? blacklistInput.value.split("\n") : "";
  4609. rulesData.hideBar = hideBarInput.checked;
  4610. rulesData.hideBarButNoStop = hideBarButNoStopInput.checked;
  4611. rulesData.dbClick2Stop = dbClick2StopInput.checked;
  4612. rulesData.enableWhiteList = !enableWhiteListInput.checked;
  4613. rulesData.enableDebug = enableDebugInput.checked;
  4614. rulesData.enableHistory = enableHistoryInput.checked;
  4615. rulesData.enableHistoryAfterInsert = enableHistoryAfterInsertInput.checked;
  4616. rulesData.openInNewTab = openInNewTabInput.checked;
  4617. rulesData.hideLoadingIcon = hideLoadingIconInput.checked;
  4618. rulesData.hideBarArrow = hidePageBarArrowInput.checked;
  4619. rulesData.initRun = initRunInput.checked;
  4620. rulesData.autoLoadNum = autoLoadNumInput.value !== "0" ? autoLoadNumInput.value : '';
  4621. rulesData.rate = parseInt(rateInput.value) || 1;
  4622. rulesData.preload = preloadInput.checked;
  4623. rulesData.manualMode = manualModeInput.checked;
  4624. rulesData.clickMode = clickModeInput.checked;
  4625. rulesData.pageBarMenu = pageBarMenuInput.checked;
  4626. rulesData.arrowToScroll = arrowToScrollInput.checked;
  4627. rulesData.contentVisibility = contentVisibilityInput.checked;
  4628. if (rulesData.sideController != sideControllerInput.checked) {
  4629. rulesData.sideControllerPos = false;
  4630. }
  4631. rulesData.sideController = sideControllerInput.checked;
  4632. rulesData.pageElementCss = pageElementCssInput.value;
  4633. rulesData.customCss = customCssInput.value;
  4634. rulesData.upBtnImg = upBtnImgInput.value;
  4635. rulesData.downBtnImg = downBtnImgInput.value;
  4636. rulesData.sideControllerIcon = sideControllerIconInput.value;
  4637. rulesData.loadingText = loadingTextInput.value;
  4638. rulesData.dbClick2StopCtrl = dbClick2StopCtrlInput.checked;
  4639. rulesData.dbClick2StopAlt = dbClick2StopAltInput.checked;
  4640. rulesData.dbClick2StopShift = dbClick2StopShiftInput.checked;
  4641. rulesData.dbClick2StopMeta = dbClick2StopMetaInput.checked;
  4642. rulesData.dbClick2StopKey = dbClick2StopKeyInput.value;
  4643. storage.setItem("rulesData", rulesData);
  4644. let customUrls = customUrlsInput.value.trim();
  4645. if (customUrls) {
  4646. customUrls = customUrls.split(/\n/);
  4647. for (let c = 0; c < customUrls.length; c++) {
  4648. let url;
  4649. if (/^0\s*\|/.test(customUrls[c])) {
  4650. url = customUrls[c].replace(/^0\s*\|\s*/, "").trim();
  4651. if (!/^http/.test(url)) {
  4652. showTips(i18n("errorWrongUrl"));
  4653. return;
  4654. }
  4655. } else {
  4656. url = customUrls[c].trim();
  4657. if (!/^http/.test(url)) {
  4658. showTips(i18n("errorWrongUrl"));
  4659. return;
  4660. }
  4661. }
  4662. let maxId = 1, hasUrl = false;
  4663. if (!rulesData.urls) {
  4664. rulesData.urls = [];
  4665. }
  4666. ruleUrls.forEach(u => {
  4667. if (maxId < u.id) {
  4668. maxId = u.id;
  4669. }
  4670. if (u.url == url) {
  4671. hasUrl = true;
  4672. }
  4673. });
  4674. if (hasUrl) break;
  4675. if (!rulesData.sort) rulesData.sort = [1];
  4676. rulesData.urls.push({id: maxId + 1, url: url});
  4677. rulesData.sort.push(maxId + 1);
  4678. storage.setItem("rulesData", rulesData);
  4679. }
  4680. }
  4681. showTips(i18n("settingsSaved"));
  4682. //location.reload();
  4683. };
  4684. return true;
  4685. }
  4686.  
  4687. var inUpdate = false;
  4688. function updateRules (success, fail, keepCache) {
  4689. if (!storage.supportCrossSave()) {
  4690. fail({url:''}, "Not support cross storage");
  4691. return;
  4692. }
  4693. if (inUpdate) return;
  4694. inUpdate = true;
  4695. let ruleIndex = ruleUrls.length - 1;
  4696. if (!keepCache) {
  4697. storage.setItem("hpRules", []);
  4698. storage.setItem("smartRules", []);
  4699. }
  4700. function addNextRule() {
  4701. if (ruleIndex < 0) {
  4702. let now = new Date().getTime();
  4703. storage.setItem("ruleLastUpdate", now);
  4704. storage.setItem("rules", ruleParser.rules);
  4705. inUpdate = false;
  4706. success();
  4707. } else {
  4708. let rule = ruleUrls[ruleIndex--];
  4709. ruleParser.addRuleByUrl(rule.url, rule.id, (json, err) => {
  4710. if (!json) {
  4711. fail(rule, err);
  4712. }
  4713. addNextRule();
  4714. })
  4715. }
  4716. }
  4717. addNextRule();
  4718. }
  4719.  
  4720. function objIsArr(obj) {
  4721. return obj &&
  4722. typeof obj === 'object' &&
  4723. typeof obj.length === 'number' &&
  4724. !(obj.propertyIsEnumerable('length'));
  4725. }
  4726.  
  4727. function isVisible(el, win) {
  4728. if(!el || !el.offsetParent)return false;
  4729. var loopable = true,
  4730. visible = el.nodeName && win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  4731. while(loopable && visible) {
  4732. el = el.parentNode;
  4733.  
  4734. if(el && !/^BODY$/i.test(el.nodeName)) {
  4735. visible = win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  4736. }else {
  4737. loopable = false;
  4738. }
  4739. }
  4740. return visible;
  4741. }
  4742.  
  4743. function getElementTop(ele) {
  4744. if (!ele) return 0;
  4745. if (ele.getBoundingClientRect) {
  4746. return ele.getBoundingClientRect().top + document.documentElement.scrollTop;
  4747. }
  4748. var actualTop = ele.offsetTop;
  4749. var current = ele.offsetParent;
  4750. while (current) {
  4751. actualTop += current.offsetTop;
  4752. current = current.offsetParent;
  4753. }
  4754. return actualTop;
  4755. }
  4756.  
  4757. function getElementLeft(ele) {
  4758. if (!ele) return 0;
  4759. if (ele.getBoundingClientRect) {
  4760. return ele.getBoundingClientRect().left + document.documentElement.scrollLeft;
  4761. }
  4762. var actualLeft = ele.offsetLeft;
  4763. var current = ele.offsetParent;
  4764. while (current) {
  4765. actualLeft += current.offsetLeft;
  4766. current = current.offsetParent;
  4767. }
  4768. return actualLeft;
  4769. }
  4770.  
  4771. function getElementBottom(ele) {
  4772. return getElementTop(ele) + (ele.offsetHeight || ele.scrollHeight);
  4773. }
  4774.  
  4775. function getFormatJSON(obj){
  4776. if(!objIsArr(obj) || obj.length === 0)return "";
  4777. return JSON.stringify(obj, null, 4);
  4778. }
  4779.  
  4780. function globMatch(first, second) {
  4781. if (first === '*') {
  4782. return true;
  4783. }
  4784. if (first.length == 0 && second.length == 0){
  4785. return true;
  4786. }
  4787.  
  4788. if (first.length > 1 && first[0] == '*' &&
  4789. second.length == 0){
  4790. return false;
  4791. }
  4792.  
  4793. if ((first.length > 1 && first[0] == '?') ||
  4794. (first.length != 0 && second.length != 0 &&
  4795. first[0] == second[0])){
  4796. return globMatch(first.substring(1),
  4797. second.substring(1));
  4798. }
  4799.  
  4800. if (first.length > 0 && first[0] == '*'){
  4801. return globMatch(first.substring(1), second) ||
  4802. globMatch(first, second.substring(1));
  4803. }
  4804.  
  4805. return false;
  4806. }
  4807.  
  4808. function initRules(callback) {
  4809. /*0 wedata格式,1 pagetual格式*/
  4810. ruleUrls = [
  4811. {
  4812. id: 1,
  4813. url:'http://wedata.net/databases/AutoPagerize/items_all.json',
  4814. type: 0,
  4815. }
  4816. ];
  4817.  
  4818. ruleParser.initSavedRules(() => {
  4819. storage.getItem("rulesData", data => {
  4820. if (data) {
  4821. rulesData = data;
  4822. if (data.urls) ruleUrls = ruleUrls.concat(data.urls);
  4823. if (data.sort) {
  4824. let urls = [];
  4825. data.sort.forEach(id => {
  4826. for (let s = 0; s < ruleUrls.length; s++) {
  4827. if (id == ruleUrls[s].id) {
  4828. urls.push(ruleUrls[s]);
  4829. break;
  4830. }
  4831. }
  4832. });
  4833. ruleUrls = urls;
  4834. }
  4835. }
  4836. let upBtnImg = rulesData.upBtnImg, downBtnImg = rulesData.downBtnImg, _sideControllerIcon = rulesData.sideControllerIcon;
  4837. if (upBtnImg && downBtnImg) {
  4838. downSvgCSS = downSvgCSS.replace("transform: rotate(180deg);", "");
  4839. } else if (upBtnImg && !downBtnImg) {
  4840. downBtnImg = upBtnImg;
  4841. } else if(downBtnImg && !upBtnImg) {
  4842. upBtnImg = downBtnImg;
  4843. }
  4844. if (upBtnImg) {
  4845. upSvg = /https?:|data/.test(upBtnImg) ? `<img class="pagetual" src="${upBtnImg}"/>` : `<span>${upBtnImg}</span>`;
  4846. }
  4847. if (downBtnImg) {
  4848. downSvg = /https?:|data/.test(downBtnImg) ? `<img class="pagetual" src="${downBtnImg}"/>` : `<span>${downBtnImg}</span>`;
  4849. }
  4850. if (_sideControllerIcon) {
  4851. sideControllerIcon = /https?:|data/.test(_sideControllerIcon) ? `<img class="pagetual" src="${_sideControllerIcon}"/>` : `<span>${_sideControllerIcon}</span>`;
  4852. }
  4853. setLoadingDiv(rulesData.loadingText || i18n("loadingText"));
  4854. if (typeof(rulesData.opacity) == "undefined") {
  4855. rulesData.opacity = 0.3;
  4856. }
  4857. if (typeof(rulesData.hideBar) == "undefined") {
  4858. rulesData.hideBar = false;
  4859. }
  4860. if (typeof(rulesData.dbClick2Stop) == "undefined") {
  4861. rulesData.dbClick2Stop = true;
  4862. }
  4863. if (typeof(rulesData.enableWhiteList) == "undefined") {
  4864. rulesData.enableWhiteList = false;
  4865. }
  4866. if (typeof(rulesData.enableHistory) == "undefined") {
  4867. rulesData.enableHistory = false;
  4868. }
  4869. if (typeof(rulesData.openInNewTab) == "undefined") {
  4870. rulesData.openInNewTab = true;
  4871. }
  4872. if (typeof(rulesData.enableDebug) == "undefined") {
  4873. rulesData.enableDebug = true;
  4874. }
  4875. if (typeof(rulesData.initRun) == "undefined") {
  4876. rulesData.initRun = true;
  4877. }
  4878. if (typeof(rulesData.preload) == "undefined") {
  4879. rulesData.preload = true;
  4880. }
  4881. if (typeof(rulesData.manualMode) == "undefined") {
  4882. rulesData.manualMode = false;
  4883. }
  4884. if (typeof(rulesData.clickMode) == "undefined") {
  4885. rulesData.clickMode = false;
  4886. }
  4887. if (typeof(rulesData.pageBarMenu) == "undefined") {
  4888. rulesData.pageBarMenu = true;
  4889. }
  4890. if (typeof(rulesData.arrowToScroll) == "undefined") {
  4891. rulesData.arrowToScroll = false;
  4892. }
  4893. if (typeof(rulesData.hideLoadingIcon) == "undefined") {
  4894. rulesData.hideLoadingIcon = false;
  4895. }
  4896. if (typeof(rulesData.hideBarArrow) == "undefined") {
  4897. rulesData.hideBarArrow = false;
  4898. }
  4899. if (rulesData.blacklist && rulesData.blacklist.length > 0) {
  4900. let href = location.href.slice(0, 500);
  4901. for (let b in rulesData.blacklist) {
  4902. let curGlob = rulesData.blacklist[b];
  4903. if (globMatch(curGlob, href)) {
  4904. forceState == 1;
  4905. return;
  4906. }
  4907. }
  4908. }
  4909. if (rulesData.autoLoadNum && rulesData.initRun) {
  4910. autoLoadNum = parseInt(rulesData.autoLoadNum);
  4911. }
  4912. openInNewTab = rulesData.openInNewTab ? 1 : 0;
  4913. enableDebug = rulesData.enableDebug;
  4914. storage.getItem("nextSwitch_" + location.host, i => {
  4915. storage.getItem("forceState_" + location.host, v => {
  4916. storage.getItem("ruleLastUpdate", date => {
  4917. if (typeof(i) !== "undefined") {
  4918. nextIndex = i;
  4919. }
  4920. if (typeof(v) == "undefined") {
  4921. v = (rulesData.enableWhiteList ? 1 : 0);
  4922. }
  4923. forceState = v;
  4924. updateDate = date;
  4925. if (initConfig()) return;
  4926. if (forceState == 1) return;
  4927. let now = new Date().getTime();
  4928. if (!date || now - date > 2 * 24 * 60 * 60 * 1000) {
  4929. updateRules(() => {
  4930. }, (rule, err) => {}, true);
  4931. storage.setItem("ruleLastUpdate", now);
  4932. }
  4933. callback();
  4934. });
  4935. });
  4936. });
  4937. });
  4938. });
  4939. }
  4940.  
  4941. function requestDoc(url, callback){
  4942. let postParams = url.match(/#p{(.*)}$/);
  4943. if (postParams) {
  4944. postParams = postParams[1];
  4945. url = url.replace(/#p{.*/, "");
  4946. }
  4947. _GM_xmlhttpRequest({
  4948. url: url,
  4949. method: postParams ? 'POST' : 'GET',
  4950. data: postParams,
  4951. overrideMimeType: 'text/html;charset=' + (document.characterSet || document.charset || document.inputEncoding),
  4952. headers: {
  4953. 'Referer': location.href,
  4954. 'User-Agent': navigator.userAgent,
  4955. "Content-Type": (postParams ? "application/x-www-form-urlencoded" : "text/html") + ";charset=" + (document.characterSet || document.charset || document.inputEncoding),
  4956. },
  4957. timeout: 20000,
  4958. onload: async function(res) {
  4959. var doc = null, response = res.response;
  4960. let preCode = ruleParser.curSiteRule.pageElementPre || ruleParser.curSiteRule.pagePre;
  4961. if (preCode) {
  4962. try {
  4963. if (typeof _unsafeWindow.pagetualPagePre != 'undefined') {
  4964. response = _unsafeWindow.pagetualPagePre(response);
  4965. } else if (preCode.length == 2) {
  4966. response = response.replace(new RegExp(preCode[0], "gi"), preCode[1]);
  4967. } else {
  4968. response = Function("response",'"use strict";' + preCode)(response);
  4969. }
  4970. } catch(e) {
  4971. debug(e);
  4972. }
  4973. }
  4974. try {
  4975. doc = document.implementation.createHTMLDocument('');
  4976. doc.documentElement.innerHTML = response;
  4977. let base = doc.querySelector("base");
  4978. ruleParser.basePath = base ? base.href : url;
  4979. }
  4980. catch (e) {
  4981. debug('parse error:' + e.toString());
  4982. }
  4983. let pageElement = ruleParser.getPageElement(doc);
  4984. if ((!pageElement || pageElement.length == 0) && res.status >= 400) {
  4985. debug(res.status, "Error status");
  4986. return callback(false);
  4987. }
  4988. if (inCors && (!pageElement || pageElement.length == 0)) {
  4989. let article = doc.querySelectorAll(mainSel);
  4990. if (article && article.length > 0) {
  4991. if (article.length == 1) {
  4992. article = article[0];
  4993. ruleParser.curSiteRule.pageElement = article.nodeName.toLowerCase() + (article.id ? "#" + article.id : "") + (article.className ? "." + article.className : "") + ">*";
  4994. pageElement = article.children;
  4995. } else {
  4996. ruleParser.curSiteRule.pageElement = mainSel;
  4997. pageElement = article;
  4998. }
  4999. } else {
  5000. ruleParser.curSiteRule.pageElement = allOfBody;
  5001. pageElement = ruleParser.getPageElement(doc);
  5002. }
  5003. ruleParser.getInsert(true);
  5004. }
  5005. //只有1的話怕不是圖片哦
  5006. if (pageElement && (pageElement.length > 1 || (pageElement.length == 1 && !/^IMG$/i.test(pageElement[0].nodeName)))) {
  5007. await ruleParser.insertPage(doc, pageElement, url, callback, false);
  5008. if (ruleParser.curSiteRule.action == 1) {
  5009. requestFromIframe(url, (doc, eles) => {
  5010. loadPageOver();
  5011. if (eles) {
  5012. ruleParser.insertPage(doc, eles, url, callback, true);
  5013. }
  5014. });
  5015. } else ruleParser.curSiteRule.action = 0;
  5016. } else if (ruleParser.curSiteRule.singleUrl || curPage == 1) {
  5017. ruleParser.curSiteRule.action = 1;
  5018. requestFromIframe(url, (doc, eles) => {
  5019. loadPageOver();
  5020. if (eles) {
  5021. ruleParser.insertPage(doc, eles, url, callback, true);
  5022. }
  5023. });
  5024. } else {
  5025. debug("Stop as no page element");
  5026. showTips(i18n("noValidContent"), "", "", url);
  5027. isPause = true;
  5028. callback(false);
  5029. }
  5030. },
  5031. onerror: function(e) {
  5032. debug(e, "NetError");
  5033. callback(false);
  5034. },
  5035. ontimeout: function(e) {
  5036. debug(e, "NetTimeout");
  5037. callback(false);
  5038. }
  5039. });
  5040. }
  5041.  
  5042. function initPage() {
  5043. ruleParser.initPage(() => {
  5044. if (ruleParser.curSiteRule.autoLoadNum) {
  5045. autoLoadNum = ruleParser.curSiteRule.autoLoadNum;
  5046. }
  5047. if (ruleParser.curSiteRule.nextLink && Array && Array.isArray && Array.isArray(ruleParser.curSiteRule.nextLink)) {
  5048. _GM_registerMenuCommand(i18n("nextSwitch"), () => {
  5049. NextSwitch.getInstance().start();
  5050. });
  5051. }
  5052. if (ruleParser.nextLinkHref) {
  5053. let isJs = /^(javascript|#)/.test(ruleParser.nextLinkHref.replace(location.href, ""));
  5054. if (!isJs) {
  5055. let inForce = (forceState == 2 || forceState == 3);
  5056. _GM_registerMenuCommand(i18n(inForce ? "cancelForceIframe" : "forceIframe"), () => {
  5057. if (inForce) {
  5058. storage.setItem("forceState_" + location.host, "");
  5059. } else {
  5060. let _state = ruleParser.curSiteRule.action > 0 || confirm(i18n("forceAllBody")) ? 2 : 3;
  5061. storage.setItem("forceState_" + location.host, _state);
  5062. }
  5063. location.reload();
  5064. });
  5065. }
  5066. _GM_registerMenuCommand(i18n("loadNow"), () => {
  5067. let loadNum = window.prompt(i18n("loadConfirm"), "1");
  5068. if (loadNum === "" || loadNum === null) return;
  5069. autoLoadNum = Math.abs(parseInt(loadNum));
  5070. nextPage();
  5071. });
  5072. }
  5073. initListener();
  5074. });
  5075. }
  5076.  
  5077. var pageBarStyle, mainStyleEle, mainStyleStyle;
  5078. function initView() {
  5079. if (!mainStyleStyle) {
  5080. mainStyleStyle = `
  5081. .pagetual_pageBar{
  5082. -moz-transition:opacity 0.3s ease-in-out 0s;
  5083. -webkit-transition:opacity 0.3s ease-in-out 0s;
  5084. transition:opacity 0.3s ease-in-out 0s;
  5085. font-family: Arial,sans-serif !important;
  5086. text-align: center !important;
  5087. }
  5088. .pagetual_pageBar.stop {
  5089. -webkit-filter: invert(100%);
  5090. filter: invert(100%);
  5091. opacity: 1!important;
  5092. }
  5093. .pagetual_pageBar.hide {
  5094. display: none!important;
  5095. }
  5096. .pagetual_pageBar:hover {
  5097. opacity: 1!important;
  5098. }
  5099. .pagetual_pageBar span {
  5100. vertical-align: super;
  5101. }
  5102. .pagetual_pageBar a::before,
  5103. .pagetual_pageBar a::after {
  5104. content: none;
  5105. }
  5106. .pagetual_pageBar a>span {
  5107. margin-top: 0!important;
  5108. pointer-events: none;
  5109. padding: unset;
  5110. opacity: 0;
  5111. -moz-transition:margin-top 0.3s ease-in-out 0s, opacity .3s;
  5112. -webkit-transition:margin-top 0.3s ease-in-out 0s, opacity .3s;
  5113. transition:margin-top 0.3s ease-in-out 0s, opacity .3s;
  5114. transform: none;
  5115. left: 0;
  5116. margin-left: calc(50% - 20px);
  5117. }
  5118. .pagetual_pageBar a>span:hover {
  5119. color: red;
  5120. }
  5121. .pagetual_pageBar a:hover>span {
  5122. opacity: 1;
  5123. }
  5124. .pagetual_pageBar span.prevScreen,
  5125. .pagetual_pageBar span.nextScreen {
  5126. display: block!important;
  5127. }
  5128. .pagetual_pageBar a:hover>span.prevScreen {
  5129. margin-top: -30px!important;
  5130. pointer-events: all;
  5131. }
  5132. .pagetual_pageBar a:hover>span.nextScreen {
  5133. margin-top: 30px!important;
  5134. pointer-events: all;
  5135. }
  5136. .pagetual_pageBar span>svg {
  5137. -moz-transition:transform 0.5s ease, opacity 0.3s ease;
  5138. -webkit-transition:transform 0.5s ease, opacity 0.3s ease;
  5139. transition:transform 0.5 ease, opacity 0.3s ease;
  5140. opacity: 0;
  5141. }
  5142. .pagetual_pageBar:hover span>svg {
  5143. opacity: 1;
  5144. }
  5145. .pagetual_pageBar span>svg.upSvg:hover {
  5146. transform: rotate(360deg) scale3d(1.2, 1.2, 1.2);
  5147. }
  5148. .pagetual_pageBar span>svg.downSvg:hover {
  5149. transform: rotate(540deg) scale3d(1.2, 1.2, 1.2)!important;
  5150. }
  5151. .pagetual_pageBar .pagetual_pageNum{
  5152. color: #55555f;
  5153. }
  5154. .pagetual_pageBar .pagetual_pageNum:hover{
  5155. color: #ff6464;
  5156. }
  5157. .pagetual_tipsWords {
  5158. font-size: 50px;
  5159. font-weight: bold;
  5160. font-family: "黑体", -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto",
  5161. "Oxygen", "Ubuntu", "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji",
  5162. "Segoe UI Emoji", "Segoe UI Symbol";
  5163. color: #ffffff;
  5164. min-height: 70px;
  5165. max-width: 80%;
  5166. line-height: 70px;
  5167. position: fixed;
  5168. left: 50%;
  5169. top: 10%;
  5170. margin-left: -99999px;
  5171. padding: 0 15px;
  5172. z-index: 2147483647;
  5173. background-color: #000;
  5174. border: 1px solid #303030;
  5175. border-radius: 10px;
  5176. opacity: 0;
  5177. filter: alpha(opacity=65);
  5178. box-shadow: 5px 5px 20px 0px #000;
  5179. -moz-transition:opacity 0.3s ease-in-out 0s;
  5180. -webkit-transition:opacity 0.3s ease-in-out 0s;
  5181. transition:opacity 0.3s ease-in-out 0s;
  5182. pointer-events: none;
  5183. }
  5184. .pagetual_tipsWords>a {
  5185. color: #ffffff;
  5186. }
  5187. .pagetual_loading {
  5188. width: 50px;
  5189. height: 50px;
  5190. margin: 10px auto;
  5191. border-radius: 100%;
  5192. display: flex;
  5193. -webkit-animation: pagetual_loading_scaleout 1.0s infinite ease-in-out;
  5194. animation: pagetual_loading_scaleout 1.0s infinite ease-in-out;
  5195. }
  5196. @-webkit-keyframes pagetual_loading_scaleout {
  5197. 0% { -webkit-transform: scale(0.0) }
  5198. 100% {
  5199. -webkit-transform: scale(1.0);
  5200. opacity: 0;
  5201. }
  5202. }
  5203. @keyframes pagetual_loading_scaleout {
  5204. 0% {
  5205. transform: scale(0.0);
  5206. -webkit-transform: scale(0.0);
  5207. } 100% {
  5208. transform: scale(1.0);
  5209. -webkit-transform: scale(1.0);
  5210. opacity: 0;
  5211. }
  5212. }
  5213. .pagetual_loading_text {
  5214. white-space: nowrap;
  5215. -webkit-animation: pagetual_loading_opacity 2.6s infinite ease-in-out;
  5216. animation: pagetual_loading_opacity 2.6s infinite ease-in-out;
  5217. }
  5218. @-webkit-keyframes pagetual_loading_opacity {
  5219. 0% { opacity: 1 }
  5220. 50% { opacity: 0.2 }
  5221. 100% { opacity: 1 }
  5222. }
  5223. @keyframes pagetual_loading_opacity {
  5224. 0% { opacity: 1 }
  5225. 50% { opacity: 0.2 }
  5226. 100% { opacity: 1 }
  5227. }
  5228. `;
  5229. pageBarStyle = `overflow: visible;text-indent: initial;vertical-align: super;line-height:1;opacity:${rulesData.opacity};display:${rulesData.opacity==0?"none":"inline-flex"};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: relative; width: auto; max-width: 100vw; height: 30px; float: none; clear: both; margin: 5px auto; text-align: center;justify-content: center;`;
  5230. }
  5231. if (!mainStyleEle || !mainStyleEle.parentNode) {
  5232. mainStyleEle = _GM_addStyle(mainStyleStyle);
  5233. }
  5234. }
  5235. var loadingDiv = document.createElement("div");
  5236. loadingDiv.style.cssText = "text-indent: initial;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;";
  5237.  
  5238. const loadingCSS = `text-indent: unset; 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; flex: 0;`;
  5239. function setLoadingDiv(loadingText) {
  5240. loadingDiv.innerHTML = createHTML(`<p class="pagetual_loading_text" style="${loadingCSS}display: inline-block;width: 100%;">${loadingText}</p>${rulesData.hideLoadingIcon ? "" : `<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"><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"></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"></path></svg></div>`}`);
  5241. }
  5242.  
  5243. var upSvg = `<svg width="30" height="30" class="upSvg pagetual" style="display:initial;position:relative;cursor: pointer;margin: 0 8px;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"><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"></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"></path></svg>`;
  5244. var upSvgCSS = `text-align: center;display: initial;position: relative;cursor: pointer;margin: 0 8px;width: 30px;height: 30px;vertical-align: middle;fill: currentColor;overflow: hidden;`;
  5245. var downSvg = `<svg width="30" height="30" class="downSvg pagetual" style="display:initial;position:relative;cursor: pointer;margin: 0 8px;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"><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"></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"></path></svg>`;
  5246. var downSvgCSS = `text-align: center;display: initial;position: relative;cursor: pointer;margin: 0 8px;width: 30px;height: 30px;vertical-align: middle;fill: currentColor;overflow: hidden;transform: rotate(180deg);`;
  5247.  
  5248. const initStyle = `text-indent: initial;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 5px;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;`;
  5249. const pageTextStyle = `opacity: 1!important;text-indent: initial;padding: unset;border: none;background: unset!important;line-height: 30px;text-decoration: none;user-select: none;visibility: visible;position: initial;width: auto;max-width: 80%; white-space: nowrap; text-overflow: ellipsis;overflow: hidden;height: auto;float: none;clear: both;margin: 0px;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;`;
  5250. var sideControllerIcon = '';
  5251.  
  5252. var tipsWords = document.createElement("div");
  5253. tipsWords.className = "pagetual_tipsWords";
  5254.  
  5255. var isPause = false, isHideBar = false, isLoading = false, curPage = 1, forceState = 0, bottomGap = 1000, autoLoadNum = -1, nextIndex = 0, stopScroll = false, clickMode = false;
  5256. var openInNewTab = 0;
  5257.  
  5258. function changeStop(stop) {
  5259. isPause = stop;
  5260. [].forEach.call(document.querySelectorAll(".pagetual_pageBar,#pagetual-sideController"), bar => {
  5261. if (isPause) {
  5262. bar.classList.add("stop");
  5263. } else {
  5264. bar.classList.remove("stop");
  5265. }
  5266. });
  5267. }
  5268.  
  5269. function changeHideBar(hide) {
  5270. isHideBar = hide;
  5271. [].forEach.call(document.querySelectorAll(".pagetual_pageBar"), bar => {
  5272. if (isHideBar) {
  5273. bar.classList.add("hide");
  5274. } else {
  5275. bar.classList.remove("hide");
  5276. }
  5277. });
  5278. }
  5279.  
  5280. function isInViewPort(element) {
  5281. if (!getBody(document).contains(element)) return false;
  5282. if (_unsafeWindow.getComputedStyle(element).display == "none") return false;
  5283. const viewWidth = window.innerWidth || document.documentElement.clientWidth;
  5284. const viewHeight = window.innerHeight || document.documentElement.clientHeight;
  5285. const {
  5286. top,
  5287. right,
  5288. bottom,
  5289. left,
  5290. } = element.getBoundingClientRect();
  5291.  
  5292. return (
  5293. top >= 0 &&
  5294. left >= 0 &&
  5295. right <= viewWidth + 1 &&
  5296. top <= viewHeight * (ruleParser.curSiteRule.rate || rulesData.rate || 1)
  5297. );
  5298. }
  5299.  
  5300. function getPageBar() {
  5301. let preBar = null, nextBar = null;
  5302. let pageBars = [].slice.call(document.querySelectorAll(".pagetual_pageBar"));
  5303. for (let i = 0; i < pageBars.length; i++) {
  5304. let pageBar = pageBars[i];
  5305. if (!pageBar || !getBody(document).contains(pageBar)) continue;
  5306. let {
  5307. top,
  5308. right,
  5309. bottom,
  5310. left,
  5311. } = pageBar.getBoundingClientRect();
  5312. if (top > 500) {
  5313. nextBar = pageBar;
  5314. preBar = (i - 1 >= 0 ? pageBars[i - 1] : null);
  5315. if (pageBar && getBody(document).contains(pageBar)) {
  5316. let {
  5317. top,
  5318. right,
  5319. bottom,
  5320. left,
  5321. } = pageBar.getBoundingClientRect();
  5322. if (top < -500) {
  5323. preBar = pageBar;
  5324. } else preBar = (i - 2 >= 0 ? pageBars[i - 2] : null);
  5325. }
  5326. break;
  5327. }
  5328. }
  5329. if (!nextBar) preBar = pageBars[pageBars.length - 2];
  5330. return {preBar: preBar, nextBar: nextBar};
  5331. }
  5332.  
  5333. var urlChanged = false;
  5334. var urlchangeHandler = e => {
  5335. if (ruleParser && ruleParser.curSiteRule && ruleParser.curSiteRule.listenUrlChange == false) return;
  5336. isPause = true;
  5337. setTimeout(() => {
  5338. lastActiveUrl = location.href;
  5339. if (location.href == configPage[0]) {
  5340. location.reload();
  5341. } else {
  5342. setTimeout(() => {
  5343. if (guidePage.test(location.href.slice(0, 250))) {
  5344. if (typeof JSONEditor !== 'undefined') {
  5345. createEdit();
  5346. } else {
  5347. window.onload = e => {
  5348. createEdit();
  5349. }
  5350. }
  5351. } else {
  5352. urlChanged = true;
  5353. if (!ruleParser.nextLinkHref) {
  5354. isLoading = false;
  5355. }
  5356. }
  5357. }, 500);
  5358. }
  5359. }, 1);
  5360. };
  5361. window.addEventListener('pagetual_pushState', urlchangeHandler);
  5362. /*var _wr = function(type) {
  5363. var orig = history[type];
  5364. return function() {
  5365. var rv = orig.apply(this, arguments);
  5366. var e = new Event('pagetual_' + type);
  5367. e.arguments = arguments;
  5368. window.dispatchEvent(e);
  5369. return rv;
  5370. };
  5371. };
  5372. history.pushState = _wr('pushState');*/
  5373.  
  5374. function listenUrl() {
  5375. var prevState = window.location.pathname + window.location.search;
  5376. var checkUrlTime = 100;
  5377. var checkUrlTimer;
  5378. var checkFunc = () => {
  5379. if (forceState == 1) return;
  5380. if (checkUrlTime < 5000) {
  5381. checkUrlTime += checkUrlTime>>1;
  5382. }
  5383. clearTimeout(checkUrlTimer);
  5384. checkUrlTimer = setTimeout(checkFunc, checkUrlTime);
  5385. if (document.hidden) return;
  5386. let url = window.location.pathname + window.location.search;
  5387. if (prevState !== url && window.location.href != ruleParser.historyUrl) {
  5388. checkUrlTime = 2000;
  5389. prevState = url;
  5390. var e = new Event('pagetual_pushState');
  5391. e.arguments = arguments;
  5392. window.dispatchEvent(e);
  5393. }
  5394. };
  5395. checkUrlTimer = setTimeout(checkFunc, checkUrlTime);
  5396.  
  5397. document.addEventListener("click", e => {
  5398. checkUrlTime = 100;
  5399. clearTimeout(checkUrlTimer);
  5400. checkUrlTimer = setTimeout(checkFunc, checkUrlTime);
  5401. });
  5402. }
  5403.  
  5404. function distToBottom () {
  5405. let scrolly = window.scrollY;
  5406. let windowHeight = window.innerHeight || document.documentElement.clientHeight;
  5407. let scrollH = Math.max(document.documentElement.scrollHeight, getBody(document).scrollHeight);
  5408. return scrollH - scrolly - windowHeight;
  5409. }
  5410.  
  5411. let checkLoadMore, scrollHandler, clickToResetHandler, dblclickHandler, keydownHandler, hashchangeHandler, manualModeKeyHandler, pagetualNextHandler, keyupHandler;
  5412. function initListener () {
  5413. clearInterval(checkLoadMore);
  5414. document.removeEventListener('scroll', scrollHandler, true);
  5415. document.removeEventListener('wheel', scrollHandler, true);
  5416. document.removeEventListener('dblclick', dblclickHandler);
  5417. document.removeEventListener('keydown', keydownHandler);
  5418. window.removeEventListener('hashchange', hashchangeHandler, false);
  5419. document.removeEventListener('keydown', manualModeKeyHandler);
  5420. document.removeEventListener('pagetual.next', pagetualNextHandler, false);
  5421. document.removeEventListener('keyup', keyupHandler);
  5422. let loadmoreBtn, loadingMore = true, lastScroll = 0, checkLoadMoreTimes = 0;
  5423. if (!ruleParser.curSiteRule.singleUrl) {
  5424. if (ruleParser.curSiteRule.loadMore) {
  5425. loadingMore = false;
  5426. }
  5427. } else {
  5428. checkLoadMore = setInterval(() => {
  5429. loadmoreBtn = getLoadMore(document);
  5430. if (loadmoreBtn && isVisible(loadmoreBtn, _unsafeWindow)) {
  5431. loadingMore = false;
  5432. clearInterval(checkLoadMore);
  5433. } else if (checkLoadMoreTimes++ > 10) {
  5434. clearInterval(checkLoadMore);
  5435. }
  5436. }, 1000);
  5437. }
  5438. clickMode = typeof ruleParser.curSiteRule.clickMode == 'undefined' ? rulesData.clickMode : ruleParser.curSiteRule.clickMode;
  5439. let clickNext = async () => {
  5440. let nextLink = ruleParser.nextLinkHref;
  5441. if (!nextLink) return;
  5442. let isJs = /^(javascript|#)/.test(nextLink.replace(location.href, ""));
  5443. if (isJs) {
  5444. let nextBtn = await ruleParser.getNextLink(document);
  5445. if (nextBtn) emuClick(nextBtn);
  5446. } else {
  5447. window.location.href = nextLink;
  5448. }
  5449. };
  5450. let checkScrollReach = () => {
  5451. let dist = distToBottom();
  5452. if (clickMode) {
  5453. if (dist < 10) {
  5454. clickNext();
  5455. }
  5456. } else if (dist < bottomGap) {
  5457. nextPage();
  5458. }
  5459. };
  5460. scrollHandler = e => {
  5461. if (urlChanged && !isLoading) {
  5462. ruleParser.initPage(() => {});
  5463. urlChanged = false;
  5464. }
  5465. if (isPause) return;
  5466. if (!loadingMore) {
  5467. loadmoreBtn = getLoadMore(document, loadmoreBtn);
  5468. if (loadmoreBtn) {
  5469. if (isInViewPort(loadmoreBtn)) {
  5470. emuClick(loadmoreBtn);
  5471. loadingMore = true;
  5472. setTimeout(() => {loadingMore = false}, 200);
  5473. }
  5474. } else {
  5475. loadingMore = true;
  5476. setTimeout(() => {loadingMore = false}, 200);
  5477. }
  5478. }
  5479. if (!isLoading && !stopScroll) {
  5480. checkScrollReach();
  5481. }
  5482. ruleParser.changeVisibility();
  5483. if (ruleParser.curSiteRule.lockScroll) {
  5484. let curScroll = getBody(document).scrollTop || document.documentElement.scrollTop;
  5485. if (isLoading && Math.abs(lastScroll - curScroll) > 350) {
  5486. getBody(document).scrollTop = lastScroll;
  5487. document.documentElement.scrollTop = lastScroll;
  5488. } else {
  5489. lastScroll = curScroll;
  5490. }
  5491. }
  5492. };
  5493. dblclickHandler = e => {
  5494. if (forceState == 1 || /^(INPUT|TEXTAREA|SELECT)$/i.test(e.target.nodeName)) return;
  5495. if (!rulesData.dbClick2StopKey) {
  5496. if ((rulesData.dbClick2StopCtrl && !e.ctrlKey) ||
  5497. (rulesData.dbClick2StopAlt && !e.altKey) ||
  5498. (rulesData.dbClick2StopShift && !e.shiftKey) ||
  5499. (rulesData.dbClick2StopMeta && !e.metaKey)) {
  5500. return;
  5501. }
  5502. }
  5503. if (!/^BODY$/i.test(e.target.nodeName) && e.target.className !== 'pagetual_pageBar') {
  5504. let selStr = document.getSelection().toString();
  5505. if (selStr && selStr.trim()) {
  5506. return;
  5507. }
  5508. }
  5509. if (rulesData.dbClick2Stop && (ruleParser.nextLinkHref || loadmoreBtn)) {
  5510. setTimeout(() => {
  5511. if (rulesData.hideBarButNoStop || rulesData.hideBar) {
  5512. changeHideBar(!isHideBar);
  5513. }
  5514. if (!rulesData.hideBarButNoStop) {
  5515. changeStop(!isPause);
  5516. showTips(i18n(isPause ? "disable" : "enable"));
  5517. }
  5518. if (!isPause) {
  5519. checkScrollReach();
  5520. }
  5521. }, 10);
  5522. }
  5523. };
  5524. document.addEventListener('dblclick', dblclickHandler);
  5525. clickToResetHandler = e => {
  5526. if (!ruleParser.nextLinkHref) isLoading = false;
  5527. };
  5528. document.addEventListener('click', clickToResetHandler);
  5529. if (rulesData.dbClick2StopKey) {
  5530. keydownHandler = e => {
  5531. if ((rulesData.dbClick2StopCtrl && !e.ctrlKey) ||
  5532. (rulesData.dbClick2StopAlt && !e.altKey) ||
  5533. (rulesData.dbClick2StopShift && !e.shiftKey) ||
  5534. (rulesData.dbClick2StopMeta && !e.metaKey)) {
  5535. return;
  5536. }
  5537. if (document.activeElement &&
  5538. (/^(INPUT|TEXTAREA)$/i.test(document.activeElement.nodeName) ||
  5539. document.activeElement.contentEditable == 'true')) {
  5540. return;
  5541. }
  5542. var key = e.key.toLowerCase();
  5543. if (rulesData.dbClick2StopKey.toLowerCase() == key) {
  5544. forceState = (forceState == 1 ? 0 : 1);
  5545. showTips(i18n(forceState == 1 ? "disableSiteTips" : "enableSiteTips"));
  5546. if (!ruleParser.curSiteRule.url) {
  5547. storage.setItem("forceState_" + location.host, forceState);
  5548. location.reload();
  5549. }
  5550. }
  5551. };
  5552. document.addEventListener('keydown', keydownHandler);
  5553. }
  5554. if (ruleParser.curSiteRule.listenHashChange) {
  5555. hashchangeHandler = () => {
  5556. isPause = true;
  5557. urlChanged = true;
  5558. if (!ruleParser.nextLinkHref) isLoading = false;
  5559. };
  5560. window.addEventListener('hashchange', hashchangeHandler, false);
  5561. }
  5562. let manualMode = typeof ruleParser.curSiteRule.manualMode == 'undefined' ? rulesData.manualMode : ruleParser.curSiteRule.manualMode;
  5563. if (manualMode) {
  5564. manualModeKeyHandler = e => {
  5565. if (document.activeElement &&
  5566. (/^(INPUT|TEXTAREA)$/i.test(document.activeElement.nodeName) ||
  5567. document.activeElement.contentEditable == 'true')) {
  5568. return;
  5569. }
  5570. if (e.keyCode == 39) {
  5571. clickNext();
  5572. } else if (e.keyCode == 37) {
  5573. history.back();
  5574. }
  5575. };
  5576. document.addEventListener('keydown', manualModeKeyHandler);
  5577. pagetualNextHandler = () => {
  5578. clickNext();
  5579. };
  5580. document.addEventListener('pagetual.next', pagetualNextHandler, false);
  5581. return;
  5582. }
  5583. if (rulesData.arrowToScroll) {
  5584. keyupHandler = e => {
  5585. if (document.activeElement &&
  5586. (/^(INPUT|TEXTAREA)$/i.test(document.activeElement.nodeName) ||
  5587. document.activeElement.contentEditable == 'true')) {
  5588. return;
  5589. }
  5590. if (e.keyCode == 39) {
  5591. let nextPageBar=getPageBar().nextBar;
  5592. if (nextPageBar) {
  5593. scrollToPageBar(nextPageBar);
  5594. } else {
  5595. let scrollTop = getBody(document).scrollTop || document.documentElement.scrollTop;
  5596. window.scrollTo({ top: scrollTop + (window.innerHeight || document.documentElement.clientHeight), behavior: 'smooth'});
  5597. }
  5598. } else if (e.keyCode == 37) {
  5599. let prePageBar = getPageBar().preBar;
  5600. if (prePageBar) {
  5601. scrollToPageBar(prePageBar);
  5602. } else {
  5603. let scrollTop = getBody(document).scrollTop || document.documentElement.scrollTop;
  5604. window.scrollTo({ top: scrollTop - (window.innerHeight || document.documentElement.clientHeight), behavior: 'smooth'});
  5605. }
  5606. }
  5607. };
  5608. document.addEventListener('keyup', keyupHandler);
  5609. }
  5610. if (!ruleParser.curSiteRule.wheel) {
  5611. document.addEventListener('scroll', scrollHandler, true);
  5612. }
  5613. document.addEventListener('wheel', scrollHandler, true);
  5614. }
  5615.  
  5616. function showTips(content, wordColor, backColor, href) {
  5617. initView();
  5618. getBody(document).appendChild(tipsWords);
  5619. tipsWords.style.color = wordColor || 0xFFFFFF;
  5620. tipsWords.style.backgroundColor = backColor || 0x000;
  5621. let time = 1500;
  5622. if (href) {
  5623. time = 3500;
  5624. tipsWords.innerHTML = createHTML(`<a href='${href}'>${content}</a>`);
  5625. tipsWords.style.pointerEvents = 'all';
  5626. } else {
  5627. tipsWords.innerHTML = createHTML(content);
  5628. }
  5629. tipsWords.style.marginLeft = -tipsWords.offsetWidth / 2 + "px";
  5630. setTimeout(() => {
  5631. tipsWords.style.marginLeft = -tipsWords.offsetWidth / 2 + "px";
  5632. }, 0);
  5633. setTimeout(() => {
  5634. tipsWords.style.opacity = 0.8;
  5635. setTimeout(() => {
  5636. tipsWords.style.opacity = 0;
  5637. tipsWords.style.pointerEvents = '';
  5638. }, time);
  5639. }, 1);
  5640. }
  5641.  
  5642. function getLoadMore(doc, loadmoreBtn) {
  5643. if (!loadmoreBtn || !getBody(doc).contains(loadmoreBtn) || /less/.test(loadmoreBtn.innerText)) loadmoreBtn = null;
  5644. if (!ruleParser.curSiteRule.singleUrl && !ruleParser.curSiteRule.loadMore) return null;
  5645. if (loadmoreBtn) return loadmoreBtn;
  5646. let btnSel = ruleParser.curSiteRule.loadMore || ".loadMore,.LoadMore,.load-more,.button-show-more,button[data-testid='more-results-button'],#btn_preview_remain";
  5647. if (btnSel) {
  5648. loadmoreBtn = getElement(btnSel, doc);
  5649. }
  5650. if (!loadmoreBtn) {
  5651. let buttons = doc.querySelectorAll("input,button,a,div[onclick]"), loadmoreReg = /^\s*(加载更多|加載更多|load\s*more|もっと読み込む)[.…]*\s*$/i;
  5652. for (let i = 0; i < buttons.length; i++) {
  5653. let button = buttons[i];
  5654. if (button.innerText.length > 20) continue;
  5655. if (button && loadmoreReg.test(button.innerText)) {
  5656. loadmoreBtn = button;
  5657. break;
  5658. }
  5659. }
  5660. }
  5661. if (loadmoreBtn && !ruleParser.curSiteRule.loadMore && loadmoreBtn.dataset.ajax !== "true") {
  5662. let href = loadmoreBtn.getAttribute("href");
  5663. if (href && href != "/" && !/^(javascript|#)/.test(href.replace(location.href, ""))) {
  5664. loadmoreBtn = null;
  5665. }
  5666. }
  5667. if (loadmoreBtn && /less/.test(loadmoreBtn.innerText)) loadmoreBtn = null;
  5668. return loadmoreBtn;
  5669. }
  5670.  
  5671. function scrollToPageBar(bar){
  5672. let yOffset = -20;
  5673. if (typeof ruleParser.curSiteRule.pageBarTop !== 'undefined') {
  5674. yOffset = -ruleParser.curSiteRule.pageBarTop;
  5675. }
  5676. const y = bar.getBoundingClientRect().top + window.pageYOffset + yOffset;
  5677. window.scrollTo({ top: y, behavior: 'smooth'});
  5678. }
  5679.  
  5680. const pageNumReg=/[&\/\?](p=|page[=\/_-]?)\d+|[_-]\d+\./;
  5681. function createPageBar(url) {
  5682. curPage++;
  5683. let posEle = null;
  5684. let scrollH = Math.max(document.documentElement.scrollHeight, getBody(document).scrollHeight);
  5685. let insert = ruleParser.getInsert();
  5686. if (!insert || !insert.parentNode) return;
  5687. posEle = insert;
  5688. while (posEle && !posEle.offsetParent) {
  5689. posEle = posEle.previousElementSibling || posEle.parentNode;
  5690. }
  5691. if (posEle) {
  5692. let actualBottom = getElementBottom(posEle);
  5693. bottomGap = scrollH - actualBottom + (window.innerHeight || document.documentElement.clientHeight) * (ruleParser.curSiteRule.rate || rulesData.rate || 1);
  5694. if (bottomGap < 100) bottomGap = 100;
  5695. } else {
  5696. bottomGap = 1000;
  5697. }
  5698. if (rulesData.opacity == 0 || ruleParser.curSiteRule.pageBar === 0) return null;
  5699. url = url.replace(/#p{.*/, "");
  5700. let example = ruleParser.curSiteRule.insertPos == 2 ? insert.children[0] : (insert.parentNode.children[0] || insert);
  5701. while (example && (/^(SCRIPT|STYLE)$/i.test(example.nodeName) || example.className == "pagetual_pageBar")) {
  5702. example = example.nextElementSibling;
  5703. }
  5704. if (!example || !example.parentNode) example = insert;
  5705. if (example.nodeType != 1) {
  5706. example = example.previousElementSibling || example.parentNode;
  5707. if (!example || example.nodeType != 1) return;
  5708. }
  5709. let exampleStyle = _unsafeWindow.getComputedStyle(example);
  5710. let inTable, inLi;
  5711. if (forceState == 2) {
  5712. inTable = inLi = false;
  5713. } else {
  5714. inTable = /^(TABLE|TBODY)$/i.test(example.parentNode.nodeName) ||
  5715. /^(TR|TBODY)$/i.test(example.nodeName) ||
  5716. exampleStyle.display == "table-row" ||
  5717. (example.nextElementSibling && /^(TR|TBODY)$/i.test(example.nextElementSibling.nodeName));
  5718. inLi = /^LI$/i.test(example.nodeName) || (example.nextElementSibling && /^LI$/i.test(example.nextElementSibling.nodeName));
  5719. }
  5720. let pageBar = document.createElement(inTable ? "tr" : (inLi ? "li" : "div"));
  5721. let upSpan = document.createElement("span");
  5722. let downSpan = document.createElement("span");
  5723. let pageText = document.createElement("a");
  5724. let pageNum;
  5725. pageBar.className = isHideBar ? "pagetual_pageBar hide" : "pagetual_pageBar";
  5726. pageBar.id = "pagetual_pageBar" + curPage;
  5727. pageBar.setAttribute("translate", "no");
  5728. if (isPause) {
  5729. pageBar.classList.add("stop");
  5730. }
  5731. pageBar.style.cssText = pageBarStyle;
  5732. pageBar.title = i18n(isPause ? "enable" : "disable");
  5733. upSpan.innerHTML = upSvg;
  5734. upSpan.children[0].style.cssText = upSvgCSS;
  5735. upSpan.title = i18n("toTop");
  5736. downSpan.innerHTML = downSvg;
  5737. downSpan.children[0].style.cssText = downSvgCSS;
  5738. downSpan.title = i18n("toBottom");
  5739. upSpan.style.cssText = initStyle;
  5740. downSpan.style.cssText = initStyle;
  5741. pageText.href = url;
  5742. pageText.style.cssText = pageTextStyle;
  5743. pageText.title = i18n("current");
  5744. if (openInNewTab == 1) pageText.target = "_blank";
  5745. pageBar.appendChild(upSpan);
  5746. pageBar.appendChild(pageText);
  5747. if (rulesData.pageBarMenu) {
  5748. pageText.addEventListener("click", e => {
  5749. e.stopPropagation();
  5750. if (e.ctrlKey || e.altKey || e.shiftKey || e.metaKey) return;
  5751. e.preventDefault();
  5752. Picker.getInstance().start();
  5753. });
  5754. }
  5755. let touched = false;
  5756. let touchBodyHandler = e => {
  5757. touched = false;
  5758. getBody(document).removeEventListener('touchstart', touchBodyHandler, { passive: false, capture: false });
  5759. };
  5760. pageText.addEventListener("touchstart", e => {
  5761. if (touched) return;
  5762. touched = true;
  5763. pageText.style.pointerEvents = 'none';
  5764. setTimeout(() => {
  5765. pageText.style.pointerEvents = 'all';
  5766. }, 250);
  5767. getBody(document).addEventListener("touchstart", touchBodyHandler, { passive: false, capture: false });
  5768. }, { passive: false, capture: false });
  5769. if (ruleParser.nextTitle) {
  5770. pageText.innerHTML = ruleParser.nextTitle + " ";
  5771. pageText.title = ruleParser.nextTitle;
  5772. }
  5773. if (ruleParser.curSiteRule.pageNum || pageNumReg.test(url)) {
  5774. pageText.innerHTML += i18n("page");
  5775. pageNum = document.createElement("span");
  5776. pageNum.innerHTML = ruleParser.getPageNumFromUrl(url);
  5777. pageNum.className = "pagetual_pageNum";
  5778. pageNum.title = i18n("inputPageNum");
  5779. pageNum.style.cssText = pageTextStyle;
  5780. pageNum.style.cursor = "pointer";
  5781. pageNum.style.color = "";
  5782. pageNum.style.marginLeft = "5px";
  5783. pageNum.addEventListener("click", e => {
  5784. let pageInput = prompt(i18n("inputPageNum"), "1");
  5785. if (pageInput) {
  5786. let pageLink = ruleParser.getLinkByPage(url, pageInput);
  5787. if (pageLink) {
  5788. _GM_openInTab(pageLink, {active:true});
  5789. }
  5790. }
  5791. e.preventDefault();
  5792. e.stopPropagation();
  5793. });
  5794. pageBar.appendChild(pageNum);
  5795. } else {
  5796. pageText.innerHTML += i18n("page") + curPage;
  5797. }
  5798. let preBtn = document.createElement("span");
  5799. preBtn.innerHTML = "∧";
  5800. preBtn.title = i18n("prevPage");
  5801. preBtn.className = "prevScreen";
  5802. preBtn.style.cssText = "display: none;text-align: center;right: unset; float: left; width: 40px; background: rgba(240, 240, 240, 0.8); position: absolute; z-index: 9999999; box-shadow: rgb(0 0 0 / 50%) 0px -5px 5px; border-radius: 20px 20px 0 0; margin-top: -30px; ";
  5803. let nextBtn = document.createElement("span");
  5804. nextBtn.innerHTML = "∨";
  5805. nextBtn.title = i18n("nextPage");
  5806. nextBtn.className = "nextScreen";
  5807. nextBtn.style.cssText = "display: none;text-align: center;right: unset; float: left; width: 40px; background: rgba(240, 240, 240, 0.8); position: absolute; z-index: 9999999; box-shadow: rgb(0 0 0 / 50%) 0px 5px 5px; border-radius: 0 0 20px 20px; margin-top: 30px; ";
  5808. let localPage = curPage;
  5809. preBtn.addEventListener("click", e => {
  5810. e.stopPropagation();
  5811. e.preventDefault();
  5812. let prePageBar = document.querySelector("#pagetual_pageBar" + (localPage - 1));
  5813. if (prePageBar) {
  5814. scrollToPageBar(prePageBar);
  5815. } else {
  5816. let scrollTop = getBody(document).scrollTop || document.documentElement.scrollTop;
  5817. window.scrollTo({ top: scrollTop - (window.innerHeight || document.documentElement.clientHeight), behavior: 'smooth'});
  5818. }
  5819. });
  5820. nextBtn.addEventListener("click", e => {
  5821. e.stopPropagation();
  5822. e.preventDefault();
  5823. let nextPageBar = document.querySelector("#pagetual_pageBar" + (localPage + 1));
  5824. if (nextPageBar) {
  5825. scrollToPageBar(nextPageBar);
  5826. } else {
  5827. scrollH = Math.max(document.documentElement.scrollHeight, getBody(document).scrollHeight);
  5828. window.scrollTo({ top: scrollH || 9999999, behavior: 'smooth'});
  5829. }
  5830. });
  5831. if (!rulesData.hideBarArrow) {
  5832. pageText.insertBefore(preBtn, pageText.firstChild);
  5833. pageText.insertBefore(nextBtn, pageText.firstChild);
  5834. }
  5835. pageBar.appendChild(downSpan);
  5836. if (forceState == 2) {
  5837. pageBar.style.width = "99%";
  5838. } else {
  5839. let parentStyle = _unsafeWindow.getComputedStyle(example.parentNode);
  5840. let parentWidth = example.parentNode.offsetWidth || parseInt(parentStyle.width);
  5841. pageBar.style.width = parentWidth - parseInt(parentStyle.paddingLeft) - parseInt(parentStyle.paddingRight) - 10 + "px";
  5842. pageBar.style.margin = '10px 5px';
  5843. if (parentStyle.display == "grid" || parentStyle.display == "inline-grid") {
  5844. pageBar.style.gridColumn = "1/-1";
  5845. }
  5846. if (inTable) {
  5847. example = (/^(TR|TBODY)$/i.test(example.nodeName)) ? example : example.nextElementSibling || example;
  5848. if (/^TBODY$/i.test(example.nodeName)) example = example.querySelector("tr");
  5849. let nextTr = example;
  5850. while (nextTr && nextTr.children.length == 0) nextTr = nextTr.nextElementSibling;
  5851. if (nextTr) example = nextTr;
  5852. let tdNum = 0;
  5853. if (exampleStyle.display == "table-row") {
  5854. [].forEach.call(example.children, el => {
  5855. tdNum += el.colSpan || 1;
  5856. });
  5857. } else {
  5858. [].forEach.call(example.children, el => {
  5859. if (/^(TD|TH)$/i.test(el.nodeName)) {
  5860. tdNum += el.colSpan || 1;
  5861. }
  5862. });
  5863. }
  5864. pageBar.style.display = "table-row";
  5865. pageBar.style.backgroundColor = "unset";
  5866. pageBar.style.lineHeight = "20px";
  5867. pageBar.style.boxShadow = "";
  5868. //pageBar.style.height="35px";
  5869. let td = document.createElement("td");
  5870. td.colSpan = tdNum || 1;
  5871. let inTd = document.createElement("div");
  5872. inTd.style.backgroundColor = "rgb(240 240 240 / 80%)";
  5873. inTd.style.borderRadius = "20px";
  5874. inTd.style.padding = "0 0";
  5875. inTd.style.margin = "0";
  5876. inTd.style.lineHeight = "20px";
  5877. inTd.style.textAlign = "center";
  5878. inTd.style.boxShadow = "rgb(0 0 0 / 67%) 0px 0px 10px 0px";
  5879. inTd.appendChild(upSpan);
  5880. inTd.appendChild(pageText);
  5881. if (pageNum) inTd.appendChild(pageNum);
  5882. inTd.appendChild(downSpan);
  5883. td.appendChild(inTd);
  5884. pageBar.appendChild(td);
  5885. } else if(inLi) {
  5886. example = /^LI$/i.test(example.nodeName) ? example : example.nextElementSibling || example;
  5887. pageBar.style.display = getComputedStyle(example).display;
  5888. pageBar.style.backgroundColor = "unset";
  5889. pageBar.style.lineHeight = "20px";
  5890. pageBar.style.boxShadow = "";
  5891. pageBar.style.maxWidth = "unset";
  5892. pageBar.style.flex = "auto";
  5893. //pageBar.style.height="35px";
  5894. let td = document.createElement("td");
  5895. td.colSpan = example.children.length;
  5896. td.style.width = '100%';
  5897. let inTd = document.createElement("div");
  5898. inTd.style.backgroundColor = "rgb(240 240 240 / 80%)";
  5899. inTd.style.borderRadius = "20px";
  5900. inTd.style.margin = "0"
  5901. inTd.style.padding = "0 0";
  5902. inTd.style.textAlign = "center";
  5903. inTd.style.minWidth = "150px";
  5904. inTd.appendChild(upSpan);
  5905. inTd.appendChild(pageText);
  5906. inTd.style.width = 'calc(100% - 20px)';
  5907. inTd.style.boxShadow = "rgb(0 0 0 / 67%) 0px 0px 10px 0px";
  5908. if (pageNum) inTd.appendChild(pageNum);
  5909. inTd.appendChild(downSpan);
  5910. if (pageBar.style.display === 'table-row') {
  5911. td.appendChild(inTd);
  5912. pageBar.appendChild(td);
  5913. } else {
  5914. inTd.style.width = '100%';
  5915. pageBar.appendChild(inTd);
  5916. }
  5917. }
  5918. }
  5919.  
  5920. upSpan.addEventListener("click", e => {
  5921. getBody(document).scrollTop = 0;
  5922. document.documentElement.scrollTop = 0;
  5923. e.preventDefault();
  5924. e.stopPropagation();
  5925. });
  5926. downSpan.addEventListener("click", e => {
  5927. changeStop(true);
  5928. pageBar.title = i18n(isPause ? "enable" : "disable");
  5929. scrollH=Math.max(document.documentElement.scrollHeight, getBody(document).scrollHeight);
  5930. getBody(document).scrollTop = scrollH || 9999999;
  5931. document.documentElement.scrollTop = scrollH || 9999999;
  5932. e.preventDefault();
  5933. e.stopPropagation();
  5934. });
  5935. pageBar.addEventListener("click", e => {
  5936. changeStop(!isPause);
  5937. pageBar.title = i18n(isPause ? "enable" : "disable");
  5938. });
  5939. ruleParser.insertElement(pageBar);
  5940. if (ruleParser.curSiteRule.pageBar && ruleParser.curSiteRule.pageBar !== 0) {
  5941. try {
  5942. ((typeof _unsafeWindow.pagetualPageBar == 'undefined') ? Function("pageBar",'"use strict";' + ruleParser.curSiteRule.pageBar) : _unsafeWindow.pagetualPageBar)(pageBar);
  5943. } catch(e) {
  5944. debug(e);
  5945. }
  5946. }
  5947.  
  5948. return pageBar;
  5949. }
  5950.  
  5951. function emuClick(btn) {
  5952. let orgHref = btn.getAttribute('href');
  5953. if (orgHref && orgHref != "#") {
  5954. btn.setAttribute('href', orgHref.replace(/#$/,""));
  5955. }
  5956. if (!PointerEvent) return btn.click();
  5957. let eventParam = {
  5958. isTrusted: true,
  5959. altKey: false,
  5960. azimuthAngle: 0,
  5961. bubbles: true,
  5962. button: 0,
  5963. buttons: 0,
  5964. clientX: 1,
  5965. clientY: 1,
  5966. cancelBubble: false,
  5967. cancelable: true,
  5968. composed: true,
  5969. ctrlKey: false,
  5970. defaultPrevented: false,
  5971. detail: 1,
  5972. eventPhase: 2,
  5973. fromElement: null,
  5974. height: 1,
  5975. isPrimary: false,
  5976. metaKey: false,
  5977. pointerId: 1,
  5978. pointerType: "mouse",
  5979. pressure: 0,
  5980. relatedTarget: null,
  5981. returnValue: true,
  5982. shiftKey: false,
  5983. toElement: null,
  5984. twist: 0,
  5985. which: 1
  5986. };
  5987. let mouseEvent = new PointerEvent("mousedown", eventParam);
  5988. btn.dispatchEvent(mouseEvent);
  5989. mouseEvent = new PointerEvent("mouseup", eventParam);
  5990. btn.dispatchEvent(mouseEvent);
  5991. let dispatchTouchEvent = (ele, type) => {
  5992. let touchEvent;
  5993. try {
  5994. touchEvent = document.createEvent('TouchEvent')
  5995. touchEvent.initTouchEvent(type, true, true)
  5996. } catch (err) {
  5997. try {
  5998. touchEvent = document.createEvent('UIEvent')
  5999. touchEvent.initUIEvent(type, true, true)
  6000. } catch (err) {
  6001. touchEvent = document.createEvent('Event')
  6002. touchEvent.initEvent(type, true, true)
  6003. }
  6004. }
  6005. if (touchEvent) {
  6006. try {
  6007. touchEvent.targetTouches = [{
  6008. pageX: 1,
  6009. pageY: 1,
  6010. clientX: 1,
  6011. clientY: 1,
  6012. target: btn
  6013. }];
  6014. touchEvent.touches = [{
  6015. pageX: 1,
  6016. pageY: 1,
  6017. clientX: 1,
  6018. clientY: 1,
  6019. target: btn
  6020. }];
  6021. touchEvent.changedTouches = [{
  6022. pageX: 1,
  6023. pageY: 1,
  6024. clientX: 1,
  6025. clientY: 1,
  6026. target: btn
  6027. }];
  6028. } catch (err) {}
  6029. ele.dispatchEvent(touchEvent);
  6030. }
  6031. }
  6032. dispatchTouchEvent(btn, "touchstart");
  6033. dispatchTouchEvent(btn, "touchend");
  6034.  
  6035. btn.click();
  6036. if (orgHref && orgHref != "#") {
  6037. setTimeout(() => btn.setAttribute('href', orgHref), 0);
  6038. }
  6039. }
  6040.  
  6041. var failFromIframe = 0;
  6042. var inCors = false;
  6043. var checkRemoveIntv;
  6044. function requestFromIframe(url, callback){
  6045. if (location.protocol === 'https:' && !/^https:/.test(url)) {
  6046. showTips(i18n("noValidContent"), "", "", url);
  6047. }
  6048. url = url.indexOf('=') == -1 ? url.replace(/#[^#]*/,"") : url;
  6049. let iframe = document.createElement('iframe');
  6050. iframe.name = 'pagetual-iframe';
  6051. iframe.width = '100%';
  6052. iframe.height = '1000';
  6053. iframe.frameBorder = '0';
  6054. if (ruleParser.curSiteRule.sandbox != false) {
  6055. iframe.sandbox = "allow-same-origin allow-scripts allow-popups allow-forms";
  6056. }
  6057. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;flex:0;opacity:0!important;pointer-events:none!important;position:fixed;top:0px;left:0px;z-index:-2147483647;';
  6058. let waitTime = 100, checkEval;
  6059. if (ruleParser.curSiteRule.waitElement) {
  6060. checkEval = doc => {
  6061. return ruleParser.waitElement(doc);
  6062. };
  6063. } else if (ruleParser.curSiteRule.wait) {
  6064. if (isNaN(ruleParser.curSiteRule.wait)) {
  6065. try {
  6066. checkEval = (typeof _unsafeWindow.pagetualWait == 'undefined') ? Function("doc",'"use strict";' + ruleParser.curSiteRule.wait) : _unsafeWindow.pagetualWait;
  6067. } catch(e) {
  6068. debug(e);
  6069. }
  6070. } else {
  6071. waitTime = ruleParser.curSiteRule.wait;
  6072. }
  6073. }
  6074. if (checkRemoveIntv) clearInterval(checkRemoveIntv);
  6075. checkRemoveIntv = setInterval(() => {
  6076. if (!iframe || !getBody(document).contains(iframe)) {
  6077. clearInterval(checkRemoveIntv);
  6078. loadPageOver();
  6079. }
  6080. }, 500);
  6081. let loadedHandler = e => {
  6082. if (e.data != 'pagetual-iframe:DOMLoaded' && e.type != 'load') return;
  6083. clearInterval(checkRemoveIntv);
  6084. window.removeEventListener('message', loadedHandler, false);
  6085. iframe.removeEventListener('load', loadedHandler, false);
  6086. let tryTimes = 0;
  6087. function checkIframe() {
  6088. if (urlChanged || isPause) {
  6089. return callback(false, false);
  6090. }
  6091. try {
  6092. let doc = iframe.contentDocument || iframe.contentWindow.document;
  6093. let base = doc.querySelector("base");
  6094. ruleParser.basePath = base ? base.href : url;
  6095. let eles = ruleParser.getPageElement(doc, iframe.contentWindow);
  6096. if (checkEval && !checkEval(doc)) {
  6097. setTimeout(() => {
  6098. checkIframe();
  6099. }, waitTime);
  6100. return;
  6101. } else if (eles && eles.length > 0) {
  6102. callback(doc, eles);
  6103. } else if (tryTimes++ < 100) {
  6104. setTimeout(() => {
  6105. checkIframe();
  6106. }, waitTime);
  6107. return;
  6108. } else {
  6109. if (failFromIframe++ > 2) {
  6110. failFromIframe = 0;
  6111. debug("Stop as failFromIframe");
  6112. isPause = true;
  6113. callback(false, false);
  6114. } else {
  6115. showTips(i18n("noValidContent"), "", "", url);
  6116. callback(false, false);
  6117. }
  6118. }
  6119. } catch(e) {
  6120. inCors = true;
  6121. if (forceState === 3) {
  6122. debug("Stop as cors");
  6123. isPause = true;
  6124. }
  6125. if (!ruleParser.curSiteRule.pageElement) {
  6126. ruleParser.curSiteRule.pageElement = allOfBody;
  6127. ruleParser.getInsert(true);
  6128. }
  6129. ruleParser.curSiteRule.action = 0;
  6130. ruleParser.nextLinkHref = url;
  6131. callback(false, false);
  6132. nextPage();
  6133. }
  6134. if (iframe && iframe.parentNode) iframe.parentNode.removeChild(iframe);
  6135. }
  6136. setTimeout(() => {
  6137. checkIframe();
  6138. }, waitTime);
  6139. };
  6140. window.addEventListener('message', loadedHandler, false);
  6141. iframe.addEventListener('load', loadedHandler, false);
  6142. iframe.src = url;
  6143. try {
  6144. getBody(document).appendChild(iframe);
  6145. } catch (e) {
  6146. return callback(false, false);
  6147. }
  6148. }
  6149.  
  6150. var emuIframe, lastActiveUrl, orgContent, meetCors = false;
  6151. function emuPage(callback) {
  6152. let orgPage = null, preContent = null, iframeDoc, times = 0, loadmoreBtn, pageEle, nextLink, loadmoreEnd = false, waitTimes = 80, changed = false;
  6153. function returnFalse(log) {
  6154. debug(log);
  6155. isPause = true;
  6156. callback(false, false);
  6157. if (emuIframe && emuIframe.parentNode) {
  6158. emuIframe.parentNode.removeChild(emuIframe);
  6159. emuIframe = null;
  6160. }
  6161. }
  6162. async function checkPage() {
  6163. if (isPause) return loadPageOver();
  6164. try {
  6165. iframeDoc = emuIframe.contentDocument || emuIframe.contentWindow.document;
  6166. } catch(e) {
  6167. returnFalse("Stop as cors");
  6168. return;
  6169. }
  6170.  
  6171. let waitTime = 200, checkEval;
  6172. if (ruleParser.curSiteRule.waitElement) {
  6173. checkEval = doc => {
  6174. return ruleParser.waitElement(doc);
  6175. };
  6176. } else if(ruleParser.curSiteRule.wait) {
  6177. if (isNaN(ruleParser.curSiteRule.wait)) {
  6178. try {
  6179. checkEval = (typeof _unsafeWindow.pagetualWait == 'undefined') ? Function("doc", '"use strict";' + ruleParser.curSiteRule.wait) : _unsafeWindow.pagetualWait;
  6180. } catch(e) {
  6181. debug(e);
  6182. }
  6183. } else {
  6184. waitTime = ruleParser.curSiteRule.wait;
  6185. }
  6186. }
  6187.  
  6188. if (!orgPage) {
  6189. if (!loadmoreEnd) {
  6190. loadmoreBtn = getLoadMore(iframeDoc);
  6191. if (loadmoreBtn && isVisible(loadmoreBtn, iframeDoc.defaultView)) {
  6192. emuClick(loadmoreBtn);
  6193. let intv = setInterval(() => {
  6194. loadmoreBtn = getLoadMore(iframeDoc);
  6195. if (!loadmoreBtn || !getBody(document).contains(loadmoreBtn) || !isVisible(loadmoreBtn, iframeDoc.defaultView)) {
  6196. clearInterval(intv);
  6197. loadmoreEnd = true;
  6198. setTimeout(() => {
  6199. checkPage();
  6200. }, 500);
  6201. } else if (isInViewPort(loadmoreBtn)) {
  6202. emuClick(loadmoreBtn);
  6203. }
  6204. }, 200);
  6205. return;
  6206. } else {
  6207. loadmoreEnd = true;
  6208. }
  6209. }
  6210. if (checkEval && !checkEval(iframeDoc)) {
  6211. waitTimes = 50;
  6212. setTimeout(() => {
  6213. checkPage();
  6214. }, waitTime);
  6215. return;
  6216. } else {
  6217. nextLink = await ruleParser.getNextLink(iframeDoc);
  6218. pageEle = ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true);
  6219. if (!pageEle || pageEle.length==0 || !nextLink) {
  6220. if (waitTimes-- > 0) {
  6221. setTimeout(() => {
  6222. checkPage();
  6223. }, waitTime);
  6224. return;
  6225. }
  6226. }
  6227. }
  6228. if (!pageEle || pageEle.length == 0) {
  6229. returnFalse("Stop as no page when emu");
  6230. return;
  6231. }
  6232. if (/^UL$/i.test(pageEle[0].nodeName)) pageEle = pageEle[0].children;
  6233. pageEle = pageEle[parseInt(pageEle.length / 2)];
  6234. while(pageEle && !pageEle.offsetParent) {
  6235. if (pageEle.nextElementSibling) pageEle = pageEle.nextElementSibling;
  6236. else break;
  6237. }
  6238. if (ruleParser.curSiteRule.singleUrl && orgContent != pageEle.innerHTML) {
  6239. orgContent = pageEle.innerHTML;
  6240. if (waitTimes-- > 0) {
  6241. setTimeout(() => {
  6242. checkPage();
  6243. }, waitTime);
  6244. return;
  6245. }
  6246. }
  6247. orgPage = pageEle;
  6248. if (nextLink) {
  6249. if (/^IMG$/i.test(orgPage.nodeName)) {
  6250. if (!ruleParser.curSiteRule.lazyImgSrc) ruleParser.curSiteRule.lazyImgSrc = "0";
  6251. if (orgPage.src) {
  6252. orgContent = orgPage.src;
  6253. } else {
  6254. setTimeout(() => {
  6255. checkPage();
  6256. }, 500);
  6257. return;
  6258. }
  6259. } else {
  6260. orgContent = orgPage.innerHTML;
  6261. }
  6262. preContent = orgContent;
  6263. if (!isVisible(nextLink, iframeDoc.defaultView)) {
  6264. returnFalse("Stop as next hide when emu");
  6265. } else {
  6266. emuClick(nextLink);
  6267. setTimeout(() => {
  6268. checkPage();
  6269. }, 500);
  6270. }
  6271. } else {
  6272. returnFalse("Stop as no next when emu");
  6273. }
  6274. return;
  6275. }
  6276. if (!ruleParser.checkStopSign(nextLink, iframeDoc)) return returnFalse("Stop as stopSign");;
  6277. if (times++ > 200) {
  6278. returnFalse("Stop as timeout when emu");
  6279. return;
  6280. }
  6281. let eles = ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true), checkItem;
  6282. if (eles && eles.length > 0) {
  6283. checkItem = eles;
  6284. if (/^UL$/i.test(eles[0].nodeName)) checkItem = eles[0].children;
  6285. checkItem = checkItem[parseInt(checkItem.length / 2)];
  6286. while(checkItem && !checkItem.offsetParent) {
  6287. if (checkItem.nextElementSibling) checkItem = checkItem.nextElementSibling;
  6288. else break;
  6289. }
  6290. }
  6291. if (!checkItem || (checkEval && !checkEval(iframeDoc))) {
  6292. if (checkEval) times = 0;
  6293. setTimeout(() => {
  6294. checkPage();
  6295. }, waitTime);
  6296. } else {
  6297. let checkInner;
  6298. if (/^IMG$/i.test(checkItem.nodeName)) {
  6299. if (checkItem.src) {
  6300. checkInner = checkItem.src;
  6301. } else {
  6302. setTimeout(() => {
  6303. checkPage();
  6304. }, waitTime);
  6305. return;
  6306. }
  6307. } else {
  6308. checkInner = checkItem.innerHTML;
  6309. }
  6310. if (orgPage != checkItem || checkInner != preContent) {
  6311. changed = true;
  6312. orgPage = checkItem;
  6313. preContent = checkInner;
  6314. setTimeout(() => {
  6315. checkPage();
  6316. }, waitTime);
  6317. } else if (changed) {
  6318. times = 0;
  6319. if (orgContent == preContent && (ruleParser.curSiteRule.singleUrl || ruleParser.curSiteRule.stopSame)) {
  6320. returnFalse("Stop as same content");
  6321. } else {
  6322. orgContent = preContent;
  6323. callback(iframeDoc, eles);
  6324. }
  6325. } else {
  6326. if (times % 10 === 1) {
  6327. if (!nextLink || !nextLink.offsetParent) {
  6328. nextLink = await ruleParser.getNextLink(iframeDoc);
  6329. }
  6330. if (nextLink) {
  6331. emuClick(nextLink);
  6332. }
  6333. }
  6334. setTimeout(() => {
  6335. checkPage();
  6336. }, waitTime);
  6337. }
  6338. }
  6339. }
  6340. if (!emuIframe) {
  6341. let loaded = false;
  6342. emuIframe = document.createElement('iframe');
  6343. emuIframe.name = 'pagetual-iframe';
  6344. let notSetSandbox = typeof ruleParser.curSiteRule.sandbox == 'undefined';
  6345. if (notSetSandbox || ruleParser.curSiteRule.sandbox == true) {
  6346. emuIframe.sandbox = "allow-same-origin allow-scripts allow-popups allow-forms";
  6347. } else if (ruleParser.curSiteRule.sandbox) {
  6348. emuIframe.sandbox = ruleParser.curSiteRule.sandbox;
  6349. }
  6350. emuIframe.width = '100%';
  6351. emuIframe.height = '100%';
  6352. emuIframe.frameBorder = '0';
  6353. emuIframe.style.cssText = 'margin:0!important;padding:0!important;flex:0;opacity:0!important;pointer-events:none!important;position:fixed;top:0px;left:0px;z-index:-2147483647;';
  6354. emuIframe.addEventListener("load", e => {
  6355. setTimeout(() => {
  6356. try {
  6357. iframeDoc = emuIframe.contentDocument || emuIframe.contentWindow.document;
  6358. } catch(e) {
  6359. if (e.message && e.message.indexOf("cross-origin") != -1 && notSetSandbox && emuIframe.hasAttribute("sandbox")) {
  6360. emuIframe.removeAttribute("sandbox");
  6361. meetCors = true;
  6362. callback(false, false);
  6363. } else {
  6364. returnFalse("Stop as cors");
  6365. }
  6366. return;
  6367. }
  6368. meetCors = false;
  6369. let code = ruleParser.curSiteRule.init;
  6370. if (code) {
  6371. try {
  6372. Function('doc','win','iframe','"use strict";' + code)(iframeDoc, iframeDoc.defaultView, emuIframe);
  6373. } catch(e) {
  6374. debug(e);
  6375. }
  6376. }
  6377. if (loaded) return;
  6378. loaded = true;
  6379. checkPage();
  6380. }, 500);
  6381. });
  6382. if (!lastActiveUrl) lastActiveUrl = location.href;
  6383. emuIframe.src = lastActiveUrl;
  6384. getBody(document).appendChild(emuIframe);
  6385. } else {
  6386. if (emuIframe.src != lastActiveUrl || meetCors) {
  6387. emuIframe.src = lastActiveUrl;
  6388. return;
  6389. }
  6390. checkPage();
  6391. }
  6392. }
  6393.  
  6394. var scrollToResizeInited = false;
  6395. var resizePool = [];
  6396. var scrollingToResize = false;
  6397.  
  6398. function isTouchViewPort(element) {
  6399. const viewWidth = window.innerWidth || document.documentElement.clientWidth;
  6400. const viewHeight = window.innerHeight || document.documentElement.clientHeight;
  6401. const {
  6402. top,
  6403. right,
  6404. bottom,
  6405. left,
  6406. } = element.getBoundingClientRect();
  6407.  
  6408. return (
  6409. top < viewHeight &&
  6410. left < viewWidth &&
  6411. right > 0 &&
  6412. bottom > 0
  6413. );
  6414. }
  6415.  
  6416. function resizeIframe(iframe, frameDoc, pageEle) {
  6417. if (ruleParser.curSiteRule.singleUrl || forceState === 2) {
  6418. iframe.style.height = (getBody(frameDoc).scrollHeight || getBody(frameDoc).offsetHeight || 500) + "px";
  6419. iframe.style.minHeight = iframe.style.height;
  6420. iframe.style.width = "100%";
  6421. frameDoc.documentElement.scrollTop = 0;
  6422. frameDoc.documentElement.scrollLeft = 0;
  6423. } else {
  6424. if (pageEle) {
  6425. let fitWidth = ruleParser.curSiteRule.fitWidth !== false;
  6426. let targetElement = pageEle[0];
  6427. if (!targetElement) return;
  6428. if (pageEle.length > 1) {
  6429. targetElement = targetElement.parentNode;
  6430. }
  6431. let scrollHeight = targetElement.scrollHeight || targetElement.offsetHeight || 500;
  6432. iframe.style.height = scrollHeight + "px";
  6433. let scrollTop = 0, scrollLeft = 0;
  6434. getBody(frameDoc).scrollTop = 0;
  6435. getBody(frameDoc).scrollLeft = 0;
  6436. while (targetElement && targetElement.offsetParent) {
  6437. targetElement.offsetParent.scrollTop = targetElement.offsetTop;
  6438. if (targetElement.offsetParent.scrollTop == 0) {
  6439. scrollTop += targetElement.offsetTop;
  6440. }
  6441. if (fitWidth) {
  6442. targetElement.offsetParent.scrollLeft = targetElement.offsetLeft;
  6443. if (targetElement.offsetParent.scrollLeft == 0) {
  6444. scrollLeft += targetElement.offsetLeft;
  6445. }
  6446. }
  6447. targetElement = targetElement.offsetParent;
  6448. }
  6449. frameDoc.documentElement.scrollTop = scrollTop;
  6450. frameDoc.documentElement.scrollLeft = scrollLeft;
  6451. if (frameDoc.documentElement.scrollTop == 0 && frameDoc.documentElement.scrollLeft == 0) {
  6452. getBody(frameDoc).scrollTop += scrollTop;
  6453. getBody(frameDoc).scrollLeft += scrollLeft;
  6454. }
  6455. if (!fitWidth && iframe.style.marginLeft == '0px') {
  6456. iframe.style.width = "100vw";
  6457. iframe.style.marginLeft = -iframe.getBoundingClientRect().left + "px";
  6458. }
  6459. }
  6460. }
  6461. }
  6462.  
  6463. function scrollToResize(e) {
  6464. if (scrollingToResize) return;
  6465. else {
  6466. scrollingToResize = true;
  6467. let resizeHandler = () => {
  6468. let touched = 0;
  6469. for (let i in resizePool) {
  6470. let resizeArr = resizePool[i];
  6471. let iframe = resizeArr[1]();
  6472. if (isTouchViewPort(iframe)) {
  6473. touched++;
  6474. let pageEle = resizeArr[0]();
  6475. let frameDoc = resizeArr[2]();
  6476. resizeIframe(iframe, frameDoc, pageEle);
  6477. } else if (touched) {
  6478. if (touched == 1) {
  6479. let pageEle = resizeArr[0]();
  6480. let frameDoc = resizeArr[2]();
  6481. resizeIframe(iframe, frameDoc, pageEle);
  6482. }
  6483. break;
  6484. } else if (!iframe.parentNode) {
  6485. resizePool.splice(i, 1);
  6486. break;
  6487. }
  6488. }
  6489. };
  6490. setTimeout(() => {
  6491. scrollingToResize = false;
  6492. }, 300);
  6493. resizeHandler();
  6494. }
  6495. }
  6496.  
  6497. function forceIframe(url, callback) {
  6498. url = url.indexOf('=') == -1 ? url.replace(/#[^#]*/,"") : url;
  6499. let curIframe = document.createElement('iframe'), iframeDoc, pageElement = null, isloaded = false, inAction = true;
  6500. let loadedHandler = () => {
  6501. inAction = false;
  6502. let getPageEle = () => {
  6503. if (ruleParser.curSiteRule.singleUrl) {
  6504. return null;
  6505. } else {
  6506. if (!pageElement || pageElement.length === 0 || !pageElement[0].offsetParent) {
  6507. pageElement = ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView);
  6508. }
  6509. return pageElement;
  6510. }
  6511. };
  6512. resizeIframe(curIframe, iframeDoc, getPageEle());
  6513. if (isloaded) return;
  6514. isloaded = true;
  6515. let getIframe = () => {
  6516. return curIframe;
  6517. };
  6518. let getFrameDoc = () => {
  6519. return iframeDoc;
  6520. };
  6521. ruleParser.insertPage(iframeDoc, [], url, ele => {
  6522. callback(curIframe);
  6523. }, true);
  6524. resizePool.push([getPageEle, getIframe, getFrameDoc]);
  6525. };
  6526. let checkIframeTimer = setInterval(() => {
  6527. if (!curIframe.parentNode) {
  6528. clearInterval(checkIframeTimer);
  6529. return isloaded || callback(false);
  6530. }
  6531. }, 500);
  6532. curIframe.name = 'pagetual-iframe';
  6533. curIframe.sandbox = "allow-same-origin allow-scripts allow-popups allow-forms";
  6534. curIframe.frameBorder = '0';
  6535. curIframe.scrolling = "no";
  6536. curIframe.style.cssText = 'display: block; visibility: visible; float: none; clear: both; width: 100%; height: 0; background: initial; border: 0px; border-radius: 0px; margin: 0px; padding: 0px; z-index: 2147483647;content-visibility: auto;contain-intrinsic-size: auto 300px;';
  6537. curIframe.addEventListener("load", e => {
  6538. clearInterval(checkIframeTimer);
  6539. try {
  6540. iframeDoc = curIframe.contentDocument || curIframe.contentWindow.document;
  6541. } catch(e) {
  6542. debug("Stop as cors");
  6543. isPause = true;
  6544. callback(false);
  6545. return;
  6546. }
  6547. let css = ruleParser.curSiteRule.css || rulesData.customCss;
  6548. if (css) {
  6549. css = css.replace(/^inIframe:/, "");
  6550. let styleEle=iframeDoc.createElement("style");
  6551. styleEle.innerHTML=css;
  6552. iframeDoc.head.appendChild(styleEle);
  6553. }
  6554. loadedHandler();
  6555. let code = ruleParser.curSiteRule.init;
  6556. if (code) {
  6557. try {
  6558. Function('doc','win','iframe','"use strict";' + code)(iframeDoc,iframeDoc.defaultView,curIframe);
  6559. } catch(e) {
  6560. debug(e);
  6561. }
  6562. }
  6563. });
  6564. let checkTimes = 0, findPageEle = false;
  6565. let forceRefresh = e => {
  6566. if (inAction || !iframeDoc) return;
  6567. inAction = true;
  6568. let foundNext = () => {
  6569. document.removeEventListener("scroll", forceRefresh);
  6570. }
  6571. setTimeout(async () => {
  6572. inAction = false;
  6573. if (!ruleParser.nextLinkHref) {
  6574. checkTimes++;
  6575. await ruleParser.getNextLink(iframeDoc);
  6576. if (ruleParser.nextLinkHref) {
  6577. foundNext();
  6578. if (isLoading) isLoading = false;
  6579. } else if (checkTimes >= 10) {
  6580. foundNext();
  6581. } else if (checkTimes >= 3 && !findPageEle) {
  6582. if (!pageElement) pageElement = ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView);
  6583. if (!pageElement) {
  6584. inAction = true;
  6585. curIframe.contentWindow.location.reload();
  6586. } else {
  6587. findPageEle = true;
  6588. }
  6589. }
  6590. } else {
  6591. foundNext();
  6592. }
  6593. }, 100);
  6594. };
  6595. document.addEventListener("scroll", forceRefresh);
  6596. curIframe.src = url;
  6597. let insert = ruleParser.getInsert();
  6598. if (ruleParser.curSiteRule.singleUrl || forceState == 2) {
  6599. getBody(document).appendChild(loadingDiv);
  6600. getBody(document).appendChild(curIframe);
  6601. } else {
  6602. ruleParser.insertElement(curIframe);
  6603. }
  6604.  
  6605. if (!scrollToResizeInited) {
  6606. scrollToResizeInited = true;
  6607. document.addEventListener("scroll", scrollToResize);
  6608. }
  6609. return curIframe;
  6610. }
  6611.  
  6612. function loadPageOver() {
  6613. isLoading = false;
  6614. stopScroll = true;
  6615. let dist = distToBottom();
  6616. let rate = (ruleParser.curSiteRule.rate || rulesData.rate || 1);
  6617. if (rate != 1 && !clickMode) {
  6618. setTimeout(() => {
  6619. if (dist < bottomGap) {
  6620. nextPage();
  6621. }
  6622. }, 1);
  6623. }
  6624. setTimeout(() => {stopScroll = false}, 300);
  6625. setTimeout(() => {
  6626. if(loadingDiv.parentNode && !isLoading){
  6627. loadingDiv.parentNode.removeChild(loadingDiv);
  6628. }
  6629. }, 0);
  6630. }
  6631.  
  6632. function checkAutoLoadNum() {
  6633. if (autoLoadNum >= 0) {
  6634. if (autoLoadNum != 0 && --autoLoadNum == 0) {
  6635. autoLoadNum = -1;
  6636. } else {
  6637. setTimeout(() => nextPage(), 1);
  6638. }
  6639. }
  6640. }
  6641.  
  6642. var tryTimes = 0;
  6643. async function nextPage() {
  6644. if (typeof ruleParser.curSiteRule.manualMode == 'undefined' ? rulesData.manualMode : ruleParser.curSiteRule.manualMode) return;
  6645. if (clickMode) return;
  6646. if (isPause || isLoading || forceState == 1) return;
  6647. if (ruleParser.curSiteRule.delay) {
  6648. try {
  6649. let checkDelay = ((typeof _unsafeWindow.pagetualDelay=='undefined') ? Function('"use strict";' + ruleParser.curSiteRule.delay) : _unsafeWindow.pagetualDelay)();
  6650. if (!checkDelay) return;
  6651. } catch(e) {
  6652. debug(e);
  6653. }
  6654. }
  6655. let nextLink = ruleParser.nextLinkHref;
  6656. if (!nextLink) {
  6657. isLoading = true;
  6658. if (curPage == 1) {
  6659. await ruleParser.getNextLink(document);
  6660. nextLink = ruleParser.nextLinkHref;
  6661. }
  6662. if (!nextLink) {
  6663. if (curPage == 1 && (ruleParser.curSiteRule.pinUrl || tryTimes++ <= 10)) {
  6664. setTimeout(() => {isLoading = false}, 500);
  6665. }
  6666. return;
  6667. }
  6668. isLoading = false;
  6669. }
  6670. let pvGallery = document.querySelector("span.pv-gallery-container");
  6671. if (pvGallery && pvGallery.style.display != "none") return;
  6672. let insert = ruleParser.getInsert();
  6673. if (insert) {
  6674. if (curPage == 1) initView();
  6675. SideController.setup();
  6676. /*if (curPage == 1) {
  6677. window.postMessage({
  6678. insert: geneSelector(ruleParser.curSiteRule.insertPos == 2 ? insert : insert.parentNode, true),
  6679. command: 'pagetual.insert'
  6680. }, '*');
  6681. }*/
  6682. let isJs = ruleParser.curSiteRule.action == 3 || /^(javascript|#)/.test(nextLink.replace(location.href, ""));
  6683. if (!isJs) {
  6684. emuIframe = null;
  6685. lastActiveUrl = nextLink;
  6686. if (location.protocol == "https:" && /^http:/.test(nextLink)) {
  6687. nextLink = nextLink.replace(/^http/, "https");
  6688. }
  6689. }
  6690. isLoading = true;
  6691. ruleParser.insertElement(loadingDiv);
  6692. let parent = loadingDiv.parentNode;
  6693. if (/^TBODY$/i.test(parent.nodeName)) {
  6694. parent = parent.parentNode;
  6695. }
  6696. if (/^TABLE$/i.test(parent.nodeName)) {
  6697. parent.parentNode.appendChild(loadingDiv);
  6698. }
  6699. loadingDiv.style.cssText = loadingCSS;
  6700. if (curPage == 1 && isJs && ruleParser.curSiteRule.singleUrl) {
  6701. loadingDiv.style.display = "none";
  6702. }
  6703. let sleep = ruleParser.curSiteRule.sleep || 0;
  6704. setTimeout(() => {
  6705. if (ruleParser.curSiteRule.pageElementByJs) {
  6706. var over = eles => {
  6707. loadPageOver();
  6708. if (urlChanged || isPause) return;
  6709. if (eles) {
  6710. ruleParser.insertPage(document, eles, nextLink, () => {
  6711. createPageBar(nextLink);
  6712. checkAutoLoadNum();
  6713. }, true);
  6714. } else {
  6715. debug("Stop as no page when get by js");
  6716. isPause = true;
  6717. }
  6718. };
  6719. try {
  6720. ((typeof _unsafeWindow.pagetualPageElementByJs == 'undefined') ? Function("over", "pageNum",'"use strict";' + ruleParser.curSiteRule.pageElementByJs) : _unsafeWindow.pagetualPageElementByJs)(over, curPage);
  6721. } catch(e) {
  6722. debug(e);
  6723. }
  6724. } else if ((forceState == 2 || ruleParser.curSiteRule.action == 2) && !isJs) {
  6725. forceIframe(nextLink, (iframe) => {
  6726. loadPageOver();
  6727. if (urlChanged || isPause) return;
  6728. let pageBar = createPageBar(nextLink);
  6729. if (pageBar && iframe && iframe.parentNode) iframe.parentNode.insertBefore(pageBar, iframe);
  6730. checkAutoLoadNum();
  6731. });
  6732. } else if ((forceState == 3 || ruleParser.curSiteRule.action == 1) && !isJs) {
  6733. requestFromIframe(nextLink, (doc, eles) => {
  6734. loadPageOver();
  6735. if (urlChanged || isPause) return;
  6736. if (eles) {
  6737. ruleParser.insertPage(doc, eles, nextLink, () => {
  6738. createPageBar(nextLink);
  6739. checkAutoLoadNum();
  6740. }, true);
  6741. }
  6742. });
  6743. } else {
  6744. if (!isJs) {
  6745. requestDoc(nextLink, (eles) => {
  6746. loadPageOver();
  6747. if (urlChanged || isPause) return;
  6748. if (eles) {
  6749. createPageBar(nextLink);
  6750. checkAutoLoadNum();
  6751. }
  6752. });
  6753. } else {
  6754. emuPage((doc, eles) => {
  6755. loadPageOver();
  6756. if (urlChanged || isPause) return;
  6757. if (eles) {
  6758. ruleParser.insertPage(doc, eles, "", () => {
  6759. createPageBar(nextLink);
  6760. checkAutoLoadNum();
  6761. }, true);
  6762. }
  6763. });
  6764. }
  6765. }
  6766. },sleep);
  6767. }
  6768. }
  6769.  
  6770. function init() {
  6771. if (document.readyState == 'loading' || document.readyState == 'uninitialized') {
  6772. let domReady = e => {
  6773. initRules(() => {
  6774. initPage();
  6775. });
  6776. document.removeEventListener("DOMContentLoaded", domReady, false);
  6777. }
  6778. document.addEventListener("DOMContentLoaded", domReady, false);
  6779. } else {
  6780. initRules(() => {
  6781. initPage();
  6782. });
  6783. }
  6784. }
  6785.  
  6786. function visibilitychangeHandler() {
  6787. document.removeEventListener('visibilitychange', visibilitychangeHandler);
  6788. init();
  6789. }
  6790.  
  6791. setTimeout(() => {
  6792. if (document.hidden) {
  6793. document.addEventListener('visibilitychange', visibilitychangeHandler);
  6794. } else {
  6795. init();
  6796. }
  6797. }, 300);
  6798. })();

QingJ © 2025

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