东方永页机

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

当前为 2023-05-12 提交的版本,查看 最新版本

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

QingJ © 2025

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