东方永页机

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

当前为 2023-09-18 提交的版本,查看 最新版本

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

QingJ © 2025

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