东方永页机

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

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

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

QingJ © 2025

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