东方永页机

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

当前为 2024-07-25 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Pagetual
  3. // @name:zh-CN 东方永页机
  4. // @name:zh-TW 東方永頁機
  5. // @name:ja 東方永頁機
  6. // @name:ko 東方永頁機
  7. // @name:ru Pagetual
  8. // @name:de Pagetual
  9. // @name:es Pagetual
  10. // @name:fr Pagetual
  11. // @name:it Pagetual
  12. // @namespace hoothin
  13. // @version 1.9.37.86
  14. // @description Perpetual pages - powerful auto-pager script. Auto fetching next paginated web pages and inserting into current page for infinite scroll. Support thousands of web sites without any rule.
  15. // @description:zh-CN 终极自动翻页 - 加载并拼接下一分页内容至当前页尾,智能适配任意网页
  16. // @description:zh-TW 終極自動翻頁 - 加載並拼接下一分頁內容至當前頁尾,智能適配任意網頁
  17. // @description:ja Webページを自動で読み込み継ぎ足し表示を行うブラウザ拡張です、次のページ付けされた Web ページの自動読み込みと現在のページへの挿入 ルールなしで何千もの Web サイトをサポートします。
  18. // @description:ko 페이지가 매겨진 다음 웹 페이지를 자동으로 로드하고 현재 페이지에 삽입합니다. 규칙 없이 수천 개의 웹 사이트를 지원합니다.
  19. // @description:ru Автоматическая подгрузка следующих страниц и вставка их содержимого в текущую страницу. Поддерживает тысячи сайтов даже с настройками по умолчанию.
  20. // @description:de Automatisches Laden der nächsten paginierten Webseiten und Einfügen in die aktuelle Seite. Unterstützen Sie Tausende von Websites ohne Regeln.
  21. // @description:es Carga automática de las siguientes páginas web paginadas e inserción en la página actual. Admite miles de sitios web sin ninguna regla.
  22. // @description:fr Chargement automatique des pages Web paginées suivantes et insertion dans la page en cours. Prend en charge des milliers de sites Web sans aucune règle.
  23. // @description:it Caricamento automatico delle pagine Web impaginate successive e inserimento nella pagina corrente. Supporta migliaia di siti web senza alcuna regola.
  24. // @author hoothin
  25. // @license MPL-2.0
  26. // @match *://*/*
  27. // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAAdVBMVEUAAAD3VU33VU32VEz8U073VU32VU33VU32VUz0Uk/3VE32VU32VUz2VU32VU32VU32VU33VU33U0z2VU34Wkv3VE32VUz/mpj/nJj2VUz2VU32VE33VEz2VU32VU32VUz3VE32VEz3VE3/mZf2Vkz2VU3/mpilFFolAAAAJXRSTlMA3Lp/GvTBT5YQLuawZ/DOyZwlPQeKc21N04+FX1bqpm9DNoB4T68ePwAAAitJREFUWMPt1tuasiAUBuCFCG5Rs3QybTPV1/1f4v/3PDkyIojn8x5qBrI+ltAfh32/yysmBKvyXb+njb6bDL9kzTd5SzjDAsYT8nFoGSxYe6BVqoNDp2jFDit25BRgVUAODB4YWcETWVTwVNGiGN5iWtBgg4YMCpsoI38dNunmmWyxUTvbPwwbsYR0fIzZLQ0pTG8eieRmBLMmpdH9uimQEf6TNRnXXKLZHixpJtywLzOgMHtFCqdM64DahHRnOE1dsrekm9wr2WtLcAlpdHwcp1pAJySXYnERclzp4+v19jXdmcTvQUJtz+ZaI4i05/V/UGYrCxbaAsOYoNfIKEQxpqQuzCgJJJ/3f42O8ywEZuMVWi/8hODxGj3GW2b0udkbGULLDOjimAG0S3fLGlBnXQM9irG1CiQdVQi0dqQsOSDlyEEz7Vy9OxxfR71VCXsSB23jMrKJYZXSjw57sqgLn5Z0wolsOCz0RyJkyeYjgz7pwwVq20eboZwtVUl2EnN5gJ50dQZFdryATvABRTr/tJXkUMdaAK5pwtCapwtFLskguwuyMh/Sd9WChQ4sIvIUYSk3PYqQvCQlOC04IfN7PkdjOyRKWhdKXMmiAFt9i3sJ5jxoRuR0vqAghxxwHuqfQE5OHGDKOrwEnqs1DgAZ2e4Eev1d45TN7JfhrQLKgfwMFYAsvp33dXII073aVQLI2gN5S58lfmGnKKFtah7nkgnBZB7zlP7Y/QNiTM6sYNzawwAAAABJRU5ErkJggg==
  28. // @grant GM_xmlhttpRequest
  29. // @grant GM_registerMenuCommand
  30. // @grant GM_notification
  31. // @grant GM_getValue
  32. // @grant GM_setValue
  33. // @grant GM_addStyle
  34. // @grant GM_openInTab
  35. // @grant GM_deleteValue
  36. // @grant GM_info
  37. // @grant GM_setClipboard
  38. // @grant GM.xmlHttpRequest
  39. // @grant GM.registerMenuCommand
  40. // @grant GM.notification
  41. // @grant GM.getValue
  42. // @grant GM.setValue
  43. // @grant GM.addStyle
  44. // @grant GM.openInTab
  45. // @grant GM.deleteValue
  46. // @grant GM.info
  47. // @grant GM.setClipboard
  48. // @homepage https://github.com/hoothin/UserScripts/tree/master/Pagetual
  49. // @supportURL https://github.com/hoothin/UserScripts/issues
  50. // @connect wedata.net
  51. // @connect githubusercontent.com
  52. // @connect ghproxy.com
  53. // @connect hoothin.github.io
  54. // @run-at document-end
  55. // @connect *
  56. // @contributionURL https://ko-fi.com/hoothin
  57. // @contributionAmount 1
  58. // ==/UserScript==
  59.  
  60. (function() {
  61. 'use strict';
  62. const pauseVideo = () => {
  63. setTimeout(() => {
  64. [].forEach.call(document.querySelectorAll("video"), video => {
  65. video.removeAttribute && video.removeAttribute("autoplay");
  66. video.pause && video.pause();
  67. });
  68. }, 1000);
  69. };
  70. if (window.name === 'pagetual-iframe' || (window.frameElement && window.frameElement.name === 'pagetual-iframe')) {
  71. [].forEach.call(document.querySelectorAll("iframe"), iframe => {
  72. iframe.name = 'pagetual-iframe';
  73. });
  74. var domloaded = function() {
  75. window.parent.postMessage('pagetual-iframe:DOMLoaded', '*');
  76. };
  77. if (window.opera) {
  78. document.addEventListener('DOMContentLoaded', domloaded, false);
  79. pauseVideo();
  80. } else {
  81. domloaded();
  82. if (document.readystate === 'complete') {
  83. pauseVideo();
  84. } else {
  85. window.addEventListener('load', () => {
  86. pauseVideo();
  87. }, false);
  88. }
  89. }
  90. if (getComputedStyle(document.documentElement).display === 'none') {
  91. document.documentElement.style.display = 'block';
  92. }
  93. if (document.body && getComputedStyle(document.body).display === 'none') {
  94. document.body.style.display = 'block';
  95. }
  96. return;
  97. }
  98.  
  99. if (window.top !== window.self) {
  100. try {
  101. if (window.self.innerWidth < 300 || window.self.innerHeight < 300) {
  102. return;
  103. }
  104. } catch(e) {
  105. return;
  106. }
  107. }
  108.  
  109. const noRuleTest = false;
  110. const lang = navigator.appName === "Netscape" ? navigator.language : navigator.userLanguage;
  111. const langData = [
  112. {
  113. // English translation update by github.com/https433, admin@abby0666.xyz.
  114. name: "English",
  115. match: ["en"],
  116. lang: {
  117. enableDebug: "Enable debug output to console.",
  118. updateNotification: "Notification after rules updated",
  119. disable: "Temporarily disable.",
  120. disableSite: "Toggle disabled state.",
  121. disableSiteTips: "Disabled on this site.",
  122. enableSiteTips: "Enabled on this site.",
  123. enable: "Enable automatic page turning.",
  124. toTop: "Back to Top.",
  125. toBottom: "Go to Bottom.",
  126. current: "Current Page.",
  127. forceIframe: "Force to join next page",
  128. cancelForceIframe: "Cancel Force join",
  129. configure: "Configure Pagetual",
  130. firstUpdate: "Click here to initialize the default rule list",
  131. update: "Update online rules",
  132. click2update: "Click to update rules from url now",
  133. loadNow: "Load next automatically",
  134. loadConfirm: "How many pages do you want to load? (0 means infinite)",
  135. noNext: "No next link found, please create a new rule",
  136. passSec: "Updated #t# seconds ago",
  137. passMin: "Updated #t# minutes ago",
  138. passHour: "Updated #t# hours ago",
  139. passDay: "Updated #t# days ago",
  140. cantDel: "Can't delete builtin rules",
  141. confirmDel: "Are you sure you want to delete this rule?",
  142. updateSucc: "Update succeeded",
  143. beginUpdate: "Begin update, wait a moment please",
  144. customUrls: "Import Pagetual or AutoPagerize rule url, one url per line.",
  145. customRules: "Input custom rules. <a href='#t#'>✍️Contribute rules</a>",
  146. save: "Save",
  147. loadingText: "Shojo Now Loading...",
  148. opacity: "Opacity",
  149. opacityPlaceholder: "0: hide spacer",
  150. hideBar: "Hide the pagnation spacer",
  151. hideBarButNoStop: "Hide but not stop",
  152. dbClick2Stop: "Double-click on the blank space to pause",
  153. sortTitle: "Sorting takes effect after the next rule update",
  154. autoRun: "Auto enable (blacklist mode)",
  155. autoLoadNum: "Amount for preload pages",
  156. turnRate: "Turn the next page when it's less than 【X】 times page height from the footer",
  157. inputPageNum: "Enter page number to jump",
  158. enableHistory: "Write browsing history after page turning",
  159. enableHistoryAfterInsert: "Write browsing history immediately after splicing, otherwise write after browsing",
  160. contentVisibility: "Automatically switch content-visibility to improve rendering performance",
  161. initRun: "Turn pages immediately after opening",
  162. preload: "Preload next page for speeding up",
  163. click2ImportRule: "Click to import base rules link, and then wait until the update is complete: ",
  164. forceAllBody: "Join full body of page?",
  165. openInNewTab: "Open urls of additions in new tab",
  166. importSucc: "Import complete",
  167. import: "Import",
  168. editCurrent: "Edit rule for current website.",
  169. editBlacklist: "Edit the url blacklist, one entry per line, Supports [?,*] wildcarding.",
  170. upBtnImg: "Icon of back to top",
  171. downBtnImg: "Icon of go to footer",
  172. sideControllerIcon: "Icon of sidebar",
  173. loadingTextTitle: "Loading.",
  174. dbClick2StopCtrl: "Ctrl key",
  175. dbClick2StopAlt: "Alt key",
  176. dbClick2StopShift: "Shift key",
  177. dbClick2StopMeta: "Meta key",
  178. dbClick2StopKey: "Shortcut key",
  179. pageElementCss: "Custom style for main page elements",
  180. customCss: "Custom complete css",
  181. firstAlert: "You have not imported the base rule, please select the appropriate rule to import",
  182. picker: "Pagetual page element picker",
  183. closePicker: "Close Pagetual picker",
  184. pickerPlaceholder: "Element selector, (Advanced users only, leave blank otherwise)",
  185. pickerCheck: "Check selector and copy",
  186. switchSelector: "Click to switch element",
  187. gotoEdit: "Go to edit rule with current selector",
  188. manualMode: "Disable splicing, manually advance next page using the right arrow key (or dispatch event 'pagetual.next')",
  189. clickMode: "Disable splicing, automatically click the next page when scrolling to the end of the page",
  190. pageBarMenu: "Click the center of the page bar to open the picker menu",
  191. nextSwitch: "Switch next link",
  192. arrowToScroll: "Press left arrow to scroll back and right arrow to advance page",
  193. sideController: "Display the paging control bar in the sidebar",
  194. sideControllerScroll: "Scroll toggle",
  195. sideControllerAlways: "Always show",
  196. hideLoadingIcon: "Hide loading animation",
  197. hideBarArrow: "Hide arrow for page bar",
  198. duplicate: "Duplicate Pagetual have been installed, check your script manager!",
  199. forceStateIframe: "Embed full page as iframe",
  200. forceStateDynamic: "Load dynamic content via iframe",
  201. forceStateDisable: "Disable page turning on this site",
  202. autoScrollRate: "Scroll speed (1~1000)",
  203. disableAutoScroll: "Stop Auto Scroll",
  204. enableAutoScroll: "Enable Auto Scroll",
  205. toggleAutoScroll: "Toggle Auto Scroll",
  206. ruleRequest: "Rule Request",
  207. page: "Page ",
  208. prevPage: "Prev page",
  209. nextPage: "Next page",
  210. errorRulesMustBeArray: "Rules must be an Array!",
  211. errorJson: "JSON error, Check again!",
  212. editSuccess: "Edit successfully",
  213. errorWrongUrl: "Wrong url, Check again!",
  214. errorAlreadyExists: "A rule already exists!",
  215. settingsSaved: "The settings are saved, refresh to view",
  216. iframe: "Forced split by iframe.",
  217. dynamic: "Dynamic loading.",
  218. reloadPage: "Edit completed, reload now?",
  219. copied: "Copied",
  220. noValidContent: "No valid content detected, a Captcha may be present",
  221. outOfDate: "The script is outdated, update to the latest version please.",
  222. hideBarTips: "Hide the pagination bar, toggle immersive experience",
  223. setConfigPage: "Set current page as the default configuration page",
  224. wedata2github: "Change the wedata address to the mirror address in the github repository",
  225. addOtherProp: "Add rule properties",
  226. addNextSelector: "Add selector content as nextLink",
  227. addPageSelector: "Add selector content as pageElement",
  228. propName: "Enter rule property name",
  229. propValue: "Enter rule property value",
  230. customFirst: "Ignore cache for local custom rules",
  231. rulesExample: "Rules Example",
  232. lastPage: "Reached the last page",
  233. lastPageTips: "Show tips when reaching the last page"
  234. }
  235. },
  236. {
  237. // Translated by SrKalopsia (srkalopsia@gmail.com).
  238. name: "Español",
  239. match: ["es", "es-ES"],
  240. lang: {
  241. enableDebug: "Habilitar salida de depuración",
  242. updateNotification: "Notificación después de actualizar las reglas",
  243. disable: "Desactivar",
  244. disableSite: "Alternar estado desactivado",
  245. disableSiteTips: "Desactivado en este sitio",
  246. enableSiteTips: "Activado en este sitio",
  247. enable: "Habilitar",
  248. toTop: "Ir al inicio",
  249. toBottom: "Ir al final",
  250. current: "Página actual",
  251. forceIframe: "Forzar para unirse a la siguiente página",
  252. cancelForceIframe: "Cancelar unión forzada",
  253. configure: "Configurar",
  254. firstUpdate: "Haga clic aquí para inicializar las reglas",
  255. update: "Actualizar reglas en línea",
  256. click2update: "Haga clic para actualizar las reglas desde la URL ahora",
  257. loadNow: "Cargar el siguiente automáticamente",
  258. loadConfirm: "¿Cuántas páginas desea cargar? (0 significa infinito)",
  259. noNext: "No se encontró el enlace siguiente, por favor cree una nueva regla",
  260. passSec: "Actualizado hace #t# segundos",
  261. passMin: "Actualizado hace #t# minutos",
  262. passHour: "Actualizado hace #t# horas",
  263. passDay: "Actualizado hace #t# días",
  264. cantDel: "No se pueden eliminar las reglas incorporadas",
  265. confirmDel: "¿Está seguro de que desea eliminar esta regla?",
  266. updateSucc: "Actualización exitosa",
  267. beginUpdate: "Comenzar actualización, espere un momento por favor",
  268. customUrls: "Importar URL de reglas de Pagetual o AutoPagerize, una URL por línea",
  269. customRules: "Introduzca reglas personalizadas. <a href='#t#'>✍️Contribuir reglas</a>",
  270. save: "Guardar",
  271. loadingText: "Shojo Cargando...",
  272. opacity: "Opacidad",
  273. opacityPlaceholder: "0: ocultar espaciador",
  274. hideBar: "Ocultar el espaciador de paginación",
  275. hideBarButNoStop: "Ocultar pero no detener",
  276. dbClick2Stop: "Haga doble clic en el espacio en blanco para pausar",
  277. sortTitle: "La ordenación surtirá efecto después de la próxima actualización de reglas",
  278. autoRun: "Habilitar automáticamente (modo lista negra)",
  279. autoLoadNum: "Cantidad de páginas para precargar",
  280. turnRate: "Pasar a la siguiente página cuando esté a menos de 【X】 veces la altura de la página desde el pie de página",
  281. inputPageNum: "Ingrese el número de página para saltar",
  282. enableHistory: "Escribir historial de navegación después de pasar la página",
  283. enableHistoryAfterInsert: "Escribir historial de navegación inmediatamente después de unir, de lo contrario escribir después de navegar",
  284. contentVisibility: "Cambiar automáticamente la visibilidad del contenido para mejorar el rendimiento de renderización",
  285. initRun: "Pasar páginas inmediatamente después de abrir",
  286. preload: "Precargar la siguiente página para acelerar",
  287. click2ImportRule: "Haga clic para importar el enlace de reglas base, luego espere hasta que la actualización esté completa: ",
  288. forceAllBody: "¿Unir el cuerpo completo de la página?",
  289. openInNewTab: "Abrir URLs de adiciones en una nueva pestaña",
  290. importSucc: "Importación completada",
  291. import: "Importar",
  292. editCurrent: "Editar regla para la actual",
  293. editBlacklist: "Editar URLs de la lista negra, una por línea, admite ? * para comodín",
  294. upBtnImg: "Icono de volver al inicio",
  295. downBtnImg: "Icono de ir al pie de página",
  296. sideControllerIcon: "Icono de la barra lateral",
  297. loadingTextTitle: "Texto de carga",
  298. dbClick2StopCtrl: "Tecla Ctrl",
  299. dbClick2StopAlt: "Tecla Alt",
  300. dbClick2StopShift: "Tecla Shift",
  301. dbClick2StopMeta: "Tecla Meta",
  302. dbClick2StopKey: "Tecla de acceso rápido",
  303. pageElementCss: "Estilo personalizado para los elementos principales de la página",
  304. customCss: "CSS completo personalizado",
  305. firstAlert: "No ha importado la regla base, por favor seleccione la regla adecuada para importar",
  306. picker: "Selector de elementos de página de Pagetual",
  307. closePicker: "Cerrar selector de Pagetual",
  308. pickerPlaceholder: "Selector de elementos, déjelo vacío si no tiene idea",
  309. pickerCheck: "Comprobar selector y copiar",
  310. switchSelector: "Haga clic para cambiar el elemento",
  311. gotoEdit: "Ir a editar la regla con el selector actual",
  312. manualMode: "Deshabilitar unión, pasar páginas manualmente con las teclas de flecha derecha (o despachar evento 'pagetual.next')",
  313. clickMode: "Deshabilitar unión, hacer clic automáticamente en la siguiente página al desplazarse al final de la página",
  314. pageBarMenu: "Haga clic en el centro de la barra de página para abrir el menú del selector",
  315. nextSwitch: "Cambiar al siguiente enlace",
  316. arrowToScroll: "Presione la tecla de flecha izquierda para desplazarse anterior y la tecla de flecha derecha para desplazarse siguiente",
  317. sideController: "Mostrar la barra de control de paginación en la barra lateral",
  318. sideControllerScroll: "Alternar desplazamiento",
  319. sideControllerAlways: "Mostrar siempre",
  320. hideLoadingIcon: "Ocultar animación de carga",
  321. hideBarArrow: "Ocultar flecha para la barra de página",
  322. duplicate: "Pagetual duplicado ha sido instalado, ¡revise su gestor de scripts!",
  323. forceStateIframe: "Incrustar página completa como iframe",
  324. forceStateDynamic: "Cargar contenido dinámico a través de iframe",
  325. forceStateDisable: "Deshabilitar pasar páginas en este sitio",
  326. autoScrollRate: "Velocidad de desplazamiento (1~1000)",
  327. disableAutoScroll: "Detener desplazamiento automático",
  328. enableAutoScroll: "Habilitar desplazamiento automático",
  329. toggleAutoScroll: "Alternar desplazamiento automático",
  330. ruleRequest: "Solicitud de regla",
  331. page: "Página ",
  332. prevPage: "Página anterior",
  333. nextPage: "Página siguiente",
  334. errorRulesMustBeArray: "¡Las reglas deben ser un array!",
  335. errorJson: "Error JSON, ¡verifique de nuevo!",
  336. editSuccess: "Editado exitosamente",
  337. errorWrongUrl: "URL incorrecta, ¡verifique de nuevo!",
  338. errorAlreadyExists: "¡Ya existe!",
  339. settingsSaved: "La configuración se ha guardado, actualice para ver",
  340. iframe: "Iframe",
  341. dynamic: "Dinámico",
  342. reloadPage: "Edición completada, ¿recargar página ahora?",
  343. copied: "Copiado",
  344. noValidContent: "No se detectó contenido válido, puede ser necesario realizar una acción de Captcha, haga clic para ver",
  345. outOfDate: "El script está desactualizado, ¡actualice a la última versión a tiempo!",
  346. hideBarTips: "Ocultar la barra de paginación, alternar experiencia inmersiva",
  347. setConfigPage: "Establecer la página actual como la página de configuración predeterminada",
  348. wedata2github: "Cambiar la dirección de wedata a la dirección espejo en el repositorio de GitHub",
  349. addOtherProp: "Agregar propiedad de regla",
  350. addNextSelector: "Agregar contenido del selector como nextLink",
  351. addPageSelector: "Agregar contenido del selector como pageElement",
  352. propName: "Ingrese el nombre de la propiedad de la regla",
  353. propValue: "Ingrese el valor de la propiedad de la regla",
  354. customFirst: "Ignorar caché para reglas personalizadas locales",
  355. rulesExample: "Ejemplo de reglas",
  356. lastPage: "Llegó a la última página",
  357. lastPageTips: "Mostrar consejos al llegar a la última página"
  358. }
  359. },
  360. {
  361. // Translated by Prankster 199 (vfggf95565).
  362. name: "Arabic",
  363. match: ["ar", "ar-AE", "ar-BH", "ar-DZ", "ar-EG", "ar-IQ", "ar-JO", "ar-KW", "ar-LB", "ar-LY", "ar-MA", "ar-OM", "ar-QA", "ar-SA", "ar-SY", "ar-TN", "ar-YE"],
  364. encode: true, // In Firefox, Arabic characters may cause issues.
  365. lang: {
  366. enableDebug: "%D8%AA%D9%85%D9%83%D9%8A%D9%86%20%D8%AA%D8%B5%D8%AD%D9%8A%D8%AD%20%D8%A7%D9%84%D8%A3%D8%AE%D8%B7%D8%A7%D8%A1",
  367. updateNotification: "%D8%A5%D8%B4%D8%B9%D8%A7%D8%B1%20%D8%A8%D8%B9%D8%AF%20%D8%AA%D8%AD%D8%AF%D9%8A%D8%AB%20%D8%A7%D9%84%D9%82%D9%88%D8%A7%D8%B9%D8%AF",
  368. disable: "%D9%85%D8%B9%D8%B7%D9%84",
  369. disableSite: "%D8%AA%D8%A8%D8%AF%D9%8A%D9%84%20%D8%AD%D8%A7%D9%84%D8%A9%20%D8%A7%D9%84%D8%AA%D8%B9%D8%B7%D9%8A%D9%84/%D8%A7%D9%84%D8%AA%D9%81%D8%B9%D9%8A%D9%84%20%D9%84%D9%84%D9%85%D9%88%D9%82%D8%B9",
  370. disableSiteTips: "%D9%85%D8%B9%D8%B7%D9%84%20%D8%B9%D9%84%D9%89%20%D9%87%D8%B0%D8%A7%20%D8%A7%D9%84%D9%85%D9%88%D9%82%D8%B9",
  371. enableSiteTips: "%D9%85%D9%81%D8%B9%D9%84%20%D8%B9%D9%84%D9%89%20%D9%87%D8%B0%D8%A7%20%D8%A7%D9%84%D9%85%D9%88%D9%82%D8%B9",
  372. enable: "%D9%85%D9%81%D8%B9%D9%84",
  373. toTop: "%D8%A5%D9%84%D9%89%20%D8%A7%D9%84%D8%A3%D8%B9%D9%84%D9%89",
  374. toBottom: "%D8%A5%D9%84%D9%89%20%D8%A7%D9%84%D8%A3%D8%B3%D9%81%D9%84",
  375. current: "%D8%A7%D9%84%D8%B5%D9%81%D8%AD%D8%A9%20%D8%A7%D9%84%D8%AD%D8%A7%D9%84%D9%8A%D8%A9",
  376. forceIframe: "%D8%A5%D8%AC%D8%A8%D8%A7%D8%B1%20%D8%B9%D9%84%D9%89%20%D8%A7%D9%84%D8%A7%D9%86%D8%B6%D9%85%D8%A7%D9%85%20%D9%84%D9%84%D8%B5%D9%81%D8%AD%D8%A9%20%D8%A7%D9%84%D8%AA%D8%A7%D9%84%D9%8A%D8%A9",
  377. cancelForceIframe: "%D8%A5%D9%84%D8%BA%D8%A7%D8%A1%20%D8%A7%D9%84%D8%A7%D9%86%D8%B6%D9%85%D8%A7%D9%85%20%D8%A7%D9%84%D9%82%D8%B3%D8%B1%D9%8A",
  378. configure: "%D8%A5%D8%B9%D8%AF%D8%A7%D8%AF",
  379. firstUpdate: "%D8%A7%D9%86%D9%82%D8%B1%20%D9%87%D9%86%D8%A7%20%D9%84%D8%AA%D9%81%D8%B9%D9%8A%D9%84%20%D8%A7%D9%84%D9%82%D9%88%D8%A7%D8%B9%D8%AF%20%D9%84%D8%A3%D9%88%D9%84%20%D9%85%D8%B1%D8%A9",
  380. update: "%D8%AA%D8%AD%D8%AF%D9%8A%D8%AB%20%D8%A7%D9%84%D9%82%D9%88%D8%A7%D8%B9%D8%AF%20%D8%B9%D8%A8%D8%B1%20%D8%A7%D9%84%D8%A5%D9%86%D8%AA%D8%B1%D9%86%D8%AA",
  381. click2update: "%D8%A7%D9%86%D9%82%D8%B1%20%D9%84%D8%AA%D8%AD%D8%AF%D9%8A%D8%AB%20%D8%A7%D9%84%D9%82%D9%88%D8%A7%D8%B9%D8%AF%20%D9%85%D9%86%20%D8%A7%D9%84%D8%B1%D8%A7%D8%A8%D8%B7%20%D8%A7%D9%84%D8%A2%D9%86",
  382. loadNow: "%D8%AA%D8%AD%D9%85%D9%8A%D9%84%20%D8%A7%D9%84%D8%AA%D8%A7%D9%84%D9%8A%20%D8%AA%D9%84%D9%82%D8%A7%D8%A6%D9%8A%D9%8B%D8%A7",
  383. loadConfirm: "%D9%83%D9%85%20%D8%B9%D8%AF%D8%AF%20%D8%A7%D9%84%D8%B5%D9%81%D8%AD%D8%A7%D8%AA%20%D8%A7%D9%84%D8%AA%D9%8A%20%D8%AA%D8%B1%D8%BA%D8%A8%20%D8%AA%D8%AD%D9%85%D9%8A%D9%84%D9%87%D8%A7%D8%9F%20(0%20%D9%8A%D8%B9%D9%86%D9%8A%20%D9%84%D8%A7%D9%86%D9%87%D8%A7%D8%A6%D9%8A)",
  384. noNext: "%D9%84%D9%85%20%D9%8A%D8%AA%D9%85%20%D8%A7%D9%84%D8%B9%D8%AB%D9%88%D8%B1%20%D8%B9%D9%84%D9%89%20%D8%B1%D8%A7%D8%A8%D8%B7%20%D8%A7%D9%84%D8%B5%D9%81%D8%AD%D8%A9%20%D8%A7%D9%84%D8%AA%D8%A7%D9%84%D9%8A%D8%A9%D8%8C%20%D9%8A%D8%B1%D8%AC%D9%89%20%D8%A5%D9%86%D8%B4%D8%A7%D8%A1%20%D9%82%D8%A7%D8%B9%D8%AF%D8%A9%20%D8%AC%D8%AF%D9%8A%D8%AF%D8%A9",
  385. passSec: "%D8%AA%D9%85%20%D8%A7%D9%84%D8%AA%D8%AD%D8%AF%D9%8A%D8%AB%20%D9%85%D9%86%D8%B0%20#t#%20%D8%AB%D8%A7%D9%86%D9%8A%D8%A9",
  386. passMin: "%D8%AA%D9%85%20%D8%A7%D9%84%D8%AA%D8%AD%D8%AF%D9%8A%D8%AB%20%D9%85%D9%86%D8%B0%20#t#%20%D8%AF%D9%82%D9%8A%D9%82%D8%A9",
  387. passHour: "%D8%AA%D9%85%20%D8%A7%D9%84%D8%AA%D8%AD%D8%AF%D9%8A%D8%AB%20%D9%85%D9%86%D8%B0%20#t#%20%D8%B3%D8%A7%D8%B9%D8%A9",
  388. passDay: "%D8%AA%D9%85%20%D8%A7%D9%84%D8%AA%D8%AD%D8%AF%D9%8A%D8%AB%20%D9%85%D9%86%D8%B0%20#t#%20%D9%8A%D9%88%D9%85",
  389. cantDel: "%D9%84%D8%A7%20%D9%8A%D9%85%D9%83%D9%86%20%D8%AD%D8%B0%D9%81%20%D8%A7%D9%84%D9%82%D9%88%D8%A7%D8%B9%D8%AF%20%D8%A7%D9%84%D9%85%D8%AF%D9%85%D8%AC%D8%A9",
  390. confirmDel: "%D9%87%D9%84%20%D8%A3%D9%86%D8%AA%20%D9%85%D8%AA%D8%A3%D9%83%D8%AF%20%D9%85%D9%86%20%D8%AD%D8%B0%D9%81%20%D9%87%D8%B0%D9%87%20%D8%A7%D9%84%D9%82%D8%A7%D8%B9%D8%AF%D8%A9%D8%9F",
  391. updateSucc: "%D8%AA%D9%85%20%D8%A7%D9%84%D8%AA%D8%AD%D8%AF%D9%8A%D8%AB%20%D8%A8%D9%86%D8%AC%D8%A7%D8%AD",
  392. beginUpdate: "%D8%A8%D8%AF%D8%A3%20%D8%A7%D9%84%D8%AA%D8%AD%D8%AF%D9%8A%D8%AB%D8%8C%20%D9%8A%D8%B1%D8%AC%D9%89%20%D8%A7%D9%84%D8%A7%D9%86%D8%AA%D8%B8%D8%A7%D8%B1%20%D9%84%D8%AD%D8%B8%D8%A9",
  393. customUrls: "%D8%A7%D8%B3%D8%AA%D9%8A%D8%B1%D8%A7%D8%AF%20%D8%B1%D8%A7%D8%A8%D8%B7%20%D9%82%D8%A7%D8%B9%D8%AF%D8%A9%20Pagetual%20%D8%A3%D9%88%20AutoPagerize%D8%8C%20%D8%B1%D8%A7%D8%A8%D8%B7%20%D9%88%D8%A7%D8%AD%D8%AF%20%D9%84%D9%83%D9%84%20%D8%B3%D8%B7%D8%B1",
  394. customRules: "%D8%A5%D8%AF%D8%AE%D8%A7%D9%84%20%D8%A7%D9%84%D9%82%D9%88%D8%A7%D8%B9%D8%AF%20%D8%A7%D9%84%D9%85%D8%AE%D8%B5%D8%B5%D8%A9.%20%3Ca%20href='#t#'%3E%E2%9C%8D%EF%B8%8F%D8%B3%D8%A7%D9%87%D9%85%20%D8%A8%D8%A7%D9%84%D9%82%D9%88%D8%A7%D8%B9%D8%AF%3C/a%3E",
  395. save: "%D8%AD%D9%81%D8%B8",
  396. loadingText: "%D8%AC%D8%A7%D8%B1%D9%8D%20%D8%A7%D9%84%D8%AA%D8%AD%D9%85%D9%8A%D9%84...",
  397. opacity: "%D8%A7%D9%84%D8%B4%D9%81%D8%A7%D9%81%D9%8A%D8%A9",
  398. opacityPlaceholder: "0:%20%D8%A5%D8%AE%D9%81%D8%A7%D8%A1%20%D8%A7%D9%84%D9%81%D8%A7%D8%B5%D9%84",
  399. hideBar: "%D8%A5%D8%AE%D9%81%D8%A7%D8%A1%20%D8%A7%D9%84%D9%81%D8%A7%D8%B5%D9%84%20%D8%A7%D9%84%D8%AA%D8%B5%D9%81%D8%AD%D9%8A",
  400. hideBarButNoStop: "%D8%A5%D8%AE%D9%81%D8%A7%D8%A1%D8%8C%20%D9%84%D9%83%D9%86%20%D9%84%D8%A7%20%D8%AA%D8%AA%D9%88%D9%82%D9%81",
  401. dbClick2Stop: "%D8%A7%D9%86%D9%82%D8%B1%20%D9%85%D8%B2%D8%AF%D9%88%D8%AC%20%D8%B9%D9%84%D9%89%20%D8%A7%D9%84%D9%85%D8%B3%D8%A7%D8%AD%D8%A9%20%D8%A7%D9%84%D9%81%D8%A7%D8%B1%D8%BA%D8%A9%20%D9%84%D9%84%D8%A5%D9%8A%D9%82%D8%A7%D9%81",
  402. sortTitle: "%D9%8A%D8%AA%D9%85%20%D8%AA%D9%81%D8%B9%D9%8A%D9%84%20%D8%A7%D9%84%D9%81%D8%B1%D8%B2%20%D8%A8%D8%B9%D8%AF%20%D8%A7%D9%84%D8%AA%D8%AD%D8%AF%D9%8A%D8%AB%20%D8%A7%D9%84%D8%AA%D8%A7%D9%84%D9%8A%20%D9%84%D9%84%D9%82%D9%88%D8%A7%D8%B9%D8%AF",
  403. autoRun: "%D8%AA%D9%85%D9%83%D9%8A%D9%86%20%D8%AA%D9%84%D9%82%D8%A7%D8%A6%D9%8A%20(%D9%88%D8%B6%D8%B9%20%D8%A7%D9%84%D9%82%D8%A7%D8%A6%D9%85%D8%A9%20%D8%A7%D9%84%D8%B3%D9%88%D8%AF%D8%A7%D8%A1)",
  404. autoLoadNum: "%D8%B9%D8%AF%D8%AF%20%D8%B5%D9%81%D8%AD%D8%A7%D8%AA%20%D8%A7%D9%84%D8%AA%D8%AD%D9%85%D9%8A%D9%84%20%D8%A7%D9%84%D9%85%D8%B3%D8%A8%D9%82",
  405. turnRate: "%D8%A7%D9%84%D8%A7%D9%86%D8%AA%D9%82%D8%A7%D9%84%20%D9%84%D9%84%D8%B5%D9%81%D8%AD%D8%A9%20%D8%A7%D9%84%D8%AA%D8%A7%D9%84%D9%8A%D8%A9%20%D8%B9%D9%86%D8%AF%D9%85%D8%A7%20%D8%AA%D9%83%D9%88%D9%86%20%D8%A7%D9%84%D9%85%D8%B3%D8%A7%D9%81%D8%A9%20%D8%A3%D9%82%D9%84%20%D9%85%D9%86%20%E3%80%90X%E3%80%91%20%D9%85%D8%B1%D8%A7%D8%AA%20%D8%A7%D8%B1%D8%AA%D9%81%D8%A7%D8%B9%20%D8%A7%D9%84%D8%B5%D9%81%D8%AD%D8%A9%20%D9%85%D9%86%20%D8%A7%D9%84%D8%AA%D8%B0%D9%8A%D9%8A%D9%84",
  406. inputPageNum: "%D8%A3%D8%AF%D8%AE%D9%84%20%D8%B1%D9%82%D9%85%20%D8%A7%D9%84%D8%B5%D9%81%D8%AD%D8%A9%20%D9%84%D9%84%D8%A7%D9%86%D8%AA%D9%82%D8%A7%D9%84",
  407. enableHistory: "%D9%83%D8%AA%D8%A7%D8%A8%D8%A9%20%D8%B3%D8%AC%D9%84%20%D8%A7%D9%84%D8%AA%D8%B5%D9%81%D8%AD%20%D8%A8%D8%B9%D8%AF%20%D8%AA%D8%AD%D9%88%D9%8A%D9%84%20%D8%A7%D9%84%D8%B5%D9%81%D8%AD%D8%A9",
  408. enableHistoryAfterInsert: "%D9%83%D8%AA%D8%A7%D8%A8%D8%A9%20%D8%B3%D8%AC%D9%84%20%D8%A7%D9%84%D8%AA%D8%B5%D9%81%D8%AD%20%D9%81%D9%88%D8%B1%D9%8B%D8%A7%20%D8%A8%D8%B9%D8%AF%20%D8%A7%D9%84%D8%AF%D9%85%D8%AC%D8%8C%20%D8%A3%D9%88%20%D8%A8%D8%B9%D8%AF%20%D8%A7%D9%84%D8%AA%D8%B5%D9%81%D8%AD",
  409. contentVisibility: "%D8%A7%D9%84%D8%AA%D9%86%D9%82%D9%84%20%D8%A7%D9%84%D8%AA%D9%84%D9%82%D8%A7%D8%A6%D9%8A%20%D9%84%D8%B1%D8%A4%D9%8A%D8%A9%20%D8%A7%D9%84%D9%85%D8%AD%D8%AA%D9%88%D9%89,%20%D9%84%D8%AA%D8%AD%D8%B3%D9%8A%D9%86%20%D8%A3%D8%AF%D8%A7%D8%A1%20%D8%A7%D9%84%D8%B9%D8%B1%D8%B6",
  410. initRun: "%D8%A7%D9%84%D8%A7%D9%86%D8%AA%D9%82%D8%A7%D9%84%20%D8%A8%D9%8A%D9%86%20%D8%A7%D9%84%D8%B5%D9%81%D8%AD%D8%A7%D8%AA%20%D9%81%D9%88%D8%B1%20%D8%A7%D9%84%D9%81%D8%AA%D8%AD",
  411. preload: "%D8%AA%D8%AD%D9%85%D9%8A%D9%84%20%D8%A7%D9%84%D8%B5%D9%81%D8%AD%D8%A9%20%D8%A7%D9%84%D8%AA%D8%A7%D9%84%D9%8A%D8%A9%20%D9%85%D8%B3%D8%A8%D9%82%D9%8B%D8%A7%20%D9%84%D8%AA%D8%B3%D8%B1%D9%8A%D8%B9%20%D8%A7%D9%84%D8%A3%D8%AF%D8%A7%D8%A1",
  412. click2ImportRule: "%D8%A7%D9%86%D9%82%D8%B1%20%D9%84%D8%A7%D8%B3%D8%AA%D9%8A%D8%B1%D8%A7%D8%AF%20%D8%B1%D8%A7%D8%A8%D8%B7%20%D8%A7%D9%84%D9%82%D9%88%D8%A7%D8%B9%D8%AF%20%D8%A7%D9%84%D8%A3%D8%B3%D8%A7%D8%B3%D9%8A%D8%A9%D8%8C%20%D8%AB%D9%85%20%D8%A7%D9%86%D8%AA%D8%B8%D8%B1%20%D8%AD%D8%AA%D9%89%20%D9%8A%D9%83%D8%AA%D9%85%D9%84%20%D8%A7%D9%84%D8%AA%D8%AD%D8%AF%D9%8A%D8%AB",
  413. forceAllBody: "%D8%AF%D9%85%D8%AC%20%D9%83%D8%A7%D9%85%D9%84%20%D8%A7%D9%84%D8%B5%D9%81%D8%AD%D8%A9%20%D9%83%D8%A5%D8%B7%D8%A7%D8%B1%D8%9F",
  414. openInNewTab: "%D9%81%D8%AA%D8%AD%20%D8%A7%D9%84%D8%B1%D9%88%D8%A7%D8%A8%D8%B7%20%D8%A7%D9%84%D8%A5%D8%B6%D8%A7%D9%81%D9%8A%D8%A9%20%D9%81%D9%8A%20%D8%B9%D9%84%D8%A7%D9%85%D8%A9%20%D8%AA%D8%A8%D9%88%D9%8A%D8%A8%20%D8%AC%D8%AF%D9%8A%D8%AF%D8%A9",
  415. importSucc: "%D8%AA%D9%85%20%D8%A7%D9%84%D8%A7%D8%B3%D8%AA%D9%8A%D8%B1%D8%A7%D8%AF%20%D8%A8%D9%86%D8%AC%D8%A7%D8%AD",
  416. import: "%D8%A7%D8%B3%D8%AA%D9%8A%D8%B1%D8%A7%D8%AF",
  417. editCurrent: "%D8%AA%D8%AD%D8%B1%D9%8A%D8%B1%20%D8%A7%D9%84%D9%82%D8%A7%D8%B9%D8%AF%D8%A9%20%D9%84%D9%84%D8%AD%D8%A7%D9%84%D9%8A%D8%A9",
  418. editBlacklist: "%D8%AA%D8%AD%D8%B1%D9%8A%D8%B1%20%D8%B9%D9%86%D8%A7%D9%88%D9%8A%D9%86%20%D8%A7%D9%84%D9%82%D8%A7%D8%A6%D9%85%D8%A9%20%D8%A7%D9%84%D8%B3%D9%88%D8%AF%D8%A7%D8%A1%D8%8C%20%D8%B3%D8%B7%D8%B1%20%D8%A8%D8%B3%D8%B7%D8%B1%D8%8C%20%D8%AF%D8%B9%D9%85%D8%9F%20*%20%D9%84%D9%84%D8%B1%D9%85%D9%88%D8%B2%20%D8%A7%D9%84%D9%85%D8%AA%D8%AD%D8%B1%D9%83%D8%A9",
  419. upBtnImg: "%D8%A3%D9%8A%D9%82%D9%88%D9%86%D8%A9%20%D8%A7%D9%84%D8%B9%D9%88%D8%AF%D8%A9%20%D8%A5%D9%84%D9%89%20%D8%A7%D9%84%D8%A3%D8%B9%D9%84%D9%89",
  420. downBtnImg: "%D8%A3%D9%8A%D9%82%D9%88%D9%86%D8%A9%20%D8%A7%D9%84%D8%A7%D9%86%D8%AA%D9%82%D8%A7%D9%84%20%D8%A5%D9%84%D9%89%20%D8%A7%D9%84%D8%A3%D8%B3%D9%81%D9%84",
  421. sideControllerIcon: "%D8%A3%D9%8A%D9%82%D9%88%D9%86%D8%A9%20%D8%A7%D9%84%D8%B4%D8%B1%D9%8A%D8%B7%20%D8%A7%D9%84%D8%AC%D8%A7%D9%86%D8%A8%D9%8A",
  422. loadingTextTitle: "%D8%AA%D8%AD%D9%85%D9%8A%D9%84%20%D8%A7%D9%84%D9%86%D8%B5",
  423. dbClick2StopCtrl: "%D9%85%D9%81%D8%AA%D8%A7%D8%AD%20Ctrl",
  424. dbClick2StopAlt: "%D9%85%D9%81%D8%AA%D8%A7%D8%AD%20Alt",
  425. dbClick2StopShift: "%D9%85%D9%81%D8%AA%D8%A7%D8%AD%20Shift",
  426. dbClick2StopMeta: "%D9%85%D9%81%D8%AA%D8%A7%D8%AD%20Meta",
  427. dbClick2StopKey: "%D9%85%D9%81%D8%A7%D8%AA%D9%8A%D8%AD%20%D8%A7%D9%84%D8%A7%D8%AE%D8%AA%D8%B5%D8%A7%D8%B1",
  428. pageElementCss: "%D9%86%D9%85%D8%B7%20%D9%85%D8%AE%D8%B5%D8%B5%20%D9%84%D8%B9%D9%86%D8%A7%D8%B5%D8%B1%20%D8%A7%D9%84%D8%B5%D9%81%D8%AD%D8%A9%20%D8%A7%D9%84%D8%B1%D8%A6%D9%8A%D8%B3%D9%8A%D8%A9",
  429. customCss: "%D9%85%D8%AE%D8%B5%D8%B5%20%D8%A8%D8%A7%D9%84%D9%83%D8%A7%D9%85%D9%84%20CSS%20%D9%86%D9%85%D8%B7",
  430. firstAlert: "%D9%84%D9%85%20%D8%AA%D8%B3%D8%AA%D9%88%D8%B1%D8%AF%20%D8%A7%D9%84%D9%82%D8%A7%D8%B9%D8%AF%D8%A9%20%D8%A7%D9%84%D8%A3%D8%B3%D8%A7%D8%B3%D9%8A%D8%A9%20%D8%A8%D8%B9%D8%AF%D8%8C%20%D9%8A%D8%B1%D8%AC%D9%89%20%D8%A7%D8%AE%D8%AA%D9%8A%D8%A7%D8%B1%20%D8%A7%D9%84%D9%82%D8%A7%D8%B9%D8%AF%D8%A9%20%D8%A7%D9%84%D9%85%D9%86%D8%A7%D8%B3%D8%A8%D8%A9%20%D9%84%D9%84%D8%A7%D8%B3%D8%AA%D9%8A%D8%B1%D8%A7%D8%AF",
  431. picker: "%D9%85%D8%AD%D8%AF%D8%AF%20%D8%B9%D9%86%D8%A7%D8%B5%D8%B1%20%D8%A7%D9%84%D8%B5%D9%81%D8%AD%D8%A9%20Pagetual",
  432. closePicker: "%D8%A5%D8%BA%D9%84%D8%A7%D9%82%20%D9%85%D8%AD%D8%AF%D8%AF%20Pagetual",
  433. pickerPlaceholder: "%D9%85%D8%AD%D8%AF%D8%AF%20%D8%A7%D9%84%D8%B9%D9%86%D8%A7%D8%B5%D8%B1%D8%8C%20%D8%A7%D8%AA%D8%B1%D9%83%D9%87%20%D9%81%D8%A7%D8%B1%D8%BA%D9%8B%D8%A7%20%D8%A5%D8%B0%D8%A7%20%D9%83%D9%86%D8%AA%20%D9%84%D8%A7%20%D8%AA%D8%B9%D8%B1%D9%81",
  434. pickerCheck: "%D8%AA%D8%AD%D9%82%D9%82%20%D9%85%D9%86%20%D8%A7%D9%84%D9%85%D8%AD%D8%AF%D8%AF%20%D9%88%D9%86%D8%B3%D8%AE",
  435. switchSelector: "%D8%A7%D9%86%D9%82%D8%B1%20%D9%84%D9%84%D8%AA%D8%A8%D8%AF%D9%8A%D9%84%20%D8%A8%D9%8A%D9%86%20%D8%A7%D9%84%D8%B9%D9%86%D8%A7%D8%B5%D8%B1",
  436. gotoEdit: "%D8%A7%D8%B0%D9%87%D8%A8%20%D9%84%D8%AA%D8%AD%D8%B1%D9%8A%D8%B1%20%D8%A7%D9%84%D9%82%D8%A7%D8%B9%D8%AF%D8%A9%20%D8%A8%D8%A7%D9%84%D9%85%D8%AD%D8%AF%D8%AF%20%D8%A7%D9%84%D8%AD%D8%A7%D9%84%D9%8A",
  437. manualMode: "%D8%AA%D8%B9%D8%B7%D9%8A%D9%84%20%D8%A7%D9%84%D8%AF%D9%85%D8%AC/%D8%A7%D9%84%D8%B1%D8%A8%D8%B7%D8%8C%20%D9%88%D8%A7%D8%B3%D8%AA%D8%AE%D8%AF%D8%A7%D9%85%20%D9%85%D9%81%D8%AA%D8%A7%D8%AD%20%D8%A7%D9%84%D8%A7%D8%AA%D8%AC%D8%A7%D9%87%20%D8%A7%D9%84%D8%A3%D9%8A%D9%85%D9%86%20%D9%8A%D8%AF%D9%88%D9%8A%D9%8B%D8%A7%20%D9%84%D9%84%D8%AA%D9%85%D8%B1%D9%8A%D8%B1%D8%8C%20%D9%88%D8%A7%D8%B3%D8%AA%D8%AE%D8%AF%D8%A7%D9%85%20%D9%85%D9%81%D8%AA%D8%A7%D8%AD%20%D8%A7%D9%84%D8%B3%D9%87%D9%85%20%D8%A7%D9%84%D8%A3%D9%8A%D8%B3%D8%B1%20%D9%84%D9%84%D8%B1%D8%AC%D9%88%D8%B9",
  438. clickMode: "%D8%AA%D8%B9%D8%B7%D9%8A%D9%84%20%D8%A7%D9%84%D8%AF%D9%85%D8%AC/%D8%A7%D9%84%D8%B1%D8%A8%D8%B7%D8%8C%20%D8%B9%D9%86%D8%AF%20%D8%A7%D9%84%D8%AA%D9%85%D8%B1%D9%8A%D8%B1%20%D8%A5%D9%84%D9%89%20%D9%86%D9%87%D8%A7%D9%8A%D8%A9%20%D8%A7%D9%84%D8%B5%D9%81%D8%AD%D8%A9%D8%8C%20%D8%B3%D9%8A%D8%AA%D9%85%20%D8%A7%D9%84%D9%86%D9%82%D8%B1%20%D8%AA%D9%84%D9%82%D8%A7%D8%A6%D9%8A%D9%8B%D8%A7%20%D8%B9%D9%84%D9%89%20%D8%A7%D9%84%D8%B5%D9%81%D8%AD%D8%A9%20%D8%A7%D9%84%D8%AA%D8%A7%D9%84%D9%8A%D8%A9",
  439. pageBarMenu: "%D8%A7%D9%86%D9%82%D8%B1%20%D8%B9%D9%84%D9%89%20%D9%85%D8%B1%D9%83%D8%B2%20%D8%B4%D8%B1%D9%8A%D8%B7%20%D8%A7%D9%84%D8%B5%D9%81%D8%AD%D8%A9%20%D9%84%D9%81%D8%AA%D8%AD%20%D9%82%D8%A7%D8%A6%D9%85%D8%A9%20%D8%A7%D9%84%D8%AA%D8%AD%D8%AF%D9%8A%D8%AF",
  440. nextSwitch: "%D8%AA%D8%A8%D8%AF%D9%8A%D9%84%20%D8%A7%D9%84%D8%B1%D8%A7%D8%A8%D8%B7%20%D8%A7%D9%84%D8%AA%D8%A7%D9%84%D9%8A",
  441. arrowToScroll: "%D8%A7%D9%86%D9%82%D8%B1%20%D8%B9%D9%84%D9%89%20%D9%85%D9%81%D8%AA%D8%A7%D8%AD%20%D8%A7%D9%84%D8%B3%D9%87%D9%85%20%D8%A7%D9%84%D8%A3%D9%8A%D9%85%D9%86%20%D9%84%D9%84%D8%AA%D9%85%D8%B1%D9%8A%D8%B1%20%D8%A7%D9%84%D8%AA%D8%A7%D9%84%D9%8A%20%D9%88%D9%85%D9%81%D8%AA%D8%A7%D8%AD%20%D8%A7%D9%84%D8%B3%D9%87%D9%85%20%D8%A7%D9%84%D8%A3%D9%8A%D8%B3%D8%B1%20%D9%84%D9%84%D8%AA%D9%85%D8%B1%D9%8A%D8%B1%20%D8%A7%D9%84%D8%B3%D8%A7%D8%A8%D9%82",
  442. sideController: "%D8%B9%D8%B1%D8%B6%20%D8%B4%D8%B1%D9%8A%D8%B7%20%D8%A7%D9%84%D8%AA%D8%AD%D9%83%D9%85%20%D9%81%D9%8A%20%D8%A7%D9%84%D8%AA%D8%B5%D9%81%D8%AD%20%D8%A7%D9%84%D8%AA%D8%B1%D9%82%D9%8A%D9%85%20%D9%81%D9%8A%20%D8%A7%D9%84%D8%B4%D8%B1%D9%8A%D8%B7%20%D8%A7%D9%84%D8%AC%D8%A7%D9%86%D8%A8%D9%8A",
  443. sideControllerScroll: "%D8%AA%D8%A8%D8%AF%D9%8A%D9%84%20%D8%A7%D9%84%D8%AA%D9%85%D8%B1%D9%8A%D8%B1",
  444. sideControllerAlways: "%D8%B9%D8%B1%D8%B6%20%D8%AF%D8%A7%D8%A6%D9%85%D9%8B%D8%A7",
  445. hideLoadingIcon: "%D8%A5%D8%AE%D9%81%D8%A7%D8%A1%20%D8%B1%D9%85%D8%B2%20%D8%A7%D9%84%D8%AA%D8%AD%D9%85%D9%8A%D9%84",
  446. hideBarArrow: "%D8%A5%D8%AE%D9%81%D8%A7%D8%A1%20%D8%B3%D9%87%D9%85%20%D8%B4%D8%B1%D9%8A%D8%B7%20%D8%A7%D9%84%D8%B5%D9%81%D8%AD%D8%A9",
  447. duplicate: "%D8%AA%D9%85%20%D8%AA%D8%AB%D8%A8%D9%8A%D8%AA%20Pagetual%20%D9%85%D9%83%D8%B1%D8%B1%D8%8C%20%D8%AA%D8%AD%D9%82%D9%82%20%D9%85%D9%86%20%D9%85%D8%AF%D9%8A%D8%B1%20%D8%A7%D9%84%D9%86%D8%B5%D9%88%D8%B5%20%D8%A7%D9%84%D8%A8%D8%B1%D9%85%D8%AC%D9%8A%D8%A9%20%D8%A7%D9%84%D8%AE%D8%A7%D8%B5%20%D8%A8%D9%83!",
  448. forceStateIframe: "%D8%AA%D8%B6%D9%85%D9%8A%D9%86%20%D8%A7%D9%84%D8%B5%D9%81%D8%AD%D8%A9%20%D8%A8%D8%A7%D9%84%D9%83%D8%A7%D9%85%D9%84%20%D9%83%D8%A5%D8%B7%D8%A7%D8%B1",
  449. forceStateDynamic: "%D8%AA%D8%AD%D9%85%D9%8A%D9%84%20%D8%A7%D9%84%D9%85%D8%AD%D8%AA%D9%88%D9%89%20%D8%A7%D9%84%D8%AF%D9%8A%D9%86%D8%A7%D9%85%D9%8A%D9%83%D9%8A%20%D8%B9%D8%A8%D8%B1%20%D8%A7%D9%84%D8%A5%D8%B7%D8%A7%D8%B1",
  450. forceStateDisable: "%D8%AA%D8%B9%D8%B7%D9%8A%D9%84%20%D8%AA%D8%AD%D9%88%D9%8A%D9%84%20%D8%A7%D9%84%D8%B5%D9%81%D8%AD%D8%A7%D8%AA%20%D8%B9%D9%84%D9%89%20%D9%87%D8%B0%D8%A7%20%D8%A7%D9%84%D9%85%D9%88%D9%82%D8%B9",
  451. autoScrollRate: "%D8%B3%D8%B1%D8%B9%D8%A9%20%D8%A7%D9%84%D8%AA%D9%85%D8%B1%D9%8A%D8%B1%20(1~1000)",
  452. disableAutoScroll: "%D8%A5%D9%8A%D9%82%D8%A7%D9%81%20%D8%A7%D9%84%D8%AA%D9%85%D8%B1%D9%8A%D8%B1%20%D8%A7%D9%84%D8%AA%D9%84%D9%82%D8%A7%D8%A6%D9%8A",
  453. enableAutoScroll: "%D8%AA%D9%85%D9%83%D9%8A%D9%86%20%D8%A7%D9%84%D8%AA%D9%85%D8%B1%D9%8A%D8%B1%20%D8%A7%D9%84%D8%AA%D9%84%D9%82%D8%A7%D8%A6%D9%8A",
  454. toggleAutoScroll: "%D8%AA%D8%A8%D8%AF%D9%8A%D9%84%20%D8%A7%D9%84%D8%AA%D9%85%D8%B1%D9%8A%D8%B1%20%D8%A7%D9%84%D8%AA%D9%84%D9%82%D8%A7%D8%A6%D9%8A",
  455. ruleRequest: "%D8%B7%D9%84%D8%A8%20%D9%82%D8%A7%D8%B9%D8%AF%D8%A9",
  456. page: "%D8%B5%D9%81%D8%AD%D8%A9%20",
  457. prevPage: "%D8%A7%D9%84%D8%B5%D9%81%D8%AD%D8%A9%20%D8%A7%D9%84%D8%B3%D8%A7%D8%A8%D9%82%D8%A9",
  458. nextPage: "%D8%A7%D9%84%D8%B5%D9%81%D8%AD%D8%A9%20%D8%A7%D9%84%D8%AA%D8%A7%D9%84%D9%8A%D8%A9",
  459. errorRulesMustBeArray: "%D9%8A%D8%AC%D8%A8%20%D8%A3%D9%86%20%D8%AA%D9%83%D9%88%D9%86%20%D8%A7%D9%84%D9%82%D9%88%D8%A7%D8%B9%D8%AF%20%D9%85%D8%B5%D9%81%D9%88%D9%81%D8%A9!",
  460. errorJson: "%D8%AE%D8%B7%D8%A3%20%D9%81%D9%8A%20JSON%D8%8C%20%D8%AA%D8%AD%D9%82%D9%82%20%D9%85%D8%B1%D8%A9%20%D8%A3%D8%AE%D8%B1%D9%89!",
  461. editSuccess: "%D8%AA%D9%85%20%D8%A7%D9%84%D8%AA%D8%AD%D8%B1%D9%8A%D8%B1%20%D8%A8%D9%86%D8%AC%D8%A7%D8%AD",
  462. errorWrongUrl: "%D8%B9%D9%86%D9%88%D8%A7%D9%86%20URL%20%D8%AE%D8%A7%D8%B7%D8%A6%D8%8C%20%D8%AA%D8%AD%D9%82%D9%82%20%D9%85%D8%B1%D8%A9%20%D8%A3%D8%AE%D8%B1%D9%89!",
  463. errorAlreadyExists: "%D9%85%D9%88%D8%AC%D9%88%D8%AF%20%D8%A8%D8%A7%D9%84%D9%81%D8%B9%D9%84!",
  464. settingsSaved: "%D8%AA%D9%85%20%D8%AD%D9%81%D8%B8%20%D8%A7%D9%84%D8%A5%D8%B9%D8%AF%D8%A7%D8%AF%D8%A7%D8%AA%D8%8C%20%D9%82%D9%85%20%D8%A8%D8%A7%D9%84%D8%AA%D8%AD%D8%AF%D9%8A%D8%AB%20%D9%84%D8%B9%D8%B1%D8%B6",
  465. iframe: "%D8%A5%D8%B7%D8%A7%D8%B1",
  466. dynamic: "%D8%AF%D9%8A%D9%86%D8%A7%D9%85%D9%8A%D9%83%D9%8A",
  467. reloadPage: "%D8%A7%D9%83%D8%AA%D9%85%D9%84%20%D8%A7%D9%84%D8%AA%D8%AD%D8%B1%D9%8A%D8%B1%D8%8C%20%D8%A5%D8%B9%D8%A7%D8%AF%D8%A9%20%D8%AA%D8%AD%D9%85%D9%8A%D9%84%20%D8%A7%D9%84%D8%B5%D9%81%D8%AD%D8%A9%20%D8%A7%D9%84%D8%A2%D9%86%D8%9F",
  468. copied: "%D8%AA%D9%85%20%D8%A7%D9%84%D9%86%D8%B3%D8%AE",
  469. noValidContent: "%D9%84%D9%85%20%D9%8A%D8%AA%D9%85%20%D8%A7%D9%84%D9%83%D8%B4%D9%81%20%D8%B9%D9%86%20%D9%85%D8%AD%D8%AA%D9%88%D9%89%20%D8%B5%D8%A7%D9%84%D8%AD%D8%8C%20%D9%82%D8%AF%20%D9%8A%D9%83%D9%88%D9%86%20%D8%A7%D9%84%D8%A5%D8%AC%D8%B1%D8%A7%D8%A1%20Captcha%20%D9%85%D8%B7%D9%84%D9%88%D8%A8%D9%8B%D8%A7%D8%8C%20%D8%A7%D9%86%D9%82%D8%B1%20%D9%84%D8%B9%D8%B1%D8%B6",
  470. outOfDate: "%D8%A7%D9%84%D9%86%D8%B5%20%D8%A7%D9%84%D8%A8%D8%B1%D9%85%D8%AC%D9%8A%20%D9%82%D8%AF%D9%8A%D9%85%D8%8C%20%D9%82%D9%85%20%D8%A8%D8%A7%D9%84%D8%AA%D8%AD%D8%AF%D9%8A%D8%AB%20%D8%A5%D9%84%D9%89%20%D8%A7%D9%84%D8%A5%D8%B5%D8%AF%D8%A7%D8%B1%20%D8%A7%D9%84%D8%A3%D8%AD%D8%AF%D8%AB%20%D9%81%D9%8A%20%D8%A7%D9%84%D9%88%D9%82%D8%AA%20%D8%A7%D9%84%D9%85%D9%86%D8%A7%D8%B3%D8%A8!",
  471. hideBarTips: "%D8%A5%D8%AE%D9%81%D8%A7%D8%A1%20%D8%B4%D8%B1%D9%8A%D8%B7%20%D8%A7%D9%84%D8%AA%D8%AD%D9%83%D9%85%20%D9%81%D9%8A%20%D8%A7%D9%84%D8%AA%D8%B5%D9%81%D8%AD%20%D8%A7%D9%84%D8%AA%D8%B1%D9%82%D9%8A%D9%85%20%D8%8C%20%D9%88%D8%A7%D9%84%D8%AA%D8%A8%D8%AF%D9%8A%D9%84%20%D9%84%D9%88%D8%B6%D8%B9%20%D9%83%D8%A7%D9%85%D9%84%20%D8%A7%D9%84%D8%B5%D9%81%D8%AD%D8%A9",
  472. setConfigPage: "%D8%AA%D8%B9%D9%8A%D9%8A%D9%86%20%D8%A7%D9%84%D8%B5%D9%81%D8%AD%D8%A9%20%D8%A7%D9%84%D8%AD%D8%A7%D9%84%D9%8A%D8%A9%20%D9%83%D8%B5%D9%81%D8%AD%D8%A9%20%D8%A7%D9%84%D8%A5%D8%B9%D8%AF%D8%A7%D8%AF%20%D8%A7%D9%84%D8%A7%D9%81%D8%AA%D8%B1%D8%A7%D8%B6%D9%8A%D8%A9",
  473. wedata2github: "%D8%AA%D8%BA%D9%8A%D9%8A%D8%B1%20%D8%B9%D9%86%D9%88%D8%A7%D9%86%20%D8%A7%D9%84%D9%88%D9%8A%D8%A8%20%D8%AF%D8%A7%D8%AA%D8%A7%20%D8%A5%D9%84%D9%89%20%D8%A7%D9%84%D8%B9%D9%86%D9%88%D8%A7%D9%86%20%D8%A7%D9%84%D8%A8%D8%AF%D9%8A%D9%84%20%D8%A7%D9%84%D9%85%D8%B1%D8%A2%D8%A9,%20%D9%81%D9%8A%20%D9%85%D8%B3%D8%AA%D9%88%D8%AF%D8%B9%20%D8%AC%D9%8A%D8%AA%20%D9%87%D8%A7%D8%A8",
  474. addOtherProp: "%D8%A5%D8%B6%D8%A7%D9%81%D8%A9%20%D8%AE%D8%A7%D8%B5%D9%8A%D8%A9%20%D9%82%D8%A7%D8%B9%D8%AF%D8%A9",
  475. addNextSelector: "%D8%A5%D8%B6%D8%A7%D9%81%D8%A9%20%D9%85%D8%AD%D8%AA%D9%88%D9%89%20%D8%A7%D9%84%D9%85%D8%AD%D8%AF%D8%AF%20%D9%83%D9%80%20nextLink",
  476. addPageSelector: "%D8%A5%D8%B6%D8%A7%D9%81%D8%A9%20%D9%85%D8%AD%D8%AA%D9%88%D9%89%20%D8%A7%D9%84%D9%85%D8%AD%D8%AF%D8%AF%20%D9%83%D9%80%20pageElement",
  477. propName: "%D8%A3%D8%AF%D8%AE%D9%84%20%D8%A7%D8%B3%D9%85%20%D8%AE%D8%A7%D8%B5%D9%8A%D8%A9%20%D8%A7%D9%84%D9%82%D8%A7%D8%B9%D8%AF%D8%A9",
  478. propValue: "%D8%A3%D8%AF%D8%AE%D9%84%20%D9%82%D9%8A%D9%85%D8%A9%20%D8%AE%D8%A7%D8%B5%D9%8A%D8%A9%20%D8%A7%D9%84%D9%82%D8%A7%D8%B9%D8%AF%D8%A9",
  479. customFirst: "%D8%AA%D8%AC%D8%A7%D9%87%D9%84%20%D8%B0%D8%A7%D9%83%D8%B1%D8%A9%20%D8%A7%D9%84%D8%AA%D8%AE%D8%B2%D9%8A%D9%86%20%D8%A7%D9%84%D9%85%D8%A4%D9%82%D8%AA%20%D9%84%D9%84%D9%82%D9%88%D8%A7%D8%B9%D8%AF%20%D8%A7%D9%84%D9%85%D8%AE%D8%B5%D8%B5%D8%A9%20%D8%A7%D9%84%D9%85%D8%AD%D9%84%D9%8A%D8%A9",
  480. rulesExample: "%D9%85%D8%AB%D8%A7%D9%84%20%D8%B9%D9%84%D9%89%20%D8%A7%D9%84%D9%82%D9%88%D8%A7%D8%B9%D8%AF",
  481. lastPage: "%D8%AA%D9%85%20%D8%A7%D9%84%D9%88%D8%B5%D9%88%D9%84%20%D8%A5%D9%84%D9%89%20%D8%A7%D9%84%D8%B5%D9%81%D8%AD%D8%A9%20%D8%A7%D9%84%D8%A3%D8%AE%D9%8A%D8%B1%D8%A9",
  482. lastPageTips: "%D8%B9%D8%B1%D8%B6%20%D8%AA%D9%84%D9%85%D9%8A%D8%AD%D8%A7%D8%AA%20%D8%B9%D9%86%D8%AF%20%D8%A7%D9%84%D9%88%D8%B5%D9%88%D9%84%20%D8%A5%D9%84%D9%89%20%D8%A7%D9%84%D8%B5%D9%81%D8%AD%D8%A9%20%D8%A7%D9%84%D8%A3%D8%AE%D9%8A%D8%B1%D8%A9"
  483. }
  484. },
  485. {
  486. name: "简体中文",
  487. match: ["zh-CN", "zh-SG"],
  488. lang: {
  489. enableDebug: "调试模式,输出信息至控制台",
  490. updateNotification: "规则更新后提示",
  491. disable: "暂时禁用",
  492. disableSite: "站点禁用开关",
  493. disableSiteTips: "已在此站禁用",
  494. enableSiteTips: "已在此站启用",
  495. enable: "启用自动翻页",
  496. toTop: "回到顶部",
  497. toBottom: "前往页尾",
  498. current: "当前页",
  499. forceIframe: "强制拼接",
  500. cancelForceIframe: "取消强制拼接",
  501. configure: "打开配置页面",
  502. firstUpdate: "点击此处初始化规则",
  503. update: "更新在线规则",
  504. click2update: "点击立即更新规则",
  505. loadNow: "立即翻页",
  506. loadConfirm: "要翻几页?(0为不间断)",
  507. noNext: "没有找到下一页,请新建规则",
  508. passSec: "更新于 #t# 秒前",
  509. passMin: "更新于 #t# 分钟前",
  510. passHour: "更新于 #t# 小时前",
  511. passDay: "更新于 #t# 天前",
  512. cantDel: "无法删除内置规则",
  513. confirmDel: "是否确认要删除此规则?",
  514. updateSucc: "更新成功",
  515. beginUpdate: "正在更新,请耐心等待,不要关闭页面",
  516. customUrls: "导入 Pagetual 或 AutoPagerize 规则 url,一行一条",
  517. customRules: "输入【东方永页机】格式的自定义规则 <a href='#t#'>✍️贡献规则</a>",
  518. save: "保存设置",
  519. loadingText: "少女祈祷中...",
  520. opacity: "不透明值",
  521. opacityPlaceholder: "0: 隐藏分隔条",
  522. hideBar: "隐藏分页隔条",
  523. hideBarButNoStop: "隐藏但不停止",
  524. dbClick2Stop: "空白处双击暂停翻页",
  525. sortTitle: "排序在下次更新规则后生效",
  526. autoRun: "自动启用,否则为白名单模式",
  527. autoLoadNum: "自动加载指定页数",
  528. turnRate: "距离页尾【X】倍页面高度时就开始翻页",
  529. inputPageNum: "输入页码跳转",
  530. enableHistory: "翻页后写入历史记录",
  531. enableHistoryAfterInsert: "拼接后立即写入历史记录,否则浏览完毕后再行写入",
  532. contentVisibility: "自动切换 contentVisibility,提升渲染性能",
  533. initRun: "打开页面后立即尝试翻页,否则滚动至页尾再翻页",
  534. preload: "翻页前预读下一页,加速浏览",
  535. click2ImportRule: "点击下方任意一条添加规则库,并静待更新成功,请预先打开链接确认能正常访问再行导入:",
  536. forceAllBody: "是否拼接整个页面?",
  537. openInNewTab: "使拼接页面的内容在新页面打开",
  538. importSucc: "导入成功",
  539. import: "导入",
  540. editCurrent: "编辑此站规则",
  541. editBlacklist: "编辑黑名单网址,一行一条,支持? *通配符与正则",
  542. upBtnImg: "回到页首图标",
  543. downBtnImg: "前往页尾图标",
  544. sideControllerIcon: "侧边栏图标",
  545. loadingTextTitle: "加载中文字",
  546. dbClick2StopCtrl: "Ctrl",
  547. dbClick2StopAlt: "Alt",
  548. dbClick2StopShift: "Shift",
  549. dbClick2StopMeta: "Meta",
  550. dbClick2StopKey: "快捷键",
  551. pageElementCss: "页面主体框架的样式",
  552. customCss: "自定义 css",
  553. firstAlert: "你还未导入规则库,请选择合适的规则库导入哦",
  554. picker: "东方永页机主体元素抓取器",
  555. closePicker: "关闭东方永页机抓取器",
  556. pickerPlaceholder: "元素选择器,没想法建议留空",
  557. pickerCheck: "检查你编辑的选择器并复制",
  558. switchSelector: "点击切换元素",
  559. gotoEdit: "使用当前的选择器前往编辑规则",
  560. manualMode: "禁用拼接,手动用右方向键翻页,可使用左方向键返回",
  561. clickMode: "禁用拼接,滚动至页尾时自动点击下一页",
  562. pageBarMenu: "点击分隔条中间弹出菜单",
  563. nextSwitch: "切换其他页码",
  564. arrowToScroll: "左方向键滚动至上一页,右方向键滚动至下一页",
  565. sideController: "在侧边显示翻页控制栏",
  566. sideControllerScroll: "滚动开关",
  567. sideControllerAlways: "始终显示",
  568. hideLoadingIcon: "隐藏加载动画",
  569. hideBarArrow: "隐藏分隔条定位箭头",
  570. duplicate: "检测到永页机重复安装,请删除其他脚本管理器中的永页机!",
  571. forceStateIframe: "以 iframe 嵌入整页",
  572. forceStateDynamic: "通过 iframe 加载动态内容后取出",
  573. forceStateDisable: "在此站禁用",
  574. autoScrollRate: "滚动速度(1~1000)",
  575. disableAutoScroll: "停止自动滚动",
  576. enableAutoScroll: "开启自动滚动",
  577. toggleAutoScroll: "自动滚动开关",
  578. ruleRequest: "适配请求",
  579. page: "Page ",
  580. prevPage: "上一页",
  581. nextPage: "下一页",
  582. errorRulesMustBeArray: "规则必须为数组形式!",
  583. errorJson: "JSON 格式有错,请重新检查!",
  584. editSuccess: "编辑成功",
  585. errorWrongUrl: "URL 错误, 请重新检查!",
  586. errorAlreadyExists: "已经存在!",
  587. settingsSaved: "设置已保存,刷新后生效",
  588. iframe: "强制拼接",
  589. dynamic: "动态加载",
  590. reloadPage: "编辑完成,是否立即刷新页面?",
  591. copied: "已复制",
  592. noValidContent: "没有检测到有效内容,可能需要人机校验,点击查看",
  593. outOfDate: "脚本已过时,请及时更新到最新版本!",
  594. hideBarTips: "隐藏分页隔条,沉浸式体验",
  595. setConfigPage: "将当前页面设为默认配置页",
  596. wedata2github: "将 wedata 地址更改为 github 仓库内的镜像地址",
  597. addOtherProp: "添加规则属性",
  598. addNextSelector: "添加选择器内容为 nextLink",
  599. addPageSelector: "添加选择器内容为 pageElement",
  600. propName: "输入规则属性名",
  601. propValue: "输入规则属性值",
  602. customFirst: "为本地自定义规则忽略缓存",
  603. rulesExample: "自定义规则详解",
  604. lastPage: "已到达最后一页",
  605. lastPageTips: "到达最后一页时进行提示"
  606. }
  607. },
  608. {
  609. name: "正體中文",
  610. match: ["zh", "zh-TW", "zh-HK"],
  611. lang: {
  612. enableDebug: "調試模式,輸出信息至控制台",
  613. updateNotification: "規則更新后提示",
  614. disable: "暫時禁用",
  615. disableSite: "站點禁用開關",
  616. disableSiteTips: "已在此站禁用",
  617. enableSiteTips: "已在此站啟用",
  618. enable: "啟用自動翻頁",
  619. toTop: "回到頂部",
  620. toBottom: "前往頁尾",
  621. current: "當前頁",
  622. forceIframe: "強制拼接",
  623. cancelForceIframe: "取消强制拼接",
  624. configure: "打開配置頁面",
  625. firstUpdate: "點擊此處初始化規則",
  626. update: "更新在綫規則",
  627. click2update: "點擊立即更新規則",
  628. loadNow: "立即翻頁",
  629. loadConfirm: "要翻几頁?(0為不間斷)",
  630. noNext: "沒有找到下一頁,請新建規則",
  631. passSec: "更新于 #t# 秒前",
  632. passMin: "更新于 #t# 分鐘前",
  633. passHour: "更新于 #t# 小時前",
  634. passDay: "更新于 #t# 天前",
  635. cantDel: "無法刪除内置規則",
  636. confirmDel: "是否確認要刪除此規則?",
  637. updateSucc: "更新成功",
  638. beginUpdate: "正在更新,請稍候",
  639. customUrls: "導入 Pagetual 或 AutoPagerize 規則 url,一行一條",
  640. customRules: "輸入【東方永頁機】格式的自定義規則 <a href='#t#'>✍️貢獻規則</a>",
  641. save: "存儲設置",
  642. loadingText: "少女祈禱中...",
  643. opacity: "不透明值",
  644. opacityPlaceholder: "0: 隱藏分隔條",
  645. hideBar: "隱藏分頁隔條",
  646. hideBarButNoStop: "隱藏但不停止",
  647. dbClick2Stop: "空白處雙擊暫停翻頁",
  648. sortTitle: "排序在下次更新規則後生效",
  649. autoRun: "自動啓用,否則為白名單模式",
  650. autoLoadNum: "自動加載指定頁數",
  651. turnRate: "距離頁尾【X】倍頁面高度時就開始翻頁",
  652. inputPageNum: "輸入頁碼跳轉",
  653. enableHistory: "翻頁后寫入歷史記錄",
  654. enableHistoryAfterInsert: "拼接後立即寫入歷史記錄,否則瀏覽完畢後再行寫入",
  655. contentVisibility: "自動切換 contentVisibility,提升渲染性能",
  656. initRun: "打開頁面后立即嘗試翻頁,否則滾動至頁尾再翻頁",
  657. preload: "翻頁前預讀下一頁,加速瀏覽",
  658. click2ImportRule: "點擊下方添加特殊規則庫,并靜待更新成功:",
  659. forceAllBody: "是否拼接整個頁面?",
  660. openInNewTab: "使拼接頁面的内容在新頁面打開",
  661. importSucc: "導入成功",
  662. import: "導入",
  663. editCurrent: "編輯此站規則",
  664. editBlacklist: "編輯黑名單網址,一行一條,支持? *通配符與正則",
  665. upBtnImg: "回到頁首圖標",
  666. downBtnImg: "前往頁尾圖標",
  667. sideControllerIcon: "側邊欄圖標",
  668. loadingTextTitle: "加載中文字",
  669. dbClick2StopCtrl: "Ctrl",
  670. dbClick2StopAlt: "Alt",
  671. dbClick2StopShift: "Shift",
  672. dbClick2StopMeta: "Meta",
  673. dbClick2StopKey: "快捷鍵",
  674. pageElementCss: "頁面主體框架的樣式",
  675. customCss: "自定義 css",
  676. firstAlert: "你還未導入規則庫,請選擇合適的規則庫導入哦",
  677. picker: "東方永頁機主體元素抓取器",
  678. closePicker: "關閉東方永頁機抓取器",
  679. pickerPlaceholder: "元素選擇器,沒想法建議留空",
  680. pickerCheck: "檢查你編輯的選擇器並複製",
  681. switchSelector: "點擊切換元素",
  682. gotoEdit: "使用當前的選擇器前往編輯規則",
  683. manualMode: "禁用拼接,手動用右方向鍵翻頁,左方向鍵返回",
  684. clickMode: "禁用拼接,滾動至頁尾時自動點擊下一頁",
  685. pageBarMenu: "點擊分隔條中間彈出菜單",
  686. nextSwitch: "切換其他頁碼",
  687. arrowToScroll: "左方向鍵滾動至上一頁,右方向鍵滾動至下一頁",
  688. sideController: "在側邊顯示翻頁控制欄",
  689. sideControllerScroll: "滾燈開關",
  690. sideControllerAlways: "始終顯示",
  691. hideLoadingIcon: "隱藏加載動畫",
  692. hideBarArrow: "隱藏分隔條定位箭頭",
  693. duplicate: "檢測到永頁機重複安裝,請刪除其他腳本管理器中的永頁機!",
  694. forceStateIframe: "以 iframe 嵌入整頁",
  695. forceStateDynamic: "通過 iframe 加載動態內容後取出",
  696. forceStateDisable: "在此站禁用",
  697. autoScrollRate: "滾動速度(1~1000)",
  698. disableAutoScroll: "停止自動滾動",
  699. enableAutoScroll: "開啟自動滾動",
  700. toggleAutoScroll: "自動滾動開關",
  701. ruleRequest: "適配請求",
  702. page: "Page ",
  703. prevPage: "上一頁",
  704. nextPage: "下一頁",
  705. errorRulesMustBeArray: "規則必須為陣列形式!",
  706. errorJson: "JSON 格式有錯,請重新檢查!",
  707. editSuccess: "編輯成功",
  708. errorWrongUrl: "URL 錯誤, 請重新檢查!",
  709. errorAlreadyExists: "已經存在!",
  710. settingsSaved: "設置已保存,刷新後生效",
  711. iframe: "強制拼接",
  712. dynamic: "動態加載",
  713. reloadPage: "編輯完成,是否立即刷新頁面?",
  714. copied: "已復制",
  715. noValidContent: "沒有檢測到有效内容,可能需要人機校驗,點擊查看",
  716. outOfDate: "脚本已過時,請及時更新到最新版本!",
  717. hideBarTips: "隱藏分頁隔條,沉浸式體驗",
  718. setConfigPage: "將當前頁面設為默認配置頁",
  719. wedata2github: "將 wedata 地址更改為 github 倉庫內的鏡像地址",
  720. addOtherProp: "添加規則屬性",
  721. addNextSelector: "添加選擇器內容為 nextLink",
  722. addPageSelector: "添加選擇器內容為 pageElement",
  723. propName: "輸入規則屬性名",
  724. propValue: "輸入規則屬性值",
  725. customFirst: "為本地自定義規則忽略緩存",
  726. rulesExample: "自定義規則詳解",
  727. lastPage: "已到達最後一頁",
  728. lastPageTips: "到達最後一頁時進行提示"
  729. }
  730. },
  731. {
  732. name: "日本語",
  733. match: ["ja"],
  734. lang: {
  735. enableDebug: "デバッグモード",
  736. updateNotification: "ルール更新後の通知",
  737. disable: "一時的に無効",
  738. disableSite: "無効状態の切り替え",
  739. disableSiteTips: "このサイトで既に無効になっています",
  740. enableSiteTips: "このサイトで既に有効になっています",
  741. enable: "ページめくりを有効にする",
  742. toTop: "トップに戻る",
  743. toBottom: "ページの下部に移動",
  744. current: "現在のページ",
  745. forceIframe: "強制ステッチ",
  746. cancelForceIframe: "強制ステッチをキャンセル",
  747. configure: "設定ページを開く",
  748. firstUpdate: "ここをクリックしてルールを初期化します",
  749. update: "更新ルール",
  750. click2update: "今すぐルールを更新してください",
  751. loadNow: "今すぐページをめくる",
  752. loadConfirm: "数ページめくりたいですか?(0は途切れない)",
  753. noNext: "次のページが見つかりません、新しいルールを作成してください",
  754. passSec: "#t#秒前に更新",
  755. passMin: "#t#分前に更新",
  756. passHour: "#t#時間前に更新",
  757. passDay: "#t#日前に更新",
  758. cantDel: "組み込みルールを削除できません",
  759. confirmDel: "このルールを削除してもよろしいですか?",
  760. updateSucc: "更新に成功しました",
  761. beginUpdate: "更新中、お待ちください",
  762. customUrls: "インポートルールのURL、1行に1つ",
  763. customRules: "【東方永頁機】の形式でカスタムルールを入力してください <a href='#t#'>✍️寄稿ルール</a>",
  764. save: "設定を保存",
  765. loadingText: "少女祈祷中...",
  766. opacity: "不透明値",
  767. opacityPlaceholder: "0: 隠す",
  768. hideBar: "ページ区切り文字を非表示にします",
  769. hideBarButNoStop: "非表示にするが停止しない",
  770. dbClick2Stop: "空白部分をダブルクリックしてページめくりを一時停止します",
  771. sortTitle: "並べ替えは、次のルールの更新後に有効になります",
  772. autoRun: "自動的に有効",
  773. autoLoadNum: "指定したページ数を自動的に読み込みます",
  774. turnRate: "ページの端からページの高さの【X】倍になったらページをめくる",
  775. inputPageNum: "ジャンプするページ番号を入力",
  776. enableHistory: "ページめくり後の履歴を書く",
  777. enableHistoryAfterInsert: "スプライシングの直後に履歴レコードを書き込みます。それ以外の場合は、閲覧後に書き込みます",
  778. contentVisibility: "contentVisibility を自動的に切り替えてレンダリング パフォーマンスを向上させる",
  779. initRun: "Webページを開いた直後にページをめくる",
  780. preload: "事前に次のページを読む",
  781. click2ImportRule: "以下をクリックして、ルールベースを追加します:",
  782. forceAllBody: "フルページ埋め込み?",
  783. openInNewTab: "スプライスされたページのコンテンツを新しいページで開きます",
  784. importSucc: "インポート完了",
  785. import: "インポート",
  786. editCurrent: "現在のルールの編集",
  787. editBlacklist: "ブラックリストのURLを編集し、1行ずつ、サポート? *ワイルドカード",
  788. upBtnImg: "トップアイコンに戻る",
  789. downBtnImg: "フッターアイコンに移動",
  790. sideControllerIcon: "サイドバー アイコン",
  791. loadingTextTitle: "テキストをロード",
  792. dbClick2StopCtrl: "Ctrlキー",
  793. dbClick2StopAlt: "Altキー",
  794. dbClick2StopShift: "Shiftキー",
  795. dbClick2StopMeta: "Metaキー",
  796. dbClick2StopKey: "Shortcutキー",
  797. pageElementCss: "ページ本文フレームの STYLE",
  798. customCss: "カスタム css",
  799. firstAlert: "ルールベースをインポートしていないため、インポートする適切なルールベースを選択してください",
  800. picker: "Pagetualページ要素ピッカー",
  801. closePicker: "Pagetualピッカーを閉じる",
  802. pickerPlaceholder: "わからない場合は空のままにしてください",
  803. pickerCheck: "セレクターをチェックしてコピー",
  804. switchSelector: "クリックして要素を切り替えます",
  805. gotoEdit: "現在のセレクターでルールを編集する",
  806. manualMode: "スプライシングを無効にします。手動で右の矢印キーを使用してページをめくります",
  807. clickMode: "スティッチングを無効にします。ページの最後までスクロールすると、次のページが自動的にクリックされます",
  808. pageBarMenu: "ページバーの中央をクリックしてメニューをポップアップ表示",
  809. nextSwitch: "次のページに切り替え",
  810. arrowToScroll: "左矢印キーで前へ、右矢印キーで次へ",
  811. sideController: "サイドバーにページング コントロール バーを表示する",
  812. sideControllerScroll: "スクロール スイッチ",
  813. sideControllerAlways: "常に表示",
  814. hideLoadingIcon: "読み込み中のアニメーションを隠す",
  815. hideBarArrow: "分割線の位置矢印を隠す",
  816. duplicate: "Pagetual の重複インストールが検出されました。他のスクリプト マネージャで永続的なページ マシンを削除してください!",
  817. forceStateIframe: "iframe にページ全体を埋め込む",
  818. forceStateDynamic: "iframe 経由で動的コンテンツを読み込む",
  819. forceStateDisable: "このステーションでのページめくりを無効にする",
  820. autoScrollRate: "スクロール速度 (1~1000)",
  821. disableAutoScroll: "自動スクロールを停止します",
  822. enableAutoScroll: "自動スクロールを有効にする",
  823. toggleAutoScroll: "自動スクロールの切り替え",
  824. ruleRequest: "ルール要求",
  825. page: "Page ",
  826. prevPage: "Prev page",
  827. nextPage: "Next page",
  828. errorRulesMustBeArray: "Rules must be a Array!",
  829. errorJson: "JSON error, check again!",
  830. editSuccess: "Edit successfully",
  831. errorWrongUrl: "Wrong url, check again!",
  832. errorAlreadyExists: "Already exists!",
  833. settingsSaved: "The settings are saved, refresh to view",
  834. iframe: "Iframe",
  835. dynamic: "Dynamic",
  836. reloadPage: "Edit completed, reload page now?",
  837. copied: "Copied",
  838. noValidContent: "有効なコンテンツが検出されませんでした。クリックして表示",
  839. outOfDate: "スクリプトが古くなっています。最新バージョンに更新してください。",
  840. hideBarTips: "ページネーション バーを非表示にします。没入型エクスペリエンス",
  841. setConfigPage: "現在のページをデフォルト設定ページとして設定",
  842. wedata2github: "wedata アドレスを github ウェアハウスのミラー アドレスに変更",
  843. addOtherProp: "ルールプロパティを追加",
  844. addNextSelector: "セレクターのコンテンツを nextLink として追加",
  845. addPageSelector: "セレクタ コンテンツを pageElement として追加",
  846. propName: "ルールのプロパティ名を入力してください",
  847. propValue: "ルールのプロパティ値を入力してください",
  848. customFirst: "ローカルカスタムルールのキャッシュを無視する",
  849. rulesExample: "カスタムルールの詳しい説明",
  850. lastPage: "最後のページに到達しました",
  851. lastPageTips: "最後のページに到達した時にヒントを表示する"
  852. }
  853. },
  854. {
  855. name: "Русский",
  856. match: ["ru", "ru-RU"],
  857. lang: {
  858. enableDebug: "Включить отладку",
  859. updateNotification: "Уведомление после обновления правила",
  860. disable: "Выключить",
  861. disableSite: "Включить/выключить на сайте",
  862. disableSiteTips: "Выключено для этого сайта",
  863. enableSiteTips: "Включено для этого сайта",
  864. enable: "Включить",
  865. toTop: "Наверх",
  866. toBottom: "Вниз",
  867. current: "Текущая страница",
  868. forceIframe: "Подгрузить ещё страницу",
  869. cancelForceIframe: "Отменить подгрузку",
  870. configure: "Настройки",
  871. firstUpdate: "Нажмите здесь, чтобы инициализировать правила",
  872. update: "Обновить правила",
  873. click2update: "Нажмите, чтобы обновить правила",
  874. loadNow: "Загрузить следующую страницу",
  875. loadConfirm: "Сколько страниц вы хотите загрузить? (0 означает бесконечность)",
  876. noNext: "Ссылка на следующую страницу не найдена. Пожалуйста, создайте новое правило",
  877. passSec: "Обновлено #t# секунд назад",
  878. passMin: "Обновлено #t# минут назад",
  879. passHour: "Обновлено #t# часов назад",
  880. passDay: "Обновлено #t# дней назад",
  881. cantDel: "Нельзя удалить правила по умолчанию",
  882. confirmDel: "Вы уверены, что хотите удалить эту ссылку?",
  883. updateSucc: "Правила обновлены",
  884. beginUpdate: "Обновление. Пожалуйста, немного подождите",
  885. customUrls: "Ссылки с правилами для импорта. Одна ссылка на строку",
  886. customRules: "Введите пользовательские правила в формате Pagetual. <a href='#t#'>✍️Улучшить встроенные правила</a>",
  887. save: "Сохранить настройки",
  888. loadingText: "Следующая страница подгружается…",
  889. opacity: "Прозрачность",
  890. opacityPlaceholder: "0 - скрыть",
  891. hideBar: "Скрыть разделитель страниц",
  892. hideBarButNoStop: "Скрыть, но не останавливать",
  893. dbClick2Stop: "Двойной клик на странице для выключения",
  894. sortTitle: "Правило сортировки применится после следующего обновления правил",
  895. autoRun: "Автозапуск (режим черного списка)",
  896. autoLoadNum: "Количество страниц для предзагрузки",
  897. turnRate: "Подгрузить страницу, когда она будет в 【X】 раз больше высоты страницы от конца страницы",
  898. inputPageNum: "Введите номер страницы для перехода",
  899. enableHistory: "Записать историю после переключения страниц",
  900. enableHistoryAfterInsert: "Записать запись истории сразу после вставки, иначе записать после просмотра",
  901. contentVisibility: "Автоматически переключать contentVisibility для повышения производительности рендеринга",
  902. initRun: "Подгружать страницы сразу после открытия",
  903. preload: "Предзагрузка следующей страницы",
  904. click2ImportRule: "Нажмите, чтобы импортировать базовые правила: ",
  905. forceAllBody: "Присоединить страницу целиком?",
  906. openInNewTab: "Открыть дополнительные ссылки в новой вкладке",
  907. importSucc: "Импорт завершен",
  908. import: "Импорт",
  909. editCurrent: "Изменить правило для текущего сайта",
  910. editBlacklist: "Изменить черный список. Одна ссылка на строку. Поддерживаются метасимволы: ? и *",
  911. upBtnImg: "Иконка перехода к началу",
  912. downBtnImg: "Иконка перехода к концу",
  913. sideControllerIcon: "Значок боковой панели",
  914. loadingTextTitle: "Текст во время загрузки",
  915. dbClick2StopCtrl: "Ctrl",
  916. dbClick2StopAlt: "Alt",
  917. dbClick2StopShift: "Shift",
  918. dbClick2StopMeta: "Meta",
  919. dbClick2StopKey: "Клавиша",
  920. pageElementCss: "Пользовательский стиль для основных элементов страницы",
  921. customCss: "Полный пользовательский CSS",
  922. firstAlert: "Вы не импортировали базовое правило. Пожалуйста, выберите соответствующее правило для импорта",
  923. picker: "Pagetual: выбор элемента страницы",
  924. closePicker: "Закрыть окно Pagetual",
  925. pickerPlaceholder: "Если не знаете, что тут писать — оставьте поле пустым",
  926. pickerCheck: "Проверить и скопировать селектор",
  927. switchSelector: "Нажмите для выбора элемента",
  928. gotoEdit: "Перейти к редактированию правила с текущим селектором",
  929. manualMode: "Отключить автоматическую загрузку страниц. Загружать вручную с помощью стрелки вправо (или вызова события 'pagetual.next')",
  930. clickMode: "Отключить \"сшивание\" страниц. При прокрутке до конца автоматически переходить на следующую страницу",
  931. pageBarMenu: "Открывать меню кликом на середину панели страниц",
  932. nextSwitch: "Переключить ссылку на следующую страницу",
  933. arrowToScroll: "Листать страницы клавишами со стрелками влево и вправо",
  934. sideController: "Показать справа панель перемещения по вкладке",
  935. sideControllerScroll: "Переключатель прокрутки",
  936. sideControllerAlways: "Всегда показывать",
  937. hideLoadingIcon: "Скрыть анимацию загрузки",
  938. hideBarArrow: "Скрыть кнопки перемещения на разделителе",
  939. duplicate: "Похоже, Pagetual установлен несколько раз. Пожалуйста, удалите Pagetual из других менеджеров скриптов!",
  940. forceStateIframe: "Вставить полную страницу как iframe",
  941. forceStateDynamic: "Загружать динамический контент через iframe",
  942. forceStateDisable: "Отключить перелистывание страниц на этой станции",
  943. autoScrollRate: "Скорость прокрутки (1~1000)",
  944. disableAutoScroll: "Остановить автоматическую прокрутку",
  945. enableAutoScroll: "Включить автопрокрутку",
  946. toggleAutoScroll: "Переключить автопрокрутку",
  947. ruleRequest: "Запрос правил",
  948. page: "Страница ",
  949. prevPage: "Предыдущая страница",
  950. nextPage: "Следующая страница",
  951. errorRulesMustBeArray: "Правила должны быть массивом!",
  952. errorJson: "Ошибка разбора JSON. Пожалуйста, исправьте его",
  953. editSuccess: "Редактирование успешно",
  954. errorWrongUrl: "Ссылка некорректна. Пожалуйста, исправьте её",
  955. errorAlreadyExists: "Уже существует!",
  956. settingsSaved: "Настройки сохранены. Обновите страницы",
  957. iframe: "iframe",
  958. dynamic: "Динамически",
  959. reloadPage: "Редактирование завершено. Обновить страницу?",
  960. copied: "Скопировано",
  961. noValidContent: "Действительный контент не обнаружен, нажмите для просмотра",
  962. outOfDate: "Скрипт устарел, своевременно обновляйте до последней версии!",
  963. hideBarTips: "Скрыть панель разбиения на страницы, иммерсивный опыт",
  964. setConfigPage: "Установить текущую страницу в качестве страницы конфигурации по умолчанию",
  965. wedata2github: "Изменить адрес wedata на зеркальный адрес на складе github",
  966. addOtherProp: "Добавить свойство правила",
  967. addNextSelector: "Добавить содержимое селектора как nextLink",
  968. addPageSelector: "Добавить содержимое селектора как pageElement",
  969. propName: "Введите имя свойства правила",
  970. propValue: "Введите значение свойства правила",
  971. customFirst: "Игнорировать кеш для локальных пользовательских правил",
  972. rulesExample: "Подробное объяснение настраиваемых правил",
  973. lastPage: "Достигнута последняя страница",
  974. lastPageTips: "Показывать подсказки при достижении последней страницы"
  975. }
  976. }
  977. ];
  978. var langList = {};
  979. langData.forEach(lang => {
  980. langList[lang.match[0]] = lang.name;
  981. });
  982. var i18nData = langData[0].lang;
  983. function setLang(la) {
  984. for (let i = 0; i < langData.length; i++) {
  985. let lang = langData[i];
  986. if (lang && lang.match.indexOf(la) !== -1) {
  987. i18nData = lang.lang;
  988. if (lang.encode) {
  989. for (let k in i18nData) {
  990. i18nData[k] = decodeURI(i18nData[k]);
  991. }
  992. }
  993. break;
  994. }
  995. }
  996. }
  997. setLang(lang);
  998. var enableDebug = true;
  999. var _GM_xmlhttpRequest, _GM_registerMenuCommand, _GM_notification, _GM_addStyle, _GM_openInTab, _GM_info, _GM_setClipboard;
  1000. function i18n(name, param) {
  1001. return i18nData[name] ? i18nData[name].replace("#t#", param) : name;
  1002. }
  1003.  
  1004. function debug(str, title) {
  1005. if (enableDebug) {
  1006. console.log(
  1007. `%cPagetual v.${_GM_info.script.version}】 ${title ? title : 'debug'}:`,
  1008. 'color: yellow;font-size: large;font-weight: bold;background-color: darkblue;',
  1009. str
  1010. );
  1011. }
  1012. }
  1013.  
  1014. if (typeof GM_xmlhttpRequest !== 'undefined') {
  1015. _GM_xmlhttpRequest = GM_xmlhttpRequest;
  1016. } else if (typeof GM !== 'undefined' && typeof GM.xmlHttpRequest !== 'undefined') {
  1017. _GM_xmlhttpRequest = GM.xmlHttpRequest;
  1018. } else {
  1019. _GM_xmlhttpRequest = (f) => {fetch(f.url, {method: f.method || 'GET', body: f.data, headers: f.headers}).then(response => response.text()).then(data => {f.onload && f.onload({response: data})}).catch(f.onerror && f.onerror())};
  1020. }
  1021. if (typeof GM_registerMenuCommand !== 'undefined') {
  1022. _GM_registerMenuCommand = GM_registerMenuCommand;
  1023. } else if (typeof GM !== 'undefined' && typeof GM.registerMenuCommand !== 'undefined') {
  1024. _GM_registerMenuCommand = GM.registerMenuCommand;
  1025. } else {
  1026. _GM_registerMenuCommand = (s, f) => {debug(s); debug(f);};
  1027. }
  1028. if (typeof GM_info !== 'undefined') {
  1029. _GM_info = GM_info;
  1030. } else if (typeof GM !== 'undefined' && typeof GM.info !== 'undefined') {
  1031. _GM_info = GM.info;
  1032. } else {
  1033. _GM_info = {script: {}};
  1034. }
  1035. if (typeof GM_notification !== 'undefined') {
  1036. _GM_notification = GM_notification;
  1037. } else if (typeof GM !== 'undefined' && typeof GM.notification !== 'undefined') {
  1038. _GM_notification = GM.notification;
  1039. } else {
  1040. _GM_notification = (s) => {showTips(String(s.text || s));};
  1041. }
  1042. if (typeof GM_openInTab !== 'undefined') {
  1043. _GM_openInTab = GM_openInTab;
  1044. } else if (typeof GM !== 'undefined' && typeof GM.openInTab !== 'undefined') {
  1045. _GM_openInTab = GM.openInTab;
  1046. } else {
  1047. _GM_openInTab = (s,t) => {window.open(s); debug(t);};
  1048. }
  1049. if (typeof GM_addStyle !== 'undefined') {
  1050. _GM_addStyle = GM_addStyle;
  1051. } else if (typeof GM !== 'undefined' && typeof GM.addStyle !== 'undefined') {
  1052. _GM_addStyle = GM.addStyle;
  1053. } else {
  1054. _GM_addStyle = cssStr => {
  1055. let styleEle = document.createElement("style");
  1056. styleEle.innerHTML = cssStr;
  1057. document.head.appendChild(styleEle);
  1058. return styleEle;
  1059. };
  1060. }
  1061. if (typeof GM_setClipboard !== 'undefined') {
  1062. _GM_setClipboard = GM_setClipboard;
  1063. } else if (typeof GM !== 'undefined' && typeof GM.setClipboard !== 'undefined') {
  1064. _GM_setClipboard = GM.setClipboard;
  1065. } else {
  1066. _GM_setClipboard = (s, i) => {debug(s); debug(i);};
  1067. }
  1068. const _unsafeWindow = (typeof unsafeWindow === 'undefined') ? window : unsafeWindow;//兼容 ios userscripts 的寫法
  1069. const storage = {
  1070. supportGM: typeof GM_getValue === 'function' && typeof GM_getValue('a', 'b') !== 'undefined',
  1071. supportGMPromise: typeof GM !== 'undefined' && typeof GM.getValue === 'function' && typeof GM.getValue('a', 'b') !== 'undefined' && typeof GM.getValue('a', 'b').then === 'function',
  1072. supportCrossSave: function() {
  1073. return this.supportGM || this.supportGMPromise;
  1074. },
  1075. mxAppStorage: (function() {
  1076. try {
  1077. return window.external.mxGetRuntime().storage;
  1078. } catch(e) {
  1079. }
  1080. })(),
  1081. operaUJSStorage: (function() {
  1082. try {
  1083. return window.opera.scriptStorage;
  1084. } catch(e) {
  1085. }
  1086. })(),
  1087. setItem: function(key, value) {
  1088. if (this.supportGMPromise) {
  1089. GM.setValue(key, value);
  1090. if (value === "" && typeof GM !== 'undefined' && typeof GM.deleteValue !== 'undefined') {
  1091. GM.deleteValue(key);
  1092. }
  1093. } else if (this.supportGM) {
  1094. GM_setValue(key, value);
  1095. if (value === "" && typeof GM_deleteValue !== 'undefined') {
  1096. GM_deleteValue(key);
  1097. }
  1098. } else if (this.operaUJSStorage) {
  1099. this.operaUJSStorage.setItem(key, value);
  1100. } else if (this.mxAppStorage) {
  1101. this.mxAppStorage.setConfig(key, value);
  1102. } else if (window.localStorage) {
  1103. window.localStorage.setItem(key, value);
  1104. }
  1105. },
  1106. getItem: function(key, cb) {
  1107. var value;
  1108. if (this.supportGMPromise) {
  1109. value = GM.getValue(key).then(v => {cb(v);});
  1110. return;
  1111. } else if (this.supportGM) {
  1112. value = GM_getValue(key);
  1113. } else if (this.operaUJSStorage) {
  1114. value = this.operaUJSStorage.getItem(key);
  1115. } else if (this.mxAppStorage) {
  1116. value = this.mxAppStorage.getConfig(key);
  1117. } else if (window.localStorage) {
  1118. value = window.localStorage.getItem(key);
  1119. }
  1120. cb(value);
  1121. }
  1122. };
  1123. async function getData(key) {
  1124. return new Promise((resolve) => {
  1125. storage.getItem(key, value => {
  1126. resolve(value);
  1127. });
  1128. });
  1129. }
  1130. async function getListData(list, key) {
  1131. return new Promise((resolve) => {
  1132. storage.getItem(list, listData => {
  1133. let value;
  1134. if (listData) {
  1135. for(var i = 0; i < listData.length; i++) {
  1136. let data = listData[i];
  1137. if (data.k === key) {
  1138. value = data.v;
  1139. break;
  1140. }
  1141. }
  1142. }
  1143. resolve(value);
  1144. });
  1145. });
  1146. }
  1147. function setListData(list, key, value, length) {
  1148. storage.getItem(list, listData => {
  1149. if (!listData) {
  1150. listData = [];
  1151. }
  1152. listData = listData.filter(data => data && data.k !== key);
  1153. if (value !== "") {
  1154. listData.unshift({k: key, v: value});
  1155. if (listData.length > (length || 100)) {
  1156. listData.pop();
  1157. }
  1158. }
  1159. storage.setItem(list, listData);
  1160. });
  1161. }
  1162. const isMobile = ('ontouchstart' in document.documentElement);
  1163. const configPage = [`https://pagetual.hoothin.com/${lang === 'zh-CN' ? 'cn/' : ''}rule.html`,
  1164. "https://github.com/hoothin/UserScripts/tree/master/Pagetual",
  1165. "https://hoothin.github.io/UserScripts/Pagetual/"];
  1166. const firstRunPage = "https://pagetual.hoothin.com/firstRun";
  1167. const guidePage = /^https?:\/\/.*pagetual.*rule\.html/i;
  1168. const ruleImportUrlReg = /greasyfork\.org\/.*scripts\/438684(\-[^\/]*)?(\/discussions|\/?$|\/feedback)|github\.com\/hoothin\/UserScripts\/(tree\/master\/Pagetual|issues)|^https:\/\/pagetual\.hoothin\.com\/.*firstRun\.html/i;
  1169. const allOfBody = "body>*";
  1170. const mainSel = ["article,.article","[role=main],main,.main,#main","#results"];
  1171. 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\u005c\u0073\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\u0412\u043f\u0435\u0440\u0435\u0434", "i");
  1172. const nextTextReg2 = new RegExp("\u005e\u0028\u005b\u4e0b\u540e\u5f8c\u6b21\u005d\u005b\u4e00\u30fc\u0031\u005d\u003f\u005b\u7ae0\u8bdd\u8a71\u8282\u7bc0\u5e45\u005d\u007c\u006e\u0065\u0078\u0074\u002e\u003f\u0063\u0068\u0061\u0070\u0074\u0065\u0072\u0029\u0028\u005b\u003a\uff1a\u005c\u002d\u005f\u2014\u005c\u0073\u005c\u002e\u3002\u003e\u0023\u00b7\u005c\u005b\u3010\u3001\uff08\u005c\u0028\u002f\u002c\uff0c\uff1b\u003b\u2192\u005d\u007c\u0024\u0029", "i");
  1173. const lazyImgAttr = ["data-lazy-src", "data-s", "data-lazy", "data-isrc", "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"];
  1174. var rulesData = {uninited: true, firstRun: true, sideController: !isMobile}, ruleUrls, updateDate, loadNowNum = 5, autoScrollRate = 50;
  1175. var isPause = false, manualPause = false, isHideBar = false, isLoading = false, curPage = 1, forceState = 0, autoScroll = 0, autoScrollInterval, bottomGap = 1000, autoLoadNum = -1, nextIndex = 0, stopScroll = false, clickMode = false, openInNewTab = 0, charset = "UTF-8", charsetValid = true, urlWillChange = false, hidePageBar = false;
  1176. var tryTimes = 0, showedLastPageTips = false, rate = 1, author = '';
  1177.  
  1178. function getBody(doc) {
  1179. return doc.body || doc.querySelector('body') || doc;
  1180. }
  1181.  
  1182. function getElementByXpath(xpath, doc, contextNode) {
  1183. if (doc && doc.ownerDocument) doc = doc.ownerDocument;
  1184. doc = (doc && doc.evaluate) ? doc : document;
  1185. contextNode = contextNode || doc;
  1186. try {
  1187. let xpathNode = (s, d, n) => {
  1188. let result = d.evaluate(s, n, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null);
  1189. return result.singleNodeValue && result.singleNodeValue.nodeType === 1 && result.singleNodeValue;
  1190. };
  1191. let selSplit = xpath.split(" =>> ");
  1192. if (selSplit.length === 2) {
  1193. let ele = xpathNode(selSplit[0], doc, contextNode);
  1194. if (ele && ele.shadowRoot) {
  1195. return xpathNode(selSplit[1], ele.shadowRoot, ele.shadowRoot);
  1196. }
  1197. } else {
  1198. return xpathNode(xpath, doc, contextNode);
  1199. }
  1200. } catch (err) {
  1201. debug(`Invalid xpath: ${xpath}`);
  1202. }
  1203. return null;
  1204. }
  1205.  
  1206. function getAllElementsByXpath(xpath, contextNode, doc) {
  1207. if (doc && doc.ownerDocument) doc = doc.ownerDocument;
  1208. doc = (doc && doc.evaluate) ? doc : document;
  1209. contextNode = contextNode || doc;
  1210. var result = [];
  1211. try {
  1212. var query = doc.evaluate(xpath, contextNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  1213. for (var i = 0; i < query.snapshotLength; i++) {
  1214. var node = query.snapshotItem(i);
  1215. if (node.nodeType === 1) {
  1216. result.push(node);
  1217. }
  1218. }
  1219. } catch (err) {
  1220. debug(`Invalid xpath: ${xpath}`);
  1221. }
  1222. return result;
  1223. }
  1224.  
  1225. function isXPath(xpath) {
  1226. if (!xpath) {
  1227. return false;
  1228. }
  1229. return /^\(*(descendant::|\.\/|\/|id\()/.test(xpath);
  1230. }
  1231.  
  1232. function getAllElements(sel, doc, contextNode) {
  1233. try {
  1234. if (sel.indexOf(" =>> ") !== -1) {
  1235. let result = getElement(sel, doc, contextNode);
  1236. return result && [result];
  1237. }
  1238. if (!isXPath(sel)) {
  1239. return doc.querySelectorAll(sel);
  1240. }
  1241. } catch(e) {
  1242. debug(e, 'Error selector');
  1243. }
  1244. return getAllElementsByXpath(sel, contextNode, doc);
  1245. }
  1246.  
  1247. function getElement(sel, doc, contextNode, bySort) {
  1248. try {
  1249. if (!isXPath(sel)) {
  1250. let checkShadow = s => {
  1251. let selSplit = s.split(" =>> ");
  1252. if (selSplit.length === 2) {
  1253. let ele = doc.querySelector(selSplit[0]);
  1254. return ele && ele.shadowRoot && ele.shadowRoot.querySelector(selSplit[1]);
  1255. } else return doc.querySelector(s);
  1256. };
  1257. if (!bySort) {
  1258. return checkShadow(sel);
  1259. } else {
  1260. let selArr = sel.split(",");
  1261. try {
  1262. for (let i = 0; i < selArr.length; i++) {
  1263. let ele = checkShadow(selArr[i].trim());
  1264. if (ele) {
  1265. return ele;
  1266. }
  1267. }
  1268. } catch(e) {
  1269. return checkShadow(sel);
  1270. }
  1271. return null;
  1272. }
  1273. }
  1274. } catch(e) {
  1275. debug(e, 'Error selector');
  1276. }
  1277. return getElementByXpath(sel, doc, contextNode);
  1278. }
  1279.  
  1280. function compareNodeName(node, names) {
  1281. if (!node || !node.nodeName || !node.nodeName.toLowerCase) {
  1282. return false;
  1283. }
  1284. let nodeName = node.nodeName.toLowerCase();
  1285. for (let i = 0; i < names.length; i++) {
  1286. if (names[i] === nodeName) {
  1287. return true;
  1288. }
  1289. }
  1290. return false;
  1291. }
  1292.  
  1293. function geneSelector(ele, addID, exact) {
  1294. let selector = ele.nodeName.toLowerCase();
  1295. //Google id class都是隨機。百度更過分,style script順序都是隨機的
  1296. if (selector !== "html" && selector !== "body") {
  1297. let hasId = false;
  1298. if (addID && ele.id && /^[a-z_][\w\-_]*$/i.test(ele.id)) {
  1299. if (ele.ownerDocument && ele.ownerDocument.querySelectorAll("#" + ele.id).length === 1) {
  1300. hasId = true;
  1301. selector = '#' + ele.id;
  1302. }
  1303. }
  1304. if (!hasId) {
  1305. let className = "";
  1306. if (ele.className) {
  1307. let classList = ele.classList;
  1308. for (let i = 0; i < classList.length; i++) {
  1309. let c = classList[i];
  1310. if (c !== 'scrolling' && /^[a-z_][\w\-_]*$/.test(c) && !/\d{4,}/.test(c)) {
  1311. className += '.' + c;
  1312. }
  1313. }
  1314. selector += className;
  1315. }
  1316. let parent = ele.parentElement;
  1317. if (parent) {
  1318. if (exact) {
  1319. let i, nth = 0, all = 0;
  1320. for (i = 0; i < parent.children.length; i++) {
  1321. if (parent.children[i].nodeName === ele.nodeName) {
  1322. all++;
  1323. if (parent.children[i] === ele) {
  1324. nth = all;
  1325. }
  1326. if (nth > 0 && all > 1) {
  1327. break;
  1328. }
  1329. }
  1330. }
  1331. selector += (all === 1 ? "" : `:nth-of-type(${nth})`);
  1332. } else if (!className && !hasId && parent.children.length > 1 && !compareNodeName(parent, ["html"])) {
  1333. let prevE = ele.previousElementSibling;
  1334. if (prevE && prevE.className) {
  1335. let classList = prevE.classList;
  1336. for (let i = 0; i < classList.length; i++) {
  1337. let c = classList[i];
  1338. if (c !== 'scrolling' && /^[a-z_][\w\-_]*$/.test(c) && !/\d{4,}/.test(c)) {
  1339. className += '.' + c;
  1340. }
  1341. }
  1342. if (className) {
  1343. selector = prevE.nodeName.toLowerCase() + className + "+" + selector;
  1344. }
  1345. }
  1346. if (!className) {
  1347. let i, nth = 0, all = 0;
  1348. for (i = 0; i < parent.children.length; i++) {
  1349. if (parent.children[i].nodeName === ele.nodeName) {
  1350. all++;
  1351. if (parent.children[i] === ele) {
  1352. nth = all;
  1353. }
  1354. if (nth > 0 && all > 1) {
  1355. break;
  1356. }
  1357. }
  1358. }
  1359. selector += (all === 1 ? "" : `:nth-of-type(${nth})`);
  1360. }
  1361. }
  1362. selector = geneSelector(parent, addID, exact) + ' > ' + selector;
  1363. }
  1364. }
  1365. }
  1366. return selector;
  1367. }
  1368.  
  1369. function createXPathFromElement(elm) {
  1370. let allNodes = document.getElementsByTagName('*'), segs;
  1371. for (segs = []; elm && elm.nodeType === 1; elm = elm.parentNode) {
  1372. if (compareNodeName(elm, ["body", "html"])) {
  1373. segs.unshift(elm.localName.toLowerCase());
  1374. continue;
  1375. }
  1376. if (elm.hasAttribute && elm.hasAttribute('id')) {
  1377. var uniqueIdCount = 0;
  1378. for (var n = 0; n < allNodes.length; n++) {
  1379. if (allNodes[n].hasAttribute('id') && allNodes[n].id === elm.id) {
  1380. uniqueIdCount++;
  1381. }
  1382. if (uniqueIdCount > 1) {
  1383. break;
  1384. }
  1385. }
  1386. if ( uniqueIdCount === 1) {
  1387. segs.unshift('id("' + elm.getAttribute('id') + '")');
  1388. return segs.join('/');
  1389. } else {
  1390. segs.unshift(elm.localName.toLowerCase() + '[@id="' + elm.getAttribute('id') + '"]');
  1391. }
  1392. } else if (elm.hasAttribute && elm.hasAttribute('class')) {
  1393. segs.unshift(elm.localName.toLowerCase() + '[@class="' + elm.getAttribute('class') + '"]');
  1394. } else {
  1395. let i, sib;
  1396. for (i = 1, sib = elm.previousSibling; sib; sib = sib.previousSibling) {
  1397. if (sib.localName === elm.localName) {
  1398. i++;
  1399. }
  1400. }
  1401. segs.unshift(elm.localName.toLowerCase() + '[' + i + ']');
  1402. }
  1403. }
  1404. return segs.length ? '/' + segs.join('/') : null;
  1405. }
  1406.  
  1407. const escapeHTMLPolicy = (_unsafeWindow.trustedTypes && _unsafeWindow.trustedTypes.createPolicy) ? _unsafeWindow.trustedTypes.createPolicy('pagetual_default', {
  1408. createHTML: (string, sink) => string
  1409. }) : null;
  1410.  
  1411. function createHTML(html) {
  1412. return escapeHTMLPolicy ? escapeHTMLPolicy.createHTML(html) : html;
  1413. }
  1414.  
  1415. const AsyncFunction = Object.getPrototypeOf(async function(){}).constructor;
  1416.  
  1417. async function sleep(time) {
  1418. await new Promise((resolve) => {
  1419. setTimeout(() => {
  1420. resolve();
  1421. }, time);
  1422. });
  1423. }
  1424.  
  1425. class RuleParser {
  1426. constructor() {
  1427. this.hpRules = [];
  1428. this.smartRules = [];
  1429. this.customRules = [];
  1430. this.rules = [];
  1431. this.pageDoc = document;
  1432. this.nextLinkHref = null;
  1433. this.nextTitle = "";
  1434. this.oldUrl = "";
  1435. this.curUrl = location.href;
  1436. this.curSiteRule = {};
  1437. }
  1438.  
  1439. async initSavedRules(callback) {
  1440. var self = this;
  1441. let smartRules = await getData("smartRules");
  1442. if (smartRules) self.smartRules = smartRules;
  1443. let hpRules = await getData("hpRules");
  1444. if (hpRules) self.hpRules = hpRules;
  1445. let customRules = await getData("customRules");
  1446. if (customRules) self.customRules = customRules;
  1447. if (_unsafeWindow.pagetualRules && _unsafeWindow.pagetualRules.length) {
  1448. _unsafeWindow.pagetualRules.forEach(rule => {
  1449. rule.isScript = true;
  1450. });
  1451. self.customRules = _unsafeWindow.pagetualRules.concat(self.customRules);
  1452. }
  1453. let rules = await getData("rules");
  1454. if (rules) self.rules = rules;
  1455. callback();
  1456. }
  1457.  
  1458. saveCurSiteRule() {
  1459. /*if(!this.curSiteRule || !this.curSiteRule.url || this.curSiteRule.smart || this.curSiteRule.url.length<13)return;
  1460. this.hpRules=this.hpRules.filter(item=>{return item&&item.url!=this.curSiteRule.url});
  1461. this.hpRules.unshift(this.curSiteRule);
  1462. if(this.hpRules.length>30){
  1463. this.hpRules.pop();
  1464. }
  1465. storage.setItem("hpRules", this.hpRules);*/
  1466. }
  1467.  
  1468. requestJSON(url, callback) {
  1469. _GM_xmlhttpRequest({
  1470. url: url,
  1471. method: 'GET',
  1472. timeout: 1000000,
  1473. headers: {
  1474. 'accept': 'application/json,text/html',
  1475. 'Referer': url,
  1476. },
  1477. onload: function(res) {
  1478. let json = null;
  1479. try {
  1480. json = JSON.parse(res.response || res.responseText);
  1481. } catch(e) {
  1482. debug(e, 'Error json');
  1483. }
  1484. callback(json);
  1485. },
  1486. onerror: function(e) {
  1487. callback(null, e);
  1488. },
  1489. ontimeout: function(e) {
  1490. callback(null, e);
  1491. }
  1492. });
  1493. }
  1494.  
  1495. formatRule(item, from) {
  1496. if (item.data && item.data.url) {
  1497. let result = {
  1498. name: item.name,
  1499. from: from,
  1500. action: item.data.forceIframe === "true" ? 1 : undefined,
  1501. url: item.data.url,
  1502. pageElement: item.data.pageElement,
  1503. nextLink: item.data.nextLink,
  1504. insert: item.data.insertBefore||undefined,
  1505. updatedAt: item.updated_at
  1506. };
  1507. let _css = (item.data.Stylus || '') + (item.data.CSS || '');
  1508. if (_css) result.css = _css;
  1509. if (item.data.bookmarklet) result.pageAction = item.data.bookmarklet;
  1510. return result;
  1511. } else {
  1512. item.from = from;
  1513. return item;
  1514. }
  1515. return null;
  1516. }
  1517.  
  1518. addRuleByUrl(url, from, callback) {
  1519. if (url.indexOf("?") === -1) {
  1520. url = url + "?" + Date.now();
  1521. } else {
  1522. url = url + "&" + Date.now();
  1523. }
  1524. this.requestJSON(url, (json,err) => {
  1525. if (!json) {
  1526. debug(err, "Failed to update " + url + " rules!");
  1527. }
  1528. this.addRules(json, from);
  1529. callback(json, err);
  1530. });
  1531. }
  1532.  
  1533. addRules(rules, from) {
  1534. if (rules && rules.length > 0) {
  1535. let first = -1;
  1536. this.rules = this.rules.filter((item, i) => {
  1537. if (item.from === from) {
  1538. if (first === -1) first = i;
  1539. return false;
  1540. } else return true;
  1541. });
  1542. if (first === -1) first = 0;
  1543. rules.forEach(item => {
  1544. let rule = this.formatRule(item, from);
  1545. if (rule) {
  1546. this.rules.splice(first, 0, rule)
  1547. }
  1548. });
  1549. }
  1550. }
  1551.  
  1552. ruleMatchPre(r) {
  1553. if (r.include) {
  1554. let include;
  1555. if (Array && Array.isArray && Array.isArray(r.include)) {
  1556. include = r.include.every((sel, i) => {
  1557. let ele = getElement(sel, document);
  1558. return !!ele;
  1559. });
  1560. } else include = getElement(r.include, document);
  1561. if (!include) return false;
  1562. }
  1563. if (r.exclude) {
  1564. let exclude;
  1565. if (Array && Array.isArray && Array.isArray(r.exclude)) {
  1566. exclude = !r.exclude.every((sel, i) => {
  1567. let ele = getElement(sel, document);
  1568. return !ele;
  1569. });
  1570. } else exclude = getElement(r.exclude, document);
  1571. if (exclude) return false;
  1572. }
  1573. return true;
  1574. }
  1575.  
  1576. ruleMatchReady(r) {
  1577. let findIndex = 0;
  1578. if (r.nextLink && r.nextLink !== 0) {
  1579. let nextLinkSel = r.nextLink, nextLink;
  1580. if (Array && Array.isArray && Array.isArray(nextLinkSel)) {
  1581. nextLink = !nextLinkSel.every((sel, i) => {
  1582. let ele = getElement(sel, document);
  1583. if (ele) findIndex = i;
  1584. return !ele;
  1585. });
  1586. } else nextLink = getElement(nextLinkSel, document);
  1587. if (!nextLink) return false;
  1588. }
  1589. if (r.pageElement) {
  1590. let pageElementSel = r.pageElement, pageElement;
  1591. if (Array && Array.isArray && Array.isArray(pageElementSel)) {
  1592. pageElementSel = pageElementSel[findIndex];
  1593. }
  1594. pageElement = getElement(pageElementSel, document);
  1595. if (!pageElement) return false;
  1596. }
  1597. if (r.insert) {
  1598. let insertSel = r.insert, insert;
  1599. if (Array && Array.isArray && Array.isArray(insertSel)) {
  1600. insertSel = insertSel[findIndex];
  1601. }
  1602. insert = getElement(insertSel, document);
  1603. if (!insert) return false;
  1604. }
  1605. //if (findIndex !== 0) nextIndex = findIndex;
  1606. return true;
  1607. }
  1608.  
  1609. ruleMatch(r) {
  1610. return this.ruleMatchPre(r) && this.ruleMatchReady(r);
  1611. }
  1612.  
  1613. scrollToShow(sel, doc) {
  1614. let exclude = getElement(sel, doc);
  1615. if (exclude) {
  1616. var actualTop = exclude.offsetTop;
  1617. var current = exclude.offsetParent;
  1618. while (current !== null) {
  1619. actualTop += current.offsetTop;
  1620. current = current.offsetParent;
  1621. }
  1622. getBody(doc).scrollTop = 0;
  1623. doc.documentElement.scrollTop = 0;
  1624. let maxHeight = Math.max(getBody(doc).scrollHeight, doc.documentElement.scrollHeight);
  1625. getBody(doc).scrollTop = actualTop - 10;
  1626. doc.documentElement.scrollTop = actualTop - 10;
  1627. setTimeout(() => {
  1628. while (actualTop < maxHeight) {
  1629. actualTop += 200;
  1630. getBody(doc).scrollTop = actualTop;
  1631. doc.documentElement.scrollTop = actualTop;
  1632. }
  1633. }, 0);
  1634. return false;
  1635. }
  1636. return true;
  1637. }
  1638.  
  1639. waitElement(doc, selArr) {
  1640. if (!selArr) selArr = this.curSiteRule.waitElement;
  1641. if (!Array.isArray(selArr)) {
  1642. selArr = [selArr];
  1643. }
  1644. let includeSel = selArr[0].trim(), excludeSel;
  1645. if (selArr.length === 2) {
  1646. excludeSel = selArr[1].trim().replace(/^!/, '');
  1647. } else if (includeSel.indexOf('!') === 0) {
  1648. excludeSel = includeSel.replace(/^!/, '');
  1649. includeSel = '';
  1650. }
  1651. if (includeSel) {
  1652. let include = getElement(includeSel, doc);
  1653. if (!include) {
  1654. if (doc !== document) {
  1655. getBody(doc).scrollTop = 9999999;
  1656. if (doc.documentElement) {
  1657. doc.documentElement.scrollTop = 9999999;
  1658. }
  1659. }
  1660. return false;
  1661. }
  1662. }
  1663. if (doc === document) return true;
  1664. if (excludeSel) {
  1665. if (!this.scrollToShow(excludeSel, doc)) {
  1666. if (!loadingDiv.offsetParent && this.insert.parentNode) {
  1667. this.insertElement(loadingDiv);
  1668. }
  1669. return false;
  1670. }
  1671. }
  1672. return true;
  1673. }
  1674.  
  1675. runPageBar(pageBar) {
  1676. if (this.curSiteRule.pageBar && this.curSiteRule.pageBar !== 0) {
  1677. try {
  1678. ((typeof this.curSiteRule.pageBar === 'function') ? this.curSiteRule.pageBar : Function("pageBar",'"use strict";' + this.curSiteRule.pageBar))(pageBar);
  1679. } catch(e) {
  1680. debug(e);
  1681. }
  1682. }
  1683. }
  1684.  
  1685. runWait(cb) {
  1686. let checkEval = null, waitTime = 0;
  1687. if (this.curSiteRule.waitElement) {
  1688. checkEval = async doc => {
  1689. return await this.waitElement(doc);
  1690. };
  1691. } else if(this.curSiteRule.wait) {
  1692. if (isNaN(this.curSiteRule.wait)) {
  1693. try {
  1694. checkEval = (typeof this.curSiteRule.wait === 'function') ? this.curSiteRule.wait : new AsyncFunction("doc", '"use strict";' + this.curSiteRule.wait);
  1695. } catch(e) {
  1696. debug(e);
  1697. }
  1698. } else {
  1699. waitTime = this.curSiteRule.wait;
  1700. }
  1701. }
  1702. cb(checkEval, waitTime);
  1703. }
  1704.  
  1705. findNoNext() {
  1706. if (!this.curSiteRule || !this.curSiteRule.smart || this.curSiteRule.nextLink === 0 || this.possibleRule) return;
  1707. let self = this;
  1708. self.curSiteRule.nextLink = 0;
  1709. self.smartRules = self.smartRules.filter(item => {return item && item.url !== self.curSiteRule.url;});
  1710. self.smartRules.unshift(self.curSiteRule);
  1711. storage.setItem("smartRules", self.smartRules);
  1712. }
  1713.  
  1714. async getRule(callback) {
  1715. var href = location.href.slice(0, 500);
  1716. if (noRuleTest) {
  1717. this.curSiteRule = {};
  1718. this.curSiteRule.url = href;
  1719. this.curSiteRule.smart = true;
  1720. callback();
  1721. return;
  1722. }
  1723. if (_unsafeWindow.pagetualRule) {
  1724. this.curSiteRule = _unsafeWindow.pagetualRule;
  1725. if (!this.curSiteRule.url) this.curSiteRule.url = ".";
  1726. this.curSiteRule.isScript = true;
  1727. }
  1728. if (this.curSiteRule && this.curSiteRule.url && !this.curSiteRule.smart) {
  1729. let urlReg = new RegExp(this.curSiteRule.url, "i");
  1730. if (urlReg.test(href) && this.ruleMatch(this.curSiteRule)) {
  1731. return callback();
  1732. }
  1733. }
  1734. if (this.possibleRule) {
  1735. let urlReg = new RegExp(this.possibleRule.url, "i");
  1736. if (urlReg.test(href) && this.ruleMatch(this.possibleRule)) {
  1737. this.curSiteRule = this.possibleRule;
  1738. debug(this.curSiteRule, 'Match');
  1739. return callback();
  1740. }
  1741. }
  1742. this.curSiteRule = {};
  1743. var self = this;
  1744.  
  1745. function setRule(r) {
  1746. if (self.preSiteRule) {
  1747. href = location.href.slice(0, 500);
  1748. let urlReg = new RegExp(self.preSiteRule.url, "i");
  1749. if (urlReg.test(href) && self.ruleMatch(self.preSiteRule)) {
  1750. self.curSiteRule = self.preSiteRule;
  1751. return callback();
  1752. }
  1753. }
  1754. if (r.from === 2) {
  1755. delete r.autoLoadNum;
  1756. delete r.history;
  1757. delete r.sideController;
  1758. if (r.pageBar === 0) delete r.pageBar;
  1759. }
  1760. if (!r.smart) {
  1761. self.insert = null;
  1762. self.curSiteRule = r;
  1763. self.preSiteRule = r;
  1764. if (r.enable !== 0) debug(r, 'Match');
  1765. } else if (!self.curSiteRule || !self.curSiteRule.smart) self.curSiteRule = r;
  1766. callback();
  1767. }
  1768.  
  1769. function checkRule(r) {
  1770. if (r.from === 1 && r.url.length <= 13) return false;
  1771. let urlReg = new RegExp(r.url, "i");
  1772. if (urlReg.test(href)) {
  1773. if (!self.ruleMatchPre(r)) return false;
  1774. if (r.url.length > 15 && r.from !== 1) {
  1775. self.possibleRule = r;
  1776. }
  1777. if (r.waitElement) {
  1778. let waitTime = 500;
  1779. let checkReady = () => {
  1780. setTimeout(() => {
  1781. if (!self.waitElement(document, r.waitElement) || !self.ruleMatchReady(r)) {
  1782. checkReady();
  1783. } else {
  1784. setRule(r);
  1785. }
  1786. }, parseInt(waitTime));
  1787. };
  1788. checkReady();
  1789. debug(r, 'Wait for');
  1790. return true;
  1791. } else if (r.wait) {
  1792. let waitTime = 500, checkEval, maxCheckTimes = 50;
  1793. if (isNaN(r.wait)) {
  1794. try {
  1795. checkEval = (typeof r.wait === 'function') ? r.wait : AsyncFunction("doc",'"use strict";' + r.wait);
  1796. } catch(e) {
  1797. debug(e, 'Error when checkeval');
  1798. }
  1799. } else {
  1800. waitTime = r.wait;
  1801. }
  1802. let checkReady = () => {
  1803. if (maxCheckTimes-- <= 0) {
  1804. debug("Wait for rule ready but failed");
  1805. setRule(r);
  1806. return;
  1807. }
  1808. setTimeout(async() => {
  1809. if (!self.ruleMatchReady(r) || (checkEval && !await checkEval(document))) {
  1810. checkReady();
  1811. } else {
  1812. setRule(r);
  1813. }
  1814. }, parseInt(waitTime));
  1815. };
  1816. checkReady();
  1817. debug(r, 'Wait for');
  1818. return true;
  1819. }
  1820. if (r.pinUrl) {
  1821. setRule(r);
  1822. return true;
  1823. }
  1824. if (!self.ruleMatchReady(r)) {
  1825. return false;
  1826. }
  1827. setRule(r);
  1828. return true;
  1829. }
  1830. return false;
  1831. }
  1832.  
  1833. function checkHpRules() {
  1834. for (let i in self.hpRules) {
  1835. let rule = self.hpRules[i];
  1836. if (!rule || !rule.url || rule.smart) continue;
  1837. if (checkRule(rule)) return true;
  1838. }
  1839. return false;
  1840. }
  1841.  
  1842. function checkCustomRules() {
  1843. for (let i in self.customRules) {
  1844. let rule = self.customRules[i];
  1845. if (!rule || !rule.url) continue;
  1846. if (checkRule(rule)) return true;
  1847. }
  1848. return false;
  1849. }
  1850.  
  1851. if (rulesData.customFirst) {
  1852. if (checkCustomRules()) return;
  1853. await sleep(1);
  1854. if (checkHpRules()) return;
  1855. } else {
  1856. if (checkHpRules()) return;
  1857. await sleep(1);
  1858. if (checkCustomRules()) return;
  1859. }
  1860. await sleep(1);
  1861.  
  1862. for (let i in this.smartRules) {
  1863. let rule = this.smartRules[i];
  1864. if (!rule || !rule.url || !rule.smart) continue;
  1865. if (href === rule.url) {
  1866. setRule(rule);
  1867. return;
  1868. } else if (rule.listenUrlChange === false && href.replace(/[^\/]+$/, "") === rule.url) {
  1869. setRule(rule);
  1870. return;
  1871. }
  1872. }
  1873. let r = 0;
  1874. async function searchByTime() {
  1875. while (document.hidden) {
  1876. await sleep(1000);
  1877. }
  1878. setTimeout(() => {
  1879. let end = r + 20;
  1880. end = end > self.rules.length ? self.rules.length : end;
  1881. for (; r < end; r++) {
  1882. let rule = self.rules[r];
  1883. if (checkRule(rule)) return;
  1884. }
  1885. if (end >= self.rules.length) {
  1886. if (document.documentElement && document.documentElement.className && document.documentElement.className.indexOf && document.documentElement.className.indexOf('discourse') !== -1) {
  1887. setRule({url: href.replace(/[^\/]+$/, ""), smart: true, nextLink: 0, listenUrlChange: false});
  1888. } else {
  1889. setRule({url: href, smart: true});
  1890. }
  1891. return;
  1892. } else {
  1893. searchByTime();
  1894. }
  1895. }, 1);
  1896. }
  1897. searchByTime();
  1898. }
  1899.  
  1900. addToHpRules(instead) {
  1901. try {
  1902. if (this.curSiteRule.isScript) return;
  1903. if (!this.hpRules) this.hpRules = [];
  1904. let url = this.curSiteRule && this.curSiteRule.url, self = this;
  1905. let href = location.href.slice(0, 500);
  1906. let matchedRules = this.hpRules.filter(rule => rule != self.curSiteRule && new RegExp(rule.url, "i").test(href) && self.ruleMatch(rule));
  1907. if (url) matchedRules.unshift(this.curSiteRule);
  1908. matchedRules.sort((a, b) => {
  1909. if ((a.include || a.exclude) && (!b.include && !b.exclude)) {
  1910. return -1;
  1911. } else if ((b.include || b.exclude) && (!a.include && !a.exclude)) {
  1912. return 1;
  1913. } else {
  1914. if ((a.nextLink || a.pageElement) && (!b.nextLink && !b.pageElement)) {
  1915. return -1;
  1916. } else if ((b.nextLink || b.pageElement) && (!a.nextLink && !a.pageElement)) {
  1917. return 1;
  1918. } else {
  1919. if (a.url.length > b.url.length) {
  1920. return -1;
  1921. } else if (a.url.length < b.url.length) {
  1922. return 1;
  1923. } else {
  1924. return 0;
  1925. }
  1926. }
  1927. }
  1928. });
  1929. this.hpRules = this.hpRules.filter(item => {
  1930. return item && !matchedRules.find(rule => item.url == rule.url && JSON.stringify(item) == JSON.stringify(rule));
  1931. });
  1932. if (instead) {
  1933. if (url) {
  1934. this.hpRules.unshift(this.curSiteRule);
  1935. matchedRules = [];
  1936. }
  1937. } else {
  1938. this.hpRules = matchedRules.concat(this.hpRules);
  1939. }
  1940. if (matchedRules && matchedRules.length) this.curSiteRule = matchedRules[0];
  1941. if (this.hpRules.length > 30) {
  1942. this.hpRules.pop();
  1943. }
  1944. if (!rulesData.sort) rulesData.sort = [1];
  1945. this.hpRules.sort((a, b) => {
  1946. let aSort = -1, bSort = -1;
  1947. for (let s = 0; s < rulesData.sort.length; s++) {
  1948. if (a.from == rulesData.sort[s]) aSort = s;
  1949. if (b.from == rulesData.sort[s]) bSort = s;
  1950. if (aSort > -1 && bSort > -1) break;
  1951. }
  1952. return aSort - bSort;
  1953. });
  1954. storage.setItem("hpRules", this.hpRules);
  1955. } catch (e) {
  1956. debug(e);
  1957. }
  1958. }
  1959.  
  1960. replaceElement(doc) {
  1961. if (!doc || doc === document) return;
  1962. let replaceElementSel = this.curSiteRule.replaceElement;
  1963. if (replaceElementSel) {
  1964. if (!Array.isArray(replaceElementSel)) {
  1965. replaceElementSel = [replaceElementSel];
  1966. }
  1967. replaceElementSel.forEach(sel => {
  1968. let pageEles = getAllElements(sel, document);
  1969. let replaceEles = getAllElements(sel, doc);
  1970. for (let i = 0; i < pageEles.length; i++) {
  1971. let replaceEle = replaceEles[i];
  1972. let pageEle = pageEles[i];
  1973. if (replaceEle) {
  1974. pageEle.parentNode.replaceChild(replaceEle.cloneNode(true), pageEle);
  1975. } else break;
  1976. }
  1977. });
  1978. }
  1979. }
  1980.  
  1981. refreshByClick() {
  1982. let refreshByClickSel = this.curSiteRule.refreshByClick;
  1983. if (refreshByClickSel) {
  1984. let self = this;
  1985. if (!this.refreshByClickHandler) {
  1986. this.refreshByClickHandler = e => {
  1987. if (!self.refreshing) {
  1988. self.refreshing = true;
  1989. setTimeout(() => {
  1990. self.refreshing = false;
  1991. let checkEles = getAllElements(refreshByClickSel, document);
  1992. for (let i = 0; i < checkEles.length; i++) {
  1993. let curEle = checkEles[i];
  1994. if (curEle === e.target || curEle.contains(e.target)) {
  1995. ruleParser.urlChanged();
  1996. isPause = true;
  1997. if (!ruleParser.nextLinkHref) isLoading = false;
  1998. break;
  1999. }
  2000. }
  2001. }, 300);
  2002. }
  2003. }
  2004. }
  2005. document.removeEventListener("click", this.refreshByClickHandler);
  2006. document.addEventListener("click", this.refreshByClickHandler);
  2007. }
  2008. }
  2009.  
  2010. getValidSize(ele, win) {
  2011. if (!win) return {h: 0, w: 0};
  2012. let eleStyle = win.getComputedStyle(ele);
  2013. if (!ele.offsetParent && eleStyle.display !== "contents" && (eleStyle.position !== "fixed" || eleStyle.opacity === 0)) {
  2014. return {h: 0, w: 0};
  2015. }
  2016. if (ele.children && ele.children.length === 1 && (ele.offsetWidth === 0 || ele.offsetHeight === 0)) {
  2017. ele = ele.children[0];
  2018. }
  2019. let h = ele.scrollHeight, w;
  2020. if (eleStyle.overflow === "hidden") {
  2021. h = ele.offsetHeight;
  2022. w = ele.offsetWidth;
  2023. } else w = parseInt(ele.offsetWidth || ele.scrollWidth);
  2024. if (h === 0 && ele.parentNode && ele.parentNode.children.length === 1) {
  2025. h = ele.parentNode.scrollHeight;
  2026. }
  2027. while (h === 0 && ele.children && ele.children.length === 1) {
  2028. ele = ele.children[0];
  2029. h = ele.scrollHeight;
  2030. }
  2031. if (h === 0 && ele.children && ele.children.length) {
  2032. let maxChildSize = {h: 0}, self = this;
  2033. [].forEach.call(ele.children, el => {
  2034. let childSize = self.getValidSize(el, win);
  2035. if (childSize.h > maxChildSize.h) maxChildSize = childSize;
  2036. });
  2037. if (maxChildSize.h !== 0) return maxChildSize;
  2038. }
  2039. const maxNum = 2147483647;
  2040. let moreChild = ele.children[0], minOffsetTop = maxNum;
  2041. while (moreChild) {
  2042. if ((moreChild.offsetParent === ele || moreChild.offsetParent === ele.offsetParent)) {
  2043. let curOffsetTop = moreChild.offsetParent === ele.offsetParent ? moreChild.offsetTop - ele.offsetTop : moreChild.offsetTop;
  2044. if (curOffsetTop < minOffsetTop) {
  2045. minOffsetTop = curOffsetTop;
  2046. }
  2047. }
  2048. moreChild = moreChild.nextElementSibling;
  2049. }
  2050. if (h && minOffsetTop !== maxNum && minOffsetTop > 0) {
  2051. h -= minOffsetTop;
  2052. }
  2053. return {h: h, w: w};
  2054. }
  2055.  
  2056. checkTargetChildren(ele, curWin, articleNum, curHeight) {
  2057. let pf = false;
  2058. if (ele.parentNode) {
  2059. let paStyle = curWin.getComputedStyle(ele.parentNode);
  2060. let paDisplay = paStyle.display;
  2061. let paOverflow = paStyle.overflow;
  2062. pf = (paDisplay.indexOf('flex') !== -1 && paStyle.flexDirection.indexOf("row") === 0 && paStyle.flexWrap !== "wrap") || compareNodeName(ele.parentNode, ["ul"]) || paDisplay.indexOf('grid') !== -1 || paOverflow === "hidden";
  2063. }
  2064. let curStyle = curWin.getComputedStyle(ele);
  2065. if (ele.children.length > 1) {
  2066. if (articleNum > 1) {
  2067. return ">article";
  2068. } else {
  2069. let hasText = false;
  2070. for (let i in ele.childNodes) {
  2071. let child = ele.childNodes[i];
  2072. if (child.nodeType === 3 && child.nodeValue.trim() !== '') {
  2073. hasText = true;
  2074. break;
  2075. }
  2076. }
  2077. let gridArea = curStyle.gridArea;
  2078. if (gridArea && gridArea !== "auto" && gridArea !== "auto / auto / auto / auto") {
  2079. return ">*";
  2080. } else {
  2081. let middleChild = ele.children[parseInt(ele.children.length / 2)];
  2082. if ((curStyle.display === 'flex' && curStyle.flexDirection.indexOf("row") === 0 && curStyle.flexWrap !== "wrap") || (curStyle.float === "none" && curStyle.display !== "table-cell" && (rulesData.opacity !== 0 || hasText) && !pf)) {
  2083. return "";
  2084. } else if ((middleChild.style && middleChild.style.position === "absolute" && middleChild.style.left && middleChild.style.top) || compareNodeName(ele, ["ul"]) || curHeight === 0) {
  2085. return "";
  2086. } else {
  2087. return ">*";
  2088. }
  2089. }
  2090. }
  2091. } else if (pf || curStyle.position === "absolute") {
  2092. return ">*";
  2093. }
  2094. return "";
  2095. }
  2096.  
  2097. getPageElement(doc, curWin, dontFind) {
  2098. if (doc === document && this.docElementValid()) {
  2099. return this.docPageElement;
  2100. }
  2101. let pageElement = null;
  2102. let self = this;
  2103. let body = getBody(doc);
  2104. if (this.curSiteRule.pageElement) {
  2105. let pageElementSel = this.curSiteRule.pageElement;
  2106. if (Array && Array.isArray && Array.isArray(pageElementSel)) {
  2107. pageElementSel = pageElementSel[nextIndex < pageElementSel.length ? nextIndex : 0];
  2108. }
  2109. pageElement = getAllElements(pageElementSel, doc);
  2110. if (this.curSiteRule.smart && (!pageElement || pageElement.length === 0)) {
  2111. const childSelMatch = />\s*\*$/;
  2112. const targetChild = childSelMatch.test(pageElementSel);
  2113. if (targetChild) pageElementSel = pageElementSel.replace(childSelMatch, "");
  2114. let pageElementSelSplit = pageElementSel.split(">");
  2115. while(pageElementSelSplit && pageElementSelSplit.length > 5) {
  2116. pageElementSelSplit.shift();
  2117. let tempSel = pageElementSelSplit.join(">");
  2118. pageElement = getAllElements(tempSel, doc);
  2119. if (pageElement && pageElement.length === 1) {
  2120. if (targetChild) {
  2121. pageElement = pageElement.children;
  2122. }
  2123. this.curSiteRule.pageElement = tempSel + (targetChild ? ">*" : "");
  2124. break;
  2125. }
  2126. }
  2127. if (!pageElement || pageElement.length === 0) {
  2128. pageElementSel = pageElementSel.replace(/:nth-of-type\(\d+\)/g, "");
  2129. pageElement = getAllElements(pageElementSel, doc);
  2130. if (pageElement && pageElement.length === 1) {
  2131. if (targetChild) {
  2132. pageElement = pageElement.children;
  2133. }
  2134. this.curSiteRule.pageElement = pageElementSel + (targetChild ? ">*" : "");
  2135. }
  2136. }
  2137. }
  2138. if (this.curSiteRule.smart && pageElement && pageElement.length && curWin && curWin !== _unsafeWindow) {
  2139. if (pageElement.length === 1 && !pageElement[0].src && pageElement[0].innerHTML.trim() === "") {
  2140. pageElement = null;
  2141. } else {
  2142. let parent = pageElement[0].parentNode;
  2143. let loading = parent.querySelector('[class*=loading]');
  2144. if (loading && loading.offsetParent && loading.offsetHeight > parent.offsetHeight>>2) {
  2145. pageElement = null;
  2146. }
  2147. }
  2148. }
  2149. }
  2150. if (pageElement && pageElement.length === 1 && pageElement[0].style.display === 'none') {
  2151. pageElement = [body];
  2152. }
  2153. if (this.curSiteRule.smart && pageElement && pageElement.length > 0 && compareNodeName(pageElement[0], ["tr"])) {
  2154. let mainTr = this.insert.parentNode.querySelectorAll('tr'), mainTdNum = 0, newTdNum = 0;
  2155. mainTr = mainTr[mainTr.length - 1];
  2156. [].forEach.call(mainTr.children, el => {
  2157. if (compareNodeName(el, ["td", "th"])) {
  2158. mainTdNum += el.colSpan || 1;
  2159. }
  2160. });
  2161. [].forEach.call(pageElement[0].children, el => {
  2162. if (compareNodeName(el, ["td", "th"])) {
  2163. newTdNum += el.colSpan || 1;
  2164. }
  2165. });
  2166. if (mainTdNum !== newTdNum) {
  2167. this.curSiteRule.pageElement = this.curSiteRule.pageElement.replace(/> *table.*/, ">table");
  2168. this.getInsert(true);
  2169. return this.getPageElement(doc, curWin, dontFind);
  2170. }
  2171. }
  2172. if ((this.curSiteRule.smart || !this.curSiteRule.pageElement) && (!pageElement || pageElement.length == 0) && curWin && !dontFind) {
  2173. if (!body) return null;
  2174. let bodyHeight = parseInt(body.offsetHeight || body.scrollHeight);
  2175. let curHeight = bodyHeight, curWidth = 0;
  2176. let windowHeight = window.innerHeight || document.documentElement.clientHeight;
  2177. let windowWidth = window.innerWidth || document.documentElement.clientWidth;
  2178. let needCheckNext = (doc == document && this.initNext), nextLeftPos = 0;
  2179. if (needCheckNext && this.initNext.getBoundingClientRect) {
  2180. nextLeftPos = this.initNext.getBoundingClientRect().left;
  2181. }
  2182. function checkElement(ele) {
  2183. if (compareNodeName(ele, ["pre", "code"])) {
  2184. self.curSiteRule.pageElement = geneSelector(ele.parentNode);
  2185. debug(self.curSiteRule.pageElement, 'Page element');
  2186. return [ele.parentNode];
  2187. }
  2188. if (ele.children && ele.children.length === 1) {
  2189. let hasText = false;
  2190. for (let i in ele.childNodes) {
  2191. let child = ele.childNodes[i];
  2192. if (child.nodeType === 3 && child.nodeValue.trim() !== '') {
  2193. hasText = true;
  2194. break;
  2195. }
  2196. }
  2197. if (!hasText) {
  2198. ele = ele.children[0];
  2199. let validSize = self.getValidSize(ele, curWin);
  2200. curHeight = validSize.h;
  2201. curWidth = validSize.w;
  2202. }
  2203. }
  2204. if (compareNodeName(ele, ["picture"]) || !ele.innerText || ele.innerText.trim() === '') {
  2205. self.curSiteRule.pageElement = geneSelector(ele.parentNode) + ">" + ele.nodeName.toLowerCase();
  2206. debug(self.curSiteRule.pageElement, 'Page element');
  2207. let eles = [];
  2208. for (let i = 0; i < ele.parentNode.children.length; i++) {
  2209. let curNode = ele.parentNode.children[i];
  2210. if (curNode.nodeName === ele.nodeName && curNode.id === ele.id && curNode.className === ele.className) {
  2211. eles.push(curNode);
  2212. }
  2213. }
  2214. return eles;
  2215. }
  2216. if (compareNodeName(ele, ["form"]) && ele.parentNode !== getBody(document)) {
  2217. self.curSiteRule.pageElement = geneSelector(ele) + ">*";
  2218. debug(self.curSiteRule.pageElement, 'Page element');
  2219. return ele.children;
  2220. }
  2221. if (ele.children.length === 0 && !self.curSiteRule.pageElement) {
  2222. if (compareNodeName(ele.parentNode, ["p"])) ele = ele.parentNode;
  2223. self.curSiteRule.pageElement = geneSelector(ele.parentNode) + ">" + ele.nodeName.toLowerCase();
  2224. debug(self.curSiteRule.pageElement, 'Page element');
  2225. return getAllElements(self.curSiteRule.pageElement, doc);
  2226. }
  2227. let i, minHeight = curHeight * 0.52, curMaxEle = null, curMaxArea = 0, minWidth = Math.min(curWidth * 0.38, 500);
  2228. let isHori, preOffsetTop = -1;
  2229. let articleNum = 0;
  2230. for (i = 0; i < ele.children.length; i++) {
  2231. let curNode = ele.children[i];
  2232. if (ele !== body && /^H\d$/i.test(curNode.nodeName) && curNode.offsetParent) {
  2233. curMaxEle = null;
  2234. break;
  2235. }
  2236. if (compareNodeName(curNode, ["canvas", "nav"])) continue;
  2237. let curStyle = curWin.getComputedStyle(curNode);
  2238. if (!curNode.offsetParent && curStyle.display !== "contents" && (curStyle.position !== "fixed" || curStyle.opacity === 0)) {
  2239. continue;
  2240. }
  2241. if (!compareNodeName(curNode, ["img"]) && curNode.querySelector('img') === null && /^\s*$/.test(curNode.innerText)) continue;
  2242. if (needCheckNext && !curNode.contains(self.initNext) && getElementTop(curNode) > windowHeight) {
  2243. continue;
  2244. }
  2245. if (compareNodeName(curNode, ["article"])) articleNum++;
  2246. let validSize = self.getValidSize(curNode, curWin);
  2247. let h = validSize.h;
  2248. let w = validSize.w;
  2249. if (isNaN(h) || isNaN(w) || !h || !w) continue;
  2250. isHori = Math.abs(preOffsetTop - curNode.offsetTop) <= 20 ? true : (preOffsetTop === -1 && curNode.nextElementSibling && curNode.nextElementSibling.offsetTop === curNode.offsetTop);
  2251. if (isHori && h <= 50) continue;
  2252. /*if (isHori && nextLeftPos && curMaxEle && curWidth > 500 && curHeight > 500) {
  2253. let curRect = curNode.getBoundingClientRect();
  2254. if (curRect.left > windowWidth>>2 && curRect.left <= nextLeftPos && curRect.right > nextLeftPos) {
  2255. continue;
  2256. }
  2257. }*/
  2258. let a = h * w, moreChild = curNode.children[0];
  2259. while (moreChild) {
  2260. let validSize = self.getValidSize(moreChild, curWin);
  2261. let ch = validSize.h;
  2262. let cw = validSize.w;
  2263. if (h < ch) {
  2264. h = ch;
  2265. }
  2266. if (moreChild.innerText !== "" && ch && cw) {
  2267. a += ch * cw;
  2268. }
  2269. moreChild = moreChild.nextElementSibling;
  2270. }
  2271. let isMax = false;
  2272. if (isHori) {
  2273. if (curMaxEle) {
  2274. if (w > curWidth && (windowWidth>>1) > curWidth) {
  2275. isMax = true;
  2276. } else if (w + 300 > curWidth && a > curMaxArea) {
  2277. isMax = true;
  2278. }
  2279. }
  2280. } else {
  2281. if (curMaxEle && curMaxEle.offsetParent === curNode.offsetParent && curMaxEle.offsetTop === curNode.offsetTop) {
  2282. if (curMaxArea * 2 > a) continue;
  2283. }
  2284. isMax = curMaxArea < a;
  2285. }
  2286. if (curMaxEle === null || isMax) {
  2287. if (isHori) {
  2288. if (w < minWidth) {
  2289. continue;
  2290. }
  2291. }
  2292. if (h < minHeight) {
  2293. if (!needCheckNext || h < (minHeight>>1)) {
  2294. continue;
  2295. }
  2296. if (!ele.contains(self.initNext)) {
  2297. continue;
  2298. } else if (!curNode.contains(self.initNext) && h < curHeight >> 1) {
  2299. continue;
  2300. }
  2301. }
  2302. curHeight = h;
  2303. curMaxArea = a;
  2304. curWidth = w;
  2305. curMaxEle = curNode;
  2306. preOffsetTop = curNode.offsetTop;
  2307. }
  2308. }
  2309. let curHeightPercent = curHeight / bodyHeight;
  2310. if (curMaxEle && curHeightPercent <= 0.18) {
  2311. let article;
  2312. for (let i = 0; i < mainSel.length; i++) {
  2313. article = doc.querySelectorAll(mainSel[i]);
  2314. if (article && article.length === 1) break;
  2315. }
  2316. if (article && article.length === 1) {
  2317. article = article[0];
  2318. let childrenEnd = self.checkTargetChildren(article, curWin, articleNum, curHeight);
  2319. self.curSiteRule.pageElement = article.nodeName.toLowerCase() + (article.id ? "#" + article.id : "") + (article.className ? "." + article.className.replace(/ /g, ".") : "") + childrenEnd;
  2320. debug(self.curSiteRule.pageElement, 'Page element');
  2321. return childrenEnd ? article.children : [article];
  2322. }
  2323. curMaxEle = null;
  2324. }
  2325. if (curMaxEle && (!compareNodeName(curMaxEle, ["ul"]) || curHeightPercent > 0.8)) {
  2326. let sameClassNum = 0, hasDifferent = false;
  2327. if (curMaxEle.className) {
  2328. for(i = 0; i < ele.children.length; i++) {
  2329. let curNode = ele.children[i];
  2330. if (curMaxEle !== curNode && curNode.style.display !== 'none' && curMaxEle.className === curNode.className && curMaxEle.nodeName === curNode.nodeName){
  2331. sameClassNum++;
  2332. } else if (curMaxEle.className !== curNode.className) {
  2333. hasDifferent = true;
  2334. }
  2335. }
  2336. }
  2337. if (sameClassNum < 2 || (sameClassNum < 5 && hasDifferent)) {
  2338. return checkElement(curMaxEle);
  2339. }
  2340. }
  2341. if (ele.nodeName === "APP-ROOT") {
  2342. isPause = true;
  2343. debug(ele, "Angular root");
  2344. return null;
  2345. }
  2346. while (compareNodeName(ele, ["p", "br", "td"])) {
  2347. ele = ele.parentNode;
  2348. }
  2349. if (compareNodeName(ele, ["tbody"])) {
  2350. self.curSiteRule.pageElement = geneSelector(ele) + ">*";
  2351. if (ele.children.length > 0 && ele.children[0].querySelector("th")) {
  2352. self.curSiteRule.pageElement += ":not(:first-child)";
  2353. }
  2354. debug(self.curSiteRule.pageElement, 'Page element');
  2355. return ele.children;
  2356. }
  2357. let imgs = ele.querySelectorAll('img');
  2358. if (imgs.length === 1) {
  2359. let img = imgs[0];
  2360. if (img.offsetWidth > ele.offsetWidth / 3 * 2 && img.offsetHeight > ele.offsetHeight / 2) {
  2361. ele = img;
  2362. }
  2363. }
  2364. let childrenEnd = self.checkTargetChildren(ele, curWin, articleNum, curHeight);
  2365. if (childrenEnd) {
  2366. self.curSiteRule.pageElement = geneSelector(ele) + childrenEnd;
  2367. ele = ele.children;
  2368. } else {
  2369. if (ele.scrollHeight === 0 && ele.parentNode.children.length === 1) {
  2370. ele = ele.parentNode;
  2371. }
  2372. self.curSiteRule.pageElement = geneSelector(ele);
  2373. ele = [ele];
  2374. }
  2375. debug(self.curSiteRule.pageElement, 'Page element');
  2376. return ele;
  2377. }
  2378. pageElement = checkElement(body);
  2379. if (doc === document && pageElement && pageElement.length > 0 && self.initNext) {
  2380. let posEle = pageElement[pageElement.length - 1];
  2381. while (posEle && !posEle.offsetParent) {
  2382. posEle = posEle.previousElementSibling || posEle.parentNode;
  2383. }
  2384. if (posEle && posEle.lastElementChild) {
  2385. if (posEle.scrollHeight === 0) posEle = posEle.lastElementChild;
  2386. else if (posEle.lastElementChild.offsetTop > 500) {
  2387. posEle = posEle.lastElementChild;
  2388. }
  2389. }
  2390. let lastBottom = forceState !== 2 && forceState !== 3 && posEle && getElementBottom(posEle);
  2391. if (lastBottom && getElementTop(self.initNext) - lastBottom > 1000) {
  2392. debug("Stop as too long between next & page element, try to enable Force-Join mode.");
  2393. isPause = true;
  2394. pageElement = [];
  2395. sideController.remove();
  2396. } else {
  2397. if (pageElement.length === 1 && compareNodeName(pageElement[0], ["img"])) {
  2398. self.curSiteRule.pageBar = 0;
  2399. }
  2400. }
  2401. }
  2402. //if(pageElement)this.saveCurSiteRule();
  2403. }
  2404.  
  2405. if (doc !== document) {
  2406. this.setPageElementCss(pageElement);
  2407. this.lazyImgAction(pageElement, doc);
  2408. this.filterEles(doc, pageElement);
  2409. } else if (!this.docPageElement) {
  2410. this.setPageElementCss(pageElement, true);
  2411. this.docPageElement = pageElement;
  2412. this.filterEles(doc, pageElement);
  2413. if (this.nextLinkHref) {
  2414. this.openInNewTab(pageElement);
  2415. }
  2416. }
  2417. return pageElement;
  2418. }
  2419.  
  2420. showAddedElements() {
  2421. if (!this.addedElementsIsHide) return;
  2422. if (this.addedElePool && this.addedElePool.length) {
  2423. this.addedElePool.forEach(ele => {
  2424. ele.classList && ele.classList.remove("pagetual-hide");
  2425. });
  2426. }
  2427. this.addedElementsIsHide = false;
  2428. }
  2429.  
  2430. hideAddedElements() {
  2431. if (this.addedElePool && this.addedElePool.length) {
  2432. this.addedElePool.forEach(ele => {
  2433. ele.classList && ele.classList.add("pagetual-hide");
  2434. });
  2435. }
  2436. this.addedElementsIsHide = true;
  2437. }
  2438.  
  2439. toggleAddedElements() {
  2440. if (this.addedElementsIsHide) {
  2441. this.showAddedElements();
  2442. } else {
  2443. this.hideAddedElements();
  2444. }
  2445. }
  2446.  
  2447. changeVisibility() {
  2448. let contentVisibility = this.curSiteRule.contentVisibility || rulesData.contentVisibility;
  2449. if (!contentVisibility) return;
  2450. if (!this.changingVisibility) {
  2451. clearTimeout(this.changeVisibilityTimer);
  2452. this.changeVisibilityTimer = setTimeout(() => {
  2453. this.changingVisibility = true;
  2454. this.changeVisibility();
  2455. }, 300);
  2456. return;
  2457. }
  2458. this.changingVisibility = false;
  2459. if (!this.visibilityItems || !this.visibilityItems.length || this.visibleIndex < 0) return;
  2460. let tempIndex = this.visibleIndex, findVisible = false, lastVisible = 0;
  2461. let viewPortHeight = window.innerHeight || document.documentElement.clientHeight || getBody(document).clientHeight;
  2462. let checkItem = this.visibilityItems[tempIndex];
  2463. while(checkItem) {
  2464. if (checkItem.offsetParent) {
  2465. if (!checkItem.style.containIntrinsicSize) return;
  2466. let clientRect = checkItem.getBoundingClientRect();
  2467. let top = clientRect && clientRect.top;
  2468. let bottom = clientRect && clientRect.bottom;
  2469. if (bottom > 0 && top < viewPortHeight) {
  2470. if (!findVisible) {
  2471. findVisible = true;
  2472. lastVisible = tempIndex;
  2473. }
  2474. checkItem.style.contentVisibility = "visible";
  2475. } else {
  2476. if (top < viewPortHeight && checkItem.style.contentVisibility === "auto") {
  2477. break;
  2478. } else checkItem.style.contentVisibility = "auto";
  2479. }
  2480. }
  2481. if (tempIndex === 0) break;
  2482. tempIndex--;
  2483. checkItem = this.visibilityItems[tempIndex];
  2484. }
  2485. tempIndex = this.visibleIndex + 1;
  2486. if (findVisible) {
  2487. this.visibleIndex = lastVisible;
  2488. }
  2489. checkItem = this.visibilityItems[tempIndex];
  2490. while(checkItem) {
  2491. if (checkItem.offsetParent) {
  2492. if (!checkItem.style.containIntrinsicSize) return;
  2493. let clientRect = checkItem.getBoundingClientRect();
  2494. let top = clientRect && clientRect.top;
  2495. let bottom = clientRect && clientRect.bottom;
  2496. if (bottom > 0 && top < viewPortHeight) {
  2497. findVisible = true;
  2498. lastVisible = tempIndex;
  2499. checkItem.style.contentVisibility = "visible";
  2500. } else {
  2501. if (findVisible && checkItem.style.contentVisibility === "auto") {
  2502. break;
  2503. } else checkItem.style.contentVisibility = "auto";
  2504. }
  2505. }
  2506. if (tempIndex === this.visibilityItems.length - 1) break;
  2507. tempIndex++;
  2508. checkItem = this.visibilityItems[tempIndex];
  2509. }
  2510. if (findVisible) {
  2511. this.visibleIndex = lastVisible;
  2512. }
  2513. }
  2514.  
  2515. setPageElementCss(pageElement, init) {
  2516. let self = this;
  2517. if (pageElement && pageElement.length > 0) {
  2518. let pageElementCss = this.curSiteRule.pageElementCss || rulesData.pageElementCss;
  2519. if (!pageElementCss && init && !this.nextLinkHref) return;
  2520. let contentVisibility = this.curSiteRule.contentVisibility || rulesData.contentVisibility;
  2521. if (!contentVisibility && !pageElementCss) return;
  2522. [].forEach.call(pageElement, (ele, i) => {
  2523. if (!compareNodeName(ele, ["link", "meta", "style", "script"])) {
  2524. if (pageElementCss) {
  2525. if (pageElementCss !== '0' && !ele.dataset.pagetualPageElement) {
  2526. ele.style.cssText = (ele.style.cssText || '') + pageElementCss;
  2527. ele.dataset.pagetualPageElement = 1;
  2528. }
  2529. }
  2530. if (contentVisibility) {
  2531. ele.style.containIntrinsicSize = `auto ${ele.offsetHeight || self.preVisibleHeight || 100}px`;
  2532. if (ele.style.containIntrinsicSize) {
  2533. if (ele.offsetHeight) self.preVisibleHeight = ele.offsetHeight;
  2534. if (init) {
  2535. ele.style.contentVisibility = "visible";
  2536. self.visibilityItems.push(ele);
  2537. self.visibleIndex++;
  2538. } else {
  2539. ele.style.contentVisibility = emuIframe ? "visible" : "auto";
  2540. }
  2541. }
  2542. }
  2543. }
  2544. });
  2545. }
  2546. }
  2547.  
  2548. clearAddedElements() {
  2549. if (this.addedElePool && this.addedElePool.length) {
  2550. this.addedElePool.forEach(ele => {
  2551. if (ele.parentNode) ele.parentNode.removeChild(ele);
  2552. });
  2553. }
  2554. this.addedElePool = [];
  2555. sideController.remove();
  2556. }
  2557.  
  2558. linkHasHref(link) {
  2559. return link && link.href && link.href.replace && !this.hrefIsJs(link.href);
  2560. }
  2561.  
  2562. hrefIsJs(href) {
  2563. return /^(javascript|#|$)/.test(href.trim().replace("#p{", "").replace(location.href, ""));
  2564. }
  2565.  
  2566. async querySelectorList(source, list, defaultView) {
  2567. for (let i = 0; i < list.length; i++) {
  2568. await sleep(1);
  2569. let sel = list[i];
  2570. let result = getAllElements(sel, source);
  2571. if (result.length > 0) {
  2572. if (defaultView) {
  2573. for (let i = result.length - 1; i >= 0; i--) {
  2574. let ele = result[i];
  2575. if (isVisible(ele, defaultView)) return ele;
  2576. }
  2577. }
  2578. return result[result.length - 1];
  2579. }
  2580. }
  2581. return null;
  2582. }
  2583.  
  2584. verifyElement(ele) {
  2585. let verifyHandler = e => {
  2586. if (e.nodeType == 9) return true;
  2587. if (e.style.display === "none" || e.getAttribute("aria-disabled") === "true") {
  2588. return false;
  2589. }
  2590. if (e.className) {
  2591. if (/slick|slide|carousel|gallery|disabled\s*$/i.test(e.className)) {
  2592. return false;
  2593. } else if (e.classList) {
  2594. if (e.classList.contains('disabled') || e.classList.contains('active')) {
  2595. return false;
  2596. }
  2597. }
  2598. }
  2599. let ariaLabel = e.getAttribute("aria-label");
  2600. if (ariaLabel && /slick|slide|carousel|gallery/i.test(ariaLabel)) return false;
  2601. return true;
  2602. };
  2603. if (!ele) return false;
  2604. let i = 0;
  2605. while (ele && i++ < 6) {
  2606. if (!verifyHandler(ele)) return false;
  2607. ele = ele.parentNode;
  2608. }
  2609. return true;
  2610. }
  2611.  
  2612. async getPage(doc, exist) {
  2613. let body = getBody(doc);
  2614. let canSave = false;//發現頁碼選擇器在其他頁對不上,還是別保存了
  2615. let url = this.curUrl.slice(0, 250).replace("index.php?", "?");
  2616. let _url = url.replace(/\.s?html?$/i, "").toLowerCase();
  2617. let pageNum = 1, preStr = "", afterStr = "";
  2618. let pageTwoReg = /^[\/\?&]?[_-]?(p|page)?=?\/?2(\/[^\/]*$|\?|&|$)/i;
  2619. let pageMatch1 = url.match(/(.*[\?&]p(?:age)?=)(\d+)($|[#&].*)/i);
  2620. let doubtTextReg = /^\s*(»|>>)\s*$/;
  2621. if (pageMatch1) {
  2622. preStr = pageMatch1[1];
  2623. pageNum = parseInt(pageMatch1[2]);
  2624. afterStr = pageMatch1[3];
  2625. } else {
  2626. let pageMatch2 = url.match(/(.*[a-z\/\-_](?:p|page)?\/?)(\d+)(\.s?html?$|\/?$)/i);
  2627. if (pageMatch2) {
  2628. preStr = pageMatch2[1];
  2629. pageNum = parseInt(pageMatch2[2]);
  2630. afterStr = pageMatch2[3];
  2631. if (/^\/?$/.test(afterStr) && !/(p(age)?|_|\-|\/)$/.test(preStr)) {
  2632. preStr = "";
  2633. afterStr = "";
  2634. }
  2635. }
  2636. }
  2637. if (pageNum > 999) {
  2638. pageNum = 1;
  2639. preStr = "";
  2640. afterStr = "";
  2641. }
  2642. let curPage = doc, i, cur, jsNext;
  2643. let next1, next2, next3, next4, nextJs1, nextJs2;
  2644. let selectorList = [
  2645. ".page-next>a",
  2646. "a.next_page",
  2647. "#next_page",
  2648. ".curPage+a",
  2649. ".nextPage",
  2650. ".pagination-next>a",
  2651. "a[data-pagination=next]",
  2652. ".pageButtonsCurrent+a",
  2653. "a[class*=nextpage]",
  2654. "li.page-current+li>a",
  2655. "[class^=pag] a[rel=next]",
  2656. "[class^=Pag] [aria-label=next]",
  2657. "[aria-label='Next Page']",
  2658. "[aria-label='Next page']",
  2659. "[aria-label='next page']",
  2660. ".pagination-nav__item--next>a",
  2661. "a.pageright",
  2662. ".page-numbers.current+a",
  2663. "a.page-numbers.next",
  2664. "body [class*=pagination] li.active+span+li>a",
  2665. "body [class*=pagination] li.active+li>a",
  2666. "body [class^=pag] .current+a",
  2667. ".page_current+a",
  2668. "input[value='next']",
  2669. "input[value='Next page']",
  2670. "input[value='下一页']",
  2671. "input[value='下一頁']",
  2672. "a#pb_next",
  2673. "a#rightFix",
  2674. "a#btnPreGn",
  2675. "a.page-next",
  2676. "a.pages-next",
  2677. "a.page.right",
  2678. ".paging>.active+.item",
  2679. "a#next",
  2680. ".next>a",
  2681. ".next>button",
  2682. "a[alt=next]",
  2683. ".pg_area>em+a",
  2684. "button.next:not([disabled])",
  2685. ".btn_next:not([disabled])",
  2686. ".btn-next:not([disabled])",
  2687. "a#linkNext",
  2688. "body a[class*=page__next]",
  2689. "body [class*=pager]>a.next",
  2690. "body [class*=pagination-next]>a",
  2691. "body [class*=pagination-next]>button",
  2692. "body [class*=page--current]+li>a",
  2693. "body [class*=Pages]>.curr+a",
  2694. "body [class*=pagination] [class*=next]",
  2695. ".page>em+a",
  2696. "[name*=nextPage]",
  2697. '//button[contains(@class, "Page")][text()="Next"]',
  2698. '//button[contains(@class, "page")][text()="next"]'
  2699. ];
  2700. let next = await this.querySelectorList(body, selectorList, doc.defaultView);
  2701. if (!next) {
  2702. await sleep(1);
  2703. let nexts = body.querySelectorAll("a.next");
  2704. const prevReg = /^\s*([上前首尾]|previous)/i;
  2705. for (i = 0; i < nexts.length; i++) {
  2706. let n = nexts[i];
  2707. if (this.verifyElement(n) && this.linkHasHref(n) && !prevReg.test(n.innerText.trim())) {
  2708. next = n;
  2709. break;
  2710. }
  2711. }
  2712. }
  2713. if (next) {
  2714. let innerText = next.innerText;
  2715. let isJs = !this.linkHasHref(next);
  2716. if (innerText && nextTextReg2.test(innerText.trim())) {
  2717. if (isJs) {
  2718. if (this.verifyElement(next)) {
  2719. nextJs2 = next;
  2720. }
  2721. } else {
  2722. next2 = next;
  2723. }
  2724. next = null;
  2725. } else {
  2726. if (isJs) {
  2727. if (this.verifyElement(next)) {
  2728. jsNext = next;
  2729. }
  2730. next = null;
  2731. }
  2732. }
  2733. }
  2734. if (!next) {
  2735. await sleep(1);
  2736. next = body.querySelector("a.curr+a") ||
  2737. body.querySelector("div.wp-pagenavi>span.current+a,div.page-nav>span.current+a,div.article-paging>span+a") ||
  2738. body.querySelector(".number>ul>li.active+li>a,.pager a.next");
  2739. }
  2740. if (!next) {
  2741. await sleep(1);
  2742. let pageDiv = body.querySelector(".pages>ul,.page_no>ul");
  2743. if (pageDiv) {
  2744. cur = pageDiv.querySelector("li>b,li>strong");
  2745. if (cur) next = cur.parentNode.nextElementSibling;
  2746. if (next) next = next.querySelector("a");
  2747. }
  2748. }
  2749. if (!next) {
  2750. await sleep(1);
  2751. next = body.querySelector(".pages>a[href='javascript:;']+a");
  2752. if (next && (next.href === "javascript:;" || next.getAttribute("href") === "#")) next = null;
  2753. }
  2754. if (!next) {
  2755. await sleep(1);
  2756. let pageDiv = body.querySelector(".pagination");
  2757. if (pageDiv) {
  2758. cur = pageDiv.querySelector("[class*=current],.page-selected");
  2759. if (cur) next = cur.parentNode.nextElementSibling;
  2760. if (next) next = next.querySelector("a");
  2761. }
  2762. }
  2763. if (!next) {
  2764. await sleep(1);
  2765. cur = body.querySelector(".paginator td strong");
  2766. if (cur) {
  2767. while (cur && !compareNodeName(cur, ["td"])) {
  2768. cur = cur.parentNode;
  2769. }
  2770. next = cur && cur.nextElementSibling;
  2771. if (next) next = next.querySelector("a");
  2772. }
  2773. }
  2774. if (!next) {
  2775. await sleep(1);
  2776. let pageDivs = body.querySelectorAll("[class*=pagination],[class*=Pagination]");
  2777. if (pageDivs && pageDivs.length) {
  2778. for (let i = pageDivs.length - 1; i >= 0; i--) {
  2779. let p = pageDivs[i];
  2780. if (/(next\s*(»|>>|>|›|→|❯)?|&gt;|▶|>|›|→|❯)/i.test(p.title || p.value || '')) {
  2781. next = p.querySelector("a,button,[type='button']") || p;
  2782. break;
  2783. } else if (/^(next\s*(»|>>|>|›|→|❯)?|&gt;|▶|>|›|→|❯)$/i.test((p.innerText || '').trim())) {
  2784. next = p.querySelector("a,button,[type='button']") || p;
  2785. break;
  2786. }
  2787. }
  2788. if (next && !this.linkHasHref(next)) {
  2789. if (!jsNext) jsNext = next;
  2790. next = null;
  2791. }
  2792. }
  2793. }
  2794. if (!next) {
  2795. let isApp = !!body.querySelector("main#app");
  2796. let aTags = body.querySelectorAll("a,button,[type='button'],.btn-action");
  2797. for (i = aTags.length - 1; i >= 0; i--) {
  2798. if (next1) break;
  2799. if (i % 100 === 0) {
  2800. await sleep(1);
  2801. }
  2802. let aTag = aTags[i];
  2803. let title = aTag.title || "";
  2804. let value = aTag.value || "";
  2805. let innerText = aTag.innerText || "";
  2806. if (innerText === "" || (title !== "" && title.length < innerText.length)) {
  2807. innerText = title;
  2808. }
  2809. if (innerText === "" || (value !== "" && value.length < innerText.length)) {
  2810. innerText = value;
  2811. }
  2812. if (innerText !== "") {
  2813. if (innerText === "§") continue;
  2814. innerText = innerText.trim();
  2815. if (innerText.length > 80) continue;
  2816. }
  2817. if (!this.verifyElement(aTag)) continue;
  2818. if (aTag.dataset && aTag.dataset.preview) continue;
  2819. let availableHref = aTag.href && aTag.href.length < 250 && !/^(javascript:|#)/.test(aTag.href);
  2820. if (availableHref && /next\-?(page)?$|\/video\/|\/vod\/play\//i.test(aTag.href)) continue;
  2821. if (compareNodeName(aTag.parentNode, ["blockquote"])) continue;
  2822. if (aTag.previousElementSibling && /\b(play|volume)\b/.test(aTag.previousElementSibling.className)) continue;
  2823. if (aTag.nextElementSibling && /\b(play|volume)\b/.test(aTag.nextElementSibling.className)) continue;
  2824. let isJs = !this.linkHasHref(aTag);
  2825. if (exist && isJs && !aTag.offsetParent) continue;
  2826. if (innerText) {
  2827. innerText = innerText.split(/\n/)[0].replace(/ /g, '');
  2828. if (isJs && /^(»|>>|>|›|→|❯)$/.test(innerText)) continue;
  2829. if (innerText && innerText.length <= 25) {
  2830. if (!next1) {
  2831. if (nextTextReg1.test(innerText)) {
  2832. if (isJs) {
  2833. if (!nextJs1) nextJs1 = aTag;
  2834. } else {
  2835. next1 = aTag;
  2836. }
  2837. }
  2838. }
  2839. if (!next4) {
  2840. if (!next2) {
  2841. if (nextTextReg2.test(innerText) || /nextpage|pager\-older|next.chap/i.test(aTag.className) || /^(»|>>)$/.test(innerText)) {
  2842. if (isJs) {
  2843. if (!nextJs2) nextJs2 = aTag;
  2844. } else {
  2845. next2 = aTag;
  2846. }
  2847. }
  2848. }
  2849. if (!isApp && !next3 && !isJs) {
  2850. if (/^(next\s*(»|>>|>|›|→|❯)?|&gt;|▶|>|›|→|❯)$/i.test(aTag.textContent) && aTag.parentNode.hasAttribute && !aTag.parentNode.hasAttribute("jsaction")) {
  2851. next3 = aTag;
  2852. }
  2853. }
  2854. }
  2855. }
  2856. }
  2857. if (isJs) continue;
  2858. if (!next4) {
  2859. let prevEle = aTag.previousElementSibling;
  2860. if (prevEle && compareNodeName(prevEle, ["b", "span", "strong"])) {
  2861. if (/^\d+$/.test(aTag.innerText.trim()) && /^\d+$/.test(prevEle.innerText.trim()) && parseInt(aTag.innerText) === parseInt(prevEle.innerText) + 1) {
  2862. next4 = aTag;
  2863. }
  2864. }
  2865. }
  2866. if (urlWillChange) continue;
  2867. if (!next4 && availableHref) {
  2868. let aHref = aTag.href.indexOf("http") === 0 ? aTag.href : this.canonicalUri(aTag.href);
  2869. if (aHref.indexOf(location.hostname) === -1) continue;
  2870. let _aHref = aHref.replace("?&", "?").replace("index.php?", "?");
  2871. if (preStr || afterStr) {
  2872. let _aHrefTrim = _aHref;
  2873. if (preStr) _aHrefTrim = _aHrefTrim.replace(preStr, "");
  2874. if (afterStr) _aHrefTrim = _aHrefTrim.replace(afterStr, "");
  2875. if (_aHrefTrim == pageNum + 1) {
  2876. next4 = aTag;
  2877. }
  2878. } else if (this.curUrl !== aHref) {
  2879. _aHref = _aHref.replace(/\.s?html?$/i, "").toLowerCase();
  2880. if (_aHref.indexOf(_url) !== -1) {
  2881. let pageTwoMatch = _aHref.replace(_url, "").match(pageTwoReg);
  2882. if (pageTwoMatch) {
  2883. afterStr = pageTwoMatch[2];
  2884. next4 = aTag;
  2885. }
  2886. }
  2887. }
  2888. if (next4 && !/page/.test(next4.href)) {
  2889. let curHref = next4.getAttribute("href");
  2890. let curPageReg = new RegExp("(.*)" + (pageNum + 1) + afterStr.replace(/([\.\?])/g, '\\$1'));
  2891. let otherPageHref = curHref.replace(curPageReg, `$1${pageNum}${afterStr}`);
  2892. let otherPageEle = body.querySelector(`a[href='${otherPageHref}']`);
  2893. if (!otherPageEle) {
  2894. otherPageHref = curHref.replace(curPageReg, `$1${pageNum + 2}${afterStr}`);
  2895. otherPageEle = body.querySelector(`a[href='${otherPageHref}']`);
  2896. }
  2897. if (otherPageEle) {
  2898. let parent = otherPageEle.parentNode;
  2899. if (parent && parent.parentNode) {
  2900. parent = parent.parentNode;
  2901. if (parent.parentNode) {
  2902. parent = parent.parentNode;
  2903. }
  2904. }
  2905. if (parent && parent.contains(next4) && !/^\d+$/.test(next4.innerText.trim())) {
  2906. next4 = null;
  2907. }
  2908. }
  2909. }
  2910. }
  2911. }
  2912. if (next2 && doubtTextReg.test(next2.innerText)) {
  2913. next2 = this.verifyNext(next2, doc, false);
  2914. }
  2915. if (nextJs2 && doubtTextReg.test(nextJs2.innerText)) {
  2916. nextJs2 = this.verifyNext(nextJs2, doc, true);
  2917. }
  2918. if (next3) {
  2919. next3 = this.verifyNext(next3, doc, false);
  2920. }
  2921. }
  2922. if (!next) next = next1 || next4 || next3 || next2;
  2923. if (!next && location.pathname + location.search !== "/") {
  2924. next = jsNext || nextJs1 || nextJs2;
  2925. if (next && next.parentNode.className && next.parentNode.className.indexOf && next.parentNode.className.indexOf('tab') !== -1) next = null;
  2926. }
  2927. if (next && next.classList && (next.classList.contains("results-more") || next.classList.contains("no"))) next = null;
  2928. if (next && next.hasAttribute && next.hasAttribute("disabled")) next = null;
  2929. if (next && next.parentNode.href && compareNodeName(next.parentNode, ["a"])) next = next.parentNode;
  2930. return {next:next, canSave:canSave};
  2931. }
  2932.  
  2933. verifyNext(next, doc, isJs) {
  2934. if (!next) return null;
  2935. if (!isJs) {
  2936. let href = next.getAttribute("href");
  2937. if (href && !/\d/.test(next.getAttribute("href"))) {
  2938. return null;
  2939. }
  2940. }
  2941. if (next.previousElementSibling && compareNodeName(next.previousElementSibling, ["br"])) return null;
  2942. let eles = [];
  2943. if (next.innerText && next.innerText.indexOf("\n") === -1) {
  2944. eles = getAllElements(`//${next.nodeName}[text()='${next.innerText}']`, doc);
  2945. }
  2946. if (eles.length >= 2 && eles[0].href !== eles[1].href) {
  2947. next = null;
  2948. } else if (doc === document) {
  2949. let left = getElementLeft(next);
  2950. if (left < 20 || (document.documentElement.scrollWidth > 500 && left < 250)) {
  2951. next = null;
  2952. } else {
  2953. let top = getElementTop(next);
  2954. if (top < 20 || (left < window.innerWidth / 3 && top < window.innerHeight / 3)) {
  2955. next = null;
  2956. } else {
  2957. let bottom = top + next.offsetHeight || 0;
  2958. let scrollH = Math.max(document.documentElement.scrollHeight, getBody(document).scrollHeight);
  2959. if (scrollH - bottom < 10) next = null;
  2960. }
  2961. }
  2962. }
  2963. return next;
  2964. }
  2965.  
  2966. canonicalUri(src) {
  2967. if (!src) {
  2968. return "";
  2969. }
  2970. if (src.charAt(0) === "#") return this.curUrl + src;
  2971. if (src.charAt(0) === "?") return this.curUrl.replace(/^([^\?#]+).*/, "$1" + src);
  2972. let origin = location.protocol + '//' + location.host;
  2973. let url = this.basePath || origin;
  2974. url = url.replace(/(\?|#).*/, "");
  2975. if (/https?:\/\/[^\/]+$/.test(url)) url = url + '/';
  2976. if (url.indexOf("http") !== 0) url = origin + url;
  2977. var root_page = /^[^\?#]*\//.exec(url)[0],
  2978. root_domain = /^\w+\:\/\/\/?[^\/]+/.exec(root_page)[0],
  2979. absolute_regex = /^\w+\:\/\//;
  2980. this.updateUrl = false;
  2981. while (src.indexOf("../") === 0) {
  2982. src = src.substr(3);
  2983. root_page = root_page.replace(/\/[^\/]+\/$/, "/");
  2984. this.updateUrl = true;
  2985. }
  2986. src = src.replace(/\.\//, "");
  2987. if (/^\/\/\/?/.test(src)) {
  2988. src = location.protocol + src;
  2989. }
  2990. return (absolute_regex.test(src) ? src : ((src.charAt(0) === "/" ? root_domain : root_page) + src));
  2991. }
  2992.  
  2993. getLinkByPage(url, pageNum) {
  2994. if (!url) return null;
  2995. if (this.curSiteRule.pageNum) {
  2996. let result = this.curSiteRule.pageNum;
  2997. let strMatch = result.match(/\{.*?}/);
  2998. if (!strMatch) return null;
  2999. let urlReg = new RegExp("(" + result.replace(strMatch[0], ")\\d+(") + ")", "i");
  3000. let code = strMatch[0].replace(/^{/, "").replace(/}$/, "").replace(/\$p/g, pageNum);
  3001. if (code === pageNum) {
  3002. result = url.replace(urlReg, "$1" + code + "$2");
  3003. } else {
  3004. try {
  3005. code = Function('"use strict";return ' + code)();
  3006. if (code && code % 1 == 0) {
  3007. result = url.replace(urlReg, "$1" + code + "$2");
  3008. } else return null;
  3009. } catch(e) {
  3010. debug(e);
  3011. }
  3012. }
  3013. if (result != url) {
  3014. return result;
  3015. }
  3016. }
  3017. return url.replace(/([&\/\?](p=|page[=\/_-]?))\d+/i, "$1" + pageNum).replace(/([_-])\d+\./i, "$1" + pageNum + ".");
  3018. }
  3019.  
  3020. getPageNumFromUrl(url, defaultPage) {
  3021. if (!url) return defaultPage;
  3022. if (this.curSiteRule.pageNum) {
  3023. let result = this.curSiteRule.pageNum;
  3024. let strMatch = result.match(/\{.*?}/);
  3025. if (!strMatch) return defaultPage;
  3026. let urlReg = new RegExp(".*" + result.replace(strMatch[0], "(\\d+)") + ".*", "i");
  3027. let curShowNum = url.replace(urlReg, "$1");
  3028. if (curShowNum !== url) {
  3029. let code = strMatch[0].replace(/^{/, "").replace(/}$/, "");
  3030. if (code === "$p") {
  3031. return curShowNum;
  3032. } else {
  3033. try {
  3034. let page1 = parseInt(Function('"use strict";return ' + code.replace("$p", "0"))());
  3035. let page2 = parseInt(Function('"use strict";return ' + code.replace("$p", "1"))());
  3036. let numGap = page2 - page1;
  3037. let _page = (parseInt(curShowNum) - page1) / numGap;
  3038. if (_page && _page % 1 === 0) return _page;
  3039. else {
  3040. this.curSiteRule.pageNum = null;
  3041. return defaultPage;
  3042. }
  3043. } catch(e) {
  3044. debug(e);
  3045. }
  3046. }
  3047. } else {
  3048. return defaultPage;
  3049. }
  3050. }
  3051. let pageNum = url.replace(/.*[&\/\?](p=|page[=\/_-]?)(\d+).*/i, "$2");
  3052. return pageNum === url ? defaultPage : (pageNum.length > 4 ? defaultPage : pageNum);
  3053. }
  3054.  
  3055. reachedLastPage() {
  3056. if (rulesData.lastPageTips) {
  3057. showTips(i18n("lastPage"), "", 800);
  3058. }
  3059. _unsafeWindow.postMessage({
  3060. action: "lastPage",
  3061. command: 'pagetual'
  3062. }, '*');
  3063. if (sideController.inited) {
  3064. sideController.frame.classList.add("end");
  3065. }
  3066. }
  3067.  
  3068. async getNextLink(doc, exist) {
  3069. let nextLink = null, page, href;
  3070. let getNextLinkByForm = (form, submitBtn, n) => {
  3071. let params = [];
  3072. let formData = new FormData(form);
  3073. if (submitBtn && submitBtn.getAttribute) {
  3074. let btnValue, btnName;
  3075. btnName = submitBtn.getAttribute("name");
  3076. btnValue = submitBtn.getAttribute("value");
  3077. if (btnName && btnValue) params = [btnName + "=" + encodeURIComponent(btnValue)];
  3078. }
  3079. for (let [key, value] of formData) {
  3080. if (n && /^(p|page)$/i.test(key)) {
  3081. params.push(key + '=' + n);
  3082. } else {
  3083. params.push(key + '=' + encodeURIComponent(value));
  3084. }
  3085. }
  3086. params = params.join('&');
  3087. return form.action + (form.action.indexOf('?') === -1 ? '?' : '&') + params + (form.method === 'post' ? '#p{' + params + '}' : '');
  3088. };
  3089. if (this.curSiteRule.pageElementByJs) {
  3090. this.nextLinkHref = "#";
  3091. return true;
  3092. } else if (this.curSiteRule.nextLinkByJs) {
  3093. try {
  3094. let over = _url => {};
  3095. let targetUrl = await ((typeof this.curSiteRule.nextLinkByJs === 'function') ? this.curSiteRule.nextLinkByJs : new AsyncFunction("doc", '"use strict";' + this.curSiteRule.nextLinkByJs))(doc);
  3096. if (targetUrl) nextLink = {href: targetUrl};
  3097. } catch(e) {
  3098. debug(e);
  3099. }
  3100. } else if (this.curSiteRule.nextLinkByUrl) {
  3101. let targetUrl = this.curUrl.replace(new RegExp(this.curSiteRule.nextLinkByUrl[0], "i"), this.curSiteRule.nextLinkByUrl[1]);
  3102. if (targetUrl !== this.curUrl) {
  3103. let includeSel = this.curSiteRule.nextLinkByUrl[2];
  3104. let excludeSel = this.curSiteRule.nextLinkByUrl[3];
  3105. if (includeSel) {
  3106. includeSel = includeSel.trim();
  3107. if (!getElement(includeSel, doc)) {
  3108. this.nextLinkHref=false;
  3109. return null;
  3110. }
  3111. }
  3112. if (excludeSel) {
  3113. excludeSel = excludeSel.trim();
  3114. if (getElement(excludeSel, doc)) {
  3115. this.nextLinkHref=false;
  3116. return null;
  3117. }
  3118. }
  3119. let reps = targetUrl.match(/{.*?}/g);
  3120. if (reps) {
  3121. reps.forEach(rep => {
  3122. let code = rep.replace("{", "").replace("}", "").replace(/\(\)/g, "0");
  3123. let result = code.match(/^(\d*)\+1$/);
  3124. if (result) {
  3125. result = parseInt(result[1] || 1) + 1;
  3126. } else {
  3127. try {
  3128. result = Function('"use strict";return ' + code)();
  3129. } catch(e) {
  3130. debug(e);
  3131. }
  3132. }
  3133. targetUrl = targetUrl.replace(rep, result);
  3134. });
  3135. }
  3136. }
  3137. nextLink = {href: targetUrl};
  3138. } else if (typeof this.curSiteRule.nextLink !== 'undefined') {
  3139. let nextLinkSel = this.curSiteRule.nextLink;
  3140. if (nextLinkSel != 0) {
  3141. if (Array && Array.isArray && Array.isArray(nextLinkSel)) {
  3142. nextLink = getElement(nextLinkSel[nextIndex], doc, null, true);
  3143. if (!nextLink && curPage === 1 && nextIndex !== 0) {
  3144. nextIndex = 0;
  3145. nextLink = getElement(nextLinkSel[nextIndex], doc, null, true);
  3146. }
  3147. } else nextLink = getElement(nextLinkSel, doc, null, true);
  3148. }
  3149. if (nextLink && (this.curSiteRule.action == 0 || this.curSiteRule.action == 1 || this.curSiteRule.action == 2)) {
  3150. let form = doc.querySelector('#search-form');
  3151. if (!nextLink.href && nextLink.hasAttribute && nextLink.hasAttribute("onclick") && form) {
  3152. if (/^\d+$/.test(nextLink.innerText)) {
  3153. nextLink.href = getNextLinkByForm(form, nextLink, nextLink.innerText);
  3154. }
  3155. } else if (compareNodeName(nextLink, ["input"]) || nextLink.type === "submit") {
  3156. form = nextLink.parentNode;
  3157. while (form) {
  3158. if (compareNodeName(form, ["form"])) break;
  3159. else form = form.parentNode;
  3160. }
  3161. if (form) {
  3162. nextLink.href = getNextLinkByForm(form, nextLink);
  3163. }
  3164. }
  3165. if (nextLink.href && this.curSiteRule.action != 0) {
  3166. nextLink.href = nextLink.href.replace(/#p{.*/, "");
  3167. }
  3168. }
  3169. } else {
  3170. page = await this.getPage(doc, exist);
  3171. nextLink = page.next;
  3172. if (nextLink) {
  3173. if (compareNodeName(nextLink, ["input"]) || nextLink.type === "submit") {
  3174. if (!/next/i.test(nextLink.getAttribute("onclick"))) {
  3175. let form = nextLink.parentNode;
  3176. while (form) {
  3177. if (compareNodeName(form, ["form"])) break;
  3178. else form = form.parentNode;
  3179. }
  3180. if (form) {
  3181. nextLink.href = getNextLinkByForm(form, nextLink);
  3182. }
  3183. }
  3184. }
  3185. let parent = nextLink;
  3186. while (parent && !compareNodeName(parent, ["body"])) {
  3187. if (parent.hasAttribute && parent.hasAttribute("disabled")) {
  3188. this.nextLinkHref = false;
  3189. return null;
  3190. }
  3191. if (parent.className && parent.classList) {
  3192. if (parent.classList.contains("noClick") || parent.classList.contains("no-pages") || parent.classList.contains("disabled")) {
  3193. this.nextLinkHref = false;
  3194. return null;
  3195. }
  3196. }
  3197. if (parent.style && parent.style.display === "none") {
  3198. this.nextLinkHref = false;
  3199. return null;
  3200. }
  3201. parent = parent.parentNode;
  3202. }
  3203. if (doc === document) {
  3204. if (!this.linkHasHref(nextLink)) {
  3205. if (!isVisible(nextLink, _unsafeWindow)) {
  3206. this.nextLinkHref = false;
  3207. return null;
  3208. }
  3209. let video = document.querySelector("video,iframe[id*=play],[id*=play]>iframe,iframe[src*=player],iframe[src*=m3u8]");
  3210. if (video) {
  3211. if (video.offsetParent && video.name !== 'pagetual-iframe') {
  3212. let scrollWidth = video.scrollWidth || video.offsetWidth;
  3213. let scrollHeight = video.scrollHeight || video.offsetHeight;
  3214. if (compareNodeName(video, ["iframe"])) {
  3215. } else if (scrollWidth > 100 && scrollHeight > 100) {
  3216. let winWidth = window.innerWidth || document.documentElement.clientWidth;
  3217. let winHeight = window.innerHeight || document.documentElement.clientHeight;
  3218. if (scrollWidth > winWidth>>1 && scrollHeight > winHeight>>1) {
  3219. debug("Disable when large media found");
  3220. } else {
  3221. video = null;
  3222. }
  3223. } else {
  3224. video = null;
  3225. }
  3226. } else {
  3227. video = null;
  3228. }
  3229. }
  3230. if (video) {
  3231. isPause = true;
  3232. this.clearAddedElements();
  3233. this.nextLinkHref = false;
  3234. return null;
  3235. }
  3236. }
  3237.  
  3238. let nextLinkCs = _unsafeWindow.getComputedStyle(nextLink);
  3239. if (nextLinkCs.cursor === "not-allowed") {
  3240. this.nextLinkHref = false;
  3241. return null;
  3242. }
  3243. this.initNext = nextLink;
  3244. }
  3245. let form = doc.querySelector('#search-form');
  3246. if (!nextLink.href && nextLink.hasAttribute("onclick") && form) {
  3247. if (form && /^\d+$/.test(nextLink.innerText)) {
  3248. href = getNextLinkByForm(form, nextLink, nextLink.innerText);
  3249. }
  3250. }
  3251. }
  3252. }
  3253. if (nextLink) {
  3254. if (doc === document && nextLink.offsetParent) {
  3255. let scrollH = Math.max(document.documentElement.scrollHeight, getBody(document).scrollHeight);
  3256. let actualBottom = getElementBottom(nextLink);
  3257. bottomGap = scrollH - actualBottom + (window.innerHeight || document.documentElement.clientHeight) * rate;
  3258. if (bottomGap < 100) bottomGap = 100;
  3259. }
  3260. if (!this.checkStopSign(nextLink, doc)) {
  3261. if (curPage > 1) {
  3262. this.reachedLastPage();
  3263. }
  3264. return null;
  3265. }
  3266. if (this.curSiteRule.action == 3) {
  3267. if (doc == document) debug(nextLink, 'Next link');
  3268. this.nextLinkHref = '#';
  3269. } else {
  3270. let needUrl = (this.curSiteRule.action == 0 || this.curSiteRule.action == 1 || this.curSiteRule.action == 2);
  3271. if (!href) href = nextLink.href;
  3272. if (href && nextLink.getAttribute) {
  3273. let _href = nextLink.getAttribute("href");
  3274. if (_href) {
  3275. let realHref = _href.replace(location.href, "");
  3276. if (realHref.charAt(0) === "#" || realHref === "?"){
  3277. href = "#";
  3278. } else {
  3279. href = _href;
  3280. }
  3281. } else if (_href === "") {
  3282. href = _href;
  3283. }
  3284. }
  3285.  
  3286. if (needUrl && (href === "" || href === null)) {
  3287. this.nextLinkHref = false;
  3288. } else if (needUrl && /^(javascript:|#)/.test(href)) {
  3289. this.nextLinkHref = false;
  3290. } else {
  3291. this.nextLinkHref = (href && !/^(javascript:|#)/.test(href)) ? this.canonicalUri(href) : "#";
  3292. let tempUrl = this.nextLinkHref;
  3293. 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 + "#"))) {
  3294. this.nextLinkHref = false;
  3295. } else if (doc === document) {
  3296. debug(nextLink, 'Next link');
  3297. }
  3298. }
  3299. }
  3300. } else {
  3301. this.nextLinkHref = false;
  3302. }
  3303. this.nextLinkEle = nextLink;
  3304. this.preload();
  3305. return nextLink;
  3306. }
  3307.  
  3308. compareUrl(url1, url2) {
  3309. if (url1 === url2) return true;
  3310. if (!url1 || !url2) return false;
  3311. let url1Arr = url1.split("?");
  3312. let url2Arr = url2.split("?");
  3313. if (url1Arr[0] != url2Arr[0]) return false;
  3314. if (!url1Arr[1] || !url2Arr[1]) return false;
  3315. url1Arr = url1Arr[1].split("&").sort().join("&");
  3316. url2Arr = url2Arr[1].split("&").sort().join("&");
  3317. return url1Arr === url2Arr;
  3318. }
  3319.  
  3320. filterEles(doc, eles) {
  3321. let filter = this.curSiteRule.filter;
  3322. if (!filter || !eles || eles.length === 0) return;
  3323. if (eles.length === 1) {
  3324. eles = eles[0].children;
  3325. if (eles.length === 1) {
  3326. eles = eles[0].children;
  3327. }
  3328. }
  3329. if (typeof filter === "string") {
  3330. if (/^\d+$/.test(filter)) {
  3331. filter = {count: parseInt(filter)};
  3332. } else filter = {words: filter};
  3333. }
  3334. [].forEach.call(eles, ele => {
  3335. if (!ele.parentNode) return;
  3336. let canKeep = (() => {
  3337. let innerText = (ele.innerText && ele.innerText.trim()) || "";
  3338. if (filter.count) {
  3339. if (innerText.length < filter.count) return false;
  3340. }
  3341. if (filter.words) {
  3342. let wordsRegExp = new RegExp(filter.words, "i");
  3343. if (innerText && wordsRegExp.test(innerText)) return false;
  3344. }
  3345. if (filter.link) {
  3346. let linkRegExp = new RegExp(filter.link, "i");
  3347. if (compareNodeName(ele, ["a"]) && linkRegExp.test(ele.href)) return false;
  3348. let aChildren = ele.querySelectorAll("a");
  3349. for (let i = 0; i < aChildren.length; i++) {
  3350. let child = aChildren[i];
  3351. if (linkRegExp.test(child.href)) return false;
  3352. }
  3353. }
  3354. if (filter.selector) {
  3355. if (getElement(filter.selector, doc, ele)) return false;
  3356. }
  3357. return true;
  3358. })();
  3359. if (!canKeep) {
  3360. ele.parentNode.removeChild(ele);
  3361. }
  3362. });
  3363. }
  3364.  
  3365. checkStopSign(nextLink, doc) {
  3366. if (this.curSiteRule.stopSign) {
  3367. let typeArray = Array && Array.isArray && Array.isArray(this.curSiteRule.stopSign);
  3368. let typeObject = !typeArray && (this.curSiteRule.stopSign.include || this.curSiteRule.stopSign.exclude || this.curSiteRule.stopSign.pageNum);
  3369. if (typeArray || typeObject) {
  3370. let includeSel, excludeSel, curSign, maxSign;
  3371. if (typeArray) {
  3372. includeSel = this.curSiteRule.stopSign[0];
  3373. excludeSel = this.curSiteRule.stopSign[1];
  3374. curSign = this.curSiteRule.stopSign[2];
  3375. maxSign = this.curSiteRule.stopSign[3];
  3376. if (Array && Array.isArray && Array.isArray(includeSel) && !curSign) {
  3377. curSign = includeSel;
  3378. includeSel = false;
  3379. }
  3380. if (excludeSel && Array && Array.isArray && Array.isArray(excludeSel) && !maxSign) {
  3381. maxSign = excludeSel;
  3382. excludeSel = false;
  3383. }
  3384. } else {
  3385. includeSel = this.curSiteRule.stopSign.include;
  3386. excludeSel = this.curSiteRule.stopSign.exclude;
  3387. curSign = this.curSiteRule.stopSign.pageNum;
  3388. }
  3389. if (includeSel) {
  3390. includeSel = includeSel.trim();
  3391. if (!getElement(includeSel, doc)) {
  3392. isPause = true;
  3393. this.nextLinkHref = false;
  3394. return false;
  3395. }
  3396. }
  3397. if (excludeSel) {
  3398. excludeSel = excludeSel.trim();
  3399. if (getElement(excludeSel, doc)) {
  3400. isPause = true;
  3401. this.nextLinkHref = false;
  3402. return false;
  3403. }
  3404. }
  3405. if (curSign) {
  3406. if (!maxSign) maxSign = curSign.slice(2);
  3407. let currentEle = getElement(curSign[0], doc);
  3408. let maxEle = getElement(maxSign[0], doc);
  3409. if (currentEle && maxEle) {
  3410. let currentSignNum, maxSignNum;
  3411. if (/\(.*\)/.test(curSign[1])) {
  3412. currentSignNum = currentEle.innerText.match(new RegExp(curSign[1]));
  3413. if (currentSignNum) currentSignNum = currentSignNum[1];
  3414. } else if (currentEle.getAttribute) {
  3415. currentSignNum = currentEle.getAttribute(curSign[1]);
  3416. }
  3417. if (/\(.*\)/.test(maxSign[1])) {
  3418. maxSignNum = maxEle.innerText.match(new RegExp(maxSign[1]));
  3419. if (maxSignNum) maxSignNum = maxSignNum[1];
  3420. } else if (maxEle.getAttribute) {
  3421. maxSignNum = maxEle.getAttribute(maxSign[1]);
  3422. }
  3423. if (currentSignNum && maxSignNum && currentSignNum == maxSignNum) {
  3424. isPause = true;
  3425. this.nextLinkHref = false;
  3426. return false;
  3427. }
  3428. }
  3429. }
  3430. } else {
  3431. try {
  3432. let stopSign = ((typeof this.curSiteRule.stopSign === 'function') ? this.curSiteRule.stopSign : Function("doc", "nextLink", '"use strict";' + this.curSiteRule.stopSign))(doc, nextLink);
  3433. if (stopSign) {
  3434. isPause = true;
  3435. this.nextLinkHref = false;
  3436. return false;
  3437. }
  3438. } catch(e) {
  3439. debug(e);
  3440. }
  3441. }
  3442. }
  3443. return true;
  3444. }
  3445.  
  3446. preloadImageHandler() {
  3447. if (this.preloadingImage || !this.unCheckedImgs.length) return;
  3448. this.preloadingImage = true;
  3449. setTimeout(() => {
  3450. this.preloadingImage = false;
  3451. this.preloadImageHandler();
  3452. }, 10);
  3453. let iSrc = this.unCheckedImgs.shift();
  3454. let img = document.createElement('img');
  3455. img.src = iSrc;
  3456. this.preloadDiv.appendChild(img);
  3457. }
  3458.  
  3459. preload() {
  3460. if (!rulesData.preload) return;
  3461. if (this.curSiteRule.preload === 0) return;
  3462. if (!this.nextLinkHref || this.nextLinkHref == "#") return;
  3463. if (this.readyStateUnComplete) return;
  3464. if (document.readyState !== 'complete') {
  3465. this.readyStateUnComplete = true;
  3466. let self = this;
  3467. window.addEventListener("load", e => {
  3468. self.readyStateUnComplete = false;
  3469. self.preload();
  3470. });
  3471. return;
  3472. }
  3473. let self = this, url = this.nextLinkHref;
  3474. let postParams = url.match(/#p{(.*)}$/);
  3475. if (postParams) {
  3476. postParams = postParams[1];
  3477. url = url.replace(/#p{.*/, "");
  3478. }
  3479. _GM_xmlhttpRequest({
  3480. url: url,
  3481. method: postParams ? 'POST' : 'GET',
  3482. data: postParams,
  3483. overrideMimeType: 'text/html;charset=' + charset,
  3484. headers: {
  3485. 'Referer': location.href,
  3486. 'User-Agent': navigator.userAgent,
  3487. "Content-Type": (postParams ? "application/x-www-form-urlencoded" : "text/html") + ";charset=" + charset,
  3488. },
  3489. timeout: 10000,
  3490. onload: function(res) {
  3491. var doc = null;
  3492. try {
  3493. doc = document.implementation.createHTMLDocument('');
  3494. doc.documentElement.innerHTML = createHTML(res.response);
  3495. var body = getBody(doc);
  3496. if (!self.preloadDiv) {
  3497. self.preloadDiv = document.createElement('div');
  3498. self.preloadDiv.id = "pagetual-preload";
  3499. self.preloadDiv.style.cssText = 'display:none!important;';
  3500. getBody(document).appendChild(self.preloadDiv);
  3501. self.checkedImgs = {};
  3502. self.unCheckedImgs = [];
  3503. }
  3504. let code = self.curSiteRule.preloadImages;
  3505. if (code) {
  3506. let imgSrcArr = new Function("doc", '"use strict";' + code)(doc);
  3507. if (imgSrcArr && imgSrcArr.length) {
  3508. imgSrcArr.forEach(imgSrc => {
  3509. if (imgSrc && !self.checkedImgs[imgSrc]) {
  3510. self.checkedImgs[imgSrc] = true;
  3511. self.unCheckedImgs.push(imgSrc);
  3512. }
  3513. });
  3514. }
  3515. self.preloadImageHandler();
  3516. } else if (code !== 0 && code !== false) {
  3517. if (body && body.firstChild) {
  3518. self.lazyImgAction(body.children, doc);
  3519. }
  3520. [].forEach.call(doc.images, i => {
  3521. let iSrc = i.src;
  3522. if (iSrc && !self.checkedImgs[iSrc]) {
  3523. self.checkedImgs[iSrc] = true;
  3524. self.unCheckedImgs.push(iSrc);
  3525. }
  3526. });
  3527. self.preloadImageHandler();
  3528. }
  3529. }
  3530. catch(e) {
  3531. debug(e);
  3532. return;
  3533. }
  3534. }
  3535. });
  3536. }
  3537.  
  3538. getInsert(refresh) {
  3539. if (refresh) {
  3540. this.insert = null;
  3541. }
  3542. if (this.insert && this.insert.parentNode && document.documentElement.contains(this.insert)) {
  3543. return this.insert;
  3544. }
  3545. if (this.curSiteRule.insert) {
  3546. let insertSel = this.curSiteRule.insert;
  3547. if (Array && Array.isArray && Array.isArray(insertSel)) {
  3548. insertSel = insertSel[nextIndex < insertSel.length ? nextIndex : 0];
  3549. }
  3550. this.insert = getElement(insertSel, document, null, true);
  3551. } else {
  3552. this.docPageElement = null;
  3553. let pageElement = this.getPageElement(document, _unsafeWindow);
  3554. if (this.curSiteRule.smart && this.nextLinkHref == "#" && this.curSiteRule.pageElement === 'body') {
  3555. debug("Stop as jsNext & whole body");
  3556. isPause = true;
  3557. return null;
  3558. }
  3559. if (pageElement && pageElement.length > 0) {
  3560. let pEIndex = pageElement.length - 1;
  3561. let pELast = pageElement[pEIndex];
  3562. while(pELast && compareNodeName(pELast, ["link", "meta", "style", "script"])) {
  3563. pEIndex--;
  3564. pELast = pageElement[pEIndex];
  3565. }
  3566. this.insert = pELast.nextSibling ? pELast.nextSibling : pELast.parentNode.appendChild(document.createTextNode(' '));
  3567. }
  3568. }
  3569. return this.insert;
  3570. }
  3571.  
  3572. pageInit(doc, eles) {
  3573. let code = this.curSiteRule.pageInit;
  3574. if (code) {
  3575. let initFunc = ((typeof code == 'function') ? code : Function("doc", "eles", '"use strict";' + code));
  3576. let checkInit = (resolve) => {
  3577. try {
  3578. if (initFunc(doc, eles) === false) {
  3579. setTimeout(() => {
  3580. checkInit(resolve);
  3581. }, 100);
  3582. } else {
  3583. resolve(true);
  3584. }
  3585. } catch(e) {
  3586. resolve(false);
  3587. debug(e);
  3588. }
  3589. };
  3590. return new Promise((resolve) => {
  3591. checkInit(function(e) {
  3592. resolve(e)
  3593. });
  3594. })
  3595. }
  3596. }
  3597.  
  3598. pageAction(doc, eles) {
  3599. let code = this.curSiteRule.pageAction;
  3600. if (code) {
  3601. try {
  3602. ((typeof code == 'function') ? code : Function("doc", "eles", '"use strict";' + code))(doc, eles);
  3603. } catch(e) {
  3604. debug(e);
  3605. }
  3606. }
  3607. this.openInNewTab(eles);
  3608. this.replaceElement(doc);
  3609. }
  3610.  
  3611. openInNewTab(eles) {
  3612. if (openInNewTab) {
  3613. [].forEach.call(eles, ele => {
  3614. if (compareNodeName(ele, ["a"]) && ele.href && !/^(mailto:|javascript:)|#/.test(ele.href)) {
  3615. ele.setAttribute('target', openInNewTab == 1 ? '_blank' : '_self');
  3616. } else {
  3617. [].forEach.call(ele.querySelectorAll('a[href]:not([href^="mailto:"]):not([href^="javascript:"]):not([href^="#"])'), a => {
  3618. if (openInNewTab == 1) {
  3619. a.setAttribute('target', '_blank');
  3620. if (a.getAttribute('onclick') == 'atarget(this)') {
  3621. a.removeAttribute('onclick');
  3622. }
  3623. } else a.setAttribute('target', '_self');
  3624. });
  3625. }
  3626. });
  3627. }
  3628. }
  3629.  
  3630. lazyImgAction(eles, doc) {
  3631. if (!eles || eles.length == 0) return;
  3632. let lazyImgSrc = this.curSiteRule.lazyImgSrc;
  3633. if (lazyImgSrc === 0 || lazyImgSrc === '0') return;
  3634. let imgLazyAttrs = [];
  3635. let lazyAttrs = ["div[data-thumb]|data-src", "div.img|data-src", "div.lazy|data-src", "div.lazy|data-original", "a.lazy|data-bg", "a.lazyload|data-original"];
  3636. let removeProps = [];
  3637. let setLazyImg = img => {
  3638. let realSrc;
  3639. imgLazyAttrs.forEach(attr => {
  3640. realSrc = img.getAttribute(lazyImgSrc[0]);
  3641. if (realSrc) {
  3642. removeProps.forEach(prop => {
  3643. img.removeAttribute(prop.trim());
  3644. });
  3645. img.src = realSrc;
  3646. return;
  3647. }
  3648. })
  3649. if (!realSrc) {
  3650. let lazyAttr = "";
  3651. if (img.getAttribute("_src") && !img.src) {
  3652. lazyAttr = "_src";
  3653. realSrc = img.getAttribute(lazyAttr);
  3654. } else {
  3655. for (let i in lazyImgAttr) {
  3656. lazyAttr = lazyImgAttr[i];
  3657. let attrValue = img.getAttribute(lazyAttr);
  3658. if (attrValue) {
  3659. realSrc = attrValue;
  3660. break;
  3661. }
  3662. }
  3663. }
  3664. if (!realSrc && img._lazyrias && img._lazyrias.srcset) {
  3665. realSrc = img._lazyrias.srcset[img._lazyrias.srcset.length - 1];
  3666. lazyAttr = "_lazyrias";
  3667. }
  3668. if (!realSrc && img.srcset) {
  3669. lazyAttr = "srcset";
  3670. var srcs = img.srcset.split(/[xw],/i), largeSize = 0;
  3671. srcs.forEach(srci => {
  3672. let srcInfo = srci.trim().split(" "), curSize = parseInt(srcInfo[1]);
  3673. if (srcInfo[1] && curSize > largeSize) {
  3674. largeSize = curSize;
  3675. realSrc = srcInfo[0];
  3676. }
  3677. });
  3678. }
  3679. if (realSrc) {
  3680. img.src = realSrc;
  3681. img.removeAttribute("srcset");
  3682. img.removeAttribute(lazyAttr);
  3683. if (img.classList && img.classList.contains && img.classList.contains("lazy")) {
  3684. img.classList.remove("lazy");
  3685. }
  3686. if (img.style.display == "none") {
  3687. img.style.display = "";
  3688. }
  3689. if (img.style.visibility == "hidden") {
  3690. img.style.visibility = "";
  3691. }
  3692. if (img.style.opacity == 0) {
  3693. img.style.opacity = "";
  3694. }
  3695. }
  3696. }
  3697. };
  3698. if (lazyImgSrc) {
  3699. if (!Array.isArray(lazyImgSrc)) {
  3700. lazyAttrs = lazyImgSrc.split(",");
  3701. } else {
  3702. lazyAttrs = lazyImgSrc[0].split(",");
  3703. removeProps = lazyImgSrc[1].split(",");
  3704. }
  3705. }
  3706. lazyAttrs.forEach(attr => {
  3707. let attrArr = attr.split("|");
  3708. if (attrArr.length !== 2) {
  3709. imgLazyAttrs.push(attr.trim());
  3710. } else {
  3711. let selector = attrArr[0].trim();
  3712. let lazyAttr = attrArr[1].trim();
  3713. if (selector == "img") {
  3714. imgLazyAttrs.push(lazyAttr);
  3715. } else {
  3716. selector += "[" + lazyAttr + "]";
  3717. [].forEach.call(doc.querySelectorAll(selector), ele => {
  3718. ele.style.setProperty("background-image", "url(" + ele.getAttribute(lazyAttr) + ")", "important");
  3719. removeProps.forEach(prop => {
  3720. ele.removeAttribute(prop.trim());
  3721. });
  3722. });
  3723. }
  3724. }
  3725. });
  3726. [].forEach.call(doc.querySelectorAll("img,picture>source"), img => {
  3727. setLazyImg(img);
  3728. });
  3729. }
  3730.  
  3731. canListenUrlChange() {
  3732. if (this.curSiteRule) {
  3733. if (this.curSiteRule.listenUrlChange === true) return true;
  3734. if (this.curSiteRule.listenUrlChange === false) return false;
  3735. if (this.docElementValid()) {
  3736. return false;
  3737. }
  3738. }
  3739. return true;
  3740. }
  3741.  
  3742. checkClickHref() {
  3743. if (this.curSiteRule.smart && this.nextLinkEle && !this.linkHasHref(this.nextLinkEle)) {
  3744. this.urlChanged();
  3745. isPause = true;
  3746. if (!this.nextLinkHref) isLoading = false;
  3747. }
  3748. }
  3749.  
  3750. docElementValid() {
  3751. if (!this.docPageElement || this.docPageElement.length == 0) return false;
  3752. if (!this.checkPageEle) {
  3753. let ele;
  3754. if (this.docPageElement.length == 1) {
  3755. ele = this.docPageElement[0];
  3756. } else {
  3757. ele = this.docPageElement[Math.floor(this.docPageElement.length / 2)];
  3758. }
  3759. if (ele.children.length) {
  3760. ele = ele.children[Math.floor(ele.children.length / 2)];
  3761. }
  3762. this.checkPageEle = ele;
  3763. }
  3764. return document.documentElement.contains(this.checkPageEle);
  3765. }
  3766.  
  3767. urlChanged() {
  3768. urlChanged = true;
  3769. this.clearAddedElements();
  3770. }
  3771.  
  3772. initPage(callback) {
  3773. let self = this;
  3774. if (self.initing) return;
  3775. self.initing = true;
  3776. setTimeout(() => {
  3777. self.initing = false;
  3778. }, 100);
  3779. curPage = 1;
  3780. urlChanged = false;
  3781. tryTimes = 0;
  3782. this.clearAddedElements();
  3783. this.insert = null;
  3784. this.visibilityItems = [];
  3785. this.visibleIndex = -1;
  3786. this.pageDoc = document;
  3787. this.nextLinkHref = null;
  3788. this.curUrl = location.href;
  3789. this.oldUrl = "";
  3790. this.initUrl = location.href;
  3791. this.historyUrl = "";
  3792. this.possibleCheck = 0;
  3793. let base = document.querySelector("base");
  3794. this.basePath = (base && base.href) || location.href;
  3795. this.getRule(async () => {
  3796. if (self.curSiteRule.sideController === true || (self.curSiteRule.sideController !== false && rulesData.sideController)) {
  3797. isPause = manualPause;
  3798. }
  3799. hidePageBar = rulesData.opacity == 0 || self.curSiteRule.pageBar === 0;
  3800. if (typeof(self.curSiteRule.rate) !== "undefined") {
  3801. rate = self.curSiteRule.rate;
  3802. }
  3803. if (self.curSiteRule.enable == 0) {
  3804. debug("Stop as rule disable");
  3805. isPause = true;
  3806. _GM_registerMenuCommand(i18n("enable"), () => {
  3807. showTips(i18n("enableSiteTips"));
  3808. if(!self.customRules) {
  3809. self.customRules = [];
  3810. }
  3811. for (let i in self.customRules) {
  3812. if (self.customRules[i].url == self.curSiteRule.url) {
  3813. self.customRules.splice(i, 1);
  3814. break;
  3815. }
  3816. }
  3817. self.curSiteRule.enable = 1;
  3818. self.customRules.unshift(self.curSiteRule);
  3819. storage.setItem("customRules", self.customRules);
  3820. location.reload();
  3821. });
  3822. return;
  3823. }
  3824. if (rulesData.sideControllerAlways) {
  3825. sideController.setup();
  3826. }
  3827. //若是再亂匹配就不緩存wedata,或者只在找完本地規則之後再考慮wedata的緩存
  3828. if (self.curSiteRule.smart) {
  3829. delete self.curSiteRule.pageElement;
  3830. if (!self.possibleRule) {
  3831. self.smartRules = self.smartRules.filter(item => {return item && item.url != self.curSiteRule.url});
  3832. self.smartRules.unshift(self.curSiteRule);
  3833. if (self.smartRules.length > 100) {
  3834. self.smartRules.pop();
  3835. }
  3836. storage.setItem("smartRules", self.smartRules);
  3837. }
  3838. } else if (self.curSiteRule && self.curSiteRule.url.length > 13) {
  3839. self.addToHpRules();
  3840. }
  3841. let css;
  3842. if (rulesData.customCss && self.curSiteRule.css) {
  3843. let globalCssArr = rulesData.customCss.split("inIframe:");
  3844. let ruleCssArr = self.curSiteRule.css.split("inIframe:");
  3845. let mainCss = globalCssArr[0] + ruleCssArr[0], inCss = (globalCssArr[1] || "") + (ruleCssArr[1] || "");
  3846. css = mainCss + (inCss ? ("inIframe:" + inCss) : "");
  3847. } else {
  3848. css = self.curSiteRule.css || rulesData.customCss;
  3849. }
  3850. if (css) {
  3851. let cssArr = css.split("inIframe:");
  3852. if (cssArr && cssArr.length) {
  3853. _GM_addStyle(cssArr[0]);
  3854. }
  3855. }
  3856. if (/sidesearch=(1|true)$/.test(self.curUrl)) {
  3857. openInNewTab = 0;
  3858. } else if (typeof self.curSiteRule.openInNewTab !== 'undefined') {
  3859. openInNewTab = self.curSiteRule.openInNewTab ? 1 : 2;
  3860. }
  3861. let autoClick = self.curSiteRule.autoClick;
  3862. if (autoClick) {
  3863. let autoClickBtn;
  3864. autoClickBtn = getElement(autoClick, document, null, true);
  3865. if (autoClickBtn) {
  3866. emuClick(autoClickBtn);
  3867. }
  3868. }
  3869. let code = self.curSiteRule.init;
  3870. if (code) {
  3871. try {
  3872. await ((typeof code == 'function') ? code : new AsyncFunction('doc', 'win', 'iframe', 'click', 'enter', 'input', 'sleep', '"use strict";' + code))(null, null, null, async sel => {await clickAction(sel, document)}, async sel => {await enterAction(sel, document)}, async (sel, v) =>{await inputAction(sel, v, document)}, async time => {await sleep(time)});
  3873. } catch(e) {
  3874. debug(e);
  3875. }
  3876. }
  3877. await self.getNextLink(document, true);
  3878. if (self.curSiteRule.pageNum && self.nextLinkHref && self.nextLinkHref != "#") {
  3879. let num1st = self.getPageNumFromUrl(location.href, 1);
  3880. let num2nd = self.getPageNumFromUrl(self.nextLinkHref, 1);
  3881. if (parseInt(num2nd) != parseInt(num1st) + 1) {
  3882. self.curSiteRule.pageNum = null;
  3883. }
  3884. }
  3885. if (self.curSiteRule.smart && self.nextLinkHref == false && self.possibleRule) {
  3886. let urlReg = new RegExp(self.possibleRule.url, "i");
  3887. function checkPossible () {
  3888. if (self.possibleCheck++ < 3) {
  3889. setTimeout(() => {
  3890. if (self.curSiteRule.smart) {
  3891. var href = location.href.slice(0, 500);
  3892. if (urlReg.test(href) && self.ruleMatch(self.possibleRule)) {
  3893. self.initPage(() => {});
  3894. } else checkPossible();
  3895. }
  3896. }, 3000);
  3897. }
  3898. }
  3899. checkPossible();
  3900. }
  3901. self.refreshByClick();
  3902. if (emuIframe && emuIframe.parentNode) {
  3903. emuIframe.parentNode.removeChild(emuIframe);
  3904. emuIframe = null;
  3905. }
  3906.  
  3907. let pageElementCss = self.curSiteRule.pageElementCss || rulesData.pageElementCss;
  3908. if (pageElementCss && pageElementCss !== '0') {
  3909. self.getPageElement(document, _unsafeWindow);
  3910. }
  3911. callback();
  3912. let initRun = typeof self.curSiteRule.initRun == 'undefined' ? rulesData.initRun : self.curSiteRule.initRun;
  3913. if (self.nextLinkHref) {
  3914. sideController.setup();
  3915. if (initRun && initRun != false) {
  3916. setTimeout(() => {
  3917. nextPage();
  3918. }, 300);
  3919. }
  3920. } else isPause = false;
  3921. });
  3922. }
  3923.  
  3924. async hookUrlSetEle(ele, doc) {
  3925. let self = this;
  3926. return new Promise((resolve) => {
  3927. let catchUrl = e => {
  3928. ele.dataset.url = self.catchedUrl;
  3929. ele.setAttribute('onclick', 'window.open(this.dataset.url)');
  3930. window.removeEventListener('pagetual_openUrl', catchUrl);
  3931. resolve();
  3932. };
  3933. window.addEventListener('pagetual_openUrl', catchUrl);
  3934. emuClick(ele, doc);
  3935. });
  3936. }
  3937.  
  3938. async hookUrl(doc) {
  3939. let sel = this.curSiteRule.hookUrl;
  3940. if (!sel) return;
  3941. let self = this;
  3942. if (!this.initHook) {
  3943. this.initHook = true;
  3944. Object.defineProperty(doc.defaultView, 'open', {
  3945. get: function () {
  3946. return (s) => {
  3947. self.catchedUrl = s;
  3948. var e = new CustomEvent('pagetual_openUrl');
  3949. window.dispatchEvent(e);
  3950. }
  3951. }
  3952. });
  3953. }
  3954. let eles = getAllElements(sel, doc);
  3955. for (let i = 0; i < eles.length; i++) {
  3956. await sleep(1);
  3957. let ele = eles[i];
  3958. if (!ele.dataset.url) {
  3959. await this.hookUrlSetEle(ele, doc);
  3960. }
  3961. }
  3962. }
  3963.  
  3964. beginLoading() {
  3965. isLoading = true;
  3966. if (targetY >= 0) {
  3967. window.scrollTo({ top: targetY, behavior: 'instant'});
  3968. targetY = -1;
  3969. }
  3970. let lastScrollTop = getBody(document).scrollTop || document.documentElement.scrollTop;
  3971. ruleParser.insertElement(loadingDiv);
  3972. if (forceState == 2) {
  3973. getBody(document).appendChild(loadingDiv);
  3974. } else {
  3975. let parent = loadingDiv.parentNode;
  3976. if (compareNodeName(parent, ["tbody"])) {
  3977. parent = parent.parentNode;
  3978. }
  3979. if (compareNodeName(parent, ["table"])) {
  3980. parent.parentNode.appendChild(loadingDiv);
  3981. }
  3982. }
  3983. getBody(document).scrollTop = lastScrollTop;
  3984. document.documentElement.scrollTop = lastScrollTop;
  3985. if (sideController.inited) {
  3986. sideController.frame.classList.add("loading");
  3987. }
  3988. }
  3989.  
  3990. insertElement(ele) {
  3991. if (!this.insert || !this.insert.parentNode) {
  3992. this.getInsert();
  3993. }
  3994. if (this.insert && this.insert.parentNode) {
  3995. let self = this;
  3996. if (ele.nodeName == "#document-fragment") {
  3997. [].forEach.call(ele.children, el => {
  3998. self.addedElePool.push(el);
  3999. });
  4000. } else {
  4001. this.addedElePool.push(ele);
  4002. }
  4003. if (this.curSiteRule.insertPos == 2 || this.curSiteRule.insertPos == "in") {
  4004. this.insert.appendChild(ele);
  4005. } else {
  4006. this.insert.parentNode.insertBefore(ele, this.insert);
  4007. }
  4008. }
  4009. }
  4010.  
  4011. noValidContent(url) {
  4012. if (!this.curSiteRule.nextLinkByUrl) showTips(i18n("noValidContent"), url);
  4013. }
  4014.  
  4015. async insertPage(doc, eles, url, callback, tried) {
  4016. this.oldUrl = this.curUrl;
  4017. let oldTitle = document.title;
  4018. try {
  4019. let oldTitle = this.pageDoc.title;
  4020. } catch (e) {}
  4021. this.pageDoc = doc;
  4022. this.curUrl = url;
  4023. isLoading = true;
  4024. let nextLink = await this.getNextLink(doc);
  4025. this.nextTitle = "";
  4026. if (this.curSiteRule.pageBarText) {
  4027. if (this.curSiteRule.pageBarText == 1 || this.curSiteRule.pageBarText == true) {
  4028. this.nextTitle = doc.title;
  4029. } else {
  4030. try {
  4031. this.nextTitle = ((typeof this.curSiteRule.pageBarText == 'function') ? this.curSiteRule.pageBarText : Function("doc",'"use strict";' + this.curSiteRule.pageBarText))(doc);
  4032. } catch(e) {
  4033. debug(e);
  4034. }
  4035. }
  4036. }
  4037. if (curPage == 1 && !tried && !nextLink && this.curSiteRule.smart && this.curSiteRule.pageElement && this.curSiteRule.action != 0) {
  4038. this.curSiteRule.action = 1;
  4039. this.curUrl = location.href;
  4040. isLoading = false;
  4041. return false;
  4042. }
  4043.  
  4044. if (targetY >= 0) {
  4045. window.scrollTo({ top: targetY, behavior: 'instant'});
  4046. targetY = -1;
  4047. }
  4048. let lastScrollTop = getBody(document).scrollTop || document.documentElement.scrollTop;
  4049. this.getInsert();
  4050. await this.pageInit(doc, eles);
  4051. var self = this, newEles = [];
  4052. if (!eles || eles.length == 0 || !self.insert || !self.insert.parentNode) {
  4053. if (callback) callback(eles);
  4054. loadPageOver();
  4055. } else {
  4056. if (callback) callback(eles);
  4057. loadPageOver();
  4058. const collection = document.createDocumentFragment();
  4059. [].forEach.call(eles, ele => {
  4060. let newEle = ele.cloneNode(true);
  4061. let oldCanvass = ele.querySelectorAll("canvas");
  4062. let newCanvass = newEle.querySelectorAll("canvas");
  4063. if (self.updateUrl) {
  4064. [].forEach.call(newEle.querySelectorAll("img"), img => {
  4065. if (img.getAttribute("src")) img.src = self.canonicalUri(img.getAttribute("src"));
  4066. });
  4067. [].forEach.call(newEle.querySelectorAll("a"), a => {
  4068. if (a.getAttribute("href")) a.href = self.canonicalUri(a.getAttribute("href"));
  4069. });
  4070. }
  4071. for (let i = 0; i < oldCanvass.length; i++) {
  4072. let oldCanvas = oldCanvass[i];
  4073. let newCanvas = newCanvass[i];
  4074. newCanvas.getContext('2d').drawImage(oldCanvas, 0, 0);
  4075. }
  4076. if (!compareNodeName(newEle, ["style", "script"])) self.visibilityItems.push(newEle);
  4077. collection.appendChild(newEle)
  4078. newEles.push(newEle);
  4079. });
  4080. let css = this.curSiteRule.css;
  4081. let addCss = (parent) => {
  4082. if (css) {
  4083. let cssArr = css.split("inIframe:");
  4084. if (cssArr && cssArr.length == 2) {
  4085. let styleEle = document.createElement("style");
  4086. styleEle.innerHTML = cssArr[1];
  4087. parent.appendChild(styleEle);
  4088. }
  4089. }
  4090. };
  4091. if (this.curSiteRule.surround === "iframe") {
  4092. let ele = document.createElement("iframe");
  4093. ele.style.border = "unset";
  4094. ele.style.maxWidth = "100%";
  4095. ele.style.width = "100vw";
  4096. self.insertElement(ele);
  4097. try {
  4098. let doc = ele.contentDocument || ele.contentWindow.document;
  4099. doc.body.appendChild(collection);
  4100. ele.style.width = doc.body.scrollWidth + "px";
  4101. ele.style.height = doc.body.scrollHeight + "px";
  4102. doc.documentElement.style.overflow = "hidden";
  4103. doc.body.style.overflow = "hidden";
  4104. addCss(doc.body);
  4105. } catch(e) {
  4106. console.log(e);
  4107. }
  4108. } else if (this.curSiteRule.surround === "shadowDom") {
  4109. let ele = document.createElement("div");
  4110. self.insertElement(ele);
  4111. let shadowRoot = ele.attachShadow({ mode: "open" });
  4112. shadowRoot.appendChild(collection);
  4113. addCss(shadowRoot);
  4114. } else {
  4115. self.insertElement(collection);
  4116. }
  4117. }
  4118. getBody(document).scrollTop = lastScrollTop;
  4119. document.documentElement.scrollTop = lastScrollTop;
  4120. this.pageAction(doc, newEles);
  4121. let enableHistory = this.curSiteRule.history;
  4122. let enableHistoryAfterInsert = false;
  4123. if (enableHistory == 1) {
  4124. enableHistory = true;
  4125. } else if (enableHistory == 2) {
  4126. enableHistory = true;
  4127. enableHistoryAfterInsert = true;
  4128. } else if (enableHistory == 0) {
  4129. enableHistory = false;
  4130. } else {
  4131. enableHistory = rulesData.enableHistory;
  4132. enableHistoryAfterInsert = rulesData.enableHistoryAfterInsert;
  4133. }
  4134. if (enableHistory) {
  4135. this.historyUrl = enableHistoryAfterInsert ? this.curUrl : this.oldUrl;
  4136. if(this.historyUrl != location.href) {
  4137. let isJs = this.hrefIsJs(this.historyUrl);
  4138. if (!isJs) {
  4139. let historyTitle = enableHistoryAfterInsert ? doc.title : oldTitle;
  4140. _unsafeWindow.history.replaceState(undefined, historyTitle, this.historyUrl);
  4141. document.title = historyTitle;
  4142. }
  4143. }
  4144. }
  4145. isLoading = false;
  4146. _unsafeWindow.postMessage({
  4147. action: "insert",
  4148. command: 'pagetual'
  4149. }, '*');
  4150. return true;
  4151. }
  4152. }
  4153. var ruleParser = new RuleParser();
  4154.  
  4155. class SideController {
  4156. //static controller;
  4157. constructor() {
  4158. this.inited = false;
  4159. }
  4160.  
  4161. /*static getInstance() {
  4162. if (!SideController.controller) {
  4163. SideController.controller = new SideController();
  4164. }
  4165. return SideController.controller;
  4166. }*/
  4167.  
  4168. setup() {
  4169. if (ruleParser.curSiteRule.sideController === false) return;
  4170. if (!rulesData.sideController && !ruleParser.curSiteRule.sideController) return;
  4171. this.addToStage();
  4172. }
  4173.  
  4174. init() {
  4175. if (this.inited) return;
  4176. this.inited = true;
  4177. let self = this;
  4178. this.cssText = `
  4179. #pagetual-sideController {
  4180. position: fixed;
  4181. top: calc(50% - 83px);
  4182. left: calc(99% - 40px);
  4183. width: 40px;
  4184. border-radius: 20px;
  4185. box-shadow: rgb(0 0 0) 0px 0px 10px;
  4186. text-align: center;
  4187. background: #ffffffd0!important;
  4188. user-select: none;
  4189. z-index: 2147483646!important;
  4190. padding: 0!important;
  4191. opacity: 0.5;
  4192. transition: opacity .5s ease, background .5s, box-shadow .5s;
  4193. }
  4194. #pagetual-sideController.end {
  4195. opacity: 0.3;
  4196. }
  4197. #pagetual-sideController * {
  4198. font-weight: bold;
  4199. font-family: arial;
  4200. font-style: normal;
  4201. font-size: 20px!important;
  4202. color: black!important;
  4203. line-height: normal;
  4204. float: none;
  4205. text-align: center;
  4206. }
  4207. #pagetual-sideController.stop {
  4208. -webkit-filter: invert(100%);
  4209. filter: invert(100%);
  4210. }
  4211. .pagetual-sideController-btn {
  4212. padding: 5px 0;
  4213. cursor: pointer;
  4214. transition: transform .15s ease-in-out, opacity .3s ease;
  4215. }
  4216. #pagetual-sideController .pagetual-sideController-btn:hover {
  4217. transform: scale(1.5);
  4218. color: red!important;
  4219. }
  4220. #pagetual-sideController #pagetual-sideController-move > svg {
  4221. transition: transform .3s ease;
  4222. }
  4223. #pagetual-sideController #pagetual-sideController-move > svg:hover {
  4224. transform: scale(1.2);
  4225. }
  4226. ${rulesData.hideLoadingIcon ? '' : `
  4227. #pagetual-sideController.minSize #pagetual-sideController-move::before {
  4228. content: '';
  4229. position: absolute;
  4230. width: 34px;
  4231. height: 34px;
  4232. background-color: #1a232a;
  4233. background-repeat: no-repeat;
  4234. background-position: 0 0;
  4235. z-index: -1;
  4236. margin: -2px;
  4237. border-radius: 50%;
  4238. }
  4239. #pagetual-sideController.minSize.loading #pagetual-sideController-move::before {
  4240. background-image: conic-gradient(transparent, #a8efff, transparent 30%);
  4241. -webkit-animation: siderotate 1s linear infinite;
  4242. animation: siderotate 1s linear infinite;
  4243. }
  4244. @keyframes siderotate {
  4245. 100% {
  4246. transform: rotate(1turn);
  4247. }
  4248. }`}
  4249. #pagetual-sideController.minSize #pagetual-sideController-move > svg {
  4250. background: white;
  4251. opacity: 0;
  4252. }
  4253. #pagetual-sideController #pagetual-sideController-move > img,
  4254. #pagetual-sideController #pagetual-sideController-move > span {
  4255. width: 35px;
  4256. height: 35px;
  4257. cursor: pointer;
  4258. }
  4259. #pagetual-sideController.minSize #pagetual-sideController-move > img,
  4260. #pagetual-sideController.minSize #pagetual-sideController-move > span {
  4261. border-radius: 50px;
  4262. text-shadow: rgb(255 255 255) 0px 0px 10px;
  4263. }
  4264. #pagetual-sideController #pagetual-sideController-pagenum {
  4265. font-size: 15px!important;
  4266. line-height: 30px;
  4267. text-align: center;
  4268. position: absolute;
  4269. right: calc(50% - 15px);
  4270. top: calc(50% - 15px);
  4271. border: 1px solid #00000099;
  4272. display: inline-block;
  4273. width: 30px;
  4274. height: 30px;
  4275. box-sizing: border-box;
  4276. border-radius: 50%;
  4277. background: white;
  4278. opacity: 0;
  4279. transition: opacity .5s ease;
  4280. pointer-events: none;
  4281. }
  4282. #pagetual-sideController.minSize #pagetual-sideController-pagenum {
  4283. opacity: 1;
  4284. }
  4285. #pagetual-sideController:hover {
  4286. opacity: 1;
  4287. }
  4288. #pagetual-sideController>.extra {
  4289. bottom: 170px;
  4290. left: 0px;
  4291. width: 40px;
  4292. position: absolute;
  4293. }
  4294. #pagetual-sideController>.extra>svg {
  4295. width: 40px;
  4296. height: 30px;
  4297. opacity: 0.1;
  4298. cursor: pointer;
  4299. margin: 0 0 5px 0;
  4300. transition: opacity .3s ease;
  4301. }
  4302. #pagetual-sideController.minSize>.extra>svg {
  4303. opacity: 0;
  4304. }
  4305. #pagetual-sideController>.extra>svg:hover {
  4306. opacity: 1;
  4307. }
  4308. #pagetual-sideController.minSize {
  4309. box-shadow: rgb(0 0 0 / 0%) 0px 0px 0px;
  4310. background: #00000000!important;
  4311. pointer-events: none;
  4312. }
  4313. #pagetual-sideController.minSize #pagetual-sideController-move {
  4314. pointer-events: all;
  4315. height: 30px;
  4316. }
  4317. #pagetual-sideController.minSize .pagetual-sideController-btn {
  4318. opacity: 0;
  4319. }
  4320. `;
  4321. let frame = document.createElement("div");
  4322. frame.id = "pagetual-sideController";
  4323. frame.innerHTML = createHTML(`
  4324. <div class="extra">
  4325. <svg id="loadNow" class="pagetual" viewBox="0 0 1030 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><title>${i18n("loadNow")}</title><path d="M712.106667 525.653333l-291.413334 247.893334a21.333333 21.333333 0 0 1-14.506666 5.546666 20.053333 20.053333 0 0 1-22.186667-19.2V264.106667a20.053333 20.053333 0 0 1 20.906667-19.2 20.906667 20.906667 0 0 1 14.506666 5.546666l291.413334 247.893334a17.92 17.92 0 0 1 1.28 27.306666zM512 0a512 512 0 1 0 512 512A512 512 0 0 0 512 0z" fill="#5E5C5C"></path></svg>
  4326. <svg id="scroll" class="pagetual" viewBox="0 0 1030 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><title>${i18n("sideControllerScroll")}</title><path d="M912 544v82.64C912 846.096 732.912 1024 512 1024S112 846.096 112 626.64V544h800z" fill="#5E5C5C"></path><path d="M478.656 0v43.328a96 96 0 0 1-32.48 71.952c-27.68 24.448-41.968 48.128-42.896 71.04l-0.096 4.352v104c0 24.224 14.512 49.344 43.52 75.312a96 96 0 0 1 31.952 71.52V496H112.032L112 393.712C112 181.648 264.848 8.72 472.352 0.208L478.656 0z" fill="#999999"></path><path d="M534.24 0C747.584 5.232 912 179.504 912 393.728v102.256L534.208 496v-52.912a96 96 0 0 1 33.536-72.88c28.48-24.416 43.2-48.16 44.16-71.2l0.096-4.336v-104c0-24.352-14.928-49.52-44.784-75.488a96 96 0 0 1-33.008-72.432V0z" fill="#5E5C5C"></path></svg>
  4327. </div>
  4328. <div id="pagetual-sideController-top" class="pagetual-sideController-btn">⊼</div>
  4329. <div>
  4330. <div id="pagetual-sideController-pre" class="pagetual-sideController-btn">∧</div>
  4331. <div id="pagetual-sideController-move"><svg class="pagetual" 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>
  4332. <div id="pagetual-sideController-next" class="pagetual-sideController-btn">∨</div>
  4333. </div>
  4334. <div id="pagetual-sideController-bottom" class="pagetual-sideController-btn">⊻</div>
  4335. `);
  4336. frame.classList.add("stop");
  4337. let top = frame.querySelector("#pagetual-sideController-top");
  4338. let pre = frame.querySelector("#pagetual-sideController-pre");
  4339. let move = frame.querySelector("#pagetual-sideController-move");
  4340. let next = frame.querySelector("#pagetual-sideController-next");
  4341. let bottom = frame.querySelector("#pagetual-sideController-bottom");
  4342. let pagenum = frame.querySelector("#pagetual-sideController-pagenum");
  4343. let scroll = frame.querySelector("#scroll");
  4344. let loadNow = frame.querySelector("#loadNow");
  4345. if (rulesData.sideControllerScroll === false) {
  4346. scroll.style.display = "none";
  4347. }
  4348. if (rulesData.sideControllerLoadNow === false) {
  4349. loadNow.style.display = "none";
  4350. }
  4351. if (sideControllerIcon) move.innerHTML = sideControllerIcon;
  4352.  
  4353. frame.addEventListener("dblclick", e => {
  4354. e.preventDefault();
  4355. e.stopPropagation();
  4356. });
  4357.  
  4358. frame.addEventListener("mouseenter", e => {
  4359. clearTimeout(self.hideTimer);
  4360. frame.classList.remove("minSize");
  4361. });
  4362.  
  4363. frame.addEventListener("mouseleave", e => {
  4364. clearTimeout(self.hideTimer);
  4365. self.hideTimer = setTimeout(() => {
  4366. frame.classList.add("minSize");
  4367. }, 800);
  4368. });
  4369.  
  4370. document.body.addEventListener('touchstart', e => {
  4371. if (e.target === frame || frame.contains(e.target)) {
  4372. frame.classList.remove("minSize");
  4373. } else {
  4374. frame.classList.add("minSize");
  4375. }
  4376. });
  4377.  
  4378. scroll.addEventListener("click", e => {
  4379. autoScroll = (autoScroll ? 0 : prompt(i18n("autoScrollRate"), autoScrollRate)) || 0;
  4380. autoScroll = parseInt(autoScroll) || 0;
  4381. if (autoScroll < 0) autoScroll = 0;
  4382. if (autoScroll && autoScroll != autoScrollRate) {
  4383. autoScrollRate = autoScroll;
  4384. storage.setItem("autoScrollRate", autoScrollRate);
  4385. }
  4386. setListData("autoScroll", location.host + location.pathname, autoScroll);
  4387. startAutoScroll();
  4388. }, true);
  4389.  
  4390. loadNow.addEventListener("click", e => {
  4391. if (autoLoadNum != -1) {
  4392. autoLoadNum = -1;
  4393. return;
  4394. }
  4395. let loadNum = window.prompt(i18n("loadConfirm"), loadNowNum);
  4396. if (loadNum === "" || loadNum === null) return;
  4397. loadNum = Math.abs(parseInt(loadNum)) || 0;
  4398. if (loadNowNum != loadNum) {
  4399. loadNowNum = loadNum;
  4400. storage.setItem("loadNowNum", loadNowNum);
  4401. }
  4402. autoLoadNum = loadNum;
  4403. nextPage();
  4404. }, true);
  4405.  
  4406. pre.addEventListener("click", e => {
  4407. let prePageBar = getPageBar().preBar;
  4408. if (prePageBar) {
  4409. scrollToPageBar(prePageBar);
  4410. } else {
  4411. let scrollTop = getBody(document).scrollTop || document.documentElement.scrollTop;
  4412. targetY = scrollTop - (window.innerHeight || document.documentElement.clientHeight);
  4413. window.scrollTo({ top: targetY, behavior: 'smooth'});
  4414. }
  4415. }, true);
  4416.  
  4417. next.addEventListener("click", e => {
  4418. let pageBarObj = getPageBar();
  4419. let nextPageBar = pageBarObj.nextBar;
  4420. if (nextPageBar) {
  4421. scrollToPageBar(nextPageBar);
  4422. } else {
  4423. if (pageBarObj.preBar) {
  4424. let scrollH = Math.max(document.documentElement.scrollHeight, getBody(document).scrollHeight);
  4425. targetY = scrollH || 9999999;
  4426. window.scrollTo({ top: targetY, behavior: 'smooth'});
  4427. } else {
  4428. let scrollTop = getBody(document).scrollTop || document.documentElement.scrollTop;
  4429. targetY = scrollTop + (window.innerHeight || document.documentElement.clientHeight);
  4430. window.scrollTo({ top: targetY, behavior: 'smooth'});
  4431. }
  4432. }
  4433. }, true);
  4434.  
  4435. top.addEventListener("click", e => {
  4436. getBody(document).scrollTop=0;
  4437. document.documentElement.scrollTop=0;
  4438. e.preventDefault();
  4439. e.stopPropagation();
  4440. }, true);
  4441.  
  4442. bottom.addEventListener("click", e => {
  4443. if (!e.altKey && !e.ctrlKey && !e.shiftKey && !e.metaKey) {
  4444. changeStop(true);
  4445. }
  4446. let scrollH = Math.max(document.documentElement.scrollHeight, getBody(document).scrollHeight);
  4447. getBody(document).scrollTop = scrollH || 9999999;
  4448. document.documentElement.scrollTop = scrollH || 9999999;
  4449. e.preventDefault();
  4450. e.stopPropagation();
  4451. }, true);
  4452.  
  4453. let initX, initY, moving = false;
  4454. let removeTimer;
  4455. move.addEventListener("click", e => {
  4456. if (!moving) {
  4457. changeStop(!isPause, true);
  4458. }
  4459. }, true);
  4460. move.addEventListener("dblclick", e => {
  4461. clearTimeout(removeTimer);
  4462. document.removeEventListener("mousemove", mouseMoveHandler, true);
  4463. document.removeEventListener("mouseup", mouseUpHandler, true);
  4464. changeStop(!isPause, true);
  4465. if (isPause) {
  4466. ruleParser.hideAddedElements();
  4467. } else {
  4468. ruleParser.showAddedElements();
  4469. }
  4470. }, true);
  4471.  
  4472. move.oncontextmenu = e => {
  4473. e.preventDefault();
  4474. picker.start();
  4475. };
  4476.  
  4477. let clientX = e => {
  4478. if (e.type.indexOf('mouse') === 0) {
  4479. return e.clientX;
  4480. } else {
  4481. return e.changedTouches[0].clientX;
  4482. }
  4483. };
  4484.  
  4485. let clientY = e => {
  4486. if (e.type.indexOf('mouse') === 0) {
  4487. return e.clientY;
  4488. } else {
  4489. return e.changedTouches[0].clientY;
  4490. }
  4491. };
  4492.  
  4493. let mouseMoveHandler = e => {
  4494. if (moving) {
  4495. let windowHeight = window.innerHeight || document.documentElement.clientHeight;
  4496. let windowWidth = window.innerWidth || document.documentElement.clientWidth;
  4497. initX = (clientX(e) - 10 + 40) / windowWidth * 100;
  4498. initY = (clientY(e) - 83 + 83) / windowHeight * 100;
  4499. this.frame.style.top = `calc(${initY}% - 83px)`;
  4500. this.frame.style.left = `calc(${initX}% - 40px)`;
  4501. } else if (Math.abs(clientX(e) - initX) + Math.abs(clientY(e) - initY) > 5) {
  4502. moving = true;
  4503. clearTimeout(removeTimer);
  4504. }
  4505. };
  4506. let mouseUpHandler = e => {
  4507. clearTimeout(removeTimer);
  4508. document.removeEventListener("mousemove", mouseMoveHandler, true);
  4509. document.removeEventListener("mouseup", mouseUpHandler, true);
  4510. document.removeEventListener("touchmove", mouseMoveHandler, true);
  4511. document.removeEventListener("touchend", mouseUpHandler, true);
  4512. if (moving) {
  4513. rulesData.sideControllerPos = {x: parseInt(initX), y: parseInt(initY)};
  4514. storage.setItem("rulesData", rulesData);
  4515. }
  4516. };
  4517. let mouseDownHandler = e => {
  4518. initX = clientX(e);
  4519. initY = clientY(e);
  4520. moving = false;
  4521. clearTimeout(removeTimer);
  4522. removeTimer = setTimeout(() => {
  4523. if (e.type === "touchstart") {
  4524. picker.start();
  4525. } else {
  4526. self.remove();
  4527. }
  4528. }, 1500);
  4529. document.addEventListener("mousemove", mouseMoveHandler, true);
  4530. document.addEventListener("mouseup", mouseUpHandler, true);
  4531. document.addEventListener("touchmove", mouseMoveHandler, true);
  4532. document.addEventListener("touchend", mouseUpHandler, true);
  4533. e.stopPropagation();
  4534. e.preventDefault();
  4535. };
  4536.  
  4537. move.addEventListener("mousedown", mouseDownHandler, true);
  4538. move.addEventListener("touchstart", mouseDownHandler, { passive: false, capture: true });
  4539.  
  4540. this.frame = frame;
  4541. this.pagenum = pagenum;
  4542. if (rulesData.sideControllerPos) {
  4543. this.frame.style.top = `calc(${rulesData.sideControllerPos.y}% - 83px)`;
  4544. this.frame.style.left = `calc(${rulesData.sideControllerPos.x}% - 40px)`;
  4545. }
  4546. }
  4547.  
  4548. addToStage() {
  4549. this.init();
  4550. if (!this.styleEle || !this.styleEle.parentNode) {
  4551. this.styleEle = _GM_addStyle(this.cssText);
  4552. }
  4553. if (!isPause) {
  4554. this.frame.classList.remove("stop");
  4555. }
  4556. this.pagenum.innerHTML = createHTML(curPage);
  4557. this.frame.title = i18n("page") + curPage;
  4558. if (this.frame.parentNode) return;
  4559. getBody(document).appendChild(this.frame);
  4560. clearTimeout(this.hideTimer);
  4561. this.frame.classList.add("minSize");
  4562. }
  4563.  
  4564. remove() {
  4565. if (this.frame && this.frame.parentNode) this.frame.parentNode.removeChild(this.frame);
  4566. }
  4567. }
  4568. const sideController = new SideController();
  4569.  
  4570. class NextSwitch {
  4571. //static nextSwitch;
  4572. constructor() {
  4573. this.inited = false;
  4574. }
  4575.  
  4576. /*static getInstance() {
  4577. if (!NextSwitch.nextSwitch) {
  4578. NextSwitch.nextSwitch = new NextSwitch();
  4579. }
  4580. return NextSwitch.nextSwitch;
  4581. }*/
  4582.  
  4583. init() {
  4584. if (this.inited) return;
  4585. this.inited = true;
  4586. let self = this;
  4587. this.cssText = `
  4588. #pagetual-nextSwitch {
  4589. position: fixed;
  4590. top: 10px;
  4591. left: calc(50% - 160px);
  4592. background: aliceblue;
  4593. padding: 10px;
  4594. border-radius: 5px;
  4595. text-align: center;
  4596. opacity: 0.95;
  4597. color: #161616;
  4598. z-index: 2147483647;
  4599. font-size: 16px;
  4600. box-shadow: rgb(0 0 0) 0px 0px 10px;
  4601. }
  4602. #pagetual-nextSwitch>.title {
  4603. margin: -5px 45px 10px 45px;
  4604. font-size: 20px;
  4605. font-weight: bold;
  4606. border-bottom: 1px solid black;
  4607. user-select: none;
  4608. color: orangered;
  4609. }
  4610. #pagetual-nextSwitch>.group {
  4611. display: flex;
  4612. flex-direction: column;
  4613. }
  4614. #pagetual-nextSwitch>.group>span {
  4615. color: #161616;
  4616. cursor: pointer;
  4617. margin: 3px;
  4618. font-size: larger;
  4619. }
  4620. #pagetual-nextSwitch>.group>span:hover {
  4621. color: red;
  4622. }
  4623. #pagetual-nextSwitch>.group>span.current {
  4624. border: 2px dotted red;
  4625. border-radius: 10px;
  4626. }
  4627. #pagetual-nextSwitch>.closeSwitch {
  4628. position: absolute;
  4629. top: 3px;
  4630. right: 10px;
  4631. background: none;
  4632. border: none;
  4633. vertical-align: top;
  4634. transition: transform .15s ease-in-out;
  4635. float: right;
  4636. cursor: pointer;
  4637. }
  4638. #pagetual-nextSwitch svg {
  4639. width: 30px;
  4640. height: 30px;
  4641. vertical-align: middle;
  4642. fill: #161616;
  4643. overflow: hidden;
  4644. }
  4645. #pagetual-nextSwitch button:hover {
  4646. transform: scale(1.2);
  4647. }
  4648. `;
  4649. let frame = document.createElement("div");
  4650. frame.id = "pagetual-nextSwitch";
  4651. frame.innerHTML = createHTML(`
  4652. <div class="title">${i18n("nextSwitch")}</div>
  4653. <button type="button" class="closeSwitch">
  4654. <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2754">
  4655. <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">
  4656. </path>
  4657. </svg>
  4658. </button>
  4659. <div class="group"></div>
  4660. `);
  4661. let group = frame.querySelector(".group");
  4662. let closeBtn = frame.querySelector(".closeSwitch");
  4663. closeBtn.addEventListener("click", e => {
  4664. self.close();
  4665. }, true);
  4666. this.frame = frame;
  4667. let currentSpan;
  4668. ruleParser.curSiteRule.nextLink.forEach((link, i) => {
  4669. let span = document.createElement("span");
  4670. let target = getElement(link, document);
  4671. let index = "<b>" + (i + 1) + "</b>: ";
  4672. if (target) {
  4673. let targetInner = target.innerText.trim();
  4674. span.innerHTML = index + (targetInner || link);
  4675. } else {
  4676. span.innerHTML = index + "Not Found";
  4677. }
  4678. span.title = link;
  4679. span.addEventListener("click", e => {
  4680. if (currentSpan) currentSpan.classList.remove("current");
  4681. span.classList.add("current");
  4682. currentSpan = span;
  4683. nextIndex = i;
  4684. setListData("nextSwitch", location.host, nextIndex === 0 ? "" : nextIndex);
  4685. ruleParser.curUrl += "#pagetual";
  4686. ruleParser.oldUrl = ruleParser.curUrl;
  4687. autoLoadNum = -1;
  4688. if (!ruleParser.nextLinkHref) {
  4689. isLoading = false;
  4690. }
  4691. ruleParser.getNextLink(ruleParser.pageDoc || document);
  4692. self.close();
  4693. }, true);
  4694. if (i == nextIndex) {
  4695. span.classList.add("current");
  4696. currentSpan = span;
  4697. }
  4698. group.appendChild(span);
  4699. });
  4700. }
  4701.  
  4702. start() {
  4703. this.init();
  4704. if (!this.styleEle || !this.styleEle.parentNode) {
  4705. this.styleEle = _GM_addStyle(this.cssText);
  4706. }
  4707. document.documentElement.appendChild(this.frame);
  4708. }
  4709.  
  4710. close() {
  4711. if (this.frame.parentNode) this.frame.parentNode.removeChild(this.frame);
  4712. }
  4713. }
  4714. const nextSwitch = new NextSwitch();
  4715.  
  4716. class Picker {
  4717. //static picker;
  4718. constructor() {
  4719. this.inited = false;
  4720. }
  4721.  
  4722. /*static getInstance() {
  4723. if (!Picker.picker) {
  4724. Picker.picker = new Picker();
  4725. }
  4726. return Picker.picker;
  4727. }*/
  4728.  
  4729. init() {
  4730. if (this.inited) return;
  4731. this.inited = true;
  4732. let self = this;
  4733. this.signList = [];
  4734. this.cssText = `
  4735. body.pagetual-picker,
  4736. body.pagetual-picker *:hover,
  4737. body.pagetual-picker a:hover {
  4738. cursor: crosshair !important;
  4739. }
  4740. #pagetual-picker {
  4741. position: fixed;
  4742. top: 10px;
  4743. left: calc(50% - 178px);
  4744. background: aliceblue;
  4745. padding: 10px;
  4746. border-radius: 5px;
  4747. text-align: center;
  4748. opacity: 0.95;
  4749. color: #161616;
  4750. z-index: 2147483646;
  4751. font-size: 16px;
  4752. overflow: hidden;
  4753. box-shadow: rgb(0 0 0) 0px 0px 10px;
  4754. }
  4755. #pagetual-picker * {
  4756. margin: 0;
  4757. padding: 0;
  4758. font-family: Times New Roman;
  4759. overflow: initial;
  4760. user-select: none;
  4761. line-height: unset;
  4762. min-width: unset;
  4763. min-height: unset;
  4764. }
  4765. #pagetual-picker>.title {
  4766. margin: -5px 45px 10px 45px;
  4767. font-size: 20px;
  4768. font-weight: bold;
  4769. cursor: pointer;
  4770. border-bottom: 1px solid black;
  4771. user-select: none;
  4772. color: orangered;
  4773. height: initial;
  4774. width: initial;
  4775. position: initial;
  4776. transition: transform .3s ease;
  4777. }
  4778. #pagetual-picker>.title:hover {
  4779. transform: scale(1.1);
  4780. }
  4781. #pagetual-picker button {
  4782. background: none;
  4783. border: none;
  4784. vertical-align: top;
  4785. transition: transform .15s ease-in-out;
  4786. float: right;
  4787. cursor: pointer;
  4788. overflow: hidden;
  4789. background-color: unset!important;
  4790. }
  4791. #pagetual-picker button:hover {
  4792. transform: scale(1.2);
  4793. }
  4794. #pagetual-picker>.closePicker {
  4795. position: absolute;
  4796. top: 3px;
  4797. right: 10px;
  4798. }
  4799. #pagetual-picker>.logoIcon {
  4800. position: absolute;
  4801. top: 3px;
  4802. left: 10px;
  4803. }
  4804. #pagetual-picker>.logoIcon.showSign>svg>path {
  4805. fill: gray!important;
  4806. }
  4807. #pagetual-picker textarea{
  4808. display: inline-block;
  4809. width: calc(100% - 65px);
  4810. height: 20px;
  4811. min-width: 250px;
  4812. max-width: calc(65vw - 50px);
  4813. min-height: unset;
  4814. max-height: unset;
  4815. padding: 6px 12px;
  4816. font-size: 16px;
  4817. font-weight: 400;
  4818. line-height: 1.5;
  4819. color: #495057;
  4820. background-color: #fff;
  4821. background-clip: padding-box;
  4822. border: 1px solid #ced4da;
  4823. border-radius: 4px;
  4824. transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out;
  4825. box-sizing: content-box;
  4826. margin-right: 5px;
  4827. resize: both;
  4828. box-shadow: 0 1px 5px 1px #ddd;
  4829. overflow-wrap: anywhere;
  4830. }
  4831. #pagetual-picker textarea:focus {
  4832. color: black;
  4833. background-color: #fff;
  4834. border-color: #80bdff;
  4835. outline: 0;
  4836. box-shadow: 0 0 0 3.2px rgb(0 123 255 / 25%);
  4837. }
  4838. #pagetual-picker [type=checkbox],
  4839. #pagetual-picker [type=radio] {
  4840. line-height: 20px;
  4841. height: 25px;
  4842. width: 25px;
  4843. margin-left: 5px;
  4844. vertical-align: middle;
  4845. appearance: auto;
  4846. display: inline-block;
  4847. position: initial;
  4848. }
  4849. #pagetual-picker [type=checkbox]:after,
  4850. #pagetual-picker [type=radio]:after,
  4851. #pagetual-picker [type=checkbox]:before,
  4852. #pagetual-picker [type=radio]:before {
  4853. border: none;
  4854. background: none;
  4855. }
  4856. #pagetual-picker label {
  4857. font-size: 18px;
  4858. line-height: 25px;
  4859. vertical-align: middle;
  4860. display: inline-block;
  4861. color: black;
  4862. position: initial;
  4863. cursor: pointer;
  4864. }
  4865. #pagetual-picker .bottom {
  4866. text-align: left;
  4867. margin: 10px 0;
  4868. width: 100%;
  4869. }
  4870. #pagetual-picker .bottom>button {
  4871. float: right;
  4872. }
  4873. #pagetual-picker svg {
  4874. width: 30px;
  4875. height: 30px;
  4876. vertical-align: middle;
  4877. fill: #161616;
  4878. overflow: hidden;
  4879. }
  4880. #pagetual-picker svg * {
  4881. pointer-events: none;
  4882. }
  4883. #pagetual-picker .allpath {
  4884. font-size: 18px;
  4885. margin: 10px auto;
  4886. max-width: 330px;
  4887. word-break: break-all;
  4888. cursor: context-menu;
  4889. overflow: hidden;
  4890. max-height: 42px;
  4891. -moz-transition:max-height 1s ease-in;
  4892. -webkit-transition:max-height 1s ease-in;
  4893. transition:max-height 1s ease-in;
  4894. color: black;
  4895. }
  4896. #pagetual-picker .allpath:hover {
  4897. max-height: calc(100vh - 130px);
  4898. overflow: auto;
  4899. }
  4900. #pagetual-picker .allpath>span.path {
  4901. cursor: pointer;
  4902. }
  4903. #pagetual-picker .allpath>span.path:hover {
  4904. opacity: 0.6;
  4905. }
  4906. #pagetual-picker .allpath>span.path:hover,
  4907. #pagetual-picker .allpath>span.path.checked {
  4908. color: orangered;
  4909. }
  4910. #pagetual-picker .moreConfig {
  4911. display: flex;
  4912. justify-content: space-between;
  4913. border-top: 1px solid;
  4914. padding-top: 10px;
  4915. width: 100%;
  4916. }
  4917. #pagetual-picker .command {
  4918. width: 100%;
  4919. color: black!important;
  4920. text-align: center;
  4921. font-size: large;
  4922. margin-top: 10px;
  4923. box-shadow: 0 1px 6px 0 rgba(0, 0, 0, 0.12);
  4924. border-radius: 5px;
  4925. }
  4926. #pagetual-picker .command:hover {
  4927. color: orangered;
  4928. }
  4929. #pagetual-picker #showDetail {
  4930. float: initial;
  4931. margin-top: 10px;
  4932. }
  4933. #pagetual-picker.showDetail #showDetail {
  4934. float: right;
  4935. }
  4936. #pagetual-picker #showDetail>svg {
  4937. -moz-transition:transform 0.3s ease;
  4938. -webkit-transition:transform 0.3s ease;
  4939. transition:transform 0.3 ease;
  4940. }
  4941. #pagetual-picker.showDetail #showDetail>svg {
  4942. transform: rotate(180deg);
  4943. }
  4944. #pagetual-picker .tempRule {
  4945. display: none;
  4946. margin-top: 10px;
  4947. height: 300px;
  4948. min-height: 150px;
  4949. }
  4950. #pagetual-picker.showDetail .tempRule {
  4951. display: inline-block;
  4952. word-break: break-all;
  4953. }
  4954. #pagetual-picker #saveDetail {
  4955. display: none;
  4956. position: absolute;
  4957. bottom: 10px;
  4958. right: 8px;
  4959. }
  4960. #pagetual-picker.showDetail #saveDetail {
  4961. display: inline-block;
  4962. }
  4963. #pagetual-picker #saveDetail svg {
  4964. width: 35px;
  4965. height: 35px;
  4966. }
  4967. #pagetual-picker .addProp {
  4968. display: none;
  4969. flex-direction: column;
  4970. position: absolute;
  4971. bottom: 45px;
  4972. right: 12px;
  4973. }
  4974. #pagetual-picker.showDetail .addProp {
  4975. display: flex;
  4976. }
  4977. #pagetual-picker .addProp>button {
  4978. font-size: 30px;
  4979. font-family: Arial,sans-serif;
  4980. line-height: 35px;
  4981. color: #161616;
  4982. }
  4983. #pagetual-picker #edit{
  4984. -webkit-animation: jumpAnimation .6s 5;
  4985. animation: jumpAnimation .6s 5;
  4986. }
  4987. @keyframes jumpAnimation {
  4988. 0% {
  4989. transform: scale(1) translateY(0);
  4990. animation-timing-function: ease-out;
  4991. }
  4992. 50% {
  4993. transform: scale(1.2) translateY(-5px);
  4994. animation-timing-function: ease-in;
  4995. }
  4996. 100% {
  4997. transform: scale(1) translateY(0);
  4998. animation-timing-function: ease-out;
  4999. }
  5000. }
  5001. @-webkit-keyframes jumpAnimation {
  5002. 0% {
  5003. -webkit-transform: scale(1) translateY(0);
  5004. animation-timing-function: ease-out;
  5005. }
  5006. 50% {
  5007. -webkit-transform: scale(1.2) translateY(-5px);
  5008. animation-timing-function: ease-in;
  5009. }
  5010. 100% {
  5011. -webkit-transform: scale(1) translateY(0);
  5012. animation-timing-function: ease-out;
  5013. }
  5014. }
  5015. `;
  5016. this.mainSignDiv = this.createSignDiv();
  5017. this.allSignDiv = [];
  5018. let frame = document.createElement("div");
  5019. frame.id = "pagetual-picker";
  5020. frame.innerHTML = createHTML(`
  5021. <button title="Pagetual" type="button" class="logoIcon">
  5022. <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" style="fill: #604b4a;" 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" style="fill: #604b4a;" fill="#604b4a"></path></svg>
  5023. </button>
  5024. <div class="title" title="${i18n("configure")}">${i18n("picker")}</div>
  5025. <button title="${i18n("closePicker")}" type="button" class="closePicker">
  5026. <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" style="fill: #604b4a;" fill="#604b4a"></path></svg>
  5027. </button>
  5028. <div class="allpath" title="${i18n("switchSelector")}"></div>
  5029. <div>
  5030. <textarea class="selector" spellcheck="false" name="selector" placeholder="${i18n("pickerPlaceholder")}"></textarea>
  5031. <button id="check" title="${i18n("pickerCheck")}" type="button">
  5032. <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" style="fill: #604b4a;" fill="#604b4a"></path></svg>
  5033. </button>
  5034. </div>
  5035. <div class="bottom">
  5036. <input name="xpath" id="checkbox_id" type="checkbox" />
  5037. <label for="checkbox_id">XPath</label>
  5038. <button id="edit" title="${i18n("gotoEdit")}" type="button">
  5039. <svg viewBox="0 0 1024 1024" style="color: orangered;fill: orangered;" version="1.1" xmlns="http://www.w3.org/2000/svg">
  5040. <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">
  5041. </path>
  5042. </svg>
  5043. </button>
  5044. </div>
  5045. <div class="moreConfig">
  5046. <div title="${i18n('forceStateIframe')}">
  5047. <input name="forceState" id="forceStateIframe" type="radio" />
  5048. <label for="forceStateIframe">${i18n('iframe')}</label>
  5049. </div>
  5050. <div title="${i18n('forceStateDynamic')}">
  5051. <input name="forceState" id="forceStateDynamic" type="radio" />
  5052. <label for="forceStateDynamic">${i18n('dynamic')}</label>
  5053. </div>
  5054. <div title="${i18n('forceStateDisable')}">
  5055. <input name="forceState" id="forceStateDisable" type="radio" />
  5056. <label for="forceStateDisable">${i18n('disable')}</label>
  5057. </div>
  5058. </div>
  5059. <button id="nextSwitch" class="command" title="${i18n("nextSwitch")}" type="button">${i18n("nextSwitch")}</button>
  5060. <button id="loadNow" class="command" title="${i18n("loadNow")}" type="button">${i18n("loadNow")}</button>
  5061. <button id="autoScroll" class="command" title="${i18n("toggleAutoScroll")}" type="button"></button>
  5062. <button id="ruleRequest" class="command" title="${i18n("ruleRequest")}" type="button">${i18n("ruleRequest")}</button>
  5063. <div>
  5064. <textarea class="tempRule" spellcheck="false" placeholder="{Rule object}" title="Rule for current site"></textarea>
  5065. <button id="showDetail" title="" type="button">
  5066. <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" style="fill: orangered;" fill="orangered"></path></svg>
  5067. </button>
  5068. <div class="addProp">
  5069. <button id="addOtherProp" title="${i18n("addOtherProp")}" type="button">+</button>
  5070. <button id="addNextSelector" title="${i18n("addNextSelector")}" type="button">></button>
  5071. <button id="addPageSelector" title="${i18n("addPageSelector")}" type="button">❏</button>
  5072. </div>
  5073. <button id="saveDetail" title="${i18n("save")}" type="button">
  5074. <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" style="fill: orangered;" fill="orangered"></path></svg>
  5075. </button>
  5076. </div>
  5077. `);
  5078. let forceStateIframe = frame.querySelector("#forceStateIframe");//forceState 1 禁用 2 强嵌 3 动态
  5079. let forceStateDynamic = frame.querySelector("#forceStateDynamic");
  5080. let forceStateDisable = frame.querySelector("#forceStateDisable");
  5081. let clickRadio = e => {
  5082. let radio = e.currentTarget.querySelector('input');
  5083. if (radio.checked) {
  5084. forceState = "";
  5085. } else {
  5086. switch (radio.id) {
  5087. case "forceStateIframe":
  5088. forceState = 2;
  5089. break;
  5090. case "forceStateDynamic":
  5091. forceState = 3;
  5092. break;
  5093. case "forceStateDisable":
  5094. forceState = 1;
  5095. break;
  5096. default:
  5097. return;
  5098. }
  5099. }
  5100. setListData("forceState", location.host, forceState);
  5101. self.close();
  5102. setTimeout(() => {
  5103. location.reload();
  5104. }, 500);
  5105. };
  5106. forceStateIframe.parentNode.addEventListener("mousedown", clickRadio);
  5107. forceStateDynamic.parentNode.addEventListener("mousedown", clickRadio);
  5108. forceStateDisable.parentNode.addEventListener("mousedown", clickRadio);
  5109. if (forceState == 1) forceStateDisable.checked = true;
  5110. else if (forceState == 2) forceStateIframe.checked = true;
  5111. else if (forceState == 3) forceStateDynamic.checked = true;
  5112. let closeBtn = frame.querySelector(".closePicker");
  5113. let logoBtn = frame.querySelector(".logoIcon");
  5114. let title = frame.querySelector(".title");
  5115. let allpath = frame.querySelector(".allpath");
  5116. let selectorInput = frame.querySelector(".selector");
  5117. let xpath = frame.querySelector("#checkbox_id");
  5118. let checkBtn = frame.querySelector("#check");
  5119. let editBtn = frame.querySelector("#edit");
  5120. let nextSwitchBtn = frame.querySelector("#nextSwitch");
  5121. let autoScrollBtn = frame.querySelector("#autoScroll");
  5122. let loadNow = frame.querySelector("#loadNow");
  5123. let tempRule = frame.querySelector(".tempRule");
  5124. let showDetailBtn = frame.querySelector("#showDetail");
  5125. let saveDetailBtn = frame.querySelector("#saveDetail");
  5126. let addOtherProp = frame.querySelector("#addOtherProp");
  5127. let addNextSelector = frame.querySelector("#addNextSelector");
  5128. let addPageSelector = frame.querySelector("#addPageSelector");
  5129. let ruleRequestBtn = frame.querySelector("#ruleRequest");
  5130. ruleRequestBtn.addEventListener("click", e => {
  5131. _GM_openInTab("https://github.com/hoothin/UserScripts/issues/new?labels=Pagetual&template=custom-rule-request.md&title=Request%20Pagetual%20support%20for%20" + location.hostname + "#" + location.href, {active: true});
  5132. }, true);
  5133. autoScrollBtn.addEventListener("click", e => {
  5134. self.close();
  5135. autoScroll = (autoScroll ? 0 : prompt(i18n("autoScrollRate"), autoScrollRate)) || 0;
  5136. autoScroll = parseInt(autoScroll) || 0;
  5137. if (autoScroll < 0) autoScroll = 0;
  5138. if (autoScroll && autoScroll != autoScrollRate) {
  5139. autoScrollRate = autoScroll;
  5140. storage.setItem("autoScrollRate", autoScrollRate);
  5141. }
  5142. setListData("autoScroll", location.host + location.pathname, autoScroll);
  5143. startAutoScroll();
  5144. }, true);
  5145. addOtherProp.addEventListener("click", e => {
  5146. let propName = prompt(i18n("propName"), "author");
  5147. if (!propName) return;
  5148. let propValue = prompt(i18n("propValue"));
  5149. if (!propValue) return;
  5150. if (propValue === "true") propValue = true;
  5151. else if (propValue === "false") propValue = false;
  5152. else if (/^\d+$/.test(propValue)) propValue = parseInt(propValue);
  5153. if (propName === "author" && propValue) {
  5154. author = propValue;
  5155. storage.setItem("author", propValue);
  5156. }
  5157. let editTemp = self.getTempRule();
  5158. if (!editTemp) return;
  5159. editTemp[propName] = propValue;
  5160. self.tempRule.value = JSON.stringify(editTemp, null, 4);
  5161. }, true);
  5162. addNextSelector.addEventListener("click", e => {
  5163. let editTemp = self.getTempRule();
  5164. if (!editTemp) return;
  5165. let selector = self.selectorInput.value;
  5166. if (selector) {
  5167. editTemp.nextLink = selector;
  5168. }
  5169. self.tempRule.value = JSON.stringify(editTemp, null, 4);
  5170. }, true);
  5171. addPageSelector.addEventListener("click", e => {
  5172. let editTemp = self.getTempRule();
  5173. if (!editTemp) return;
  5174. let selector = self.selectorInput.value;
  5175. if (selector) {
  5176. editTemp.pageElement = selector;
  5177. }
  5178. self.tempRule.value = JSON.stringify(editTemp, null, 4);
  5179. }, true);
  5180. showDetailBtn.addEventListener("click", e => {
  5181. frame.classList.toggle("showDetail");
  5182. }, true);
  5183. saveDetailBtn.addEventListener("click", e => {
  5184. let editTemp = self.getTempRule(true);
  5185. if (tempRule.value && !editTemp) {
  5186. return;
  5187. }
  5188. if(!ruleParser.customRules) {
  5189. ruleParser.customRules = [];
  5190. }
  5191. ruleParser.customRules = ruleParser.customRules.filter(item => {return item.url != editTemp.url || item.name != editTemp.name});
  5192. if (tempRule.value) {
  5193. ruleParser.customRules.unshift(editTemp);
  5194. ruleParser.curSiteRule = editTemp;
  5195. } else {
  5196. ruleParser.curSiteRule = {};
  5197. isPause = true;
  5198. }
  5199. storage.setItem("customRules", ruleParser.customRules);
  5200. if (ruleParser.hpRules && ruleParser.curSiteRule && !ruleParser.curSiteRule.smart) {
  5201. ruleParser.addToHpRules(true);
  5202. }
  5203. if (window.confirm(i18n("reloadPage"))) {
  5204. setTimeout(() => {location.reload()}, 100);
  5205. }
  5206. }, true);
  5207. nextSwitchBtn.addEventListener("click", e => {
  5208. self.close();
  5209. nextSwitch.start();
  5210. }, true);
  5211. loadNow.addEventListener("click", e => {
  5212. self.close();
  5213. let loadNum = window.prompt(i18n("loadConfirm"), "1");
  5214. if (loadNum === "" || loadNum === null) return;
  5215. autoLoadNum = Math.abs(parseInt(loadNum));
  5216. nextPage();
  5217. }, true);
  5218. closeBtn.addEventListener("click", e => {
  5219. self.close();
  5220. }, true);
  5221. this.showSign = true;
  5222. logoBtn.addEventListener("click", e => {
  5223. logoBtn.classList.toggle("showSign");
  5224. self.showSign = !self.showSign;
  5225. getBody(document).classList.toggle("pagetual-picker");
  5226. }, true);
  5227. let moving = false;
  5228. let initX = 0, initY = 0, initPos = {x: 0, y: 0};
  5229. let moveHanlder = e => {
  5230. if (moving) {
  5231. frame.style.left = e.clientX - initX + "px";
  5232. frame.style.top = e.clientY - initY + "px";
  5233. e.stopPropagation();
  5234. e.preventDefault();
  5235. } else if(Math.abs(e.clientX - initPos.x) + Math.abs(e.clientY - initPos.y) > 20) {
  5236. moving = true;
  5237. }
  5238. };
  5239. let upHanlder = e => {
  5240. if (moving) {
  5241. moving = false;
  5242. } else {
  5243. _GM_openInTab(rulesData.configPage || configPage[0], {active: true});
  5244. }
  5245. document.removeEventListener("mousemove", moveHanlder, true);
  5246. title.removeEventListener("mouseup", upHanlder, true);
  5247. e.stopPropagation();
  5248. e.preventDefault();
  5249. };
  5250. title.addEventListener("mousedown", e => {
  5251. initPos = {x: e.clientX, y: e.clientY};
  5252. initX = e.clientX - parseInt(getComputedStyle(frame).left);
  5253. initY = e.clientY - parseInt(getComputedStyle(frame).top);
  5254. document.addEventListener("mousemove", moveHanlder, true);
  5255. title.addEventListener("mouseup", upHanlder, true);
  5256. });
  5257. frame.addEventListener("mouseenter", e => {
  5258. if (!self.showSign || moving) return;
  5259. if (self.mainSignDiv.parentNode) self.mainSignDiv.parentNode.removeChild(self.mainSignDiv);
  5260. self.checkInputSelector(false);
  5261. });
  5262. frame.addEventListener("mouseleave", e => {
  5263. if (!self.showSign) {
  5264. if (self.mainSignDiv.parentNode) self.mainSignDiv.parentNode.removeChild(self.mainSignDiv);
  5265. self.clearSigns();
  5266. return;
  5267. }
  5268. if (moving) return;
  5269. document.documentElement.appendChild(self.mainSignDiv);
  5270. self.clearSigns();
  5271. });
  5272. checkBtn.addEventListener("click", e => {
  5273. self.checkInputSelector();
  5274. if (this.selectorInput.value && self.foundEle) {
  5275. debug(self.foundEle);
  5276. self.foundEle[0].scrollIntoView({ behavior: "smooth" });
  5277. _GM_setClipboard(this.selectorInput.value);
  5278. showTips(i18n("copied"));
  5279. } else showTips("Null");
  5280. });
  5281. xpath.addEventListener("click", e => {
  5282. if (!selectorInput.value) {
  5283. self.setSelectorDiv("");
  5284. return;
  5285. }
  5286. let element = getElement(selectorInput.value, document);
  5287. let selector = self.getSelectorFromEle(element);
  5288. selectorInput.value = selector;
  5289. self.setSelectorDiv(selector);
  5290. });
  5291. editBtn.addEventListener("click", e => {
  5292. rulesData.editTemp = self.getTempRule();
  5293. storage.setItem("rulesData", rulesData);
  5294. _GM_openInTab(rulesData.configPage || configPage[0], {active: true});
  5295. });
  5296. editBtn.oncontextmenu = e => {
  5297. e.preventDefault();
  5298. _GM_openInTab(rulesData.configPage || configPage[0], {active: true});
  5299. };
  5300. this.frame = frame;
  5301. this.xpath = xpath;
  5302. this.allpath = allpath;
  5303. this.selectorInput = selectorInput;
  5304. this.nextSwitchBtn = nextSwitchBtn;
  5305. this.autoScrollBtn = autoScrollBtn;
  5306. this.loadNow = loadNow;
  5307. this.tempRule = tempRule;
  5308. this.logoBtn = logoBtn;
  5309. let setTitleTimer;
  5310. this.moveHandler = e => {
  5311. if (!self.showSign || e.target === document) return;
  5312. let target = self.getTarget(e.target);
  5313. self.adjustSignDiv(self.mainSignDiv, target);
  5314. clearTimeout(setTitleTimer);
  5315. setTitleTimer = setTimeout(() => {
  5316. if (self.inPicker && target.hasAttributes()) {
  5317. let title = target.nodeName.toLowerCase() + "\n";
  5318. for (const attr of target.attributes) {
  5319. title += `【${attr.name}】${attr.value ? " ➡️ " + attr.value : ""}\n`;
  5320. }
  5321. getBody(document).title = title;
  5322. }
  5323. }, 100);
  5324. };
  5325. this.clickHandler = e => {
  5326. if (!self.showSign || !e.isTrusted) return;
  5327. if (self.inPicker) {
  5328. e.stopPropagation();
  5329. e.preventDefault();
  5330. }
  5331. let target = self.getTarget(e.target);
  5332. let selector = self.getSelectorFromEle(target);
  5333. selectorInput.value = selector;
  5334. self.setSelectorDiv(selector);
  5335. };
  5336. }
  5337.  
  5338. getTempRule(detail) {
  5339. if (this.tempRule.value) {
  5340. try {
  5341. this.editTemp = JSON.parse(this.tempRule.value);
  5342. } catch (e) {
  5343. this.editTemp = null;
  5344. if (detail) {
  5345. let pos = e && e.message && e.message.match(/position (\d+)/);
  5346. if (pos) {
  5347. pos = parseInt(pos[1]);
  5348. this.tempRule.value = this.tempRule.value.slice(0, pos) + "➡️" + this.tempRule.value.slice(pos);
  5349. }
  5350. showTips(i18n("errorJson"));
  5351. return null;
  5352. }
  5353. }
  5354. }
  5355. if (!this.editTemp) {
  5356. if (ruleParser.curSiteRule.url && !ruleParser.curSiteRule.smart) {
  5357. this.editTemp = ruleParser.curSiteRule;
  5358. } else {
  5359. this.editTemp = {
  5360. name: document.title,
  5361. url: "^" + (location.origin + location.pathname).replace(/[^\/]*$/, "").replace(/^https?/, "https?").replace(/\./g, "\\."),
  5362. example: location.href
  5363. };
  5364. if (author) this.editTemp.author = author;
  5365. }
  5366. delete this.editTemp.from;
  5367. delete this.editTemp.type;
  5368. delete this.editTemp.updatedAt;
  5369. }
  5370. if (this.selectorInput.value && (!this.frame.classList.contains("showDetail") || !this.editTemp || !this.editTemp.pageElement)) {
  5371. if (this.foundEle && this.foundEle.length === 1) {
  5372. let foundEleRect = this.foundEle[0].getBoundingClientRect();
  5373. if (foundEleRect.height < 100) {
  5374. showTips("Next Link", "", 500);
  5375. this.editTemp.nextLink = this.selectorInput.value;
  5376. return this.editTemp;
  5377. }
  5378. }
  5379. showTips("Page Element", "", 500);
  5380. this.editTemp.pageElement = this.selectorInput.value;
  5381. }
  5382. return this.editTemp;
  5383. }
  5384.  
  5385. getTarget(ele) {
  5386. while (ele.parentNode && (ele.offsetWidth === 0 || ele.offsetHeight === 0)) {
  5387. ele = ele.parentNode;
  5388. }
  5389. return ele;
  5390. }
  5391.  
  5392. close() {
  5393. this.clearSigns();
  5394. if (this.frame.parentNode) this.frame.parentNode.removeChild(this.frame);
  5395. if (this.mainSignDiv.parentNode) this.mainSignDiv.parentNode.removeChild(this.mainSignDiv);
  5396. getBody(document).classList.remove("pagetual-picker");
  5397. getBody(document).removeEventListener("mousemove", this.moveHandler, true);
  5398. getBody(document).removeEventListener("click", this.clickHandler, true);
  5399. getBody(document).title = "";
  5400. this.inPicker = false;
  5401. }
  5402.  
  5403. setImportant(ele, prop, value) {
  5404. ele.style.setProperty(prop, value, "important");
  5405. }
  5406.  
  5407. createSignDiv() {
  5408. let signDiv = document.createElement("div");
  5409. this.setImportant(signDiv, "position", "absolute");
  5410. this.setImportant(signDiv, "pointer-events", "none");
  5411. this.setImportant(signDiv, "z-index", "2147483645");
  5412. this.setImportant(signDiv, "background", "rgba(120, 170, 210, 0.6)");
  5413. this.setImportant(signDiv, "transition", "all 0.15s ease-out");
  5414. this.setImportant(signDiv, "box-shadow", "rgb(0 0 0) 0px 0px 3px 0px");
  5415. return signDiv;
  5416. }
  5417.  
  5418. adjustSignDiv(div, target) {
  5419. let rect = target.getBoundingClientRect();
  5420. this.setImportant(div, "width", rect.width + "px");
  5421. this.setImportant(div, "height", rect.height + "px");
  5422. this.setImportant(div, "left", rect.left + window.scrollX + "px");
  5423. this.setImportant(div, "top", rect.top + window.scrollY + "px");
  5424. }
  5425.  
  5426. getSelectorFromEle(ele) {
  5427. return this.xpath.checked ? createXPathFromElement(ele) : geneSelector(ele, true);
  5428. }
  5429.  
  5430. fillTempRuleTextarea() {
  5431. if (!this.frame.classList.contains("showDetail") || !this.editTemp || !this.editTemp.pageElement) this.tempRule.value = JSON.stringify(this.getTempRule(), null, 4);
  5432. }
  5433.  
  5434. setSelectorDiv(selector) {
  5435. let self = this;
  5436. this.allpath.innerHTML = createHTML("");
  5437. if (selector) {
  5438. if (this.xpath.checked) {
  5439. let span = document.createElement("span");
  5440. span.innerText = selector;
  5441. span.addEventListener("click", e => {
  5442. self.selectorInput.value = selector;
  5443. self.checkInputSelector();
  5444. }, true);
  5445. this.allpath.appendChild(span);
  5446. } else {
  5447. selector.split(">").forEach((item, index) => self.geneSelectorItem(item, index));
  5448. }
  5449. }
  5450. this.checkInputSelector();
  5451. }
  5452.  
  5453. geneSelectorItem(item, index) {
  5454. let self = this;
  5455. item = item.trim();
  5456. if (!item) return;
  5457. if (index !== 0) {
  5458. let span = document.createElement("span");
  5459. span.innerText = " > ";
  5460. this.allpath.appendChild(span);
  5461. }
  5462. let span = document.createElement("span");
  5463. span.className = "path";
  5464. span.innerText = item;
  5465. span.addEventListener("click", e => {
  5466. let selector = "";
  5467. let target = e.target;
  5468. while (target) {
  5469. selector = target.innerText + selector;
  5470. target = target.previousElementSibling;
  5471. }
  5472. self.selectorInput.value = selector;
  5473. self.checkInputSelector();
  5474. if (self.checkedPath) {
  5475. self.checkedPath.classList.remove("checked");
  5476. }
  5477. span.classList.add("checked");
  5478. self.checkedPath = span;
  5479. }, true);
  5480. this.allpath.appendChild(span);
  5481. }
  5482.  
  5483. checkInputSelector(fill = true) {
  5484. let self = this;
  5485. this.clearSigns();
  5486. if (!this.selectorInput.value) return;
  5487. let eles = getAllElements(this.selectorInput.value, document);
  5488. this.foundEle = null;
  5489. if (eles && eles.length > 0) {
  5490. this.foundEle = eles;
  5491. eles.forEach(ele => {
  5492. let sign = self.createSignDiv();
  5493. document.documentElement.appendChild(sign);
  5494. self.adjustSignDiv(sign, ele);
  5495. self.signList.push(sign);
  5496. });
  5497. if (fill) this.fillTempRuleTextarea();
  5498. }
  5499. }
  5500.  
  5501. clearSigns() {
  5502. this.signList.forEach(sign => {
  5503. if (sign.parentNode) sign.parentNode.removeChild(sign);
  5504. });
  5505. this.signList = [];
  5506. }
  5507.  
  5508. start() {
  5509. this.init();
  5510. if (this.inPicker) return;
  5511. this.inPicker = true;
  5512. if (!this.styleEle || !this.styleEle.parentNode) {
  5513. this.styleEle = _GM_addStyle(this.cssText);
  5514. }
  5515. document.documentElement.appendChild(this.frame);
  5516. document.documentElement.appendChild(this.mainSignDiv);
  5517. getBody(document).classList.add("pagetual-picker");
  5518.  
  5519. this.logoBtn.classList.remove("showSign");
  5520. this.showSign = true;
  5521.  
  5522. getBody(document).addEventListener("mousemove", this.moveHandler, true);
  5523. getBody(document).addEventListener("click", this.clickHandler, true);
  5524. this.xpath.checked = isXPath(ruleParser.curSiteRule.pageElement);
  5525. this.tempRule.value = "";
  5526. this.editTemp = null;
  5527. this.frame.classList.remove("showDetail");
  5528.  
  5529. this.loadNow.style.display = ruleParser.nextLinkHref ? "block" : "none";
  5530. if (ruleParser.curSiteRule.nextLink && Array && Array.isArray && Array.isArray(ruleParser.curSiteRule.nextLink)) {
  5531. this.nextSwitchBtn.style.display = "block";
  5532. } else {
  5533. this.nextSwitchBtn.style.display = "none";
  5534. }
  5535. this.autoScrollBtn.innerText = i18n(autoScroll ? "disableAutoScroll" : "enableAutoScroll");
  5536.  
  5537. let pageElementSel = ruleParser.curSiteRule.pageElement || "";
  5538. if (Array && Array.isArray && Array.isArray(pageElementSel)) {
  5539. pageElementSel = pageElementSel[nextIndex < pageElementSel.length ? nextIndex : 0];
  5540. }
  5541. this.setSelectorDiv(pageElementSel);
  5542. this.fillTempRuleTextarea();
  5543. }
  5544. }
  5545. const picker = new Picker();
  5546.  
  5547. var editor, editorChanged = false, customRulesInput;
  5548. function createEdit() {
  5549. var options = {
  5550. mode: 'code',
  5551. modes: ['code', 'tree'],
  5552. templates: [
  5553. {
  5554. text: 'New site',
  5555. title: 'Insert a new site',
  5556. className: 'jsoneditor-type-object',
  5557. field: 'SiteTemplate',
  5558. value: {
  5559. 'name': 'Site name',
  5560. 'url': 'Site url'
  5561. }
  5562. }
  5563. ],
  5564. schema: {
  5565. "title": "Sites data",
  5566. "description": "Object containing site config",
  5567. "type": "array",
  5568. "items": {
  5569. "type": 'object',
  5570. "properties": {
  5571. "name": {
  5572. "title": "Site Name",
  5573. "description": "The site's name.",
  5574. "examples": [
  5575. "Google"
  5576. ],
  5577. "type": "string"
  5578. },
  5579. "url": {
  5580. "title": "Site Url",
  5581. "description": "The Regexp of site's url.",
  5582. "examples": [
  5583. "^https:\/\/yande\\.re\/"
  5584. ],
  5585. "type": "string"
  5586. }
  5587. },
  5588. "required": ["name", "url"]
  5589. }
  5590. },
  5591. onChange: () => {
  5592. editorChanged = true;
  5593. }
  5594. };
  5595. setTimeout(() => {
  5596. var container = document.getElementById("jsoneditor");
  5597. if (!container) {
  5598. container = document.createElement("div");
  5599. configCon.appendChild(container);
  5600. }
  5601. container.style.height = '800px';
  5602. container.innerHTML = "";
  5603. try {
  5604. editor = new _unsafeWindow.JSONEditor(container, options);
  5605. editor.set(ruleParser.customRules);
  5606. } catch (e) {
  5607. editor = null;
  5608. container.style.display = 'none';
  5609. customRulesInput.style.display = "";
  5610. }
  5611. }, 500);
  5612. }
  5613.  
  5614. function checkGuidePage(href) {
  5615. if (guidePage.test(href)) {
  5616. if (typeof _unsafeWindow.JSONEditor !== 'undefined') {
  5617. createEdit();
  5618. } else {
  5619. let timeout = 30;
  5620. let checkEditorReady = setInterval(() => {
  5621. if (typeof _unsafeWindow.JSONEditor !== 'undefined') {
  5622. createEdit();
  5623. clearInterval(checkEditorReady);
  5624. } else if (timeout-- <= 0) {
  5625. editor = null;
  5626. customRulesInput.style.display = "";
  5627. clearInterval(checkEditorReady);
  5628. }
  5629. }, 100);
  5630. }
  5631. return true;
  5632. }
  5633. return false;
  5634. }
  5635.  
  5636. function startAutoScroll() {
  5637. clearInterval(autoScrollInterval);
  5638. if (autoScroll <= 0) return;
  5639. let scrollRange_o = 1;
  5640. if (autoScroll > 1000) {
  5641. scrollRange_o = parseInt(autoScroll / 1000);
  5642. }
  5643. let devicePixelRatio = window.devicePixelRatio;
  5644. let scrollRange = Math.ceil(scrollRange_o / devicePixelRatio);
  5645.  
  5646. let scrollTarget, body = getBody(document);
  5647. let checkOverflow = ele => {
  5648. return ele.scrollHeight !== ele.clientHeight && getComputedStyle(ele).overflowY !== "hidden";
  5649. };
  5650. if (document.documentElement.scrollTop || checkOverflow(document.documentElement)) {
  5651. scrollTarget = document.documentElement;
  5652. } else if (body.scrollTop || checkOverflow(body)) {
  5653. scrollTarget = body;
  5654. } else {
  5655. let tempEle;
  5656. let img = body.querySelector('img');
  5657. if (img) {
  5658. tempEle = img;
  5659. while (tempEle && !checkOverflow(tempEle)) {
  5660. tempEle = tempEle.parentNode;
  5661. }
  5662. }
  5663. if (!tempEle && document.activeElement) {
  5664. let tempEle = document.activeElement;
  5665. while (tempEle && !checkOverflow(tempEle)) {
  5666. tempEle = tempEle.parentNode;
  5667. }
  5668. }
  5669. if (tempEle) scrollTarget = tempEle;
  5670. }
  5671. scrollTarget = scrollTarget || document.documentElement;
  5672.  
  5673. autoScrollInterval = setInterval(() => {
  5674. if (isPause && !urlChanging) return;
  5675. if (devicePixelRatio !== window.devicePixelRatio) {
  5676. devicePixelRatio = window.devicePixelRatio;
  5677. scrollRange = Math.ceil(scrollRange_o / devicePixelRatio);
  5678. }
  5679. scrollTarget.scrollTop += scrollRange;
  5680. }, parseInt(1000 / autoScroll));
  5681. }
  5682.  
  5683. var inUpdate = false;
  5684. var importHandler, configCon;
  5685. function initConfig(href) {
  5686. if (location.hostname === "github.com") {
  5687. if (location.href.indexOf("https://github.com/hoothin/UserScripts/issues/new?labels=Pagetual&template=custom-rule-request.md&title=Request%20Pagetual%20support%20for%20") === 0) {
  5688. let issue_body = document.getElementById("issue_body");
  5689. if (!issue_body) return true;
  5690. issue_body.value = issue_body.value.replace("\n", "\n" + location.hash.slice(1) + "\n");
  5691. let starButton = document.createElement("a");
  5692. starButton.href = "https://github.com/hoothin/UserScripts#star";
  5693. starButton.className = "js-toggler-target rounded-left-2 btn-with-aria-count btn-sm btn";
  5694. starButton.innerHTML = createHTML('<svg height="16" viewBox="0 0 16 16" version="1.1" width="16" class="octicon octicon-star d-inline-block mr-2"><path d="M8 .25a.75.75 0 0 1 .673.418l1.882 3.815 4.21.612a.75.75 0 0 1 .416 1.279l-3.046 2.97.719 4.192a.751.751 0 0 1-1.088.791L8 12.347l-3.766 1.98a.75.75 0 0 1-1.088-.79l.72-4.194L.818 6.374a.75.75 0 0 1 .416-1.28l4.21-.611L7.327.668A.75.75 0 0 1 8 .25Zm0 2.445L6.615 5.5a.75.75 0 0 1-.564.41l-3.097.45 2.24 2.184a.75.75 0 0 1 .216.664l-.528 3.084 2.769-1.456a.75.75 0 0 1 .698 0l2.77 1.456-.53-3.084a.75.75 0 0 1 .216-.664l2.24-2.183-3.096-.45a.75.75 0 0 1-.564-.41L8 2.694Z"></path></svg><span class="d-inline">Star</span>');
  5695. starButton.style.float = "right";
  5696. document.querySelector(".Layout-main>h2").appendChild(starButton);
  5697. return true;
  5698. } else if (location.href === "https://github.com/hoothin/UserScripts#star") {
  5699. let starButton = document.querySelector(".starring-container:not(.on)>.unstarred>form>button");
  5700. if (starButton) emuClick(starButton);
  5701. return true;
  5702. }
  5703. }
  5704. let isGuidePage = checkGuidePage(href);
  5705.  
  5706. var click2import, importUrlPres;
  5707.  
  5708. let inConfig = isGuidePage;
  5709. if (!inConfig) {
  5710. for (let i = 0; i < configPage.length; i++) {
  5711. if (configPage[i] == location.href) {
  5712. inConfig = true;
  5713. break;
  5714. }
  5715. }
  5716. }
  5717. if (!isGuidePage) {
  5718. if (location.hostname === "hoothin.github.io" || location.hostname === "pagetual.hoothin.com") isGuidePage = true;
  5719. }
  5720. configCon = document.getElementById("configCon");
  5721. if (configCon) {
  5722. configCon.parentNode.removeChild(configCon);
  5723. }
  5724. if (ruleImportUrlReg.test(href) || inConfig) {
  5725. let importing = false;
  5726. if (!inUpdate && rulesData.uninited) {
  5727. setTimeout(() => {
  5728. if (!inUpdate && !importing) showTips(i18n("firstAlert"));
  5729. }, 3000);
  5730. showTips(i18n("firstAlert"));
  5731. }
  5732. let defaultOption = document.querySelector('#discussion_rating_4');
  5733. if (defaultOption) defaultOption.checked = true;
  5734. let createImportBtn = (pre) => {
  5735. let importBtn = document.createElement("button");
  5736. importBtn.id = "pagetualImport";
  5737. importBtn.innerText = i18n("import");
  5738. importBtn.style.marginTop = "100px";
  5739. importBtn.style.float = "right";
  5740. importBtn.style.position = "relative";
  5741. importBtn.style.display = "block";
  5742. importBtn.style.fontSize = "20px";
  5743. importBtn.addEventListener("click", e => {
  5744. let parentNode = importBtn.parentNode;
  5745. if (!parentNode) return;
  5746. parentNode.removeChild(importBtn);
  5747. try {
  5748. let rules = parentNode.innerText.trim();
  5749. let isContent = /['"]name['"]/i.test(rules);
  5750. if (isContent) {
  5751. let ruleList = JSON.parse(`[${rules}]`);
  5752. for (let i in ruleList) {
  5753. let hasRule = false;
  5754. let r = ruleList[i];
  5755. for (let j in ruleParser.customRules) {
  5756. if (ruleParser.customRules[j].name == r.name) {
  5757. ruleParser.customRules[j] = r;
  5758. hasRule = true;
  5759. break;
  5760. }
  5761. }
  5762. if (!hasRule) ruleParser.customRules.push(r);
  5763. ruleParser.hpRules.unshift(r);
  5764. }
  5765. storage.setItem("customRules", ruleParser.customRules);
  5766. storage.setItem("hpRules", ruleParser.hpRules);
  5767. storage.setItem("smartRules", []);
  5768. showTips(i18n("importSucc"));
  5769. } else {
  5770. rules = rules.split("\n");
  5771. let diff = false;
  5772. for (let c = 0; c < rules.length; c++) {
  5773. let urlArr = rules[c].split("|"), url, type = 1;
  5774. if (urlArr.length == 1) {
  5775. url = urlArr[0].trim();
  5776. if (!/^http/.test(url)) {
  5777. showTips(i18n("errorWrongUrl"));
  5778. return;
  5779. }
  5780. } else if (urlArr.length == 2) {
  5781. type = urlArr[0].trim();
  5782. url = urlArr[1].trim();
  5783. if (!/^http/.test(url)) {
  5784. showTips(i18n("errorWrongUrl"));
  5785. return;
  5786. }
  5787. } else {
  5788. break;
  5789. }
  5790. let maxId = 1, hasUrl = false;
  5791. if (!rulesData.urls) {
  5792. rulesData.urls = [];
  5793. maxId = 1;
  5794. } else {
  5795. rulesData.urls.forEach(u => {
  5796. if (maxId < u.id) {
  5797. maxId = u.id;
  5798. }
  5799. if (u.url == url) {
  5800. hasUrl = true;
  5801. }
  5802. });
  5803. if (hasUrl) break;
  5804. }
  5805. diff = true;
  5806. if (!rulesData.sort) rulesData.sort = [1];
  5807. rulesData.urls.push({id: maxId + 1, url: url, type: type});
  5808. rulesData.sort.unshift(maxId + 1);
  5809. }
  5810. if (!diff) {
  5811. showTips(i18n("errorAlreadyExists"));
  5812. setTimeout(() => {
  5813. showTips(i18n("beginUpdate"), "", 50000);
  5814. updateRules(() => {
  5815. showTips(i18n("updateSucc"));
  5816. location.reload();
  5817. }, (rule, err) => {
  5818. showTips(`Failed to update ${rule.url} rules!`);
  5819. debug(err);
  5820. });
  5821. }, 500);
  5822. return;
  5823. }
  5824. storage.setItem("rulesData", rulesData);
  5825.  
  5826. if (rulesData.urls) ruleUrls = ruleUrls.concat(rulesData.urls);
  5827. if (rulesData.sort) {
  5828. let urls = [];
  5829. rulesData.sort.forEach(id => {
  5830. for (let s = 0; s < ruleUrls.length; s++) {
  5831. if (id == ruleUrls[s].id) {
  5832. urls.push(ruleUrls[s]);
  5833. break;
  5834. }
  5835. }
  5836. });
  5837. ruleUrls = urls;
  5838. }
  5839. showTips(i18n("beginUpdate"), "", 30000);
  5840. updateRules(() => {
  5841. showTips(i18n("updateSucc"));
  5842. location.reload();
  5843. }, (rule, err) => {
  5844. showTips(`Failed to update ${rule.url} rules!`);
  5845. debug(err);
  5846. });
  5847. importing = true;
  5848. }
  5849. } catch (e) {
  5850. _GM_notification(e.toString());
  5851. }
  5852. });
  5853. if (pre) {
  5854. let clientHeight = 35 - pre.clientHeight;
  5855. if (clientHeight > -20) clientHeight = -20;
  5856. importBtn.style.marginTop = `${clientHeight}px`;
  5857. pre.appendChild(importBtn);
  5858. }
  5859. return importBtn;
  5860. };
  5861. [].forEach.call(document.querySelectorAll('pre[name=pagetual],pre[name=user-content-pagetual]'), pre => {
  5862. let importBtn = createImportBtn(pre);
  5863. if (rulesData.uninited) {
  5864. pre.style.display = "";
  5865. }
  5866. });
  5867. click2import = document.querySelector("[name='user-content-click2import'],[name='click2import']");
  5868. if (click2import) {
  5869. click2import.innerText = i18n("click2ImportRule");
  5870. click2import.style.display = rulesData.uninited ? "block" : "none";
  5871. }
  5872. if (!importHandler) {
  5873. importHandler = e => {
  5874. if (compareNodeName(e.target, ["pre"])) {
  5875. let nameAttr = e.target.getAttribute("name");
  5876. if (nameAttr == "pagetual" || nameAttr == "user-content-pagetual") {
  5877. if (e.target.querySelector('#pagetualImport')) return;
  5878. let importBtn = createImportBtn(e.target);
  5879. }
  5880. }
  5881. };
  5882. }
  5883. document.removeEventListener("mouseover", importHandler);
  5884. document.addEventListener("mouseover", importHandler);
  5885.  
  5886. if (inConfig) {
  5887. if (!inUpdate && _GM_info.script && _GM_info.script.version && _GM_info.script.version !== '1.0.0') {
  5888. let versionEle = document.querySelector('.markdown-body>h1[id],article>h1');
  5889. let latestVer = versionEle && versionEle.innerText.match(/\d[\d\.]+/)[0];
  5890. if (latestVer && latestVer != _GM_info.script.version) {
  5891. showTips(i18n('outOfDate'), "", 3000);
  5892. }
  5893. }
  5894. _GM_addStyle(`
  5895. p>span:nth-child(1),p>span:nth-child(2),p>span:nth-child(3){
  5896. cursor: pointer;
  5897. user-select: none;
  5898. display: inline-block;
  5899. margin-right: 5px;
  5900. -moz-transition:color 0.3s ease, transform 0.3s;
  5901. -webkit-transition:color 0.3s ease, transform 0.3s;
  5902. transition:color 0.3s ease, transform 0.3s;
  5903. }
  5904. p>span:nth-child(1):hover,p>span:nth-child(2):hover,p>span:nth-child(3):hover{
  5905. color:red;
  5906. transform: scale(1.5);
  5907. -webkit-transform: scale(1.5);
  5908. }
  5909. .updateDate{
  5910. cursor: pointer;
  5911. user-select: none;
  5912. -moz-transition:color 0.3s ease, transform 0.3s;
  5913. -webkit-transition:color 0.3s ease, transform 0.3s;
  5914. transition:color 0.3s ease, transform 0.3s;
  5915. transform-origin: left;
  5916. -webkit-transform-origin: left;
  5917. }
  5918. .updateDate:hover{
  5919. color:red;
  5920. transform: scale(1.1);
  5921. -webkit-transform: scale(1.1);
  5922. }
  5923. input[type=number]::-webkit-inner-spin-button,
  5924. input[type=number]::-webkit-outer-spin-button {
  5925. -webkit-appearance: none;
  5926. margin: 0;
  5927. }
  5928. input[type=number] {
  5929. -moz-appearance:textfield;
  5930. }
  5931. table td>h3 {
  5932. margin: 16px!important;
  5933. padding: 0!important;
  5934. }
  5935. table td>h4 {
  5936. padding: 0!important;
  5937. }
  5938. #saveBtn {
  5939. width: 60vw;
  5940. position: fixed;
  5941. z-index: 999;
  5942. bottom: 0;
  5943. left: 20vw;
  5944. font-size: xx-large;
  5945. opacity: 0.6;
  5946. cursor: pointer;
  5947. -moz-transition:all 0.3s ease;
  5948. -webkit-transition:all 0.3s ease;
  5949. transition:all 0.3s ease;
  5950. }
  5951. #configCon #saveBtn:hover {
  5952. opacity: 1;
  5953. margin-bottom: 0px;
  5954. }
  5955. #configCon #saveBtn {
  5956. margin-bottom: -30px;
  5957. }
  5958. #configCon.showSave #saveBtn {
  5959. margin-bottom: 0px;
  5960. }
  5961. `);
  5962. configCon = document.querySelector(".markdown-body,.theme-default-content");
  5963. if (!configCon) {
  5964. setTimeout(() => {
  5965. location.reload();
  5966. }, 1000);
  5967. return true;
  5968. }
  5969. let insertPos = configCon.querySelector("hr,#jsoneditor");
  5970. configCon = document.createElement("div");
  5971. configCon.id = "configCon";
  5972. insertPos.parentNode.insertBefore(configCon, insertPos);
  5973.  
  5974. importUrlPres = document.querySelectorAll("pre[name='user-content-pagetual'],pre[name='pagetual']");
  5975. if (importUrlPres) {
  5976. [].forEach.call(importUrlPres, importUrlPre => {
  5977. importUrlPre.style.overflow = "hidden";
  5978. importUrlPre.style.display = rulesData.uninited ? "block" : "none";
  5979. });
  5980. }
  5981. let otherconfig = document.querySelector("a[name='user-content-otherconfig'],a[name='otherconfig']");
  5982. if (otherconfig) otherconfig.parentNode.removeChild(otherconfig);
  5983. let rulesExample = document.querySelector("#user-content-rules-example+a,#rules-example>a");
  5984. if (rulesExample) {
  5985. rulesExample.innerText = i18n("rulesExample");
  5986. if (lang == "zh-CN") {
  5987. rulesExample.href = rulesExample.href.replace("en", "cn");
  5988. } else if (lang == "zh-TW" || lang == "zh-HK") {
  5989. rulesExample.href = rulesExample.href.replace("/en", "");
  5990. }
  5991. }
  5992. document.documentElement.scrollTop = 0;
  5993.  
  5994. let newPos, lastPos = 0;
  5995. window.addEventListener('scroll', function(e) {
  5996. newPos = window.scrollY;
  5997. if (newPos > lastPos) {
  5998. configCon.classList.add("showSave");
  5999. } else {
  6000. configCon.classList.remove("showSave");
  6001. }
  6002. lastPos = newPos;
  6003. });
  6004. } else return isGuidePage;
  6005. } else return isGuidePage;
  6006. let ruleBarInsertPos = document.createTextNode(' ');
  6007. configCon.appendChild(ruleBarInsertPos);
  6008. class Rulebar {
  6009. init(ruleUrl) {
  6010. let id = ruleUrl.id;
  6011. this.ruleUrl = ruleUrl;
  6012. this.item = document.createElement("p");
  6013. this.item.dataset.id = id;
  6014. let url = document.createElement("a");
  6015. url.href = ruleUrl.url;
  6016. url.innerHTML = ruleUrl.url;
  6017. url.title = ruleUrl.url;
  6018. let up = document.createElement("span");
  6019. up.innerHTML = "↑ ";
  6020. up.title = i18n("sortTitle");
  6021. let down = document.createElement("span");
  6022. down.innerHTML = "↓ ";
  6023. down.title = i18n("sortTitle");
  6024. let del = document.createElement("span");
  6025. del.innerHTML = "× ";
  6026. up.onclick = e => {
  6027. this.moveUp();
  6028. };
  6029. down.onclick = e => {
  6030. this.moveDown();
  6031. };
  6032. del.onclick = e => {
  6033. this.del();
  6034. };
  6035. this.item.appendChild(up);
  6036. this.item.appendChild(down);
  6037. this.item.appendChild(del);
  6038. this.item.appendChild(url);
  6039. if (ruleParser.rules) {
  6040. url.style.maxWidth = "calc(100% - 150px)";
  6041. url.style.overflow = "hidden";
  6042. url.style.display = "inline-block";
  6043. url.style.textOverflow = "ellipsis";
  6044. url.style.verticalAlign = "bottom";
  6045. url.style.whiteSpace = "nowrap";
  6046. let rulesLength = ruleParser.rules.reduce((acc, cur) => acc + (cur.from == id ? 1 : 0), 0);
  6047. let idSpan = document.createElement("span");
  6048. idSpan.style.float = "right";
  6049. idSpan.innerHTML = `[rules: ${rulesLength}]`;
  6050. this.item.appendChild(idSpan);
  6051. this.idSpan = idSpan;
  6052. }
  6053. configCon.insertBefore(this.item, ruleBarInsertPos);
  6054. }
  6055. updateNum() {
  6056. if (ruleParser.rules) {
  6057. let rulesLength = ruleParser.rules.reduce((acc, cur) => acc + (cur.from == this.item.dataset.id ? 1 : 0), 0);
  6058. this.idSpan.innerHTML = `[rules: ${rulesLength}]`;
  6059. }
  6060. }
  6061. saveSort() {
  6062. let sort = [];
  6063. [].forEach.call(this.item.parentNode.querySelectorAll("p[data-id]"), i => {
  6064. sort.push(i.dataset.id);
  6065. });
  6066. rulesData.sort = sort;
  6067. let urls = [];
  6068. sort.forEach(id => {
  6069. for (let s = 0; s < ruleUrls.length; s++) {
  6070. if (id == ruleUrls[s].id) {
  6071. urls.push(ruleUrls[s]);
  6072. break;
  6073. }
  6074. }
  6075. });
  6076. ruleUrls = urls;
  6077. storage.setItem("rulesData", rulesData);
  6078. showTips(i18n("sortTitle"));
  6079. }
  6080. moveUp() {
  6081. let preE = this.item.previousElementSibling;
  6082. if (compareNodeName(preE, ["p"]) && preE.children.length > 1) {
  6083. this.item.parentNode.insertBefore(this.item, preE);
  6084. this.saveSort();
  6085. }
  6086. }
  6087. moveDown() {
  6088. let nextE = this.item.nextElementSibling;
  6089. if (compareNodeName(nextE, ["p"]) && nextE.children.length > 1) {
  6090. this.item.parentNode.insertBefore(nextE, this.item);
  6091. this.saveSort();
  6092. }
  6093. }
  6094. del() {
  6095. if (this.ruleUrl.id < 2) {
  6096. showTips(i18n("cantDel"));
  6097. } else if (window.confirm(i18n("confirmDel"))) {
  6098. for (let u = 0; u < rulesData.urls.length; u++) {
  6099. if (this.ruleUrl.id == rulesData.urls[u].id) {
  6100. rulesData.urls.splice(u, 1);
  6101. break;
  6102. }
  6103. }
  6104. for (let u = 0; u < ruleUrls.length; u++) {
  6105. if (this.ruleUrl.id == ruleUrls[u].id) {
  6106. ruleUrls.splice(u, 1);
  6107. break;
  6108. }
  6109. }
  6110. for (let u = 0; u < rulesData.sort.length; u++) {
  6111. if (this.ruleUrl.id == rulesData.sort[u]) {
  6112. rulesData.sort.splice(u, 1);
  6113. break;
  6114. }
  6115. }
  6116. rulesData.ruleVersion = 0;
  6117. storage.setItem("rulesData", rulesData);
  6118. ruleParser.rules = ruleParser.rules.filter(item => {return item.from != this.ruleUrl.id});
  6119. storage.setItem("rules", ruleParser.rules);
  6120. this.item.parentNode.removeChild(this.item);
  6121. //location.reload();
  6122. }
  6123. }
  6124. }
  6125. let langSelect = document.createElement("select");
  6126. langSelect.style.float = "right";
  6127. langSelect.style.position = "relative";
  6128. langSelect.style.zIndex = "1";
  6129. let option = document.createElement("option");
  6130. option.value = "";
  6131. option.innerText = "Language";
  6132. langSelect.appendChild(option);
  6133. for (let key in langList) {
  6134. let option = document.createElement("option");
  6135. option.value = key;
  6136. option.innerText = langList[key];
  6137. langSelect.appendChild(option);
  6138. }
  6139. langSelect.value = rulesData.lang || "";
  6140. configCon.appendChild(langSelect);
  6141.  
  6142. let updateP = document.createElement("p"), i = 0;
  6143. let now = new Date().getTime();
  6144.  
  6145.  
  6146. let pastDate = (new Date(updateDate)).toString(), passStr;
  6147. let passTime = (now - updateDate) / 1000;
  6148. if (isNaN(passTime)) {
  6149. passStr = i18n("firstUpdate");
  6150. } else {
  6151. if (passTime < 60) {
  6152. passStr = i18n("passSec", parseInt(passTime));
  6153. } else if (passTime < 60 * 60) {
  6154. passStr = i18n("passMin", parseInt(passTime / 60));
  6155. } else if (passTime < 60 * 60 * 24) {
  6156. passStr = i18n("passHour", parseInt(passTime / 3600));
  6157. } else {
  6158. passStr = i18n("passDay", parseInt(passTime / 86400));
  6159. }
  6160. passStr += " 🖱 " + i18n("click2update");
  6161. }
  6162.  
  6163. let rulebarList = [], updateFail = false;
  6164. updateP.className = "updateDate";
  6165. updateP.innerHTML = passStr;
  6166. updateP.title = i18n("update") + " - " + pastDate;
  6167. configCon.appendChild(updateP);
  6168. if (ruleUrls) {
  6169. ruleUrls.forEach(ruleUrl => {
  6170. let rulebar = new Rulebar();
  6171. rulebar.init(ruleUrl);
  6172. rulebarList.push(rulebar);
  6173. });
  6174. }
  6175. let customUrlsTitle = document.createElement("h2");
  6176. customUrlsTitle.innerHTML = i18n("customUrls");
  6177. configCon.appendChild(customUrlsTitle);
  6178. let customUrlsInput = document.createElement("textarea");
  6179. customUrlsInput.style.width = "100%";
  6180. customUrlsInput.style.position = "relative";
  6181. customUrlsInput.placeholder = "http://wedata.net/databases/AutoPagerize/items_all.json \nhttps://hoothin.github.io/UserScripts/Pagetual/pagetualRules.json";
  6182. customUrlsInput.spellcheck = false;
  6183. configCon.appendChild(customUrlsInput);
  6184.  
  6185. let btns = document.createElement("div");
  6186. btns.style.display = "flex";
  6187. configCon.appendChild(btns);
  6188. let upBtnImg = document.createElement("div");
  6189. upBtnImg.style.width = "33%";
  6190. let upBtnImgTitle = document.createElement("h2");
  6191. upBtnImgTitle.style.whiteSpace = "nowrap";
  6192. upBtnImgTitle.style.overflow = "auto";
  6193. upBtnImgTitle.innerHTML = i18n("upBtnImg");
  6194. upBtnImg.appendChild(upBtnImgTitle);
  6195. let upBtnImgInput = document.createElement("input");
  6196. upBtnImgInput.style.width = "100%";
  6197. upBtnImgInput.style.position = "relative";
  6198. upBtnImgInput.placeholder = "data:image/png;base64,UpBtn";
  6199. upBtnImgInput.value = rulesData.upBtnImg || '';
  6200. upBtnImgInput.spellcheck = false;
  6201. upBtnImg.appendChild(upBtnImgInput);
  6202. btns.appendChild(upBtnImg);
  6203.  
  6204. let downBtnImg = document.createElement("div");
  6205. downBtnImg.style.width = "33%";
  6206. let downBtnImgTitle = document.createElement("h2");
  6207. downBtnImgTitle.style.whiteSpace = "nowrap";
  6208. downBtnImgTitle.style.overflow = "auto";
  6209. downBtnImgTitle.innerHTML = i18n("downBtnImg");
  6210. downBtnImg.appendChild(downBtnImgTitle);
  6211. let downBtnImgInput = document.createElement("input");
  6212. downBtnImgInput.style.width = "100%";
  6213. downBtnImgInput.style.position = "relative";
  6214. downBtnImgInput.placeholder = "data:image/png;base64,DownBtn";
  6215. downBtnImgInput.value = rulesData.downBtnImg || '';
  6216. downBtnImgInput.spellcheck = false;
  6217. downBtnImg.appendChild(downBtnImgInput);
  6218. btns.appendChild(downBtnImg);
  6219.  
  6220. let sideControllerIconDiv = document.createElement("div");
  6221. sideControllerIconDiv.style.width = "33%";
  6222. let sideControllerIconTitle = document.createElement("h2");
  6223. sideControllerIconTitle.style.whiteSpace = "nowrap";
  6224. sideControllerIconTitle.style.overflow = "auto";
  6225. sideControllerIconTitle.innerHTML = i18n("sideControllerIcon");
  6226. sideControllerIconDiv.appendChild(sideControllerIconTitle);
  6227. let sideControllerIconInput = document.createElement("input");
  6228. sideControllerIconInput.style.width = "100%";
  6229. sideControllerIconInput.style.position = "relative";
  6230. sideControllerIconInput.placeholder = "📄";
  6231. sideControllerIconInput.value = rulesData.sideControllerIcon || '';
  6232. sideControllerIconInput.spellcheck = false;
  6233. sideControllerIconDiv.appendChild(sideControllerIconInput);
  6234. btns.appendChild(sideControllerIconDiv);
  6235.  
  6236. let otherBtns = document.createElement("div");
  6237. otherBtns.style.display = "flex";
  6238. configCon.appendChild(otherBtns);
  6239. let loadingText = document.createElement("div");
  6240. loadingText.style.width = "100%";
  6241. let loadingTextTitle = document.createElement("h2");
  6242. loadingTextTitle.style.whiteSpace = "nowrap";
  6243. loadingTextTitle.style.overflow = "auto";
  6244. loadingTextTitle.innerHTML = i18n("loadingTextTitle");
  6245. loadingText.appendChild(loadingTextTitle);
  6246. let loadingTextInput = document.createElement("input");
  6247. loadingTextInput.value = rulesData.loadingText || '';
  6248. loadingTextInput.placeholder = i18n("loadingText");
  6249. loadingTextInput.style.width = "100%";
  6250. loadingTextInput.style.position = "relative";
  6251. loadingTextInput.style.margin = "0";
  6252. loadingTextInput.spellcheck = false;
  6253. loadingText.appendChild(loadingTextInput);
  6254. otherBtns.appendChild(loadingText);
  6255.  
  6256. let opacity = document.createElement("div");
  6257. let opacityTitle = document.createElement("h2");
  6258. opacityTitle.style.whiteSpace = "nowrap";
  6259. opacityTitle.style.overflow = "visible";
  6260. opacityTitle.innerHTML = i18n("opacity");
  6261. opacity.appendChild(opacityTitle);
  6262. let opacityInput = document.createElement("input");
  6263. opacityInput.value = rulesData.opacity * 100;
  6264. opacityInput.type = "number";
  6265. opacityInput.min = 0;
  6266. opacityInput.max = 100;
  6267. opacityInput.style.width = "110px";
  6268. opacityInput.style.position = "relative";
  6269. opacityInput.style.margin = "0";
  6270. opacityInput.placeholder = i18n("opacityPlaceholder");
  6271. opacityInput.spellcheck = false;
  6272. opacityInput.oninput = e => {
  6273. if (opacityInput.value > 100) opacityInput.value = 100;
  6274. else if (opacityInput.value < 0) opacityInput.value = 0;
  6275. };
  6276. opacity.appendChild(opacityInput);
  6277. otherBtns.appendChild(opacity);
  6278.  
  6279. let pageElementCss = document.createElement("div");
  6280. pageElementCss.style.marginBottom = "30px";
  6281. let pageElementCssTitle = document.createElement("h2");
  6282. pageElementCssTitle.innerHTML = i18n("pageElementCss");
  6283. pageElementCss.appendChild(pageElementCssTitle);
  6284. let pageElementCssInput = document.createElement("input");
  6285. pageElementCssInput.value = rulesData.pageElementCss || '';
  6286. pageElementCssInput.style.width = "100%";
  6287. pageElementCssInput.style.position = "relative";
  6288. pageElementCssInput.style.margin = "0";
  6289. pageElementCssInput.placeholder = "font-size: xx-large;";
  6290. pageElementCssInput.spellcheck = false;
  6291. pageElementCss.appendChild(pageElementCssInput);
  6292. configCon.appendChild(pageElementCss);
  6293.  
  6294. let customCss = document.createElement("div");
  6295. customCss.style.marginBottom = "50px";
  6296. let customCssTitle = document.createElement("h2");
  6297. customCssTitle.innerHTML = i18n("customCss");
  6298. customCss.appendChild(customCssTitle);
  6299. let customCssInput = document.createElement("textarea");
  6300. customCssInput.value = rulesData.customCss || '';
  6301. customCssInput.style.width = "100%";
  6302. customCssInput.style.position = "relative";
  6303. customCssInput.style.margin = "0";
  6304. customCssInput.placeholder = ".pagetual {\n}";
  6305. customCssInput.spellcheck = false;
  6306. customCss.appendChild(customCssInput);
  6307. configCon.appendChild(customCss);
  6308.  
  6309. let configTable = document.createElement("table");
  6310. configTable.style.width = "100%";
  6311. let configTbody = document.createElement("tbody");
  6312. configTbody.style.width = "99%";
  6313. configTbody.style.display = "inline-table";
  6314. configTable.appendChild(configTbody);
  6315. configCon.appendChild(configTable);
  6316. function createCheckbox(innerText, val, tag, parentCheck, otherType, alwaysShow) {
  6317. if (typeof val == 'undefined') val = "";
  6318. let title = document.createElement(tag || "h3");
  6319. title.innerHTML = innerText;
  6320. title.style.overflowWrap = "normal";
  6321. let input = document.createElement("input");
  6322. if (otherType === 'key') {
  6323. input.type = 'text';
  6324. input.setAttribute('readOnly', 'readonly');
  6325. input.addEventListener("keydown", e => {
  6326. if (e.key === 'Escape' || e.key === 'Backspace') input.value = '';
  6327. else input.value = e.key;
  6328. e.stopPropagation();
  6329. e.preventDefault();
  6330. });
  6331. } else {
  6332. input.type = otherType || "checkbox";
  6333. }
  6334. input.style.width = "35px";
  6335. input.style.height = "20px";
  6336. input.style.float = "left";
  6337. input.style.margin = "0 2px";
  6338. input.value = val;
  6339. input.checked = val;
  6340. let td = document.createElement("td");
  6341. td.appendChild(input);
  6342. if (parentCheck) {
  6343. title.appendChild(input);
  6344. title.style.margin = "0";
  6345. td.appendChild(title);
  6346. let parent = parentCheck.parentNode.nextElementSibling;
  6347. let tr = parent.querySelector("tr");
  6348. if (!tr) {
  6349. tr = document.createElement("tr");
  6350. parent.appendChild(tr);
  6351. }
  6352. tr.appendChild(td);
  6353. if (!alwaysShow) {
  6354. if (!parentCheck.checked) {
  6355. td.style.display = "none";
  6356. }
  6357. parentCheck.addEventListener("click", e => {
  6358. td.style.display = parentCheck.checked ? "" : "none";
  6359. });
  6360. }
  6361. } else {
  6362. let tr = document.createElement("tr");
  6363. tr.appendChild(td);
  6364. td = document.createElement("td");
  6365. td.appendChild(title);
  6366. tr.appendChild(td);
  6367. configTable.children[0].appendChild(tr);
  6368. }
  6369. let xNodePos = innerText.indexOf('【X】');
  6370. if (xNodePos !== -1) {
  6371. input.style.float = "";
  6372. let xNode = title.firstChild.splitText(xNodePos);
  6373. xNode.splitText(3);
  6374. xNode.parentNode.replaceChild(input, xNode);
  6375. }
  6376. return input;
  6377. }
  6378.  
  6379. let setConfigPageInput = createCheckbox(i18n("setConfigPage"), false);
  6380. let enableWhiteListInput = createCheckbox(i18n("autoRun"), rulesData.enableWhiteList != true);
  6381. let sideControllerInput = createCheckbox(i18n("sideController"), rulesData.sideController);
  6382. let sideControllerAlwaysInput = createCheckbox(i18n("sideControllerAlways"), rulesData.sideControllerAlways, "h4", sideControllerInput);
  6383. let sideControllerScrollInput = createCheckbox(i18n("sideControllerScroll"), rulesData.sideControllerScroll !== false, "h4", sideControllerInput);
  6384. let sideControllerLoadNowInput = createCheckbox(i18n("loadNow"), rulesData.sideControllerLoadNow !== false, "h4", sideControllerInput);
  6385. let enableDebugInput = createCheckbox(i18n("enableDebug"), rulesData.enableDebug != false);
  6386. let enableHistoryInput = createCheckbox(i18n("enableHistory"), rulesData.enableHistory === true);
  6387. let enableHistoryAfterInsertInput = createCheckbox(i18n("enableHistoryAfterInsert"), rulesData.enableHistoryAfterInsert === true, "h4", enableHistoryInput);
  6388. let openInNewTabInput = createCheckbox(i18n("openInNewTab"), rulesData.openInNewTab != false);
  6389. let hidePageBarInput = createCheckbox(i18n("hideBarTips"), rulesData.opacity == 0);
  6390. let hidePageBarArrowInput = createCheckbox(i18n("hideBarArrow"), rulesData.hideBarArrow);
  6391. let hideLoadingIconInput = createCheckbox(i18n("hideLoadingIcon"), rulesData.hideLoadingIcon != false);
  6392. let initRunInput = createCheckbox(i18n("initRun"), rulesData.initRun != false);
  6393. let autoLoadNumInput = createCheckbox(i18n("autoLoadNum"), rulesData.autoLoadNum, "h4", initRunInput, "number");
  6394. let preloadInput = createCheckbox(i18n("preload"), rulesData.preload != false);
  6395. let rateInput = createCheckbox(i18n("turnRate"), rulesData.rate, "h4", preloadInput, "number", true);
  6396. let dbClick2StopInput = createCheckbox(i18n("dbClick2Stop"), rulesData.dbClick2Stop);
  6397. let manualModeInput = createCheckbox(i18n("manualMode"), rulesData.manualMode);
  6398. let clickModeInput = createCheckbox(i18n("clickMode"), rulesData.clickMode);
  6399. let pageBarMenuInput = createCheckbox(i18n("pageBarMenu"), rulesData.pageBarMenu != false);
  6400. let arrowToScrollInput = createCheckbox(i18n("arrowToScroll"), rulesData.arrowToScroll);
  6401. let contentVisibilityInput = createCheckbox(i18n("contentVisibility"), rulesData.contentVisibility);
  6402. let wedata2githubInput = createCheckbox(i18n("wedata2github"), rulesData.wedata2github);
  6403. let customFirstInput = createCheckbox(i18n("customFirst"), rulesData.customFirst);
  6404. let lastPageTipsInput = createCheckbox(i18n("lastPageTips"), rulesData.lastPageTips);
  6405. let updateNotificationInput = createCheckbox(i18n("updateNotification"), rulesData.updateNotification != false);
  6406.  
  6407. let hideBarInput = createCheckbox(i18n("hideBar"), rulesData.hideBar && !rulesData.hideBarButNoStop, "h4", dbClick2StopInput, 'radio');
  6408. hideBarInput.name = 'hideBar';
  6409. let hideBarButNoStopInput = createCheckbox(i18n("hideBarButNoStop"), rulesData.hideBarButNoStop, "h4", dbClick2StopInput, 'radio');
  6410. hideBarButNoStopInput.name = 'hideBar';
  6411. hideBarInput.addEventListener('mouseup', e => {
  6412. if (hideBarInput.checked) {
  6413. setTimeout(() => {hideBarInput.checked = false}, 0);
  6414. }
  6415. });
  6416. hideBarButNoStopInput.addEventListener('mouseup', e => {
  6417. if (hideBarButNoStopInput.checked) {
  6418. setTimeout(() => {hideBarButNoStopInput.checked = false}, 0);
  6419. }
  6420. });
  6421. hidePageBarInput.addEventListener('click', e => {
  6422. opacityInput.value = hidePageBarInput.checked ? 0 : 100;
  6423. });
  6424.  
  6425. let dbClick2StopCtrlInput = createCheckbox(i18n("dbClick2StopCtrl"), rulesData.dbClick2StopCtrl, "h4", dbClick2StopInput);
  6426. let dbClick2StopAltInput = createCheckbox(i18n("dbClick2StopAlt"), rulesData.dbClick2StopAlt, "h4", dbClick2StopInput);
  6427. let dbClick2StopShiftInput = createCheckbox(i18n("dbClick2StopShift"), rulesData.dbClick2StopShift, "h4", dbClick2StopInput);
  6428. let dbClick2StopMetaInput = createCheckbox(i18n("dbClick2StopMeta"), rulesData.dbClick2StopMeta, "h4", dbClick2StopInput);
  6429. let dbClick2StopKeyInput = createCheckbox(i18n("dbClick2StopKey"), rulesData.dbClick2StopKey, "h4", dbClick2StopInput, "key");
  6430.  
  6431. let otherConfigPage = (rulesData.configPage || configPage[0]) != location.href.replace(/#.*/, "");
  6432. if (!otherConfigPage) {
  6433. setConfigPageInput.parentNode.parentNode.style.display = "none";
  6434. }
  6435.  
  6436. updateP.onclick = e => {
  6437. updateFail = false;
  6438. //ruleParser.rules = [];
  6439. showTips(i18n("beginUpdate"), "", 30000);
  6440. updateRules(() => {
  6441. if (!updateFail) {
  6442. showTips(i18n("updateSucc"));
  6443. if (importUrlPres) {
  6444. [].forEach.call(importUrlPres, importUrlPre => {
  6445. importUrlPre.style.display = "none";
  6446. });
  6447. }
  6448. if (click2import) click2import.style.display = "none";
  6449. }
  6450. updateP.innerHTML = i18n("passSec", 0);
  6451. updateP.title = i18n("update");
  6452. rulebarList.forEach(rulebar => {
  6453. rulebar.updateNum();
  6454. });
  6455. }, (rule, err) => {
  6456. if (rule.id == 1) {
  6457. showTips(`Failed to update wedata rules! Try to switch to wedata mirror!`);
  6458. wedata2githubInput.scrollIntoView({ behavior: "smooth" });
  6459. } else {
  6460. showTips(`Failed to update ${rule.url} rules!`);
  6461. }
  6462. debug(err);
  6463. updateFail = true;
  6464. });
  6465. };
  6466. let customRulesTitle = document.createElement("h2");
  6467. 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');
  6468. configCon.appendChild(customRulesTitle);
  6469. customRulesInput = document.createElement("textarea");
  6470. customRulesInput.spellcheck = false;
  6471. configCon.appendChild(customRulesInput);
  6472. if (rulesData.editTemp) {
  6473. if (!ruleParser.customRules) {
  6474. ruleParser.customRules = [];
  6475. }
  6476. for (let i in ruleParser.customRules) {
  6477. if (ruleParser.customRules[i].url == rulesData.editTemp.url) {
  6478. ruleParser.customRules.splice(i, 1);
  6479. break;
  6480. }
  6481. }
  6482. ruleParser.customRules.unshift(rulesData.editTemp);
  6483. rulesData.editTemp = null;
  6484. storage.setItem("rulesData", rulesData);
  6485. customRulesInput.previousElementSibling.scrollIntoView();
  6486. }
  6487. customRulesInput.style.width = "100%";
  6488. customRulesInput.style.height = "800px";
  6489. 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]`;
  6490. let preCustom = getFormatJSON(ruleParser.customRules);
  6491. customRulesInput.value = preCustom;
  6492. if (isGuidePage) customRulesInput.style.display = "none";
  6493. let blacklistInput = document.createElement("textarea");
  6494. blacklistInput.style.width = "100%";
  6495. blacklistInput.style.height = "500px";
  6496. blacklistInput.style.display = "none";
  6497. blacklistInput.spellcheck = false;
  6498. blacklistInput.placeholder = "http://*.xxx.com/*/y\n/^https?://.*\\.xxx\\.com/i \t\t<= Regexp\n//http://*.aaa.com/ \t\t<= Disable\n/*http://*.bbb.com\nhttp://*.ccc.com*/ \t\t<= Block comment";
  6499. blacklistInput.value = rulesData.blacklist ? rulesData.blacklist.join("\n") : "";
  6500. let blacklistBtn = document.createElement("button");
  6501. blacklistBtn.innerText = i18n("editBlacklist");
  6502. blacklistBtn.style.width = "100%";
  6503. blacklistBtn.onclick = e => {
  6504. blacklistInput.style.display = blacklistInput.style.display == "none" ? "" : "none";
  6505. };
  6506. configCon.appendChild(blacklistBtn);
  6507. configCon.appendChild(blacklistInput);
  6508. let saveBtn = document.createElement("button");
  6509. saveBtn.innerHTML = i18n("save");
  6510. saveBtn.id = "saveBtn";
  6511. configCon.appendChild(saveBtn);
  6512. saveBtn.onclick = e => {
  6513. try {
  6514. let customRules;
  6515. if (editor) {
  6516. if (editorChanged) {
  6517. editorChanged = false;
  6518. storage.setItem("hpRules", []);
  6519. storage.setItem("smartRules", []);
  6520. }
  6521. customRules = editor.get();
  6522. if (!customRules) {
  6523. customRules = "";
  6524. } else {
  6525. if (Array && Array.isArray && !Array.isArray(customRules)) {
  6526. showTips(i18n("errorRulesMustBeArray"));
  6527. return;
  6528. }
  6529. }
  6530. } else {
  6531. if (customRulesInput.value != preCustom) {
  6532. storage.setItem("hpRules", []);
  6533. storage.setItem("smartRules", []);
  6534. }
  6535. if (customRulesInput.value == "") {
  6536. customRules = "";
  6537. } else {
  6538. customRules = JSON.parse(customRulesInput.value);
  6539. if (Array && Array.isArray && !Array.isArray(customRules)) {
  6540. showTips(i18n("errorRulesMustBeArray"));
  6541. return;
  6542. }
  6543. customRulesInput.value = JSON.stringify(customRules, null, 4);
  6544. }
  6545. }
  6546. debug(customRules);
  6547. storage.setItem("customRules", customRules);
  6548. } catch(e) {
  6549. debug(e);
  6550. let pos = e && e.message && e.message.match(/position (\d+)/);
  6551. if (pos && !editor) {
  6552. pos = parseInt(pos[1]);
  6553. customRulesInput.value = customRulesInput.value.slice(0, pos) + "➡️" + customRulesInput.value.slice(pos);
  6554. }
  6555. showTips(i18n("errorJson"));
  6556. return;
  6557. }
  6558. rulesData.lang = langSelect.value || "";
  6559. if (setConfigPageInput.checked) rulesData.configPage = location.href;
  6560. rulesData.wedata2github = wedata2githubInput.checked;
  6561. let opacity = parseInt(opacityInput.value) || 0;
  6562. if (opacity > 100) opacity = 100;
  6563. else if (opacity < 0) opacity = 0;
  6564. rulesData.opacity = opacity / 100;
  6565. rulesData.blacklist = blacklistInput.value ? blacklistInput.value.trim().split("\n") : "";
  6566. rulesData.hideBar = hideBarInput.checked;
  6567. rulesData.hideBarButNoStop = hideBarButNoStopInput.checked;
  6568. rulesData.dbClick2Stop = dbClick2StopInput.checked;
  6569. rulesData.enableWhiteList = !enableWhiteListInput.checked;
  6570. rulesData.enableDebug = enableDebugInput.checked;
  6571. rulesData.updateNotification = updateNotificationInput.checked;
  6572. rulesData.enableHistory = enableHistoryInput.checked;
  6573. rulesData.enableHistoryAfterInsert = enableHistoryAfterInsertInput.checked;
  6574. rulesData.openInNewTab = openInNewTabInput.checked;
  6575. rulesData.hideLoadingIcon = hideLoadingIconInput.checked;
  6576. rulesData.hideBarArrow = hidePageBarArrowInput.checked;
  6577. rulesData.customFirst = customFirstInput.checked;
  6578. rulesData.lastPageTips = lastPageTipsInput.checked;
  6579. rulesData.initRun = initRunInput.checked;
  6580. rulesData.autoLoadNum = autoLoadNumInput.value !== "0" ? autoLoadNumInput.value : '';
  6581. rulesData.rate = parseFloat(rateInput.value) || 0;
  6582. rulesData.preload = preloadInput.checked;
  6583. rulesData.manualMode = manualModeInput.checked;
  6584. rulesData.clickMode = clickModeInput.checked;
  6585. rulesData.pageBarMenu = pageBarMenuInput.checked;
  6586. rulesData.arrowToScroll = arrowToScrollInput.checked;
  6587. rulesData.contentVisibility = contentVisibilityInput.checked;
  6588. if (rulesData.sideController != sideControllerInput.checked) {
  6589. rulesData.sideControllerPos = false;
  6590. }
  6591. rulesData.sideController = sideControllerInput.checked;
  6592. rulesData.sideControllerScroll = sideControllerScrollInput.checked;
  6593. rulesData.sideControllerLoadNow = sideControllerLoadNowInput.checked;
  6594. rulesData.sideControllerAlways = sideControllerAlwaysInput.checked;
  6595. rulesData.pageElementCss = pageElementCssInput.value;
  6596. rulesData.customCss = customCssInput.value;
  6597. rulesData.upBtnImg = upBtnImgInput.value;
  6598. rulesData.downBtnImg = downBtnImgInput.value;
  6599. rulesData.sideControllerIcon = sideControllerIconInput.value;
  6600. rulesData.loadingText = loadingTextInput.value;
  6601. rulesData.dbClick2StopCtrl = dbClick2StopCtrlInput.checked;
  6602. rulesData.dbClick2StopAlt = dbClick2StopAltInput.checked;
  6603. rulesData.dbClick2StopShift = dbClick2StopShiftInput.checked;
  6604. rulesData.dbClick2StopMeta = dbClick2StopMetaInput.checked;
  6605. rulesData.dbClick2StopKey = dbClick2StopKeyInput.value;
  6606. storage.setItem("rulesData", rulesData);
  6607. let customUrls = customUrlsInput.value.trim(), urlImported = false;
  6608. if (customUrls) {
  6609. customUrls = customUrls.split(/\n/);
  6610. for (let c = 0; c < customUrls.length; c++) {
  6611. let url;
  6612. if (/^0\s*\|/.test(customUrls[c])) {
  6613. url = customUrls[c].replace(/^0\s*\|\s*/, "").trim();
  6614. if (!/^http/.test(url)) {
  6615. showTips(i18n("errorWrongUrl"));
  6616. return;
  6617. }
  6618. } else {
  6619. url = customUrls[c].trim();
  6620. if (!/^http/.test(url)) {
  6621. showTips(i18n("errorWrongUrl"));
  6622. return;
  6623. }
  6624. }
  6625. let maxId = 1, hasUrl = false;
  6626. if (!rulesData.urls) {
  6627. rulesData.urls = [];
  6628. }
  6629. ruleUrls.forEach(u => {
  6630. if (maxId < u.id) {
  6631. maxId = u.id;
  6632. }
  6633. if (u.url == url) {
  6634. hasUrl = true;
  6635. }
  6636. });
  6637. if (hasUrl) break;
  6638. if (!rulesData.sort) rulesData.sort = [1];
  6639. let newRule = {id: maxId + 1, url: url};
  6640. ruleUrls.push(newRule);
  6641. rulesData.urls.push(newRule);
  6642. rulesData.sort.push(maxId + 1);
  6643. storage.setItem("rulesData", rulesData);
  6644. let rulebar = new Rulebar();
  6645. rulebar.init(newRule);
  6646. rulebarList.push(rulebar);
  6647. }
  6648. }
  6649. showTips(i18n("settingsSaved"));
  6650. };
  6651. return true;
  6652. }
  6653.  
  6654. function updateRules (success, fail, keepCache) {
  6655. if (!storage.supportCrossSave()) {
  6656. fail({url:''}, "Not support cross storage");
  6657. showTips("Current platform do not support cross storage!");
  6658. return;
  6659. }
  6660. if (inUpdate) return;
  6661. inUpdate = true;
  6662. let ruleIndex = ruleUrls.length - 1;
  6663. if (!keepCache) {
  6664. storage.setItem("hpRules", []);
  6665. storage.setItem("smartRules", []);
  6666. }
  6667. let allOk = true;
  6668. let preLength = ruleParser.rules.length;
  6669. let fetchVersion = -1;
  6670. async function needUpdate(url, id) {
  6671. if (!/^https:\/\/hoothin\.github\.io\/|\/hoothin\/UserScripts\/.*\/Pagetual\/pagetualRules\.json/i.test(url)) {
  6672. return true;
  6673. }
  6674. let rulesLength = ruleParser.rules.reduce((acc, cur) => acc + (cur.from == id ? 1 : 0), 0);
  6675. if (rulesLength === 0) return true;
  6676. if (fetchVersion >= 0) {
  6677. return fetchVersion > (rulesData.ruleVersion || 0);
  6678. }
  6679. fetchVersion = await new Promise(resolve => {
  6680. _GM_xmlhttpRequest({
  6681. url: url.replace(/\/\w+\.json/i, "/version"),
  6682. method: 'GET',
  6683. timeout: 20000,
  6684. headers: {
  6685. 'accept': 'application/json,text/html'
  6686. },
  6687. onload: function(res) {
  6688. let version = parseInt(res.response || res.responseText);
  6689. resolve(version || -1);
  6690. },
  6691. onerror: function(e) {
  6692. resolve(-1);
  6693. },
  6694. ontimeout: function(e) {
  6695. resolve(-1);
  6696. }
  6697. });
  6698. });
  6699. return fetchVersion > (rulesData.ruleVersion || 0);
  6700. }
  6701. async function addNextRule() {
  6702. if (ruleIndex < 0) {
  6703. let now = new Date().getTime();
  6704. storage.setItem("ruleLastUpdate", now);
  6705. storage.setItem("rules", ruleParser.rules);
  6706. let curLength = ruleParser.rules.length;
  6707. if (curLength !== preLength && rulesData.updateNotification) {
  6708. _GM_notification({
  6709. text: `Rules has updated( ${preLength} => ${curLength} )`,
  6710. title: "Pagetual rules updated",
  6711. onclick: (event) => {
  6712. event.preventDefault();
  6713. _GM_openInTab(rulesData.configPage || configPage[0], {active: true});
  6714. }
  6715. });
  6716. }
  6717. inUpdate = false;
  6718. let rulesDataChanged = false;
  6719. if (fetchVersion >= 0 && rulesData.ruleVersion !== fetchVersion) {
  6720. rulesData.ruleVersion = fetchVersion;
  6721. rulesDataChanged = true;
  6722. }
  6723. if (rulesData.uninited && allOk && ruleUrls.length > 1) {
  6724. rulesData.uninited = false;
  6725. rulesDataChanged = true;
  6726. }
  6727. if (rulesDataChanged) {
  6728. storage.setItem("rulesData", rulesData);
  6729. }
  6730. success();
  6731. } else {
  6732. let rule = ruleUrls[ruleIndex--];
  6733. if (await needUpdate(rule.url, rule.id)) {
  6734. ruleParser.addRuleByUrl(rule.url, rule.id, (json, err) => {
  6735. if (!json) {
  6736. allOk = false;
  6737. fail(rule, err);
  6738. }
  6739. addNextRule();
  6740. });
  6741. } else {
  6742. addNextRule();
  6743. }
  6744. }
  6745. }
  6746. addNextRule();
  6747. }
  6748.  
  6749. function objIsArr(obj) {
  6750. return obj &&
  6751. typeof obj === 'object' &&
  6752. typeof obj.length === 'number' &&
  6753. !(obj.propertyIsEnumerable('length'));
  6754. }
  6755.  
  6756. function isVisible(el, win) {
  6757. if(!el || !el.offsetParent)return false;
  6758. var loopable = true,
  6759. visible = el.nodeName && win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  6760. while(loopable && visible) {
  6761. el = el.parentNode;
  6762.  
  6763. if(el && el.nodeType === 1 && !compareNodeName(el, ["body"])) {
  6764. visible = win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  6765. }else {
  6766. loopable = false;
  6767. }
  6768. }
  6769. return visible;
  6770. }
  6771.  
  6772. function getElementTop(ele) {
  6773. if (!ele) return 0;
  6774. if (ele.getBoundingClientRect) {
  6775. return ele.getBoundingClientRect().top + document.documentElement.scrollTop;
  6776. }
  6777. var actualTop = ele.offsetTop;
  6778. var current = ele.offsetParent;
  6779. while (current) {
  6780. actualTop += current.offsetTop;
  6781. current = current.offsetParent;
  6782. }
  6783. return actualTop;
  6784. }
  6785.  
  6786. function getElementLeft(ele) {
  6787. if (!ele) return 0;
  6788. if (ele.getBoundingClientRect) {
  6789. return ele.getBoundingClientRect().left + document.documentElement.scrollLeft;
  6790. }
  6791. var actualLeft = ele.offsetLeft;
  6792. var current = ele.offsetParent;
  6793. while (current) {
  6794. actualLeft += current.offsetLeft;
  6795. current = current.offsetParent;
  6796. }
  6797. return actualLeft;
  6798. }
  6799.  
  6800. function getElementBottom(ele) {
  6801. return getElementTop(ele) + (ele.offsetHeight || ele.scrollHeight);
  6802. }
  6803.  
  6804. function getFormatJSON(obj){
  6805. if(!objIsArr(obj) || obj.length === 0)return "";
  6806. return JSON.stringify(obj, null, 4);
  6807. }
  6808.  
  6809. function globMatch(first, second) {
  6810. if (first === '*') {
  6811. return true;
  6812. }
  6813. if (first.length == 0 && second.length == 0){
  6814. return true;
  6815. }
  6816.  
  6817. if (first.length > 1 && first[0] == '*' &&
  6818. second.length == 0){
  6819. return false;
  6820. }
  6821.  
  6822. if ((first.length > 1 && first[0] == '?') ||
  6823. (first.length != 0 && second.length != 0 &&
  6824. first[0] == second[0])){
  6825. return globMatch(first.substring(1),
  6826. second.substring(1));
  6827. }
  6828.  
  6829. if (first.length > 0 && first[0] == '*'){
  6830. return globMatch(first.substring(1), second) ||
  6831. globMatch(first, second.substring(1));
  6832. }
  6833.  
  6834. return false;
  6835. }
  6836.  
  6837. let pageReady = false;
  6838. function initRules(callback) {
  6839. charset = (document.characterSet || document.charset || document.inputEncoding);
  6840. let equiv = document.querySelector('[http-equiv="Content-Type"]');
  6841. if (equiv && equiv.content) {
  6842. let innerCharSet = equiv.content.match(/charset\=([^;]+)/);
  6843. if (!innerCharSet) {
  6844. charsetValid = false;
  6845. } else if (innerCharSet[1].replace("-", "").toLowerCase() != charset.replace("-", "").toLowerCase()) {
  6846. charsetValid = false;
  6847. }
  6848. } else charsetValid = false;
  6849. storage.getItem("rulesData", data => {
  6850. /*0 wedata格式,1 pagetual格式*/
  6851. ruleUrls = [{
  6852. id: 1,
  6853. url: data && data.wedata2github ? 'https://hoothin.github.io/UserScripts/Pagetual/items_all.json' : 'http://wedata.net/databases/AutoPagerize/items_all.json',
  6854. type: 0,
  6855. }];
  6856. if (data) {
  6857. rulesData = data;
  6858. if (data.urls) ruleUrls = ruleUrls.concat(data.urls);
  6859. if (data.sort) {
  6860. let urls = [];
  6861. data.sort.forEach(id => {
  6862. for (let s = 0; s < ruleUrls.length; s++) {
  6863. if (id == ruleUrls[s].id) {
  6864. urls.push(ruleUrls[s]);
  6865. break;
  6866. }
  6867. }
  6868. });
  6869. ruleUrls = urls;
  6870. }
  6871. }
  6872. if (rulesData.lang) {
  6873. setLang(rulesData.lang);
  6874. }
  6875. if (rulesData.firstRun) {
  6876. rulesData.firstRun = false;
  6877. storage.setItem("rulesData", rulesData);
  6878. setTimeout(() => {
  6879. storage.getItem("rulesData", data => {
  6880. if (data.firstRun === false) {
  6881. _GM_openInTab(firstRunPage, {active: true});
  6882. }
  6883. });
  6884. }, 100);
  6885. }
  6886. _GM_registerMenuCommand(i18n("configure"), () => {
  6887. _GM_openInTab(rulesData.configPage || configPage[0], {active: true});
  6888. });
  6889. if (rulesData.blacklist && rulesData.blacklist.length > 0) {
  6890. let href = location.href.slice(0, 500);
  6891. let commentStart = false;
  6892. for (let i = 0; i < rulesData.blacklist.length; i++) {
  6893. let curGlob = rulesData.blacklist[i];
  6894. if (!curGlob) continue;
  6895. if (curGlob.indexOf("//") == 0) continue;
  6896. if (commentStart) {
  6897. if (/\*\/$/.test(curGlob)) {
  6898. commentStart = false;
  6899. }
  6900. continue;
  6901. }
  6902. if (curGlob.indexOf("/*") == 0) {
  6903. commentStart = true;
  6904. continue;
  6905. }
  6906. if (curGlob.indexOf("/") == 0) {
  6907. let regMatch = curGlob.match(/^\/(.*)\/(\w*)$/);
  6908. if (regMatch && new RegExp(regMatch[1], regMatch[2]).test(href)) {
  6909. forceState == 1;
  6910. return;
  6911. }
  6912. } else if (globMatch(curGlob, href)) {
  6913. forceState == 1;
  6914. return;
  6915. }
  6916. }
  6917. }
  6918. _GM_registerMenuCommand(i18n("editCurrent"), () => {
  6919. picker.start();
  6920. });
  6921. ruleParser.initSavedRules(async () => {
  6922. let upBtnImg = rulesData.upBtnImg, downBtnImg = rulesData.downBtnImg, _sideControllerIcon = rulesData.sideControllerIcon;
  6923. if (upBtnImg && downBtnImg) {
  6924. downSvgCSS = downSvgCSS.replace("transform: rotate(180deg);", "");
  6925. } else if (upBtnImg && !downBtnImg) {
  6926. downBtnImg = upBtnImg;
  6927. } else if(downBtnImg && !upBtnImg) {
  6928. upBtnImg = downBtnImg;
  6929. }
  6930. if (upBtnImg) {
  6931. upSvg = /https?:|data/.test(upBtnImg) ? `<img class="pagetual" src="${upBtnImg}"/>` : `<span>${upBtnImg}</span>`;
  6932. }
  6933. if (downBtnImg) {
  6934. downSvg = /https?:|data/.test(downBtnImg) ? `<img class="pagetual" src="${downBtnImg}"/>` : `<span>${downBtnImg}</span>`;
  6935. }
  6936. if (_sideControllerIcon) {
  6937. sideControllerIcon = /https?:|data/.test(_sideControllerIcon) ? `<img class="pagetual" src="${_sideControllerIcon}"/>` : `<span>${_sideControllerIcon}</span>`;
  6938. }
  6939. setLoadingDiv(rulesData.loadingText || i18n("loadingText"));
  6940. if (typeof(rulesData.opacity) == "undefined") {
  6941. rulesData.opacity = 1;
  6942. }
  6943. if (typeof(rulesData.hideBar) == "undefined") {
  6944. rulesData.hideBar = false;
  6945. }
  6946. if (typeof(rulesData.dbClick2Stop) == "undefined") {
  6947. rulesData.dbClick2Stop = true;
  6948. }
  6949. if (typeof(rulesData.enableWhiteList) == "undefined") {
  6950. rulesData.enableWhiteList = false;
  6951. }
  6952. if (typeof(rulesData.enableHistory) == "undefined") {
  6953. rulesData.enableHistory = false;
  6954. }
  6955. if (typeof(rulesData.openInNewTab) == "undefined") {
  6956. rulesData.openInNewTab = false;
  6957. }
  6958. if (typeof(rulesData.enableDebug) == "undefined") {
  6959. rulesData.enableDebug = true;
  6960. }
  6961. if (typeof(rulesData.updateNotification) == "undefined") {
  6962. rulesData.updateNotification = true;
  6963. }
  6964. if (typeof(rulesData.initRun) == "undefined") {
  6965. rulesData.initRun = true;
  6966. }
  6967. if (typeof(rulesData.preload) == "undefined") {
  6968. rulesData.preload = true;
  6969. }
  6970. if (typeof(rulesData.customFirst) == "undefined") {
  6971. rulesData.customFirst = false;
  6972. }
  6973. if (typeof(rulesData.manualMode) == "undefined") {
  6974. rulesData.manualMode = false;
  6975. }
  6976. if (typeof(rulesData.clickMode) == "undefined") {
  6977. rulesData.clickMode = false;
  6978. }
  6979. if (typeof(rulesData.pageBarMenu) == "undefined") {
  6980. rulesData.pageBarMenu = true;
  6981. }
  6982. if (typeof(rulesData.arrowToScroll) == "undefined") {
  6983. rulesData.arrowToScroll = false;
  6984. }
  6985. if (typeof(rulesData.hideLoadingIcon) == "undefined") {
  6986. rulesData.hideLoadingIcon = false;
  6987. }
  6988. if (typeof(rulesData.hideBarArrow) == "undefined") {
  6989. rulesData.hideBarArrow = false;
  6990. }
  6991. if (typeof(rulesData.lastPageTips) == "undefined") {
  6992. rulesData.lastPageTips = true;
  6993. }
  6994. if (typeof(rulesData.rate) == "undefined") {
  6995. rulesData.rate = 1;
  6996. }
  6997. rate = rulesData.rate;
  6998. if (rulesData.autoLoadNum && rulesData.initRun) {
  6999. autoLoadNum = parseInt(rulesData.autoLoadNum);
  7000. }
  7001. openInNewTab = rulesData.openInNewTab ? 1 : 0;
  7002. enableDebug = rulesData.enableDebug;
  7003.  
  7004. let _nextSwitch = await getListData("nextSwitch", location.host);
  7005. if (typeof(_nextSwitch) !== "undefined") {
  7006. nextIndex = _nextSwitch || 0;
  7007. }
  7008.  
  7009. let _forceState = await getListData("forceState", location.host);
  7010. if (typeof(_forceState) == "undefined") {
  7011. _forceState = await getData("forceState_" + location.host);
  7012. }
  7013. if (typeof(_forceState) == "undefined") {
  7014. _forceState = (rulesData.enableWhiteList ? 1 : 0);
  7015. }
  7016. forceState = _forceState;
  7017.  
  7018. autoScroll = await getListData("autoScroll", location.host + location.pathname) || 0;
  7019.  
  7020. updateDate = await getData("ruleLastUpdate");
  7021.  
  7022. let _loadNowNum = await getData("loadNowNum");
  7023. if (typeof(_loadNowNum) != "undefined") {
  7024. loadNowNum = _loadNowNum;
  7025. }
  7026. let _autoScrollRate = await getData("autoScrollRate");
  7027. if (_autoScrollRate) {
  7028. autoScrollRate = _autoScrollRate;
  7029. }
  7030.  
  7031. author = await getData("author") || "";
  7032.  
  7033. manualPause = !!await getListData("pauseState", location.host);
  7034.  
  7035. let href = location.href.slice(0, 100);
  7036. try {
  7037. if (_unsafeWindow.initedPagetual) {
  7038. if (ruleImportUrlReg.test(href)) {
  7039. showTips(i18n('duplicate'));
  7040. }
  7041. return;
  7042. }
  7043. _unsafeWindow.initedPagetual = true;
  7044. } catch(e) {showTips(e)}
  7045. listenUrl();
  7046. _GM_registerMenuCommand(i18n("update"), () => {
  7047. showTips(i18n("beginUpdate"), "", 60000);
  7048. updateRules(() => {
  7049. showTips(i18n("updateSucc"));
  7050. location.reload();
  7051. },(rule, err) => {
  7052. showTips(`Failed to update ${rule.url} rules!`);
  7053. debug(err);
  7054. });
  7055. });
  7056. _GM_registerMenuCommand(i18n(forceState == 1 ? "enable" : "disableSite"), () => {
  7057. if (forceState == 1) {
  7058. forceState = 0;
  7059. showTips(i18n("enableSiteTips"));
  7060. changeStop(false, true);
  7061. } else {
  7062. forceState = 1;
  7063. showTips(i18n("disableSiteTips"));
  7064. changeStop(true, true);
  7065. sideController.remove();
  7066. }
  7067. setListData("forceState", location.host, forceState);
  7068. if (!ruleParser.curSiteRule.url) {
  7069. setTimeout(() => {
  7070. location.reload();
  7071. }, 500);
  7072. }
  7073. });
  7074. _GM_registerMenuCommand(i18n("toggleAutoScroll"), () => {
  7075. autoScroll = (autoScroll ? 0 : prompt(i18n("autoScrollRate"), autoScrollRate)) || 0;
  7076. autoScroll = parseInt(autoScroll) || 0;
  7077. if (autoScroll < 0) autoScroll = 0;
  7078. if (autoScroll && autoScroll != autoScrollRate) {
  7079. autoScrollRate = autoScroll;
  7080. storage.setItem("autoScrollRate", autoScrollRate);
  7081. }
  7082. setListData("autoScroll", location.host + location.pathname, autoScroll);
  7083. startAutoScroll();
  7084. });
  7085. startAutoScroll();
  7086.  
  7087.  
  7088. if (initConfig(href)) {
  7089. document.addEventListener("click", e => {
  7090. if (e.target && typeof e.target.dataset.pagetualPicker !== 'undefined') {
  7091. e.preventDefault();
  7092. e.stopPropagation();
  7093. picker.start();
  7094. }
  7095. });
  7096. return;
  7097. }
  7098. pageReady = true;
  7099. if (forceState == 1) return;
  7100. let now = new Date().getTime();
  7101. if (!updateDate || now - updateDate > 2 * 24 * 60 * 60 * 1000) {
  7102. updateRules(() => {
  7103. }, (rule, err) => {}, true);
  7104. storage.setItem("ruleLastUpdate", now);
  7105. }
  7106. callback();
  7107. });
  7108. });
  7109. }
  7110.  
  7111. let xhrFailed = false;
  7112. function requestDoc(url, callback) {
  7113. let postParams = url.match(/#p{(.*)}$/);
  7114. if (postParams) {
  7115. postParams = postParams[1];
  7116. url = url.replace(/#p{.*/, "");
  7117. }
  7118. let ruleHeaders = ruleParser.curSiteRule.headers;
  7119. let headers = {
  7120. 'Referer': location.href,
  7121. 'User-Agent': navigator.userAgent,
  7122. 'accept': 'text/html,application/xhtml+xml,application/xml',
  7123. "Content-Type": (postParams ? "application/x-www-form-urlencoded" : "text/html") + ";charset=" + charset,
  7124. };
  7125. if (ruleHeaders) {
  7126. if (ruleHeaders.referer) {
  7127. headers.referer = ruleHeaders.referer;
  7128. }
  7129. if (ruleHeaders.userAgent) {
  7130. headers.userAgent = ruleHeaders.userAgent;
  7131. }
  7132. if (ruleHeaders.accept) {
  7133. headers.accept = ruleHeaders.accept;
  7134. }
  7135. if (ruleHeaders.contentType) {
  7136. headers.contentType = ruleHeaders.contentType;
  7137. let ruleCharset = ruleHeaders.contentType.match(/charset\=([^;]+)/);
  7138. if (ruleCharset) charset = ruleCharset[1];
  7139. }
  7140. if (ruleHeaders.cookie) {
  7141. headers.cookie = ruleHeaders.cookie;
  7142. }
  7143. }
  7144. _GM_xmlhttpRequest({
  7145. url: url,
  7146. method: postParams ? 'POST' : 'GET',
  7147. data: postParams,
  7148. overrideMimeType: 'text/html;charset=' + charset,
  7149. headers: headers,
  7150. timeout: 50000,
  7151. onload: async function(res) {
  7152. if (isPause) return callback(false);
  7153. var doc = null, response = res.response;
  7154. try {
  7155. doc = document.implementation.createHTMLDocument('');
  7156. doc.documentElement.innerHTML = response;
  7157. } catch (e) {
  7158. debug('parse error:' + e.toString());
  7159. }
  7160. let pageElement = null;
  7161. let preCode = ruleParser.curSiteRule.pagePre;
  7162. if (preCode) {
  7163. try {
  7164. let preResult;
  7165. if (typeof preCode == 'function') {
  7166. preResult = await preCode(response, doc);
  7167. } else if (preCode.length == 2) {
  7168. preResult = response.replace(new RegExp(preCode[0], "gi"), preCode[1]);
  7169. } else {
  7170. preResult = await new AsyncFunction("response", "doc", '"use strict";' + preCode)(response, doc);
  7171. }
  7172. if (typeof preResult !== "undefined") {
  7173. if (typeof preResult === "string") {
  7174. doc.documentElement.innerHTML = preResult;
  7175. } else pageElement = preResult;
  7176. }
  7177. } catch(e) {
  7178. debug(e);
  7179. }
  7180. }
  7181. let base = doc.querySelector("base");
  7182. ruleParser.basePath = (base && base.href) || url;
  7183. if (charsetValid && !ruleHeaders) {
  7184. let equiv = doc.querySelector('[http-equiv="Content-Type"]');
  7185. if (equiv && equiv.content) {
  7186. let innerCharSet = equiv.content.match(/charset\=([^;]+)/);
  7187. if (innerCharSet && innerCharSet[1].replace("-", "").toLowerCase() != charset.replace("-", "").toLowerCase()) {
  7188. charset = innerCharSet[1];
  7189. return requestDoc(url, callback);
  7190. }
  7191. }
  7192. }
  7193. if (pageElement === null) {
  7194. pageElement = ruleParser.getPageElement(doc);
  7195. }
  7196. if ((!pageElement || pageElement.length == 0) && res.status >= 400) {
  7197. debug(res.status + " " + url + " " + response, "Error status");
  7198. if (!ruleParser.curSiteRule.smart || !xhrFailed) {
  7199. xhrFailed = true;
  7200. return callback(false);
  7201. }
  7202. }
  7203. if (inCors && (!pageElement || pageElement.length == 0) && ruleParser.curSiteRule.smart) {
  7204. let article;
  7205. for (let i = 0; i < mainSel.length; i++) {
  7206. article = doc.querySelectorAll(mainSel[i]);
  7207. if (article && article.length === 1) break;
  7208. }
  7209. if (article && article.length == 1) {
  7210. article = article[0];
  7211. ruleParser.curSiteRule.pageElement = article.nodeName.toLowerCase() + (article.id ? "#" + article.id : "") + (article.className ? "." + article.className.replace(/ /g, ".") : "") + ">*";
  7212. pageElement = article.children;
  7213. } else {
  7214. ruleParser.curSiteRule.pageElement = allOfBody;
  7215. pageElement = ruleParser.getPageElement(doc);
  7216. }
  7217. ruleParser.getInsert(true);
  7218. }
  7219. //只有1的話怕不是圖片哦
  7220. if (pageElement && (pageElement.length > 1 || (pageElement.length == 1 && !compareNodeName(pageElement[0], ["img"])))) {
  7221. await ruleParser.insertPage(doc, pageElement, url, callback, false);
  7222. if (ruleParser.curSiteRule.action == 1) {
  7223. isLoading = true;
  7224. requestFromIframe(url, async (doc, eles) => {
  7225. if (eles) {
  7226. await ruleParser.insertPage(doc, eles, url, callback, true);
  7227. } else isLoading = false;
  7228. });
  7229. } else ruleParser.curSiteRule.action = 0;
  7230. } else if ((ruleParser.curSiteRule.smart || curPage == 1) && !inCors) {
  7231. ruleParser.curSiteRule.action = 1;
  7232. requestFromIframe(url, async (doc, eles) => {
  7233. if (eles) {
  7234. await ruleParser.insertPage(doc, eles, url, callback, true);
  7235. } else isLoading = false;
  7236. });
  7237. } else {
  7238. debug("Stop as no page element");
  7239. ruleParser.noValidContent(url);
  7240. changeStop(true);
  7241. callback(false);
  7242. }
  7243. },
  7244. onerror: function(e) {
  7245. debug(e, "NetError");
  7246. callback(false);
  7247. },
  7248. ontimeout: function(e) {
  7249. debug(e, "NetTimeout");
  7250. callback(false);
  7251. }
  7252. });
  7253. }
  7254.  
  7255. function initPage() {
  7256. ruleParser.initPage(() => {
  7257. if (ruleParser.curSiteRule.autoLoadNum) {
  7258. autoLoadNum = ruleParser.curSiteRule.autoLoadNum;
  7259. }
  7260. if (ruleParser.curSiteRule.nextLink && Array && Array.isArray && Array.isArray(ruleParser.curSiteRule.nextLink)) {
  7261. _GM_registerMenuCommand(i18n("nextSwitch"), () => {
  7262. nextSwitch.start();
  7263. });
  7264. }
  7265. if (ruleParser.nextLinkHref) {
  7266. let isJs = ruleParser.hrefIsJs(ruleParser.nextLinkHref);
  7267. if (!isJs) {
  7268. let inForce = (forceState == 2 || forceState == 3);
  7269. _GM_registerMenuCommand(i18n(inForce ? "cancelForceIframe" : "forceIframe"), () => {
  7270. if (inForce) {
  7271. setListData("forceState", location.host, "");
  7272. } else {
  7273. let _state = ruleParser.curSiteRule.action > 0 || confirm(i18n("forceAllBody")) ? 2 : 3;
  7274. setListData("forceState", location.host, _state);
  7275. }
  7276. setTimeout(() => {
  7277. location.reload();
  7278. }, 500);
  7279. });
  7280. }
  7281. _GM_registerMenuCommand(i18n("loadNow"), () => {
  7282. if (autoLoadNum != -1) {
  7283. autoLoadNum = -1;
  7284. return;
  7285. }
  7286. let loadNum = window.prompt(i18n("loadConfirm"), loadNowNum);
  7287. if (loadNum === "" || loadNum === null) return;
  7288. loadNum = Math.abs(parseInt(loadNum)) || 0;
  7289. if (loadNowNum != loadNum) {
  7290. loadNowNum = loadNum;
  7291. storage.setItem("loadNowNum", loadNowNum);
  7292. }
  7293. autoLoadNum = loadNum;
  7294. nextPage();
  7295. });
  7296. }
  7297. initListener();
  7298. });
  7299. }
  7300.  
  7301. var pageBarStyle, mainStyleEle, mainStyleStyle;
  7302. function initView() {
  7303. if (!mainStyleStyle) {
  7304. mainStyleStyle = `
  7305. .pagetual_pageBar{
  7306. -moz-transition:all 0.3s ease-in-out 0s;
  7307. -webkit-transition:all 0.3s ease-in-out 0s;
  7308. transition:all 0.3s ease-in-out 0s;
  7309. font-family: Arial,sans-serif !important;
  7310. text-align: center !important;
  7311. }
  7312. .pagetual_pageBar.stop {
  7313. -webkit-filter: invert(100%);
  7314. filter: invert(100%);
  7315. opacity: 1!important;
  7316. }
  7317. .pagetual_pageBar.hide {
  7318. display: none!important;
  7319. }
  7320. .pagetual-hide {
  7321. display: none!important;
  7322. }
  7323. .pagetual_pageBar:hover {
  7324. opacity: 1!important;
  7325. box-shadow: 0px 0px 10px 0px #000000aa;
  7326. border-radius: 20px;
  7327. background-color: rgb(240 240 240 / 80%);
  7328. border-color: transparent!important;
  7329. }
  7330. .pagetual_pageBar span {
  7331. vertical-align: super;
  7332. }
  7333. .pagetual_pageBar a::before,
  7334. .pagetual_pageBar a::after {
  7335. content: none;
  7336. }
  7337. .pagetual_pageBar a>span {
  7338. margin-top: 0!important;
  7339. pointer-events: none;
  7340. padding: unset;
  7341. opacity: 0;
  7342. -moz-transition:margin-top 0.3s ease-in-out 0s, opacity .3s;
  7343. -webkit-transition:margin-top 0.3s ease-in-out 0s, opacity .3s;
  7344. transition:margin-top 0.3s ease-in-out 0s, opacity .3s;
  7345. transform: none;
  7346. left: 0;
  7347. margin-left: calc(50% - 20px);
  7348. }
  7349. .pagetual_pageBar a>span:hover {
  7350. color: red;
  7351. }
  7352. .pagetual_pageBar a:hover>span {
  7353. opacity: 1!important;
  7354. }
  7355. .pagetual_pageBar span.prevScreen,
  7356. .pagetual_pageBar span.nextScreen {
  7357. display: block!important;
  7358. top: unset !important;
  7359. padding: unset !important;
  7360. opacity: 0!important;
  7361. }
  7362. .pagetual_pageBar a:hover>span.prevScreen {
  7363. margin-top: -${rulesData.opacity == 1 ? 31 : 30}px!important;
  7364. pointer-events: all;
  7365. }
  7366. .pagetual_pageBar span.refreshRing {
  7367. position: absolute;
  7368. top: 0;
  7369. opacity: 0;
  7370. height: 30px;
  7371. margin-left: calc(50% - 23px);
  7372. display: block!important;
  7373. }
  7374. .pagetual_pageBar span.refreshRing>svg {
  7375. background: white;
  7376. border-radius: 50%;
  7377. }
  7378. .pagetual_pageBar a:hover>span.refreshRing {
  7379. opacity: 0.3;
  7380. -webkit-animation: pagetual_ring 2.0s infinite linear;
  7381. animation: pagetual_ring 2.0s infinite linear;
  7382. }
  7383. @-webkit-keyframes pagetual_ring {
  7384. 0% { -webkit-transform: rotate(0deg) }
  7385. 100% {
  7386. -webkit-transform: rotate(360deg);
  7387. }
  7388. }
  7389. @keyframes pagetual_ring {
  7390. 0% {
  7391. transform: rotate(0deg);
  7392. -webkit-transform: rotate(0deg);
  7393. } 100% {
  7394. transform: rotate(360deg);
  7395. -webkit-transform: rotate(360deg);
  7396. }
  7397. }
  7398. .pagetual_pageBar a:hover>span.nextScreen {
  7399. margin-top: 30px!important;
  7400. pointer-events: all;
  7401. }
  7402. .pagetual_pageBar span>svg {
  7403. -moz-transition:transform 0.5s ease, opacity 0.3s ease;
  7404. -webkit-transition:transform 0.5s ease, opacity 0.3s ease;
  7405. transition:transform 0.5 ease, opacity 0.3s ease;
  7406. opacity: 0;
  7407. }
  7408. .pagetual_pageBar.stop span>svg{
  7409. opacity: 1;
  7410. }
  7411. .pagetual_pageBar.stop span>svg>path{
  7412. transform: scale(.8);
  7413. transform-origin: center;
  7414. -moz-transition:transform 0.3s ease;
  7415. -webkit-transition:transform 0.3s ease;
  7416. transition:transform 0.3 ease;
  7417. }
  7418. .pagetual_pageBar.stop:hover span>svg>path{
  7419. transform: unset;
  7420. }
  7421. .pagetual_pageBar:hover span>svg {
  7422. opacity: 1;
  7423. }
  7424. .pagetual_pageBar span>svg.upSvg:hover {
  7425. transform: rotate(360deg) scale3d(1.2, 1.2, 1.2);
  7426. }
  7427. .pagetual_pageBar span>svg.downSvg:hover {
  7428. transform: rotate(540deg) scale3d(1.2, 1.2, 1.2)!important;
  7429. }
  7430. .pagetual_pageBar .pagetual_pageNum{
  7431. color: #55555f;
  7432. }
  7433. .pagetual_pageBar .pagetual_pageNum:hover{
  7434. color: #ff6464;
  7435. }
  7436. .pagetual_tipsWords {
  7437. font-size: 50px;
  7438. font-weight: bold;
  7439. font-family: "黑体", -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto",
  7440. "Oxygen", "Ubuntu", "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji",
  7441. "Segoe UI Emoji", "Segoe UI Symbol";
  7442. color: #ffffff;
  7443. min-height: 70px;
  7444. max-width: 80%;
  7445. line-height: 1.5;
  7446. position: fixed;
  7447. left: 50%;
  7448. top: 10%;
  7449. margin-left: -99999px;
  7450. padding: 0 15px;
  7451. z-index: 2147483647;
  7452. background-color: #000;
  7453. border: 1px solid #303030;
  7454. border-radius: 10px;
  7455. opacity: 0;
  7456. filter: alpha(opacity=65);
  7457. box-shadow: 5px 5px 20px 0px #000;
  7458. -moz-transition:opacity 0.3s ease-in-out 0s;
  7459. -webkit-transition:opacity 0.3s ease-in-out 0s;
  7460. transition:opacity 0.3s ease-in-out 0s;
  7461. pointer-events: none;
  7462. word-break: break-all;
  7463. }
  7464. .pagetual_tipsWords>a {
  7465. color: #ffffff;
  7466. }
  7467. .pagetual_loading {
  7468. width: 50px;
  7469. height: 50px;
  7470. margin: 10px auto;
  7471. border-radius: 100%;
  7472. display: flex;
  7473. -webkit-animation: pagetual_loading_scaleout 1.0s infinite ease-in-out;
  7474. animation: pagetual_loading_scaleout 1.0s infinite ease-in-out;
  7475. }
  7476. @-webkit-keyframes pagetual_loading_scaleout {
  7477. 0% { -webkit-transform: scale(0.0) }
  7478. 100% {
  7479. -webkit-transform: scale(1.0);
  7480. opacity: 0;
  7481. }
  7482. }
  7483. @keyframes pagetual_loading_scaleout {
  7484. 0% {
  7485. transform: scale(0.0);
  7486. -webkit-transform: scale(0.0);
  7487. } 100% {
  7488. transform: scale(1.0);
  7489. -webkit-transform: scale(1.0);
  7490. opacity: 0;
  7491. }
  7492. }
  7493. .pagetual_loading_text {
  7494. white-space: nowrap;
  7495. -webkit-animation: pagetual_loading_opacity 2.6s infinite ease-in-out;
  7496. animation: pagetual_loading_opacity 2.6s infinite ease-in-out;
  7497. }
  7498. @-webkit-keyframes pagetual_loading_opacity {
  7499. 0% { opacity: 1 }
  7500. 50% { opacity: 0.2 }
  7501. 100% { opacity: 1 }
  7502. }
  7503. @keyframes pagetual_loading_opacity {
  7504. 0% { opacity: 1 }
  7505. 50% { opacity: 0.2 }
  7506. 100% { opacity: 1 }
  7507. }
  7508. `;
  7509. 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%);"}`;
  7510. }
  7511. if (!mainStyleEle || !mainStyleEle.parentNode) {
  7512. mainStyleEle = _GM_addStyle(mainStyleStyle);
  7513. }
  7514. }
  7515. var loadingDiv = document.createElement("div");
  7516. if (loadingDiv.style) 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;";
  7517.  
  7518. const loadingCSS = `font-size: initial; 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;`;
  7519. function setLoadingDiv(loadingText) {
  7520. 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" style="fill: #6e6e6e;" 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" style="fill: #6e6e6e;" fill="#6e6e6e"></path></svg></div>`}`);
  7521. }
  7522.  
  7523. 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" style="fill: #604b4a;" 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" style="fill: #604b4a;" fill="#604b4a"></path></svg>`;
  7524. 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;`;
  7525. 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" style="fill: #604b4a;" 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" style="fill: #604b4a;" fill="#604b4a"></path></svg>`;
  7526. 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);`;
  7527.  
  7528. 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;`;
  7529. 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;`;
  7530. var sideControllerIcon = '';
  7531.  
  7532. var tipsWords = document.createElement("div");
  7533. tipsWords.className = "pagetual_tipsWords";
  7534.  
  7535. function changeStop(stop, save) {
  7536. isPause = stop;
  7537. [].forEach.call(getBody(document).querySelectorAll(".pagetual_pageBar,#pagetual-sideController"), bar => {
  7538. if (isPause) {
  7539. bar.classList.add("stop");
  7540. } else {
  7541. bar.classList.remove("stop");
  7542. }
  7543. });
  7544. if (!isPause) ruleParser.showAddedElements();
  7545. manualPause = isPause;
  7546. if (save && sideController.inited) setListData("pauseState", location.host, isPause ? true : "");
  7547. }
  7548.  
  7549. function changeHideBar(hide) {
  7550. isHideBar = hide;
  7551. [].forEach.call(getBody(document).querySelectorAll(".pagetual_pageBar"), bar => {
  7552. if (isHideBar) {
  7553. bar.classList.add("hide");
  7554. } else {
  7555. bar.classList.remove("hide");
  7556. }
  7557. });
  7558. }
  7559.  
  7560. function isInViewPort(element) {
  7561. const viewWidth = window.innerWidth || document.documentElement.clientWidth;
  7562. const viewHeight = window.innerHeight || document.documentElement.clientHeight;
  7563. const {
  7564. top,
  7565. right,
  7566. bottom,
  7567. left,
  7568. } = element.getBoundingClientRect();
  7569.  
  7570. return (
  7571. top >= 0 &&
  7572. left >= 0 &&
  7573. right <= viewWidth + 1 &&
  7574. top <= viewHeight * rate &&
  7575. isVisible(element, _unsafeWindow)
  7576. );
  7577. }
  7578.  
  7579. function getPageBar() {
  7580. let preBar = null, nextBar = null;
  7581. let pageBars = [].slice.call(document.querySelectorAll(".pagetual_pageBar"));
  7582. for (let i = 0; i < pageBars.length; i++) {
  7583. let pageBar = pageBars[i];
  7584. if (!pageBar || !getBody(document).contains(pageBar)) continue;
  7585. let {
  7586. top,
  7587. right,
  7588. bottom,
  7589. left,
  7590. } = pageBar.getBoundingClientRect();
  7591. if (top > 500) {
  7592. nextBar = pageBar;
  7593. preBar = (i - 1 >= 0 ? pageBars[i - 1] : null);
  7594. if (pageBar && getBody(document).contains(pageBar)) {
  7595. let {
  7596. top,
  7597. right,
  7598. bottom,
  7599. left,
  7600. } = pageBar.getBoundingClientRect();
  7601. if (top < -500) {
  7602. preBar = pageBar;
  7603. } else preBar = (i - 2 >= 0 ? pageBars[i - 2] : null);
  7604. }
  7605. break;
  7606. }
  7607. }
  7608. if (!nextBar) preBar = pageBars[pageBars.length - 2];
  7609. return {preBar: preBar, nextBar: nextBar};
  7610. }
  7611.  
  7612. var urlChanged = false;
  7613. var urlChanging = false;
  7614. var urlchangeHandler = e => {
  7615. if (ruleParser && ruleParser.curSiteRule && ruleParser.curSiteRule.listenUrlChange == false) return;
  7616. isPause = true;
  7617. setTimeout(() => {
  7618. lastActiveUrl = location.href;
  7619. if (urlChanging) return;
  7620. urlChanging = true;
  7621. let href = location.href.slice(0, 60);
  7622. if (href == configPage[1]) {
  7623. setTimeout(() => {
  7624. initConfig(href);
  7625. urlChanging = false;
  7626. }, 1000);
  7627. } else {
  7628. setTimeout(() => {
  7629. if (guidePage.test(href)) {
  7630. setTimeout(() => {
  7631. initConfig(href);
  7632. urlChanging = false;
  7633. }, 1000);
  7634. } else {
  7635. ruleParser.urlChanged();
  7636. if (!ruleParser.nextLinkHref) {
  7637. isLoading = false;
  7638. }
  7639. urlChanging = false;
  7640. //if (!pageReady && !ruleImportUrlReg.test(href)) location.reload();
  7641. }
  7642. }, 500);
  7643. }
  7644. }, 1);
  7645. };
  7646. window.addEventListener('pagetual_pushState', urlchangeHandler);
  7647. /*var _wr = function(type) {
  7648. var orig = history[type];
  7649. return function() {
  7650. var rv = orig.apply(this, arguments);
  7651. var e = new Event('pagetual_' + type);
  7652. e.arguments = arguments;
  7653. window.dispatchEvent(e);
  7654. return rv;
  7655. };
  7656. };
  7657. history.pushState = _wr('pushState');*/
  7658.  
  7659. function listenUrl() {
  7660. var prevPathname = window.location.pathname;
  7661. var prevSearch = window.location.search;
  7662. var checkUrlTime = 100;
  7663. var checkUrlTimer;
  7664. var checkClickedEle = null;
  7665. var clickedSth = false;
  7666. var checkFunc = () => {
  7667. if (forceState == 1) return;
  7668. if (checkClickedEle) {
  7669. if (!clickedSth && checkClickedEle && checkClickedEle.nodeName) {
  7670. if (compareNodeName(checkClickedEle, ["a", "button"])) {
  7671. clickedSth = true;
  7672. } else {
  7673. let targetStyle = _unsafeWindow.getComputedStyle(checkClickedEle);
  7674. if (targetStyle.cursor == "pointer") clickedSth = true;
  7675. }
  7676. }
  7677. checkClickedEle = null;
  7678. }
  7679. if (checkUrlTime < 5000) {
  7680. checkUrlTime += checkUrlTime>>1;
  7681. }
  7682. clearTimeout(checkUrlTimer);
  7683. checkUrlTimer = setTimeout(checkFunc, checkUrlTime);
  7684. if (document.hidden) return;
  7685. if (clickedSth) {
  7686. ruleParser.checkClickHref();
  7687. clickedSth = false;
  7688. } else if (!ruleParser.canListenUrlChange()) {
  7689. return;
  7690. }
  7691. if ((prevPathname !== window.location.pathname || prevSearch !== window.location.search) && window.location.href != ruleParser.historyUrl) {
  7692. checkUrlTime = 2000;
  7693. urlWillChange = true;
  7694. var e = new Event('pagetual_pushState');
  7695. e.arguments = arguments;
  7696. window.dispatchEvent(e);
  7697. clickedSth = false;
  7698. }
  7699. prevPathname = window.location.pathname;
  7700. prevSearch = window.location.search;
  7701. };
  7702. checkUrlTimer = setTimeout(checkFunc, checkUrlTime);
  7703.  
  7704. document.addEventListener("click", e => {
  7705. if (!checkClickedEle) {
  7706. checkClickedEle = e.target;
  7707. checkUrlTime = 300;
  7708. clearTimeout(checkUrlTimer);
  7709. checkUrlTimer = setTimeout(checkFunc, checkUrlTime);
  7710. }
  7711. });
  7712. }
  7713.  
  7714. let scrollContainer;
  7715. function distToBottom () {
  7716. let scrolly = window.scrollY;
  7717. let windowHeight = window.innerHeight || document.documentElement.clientHeight;
  7718. if (!scrollContainer || !document.documentElement.contains(scrollContainer)) {
  7719. if (curPage > 1 || ruleParser.nextLinkHref) {
  7720. let pageEle = ruleParser.getPageElement(document);
  7721. if (pageEle && pageEle.length) {
  7722. let parent = pageEle[0].parentNode, pageScrollY = parent.scrollTop;
  7723. while (parent && pageScrollY == 0) {
  7724. parent = parent.parentNode;
  7725. pageScrollY = parent.scrollTop;
  7726. }
  7727. if (pageScrollY) {
  7728. scrollContainer = parent;
  7729. return scrollContainer.scrollHeight - pageScrollY - windowHeight;
  7730. }
  7731. }
  7732. }
  7733. }
  7734. if (scrollContainer) {
  7735. return scrollContainer.scrollHeight - scrollContainer.scrollTop - windowHeight;
  7736. }
  7737.  
  7738. let scrollH = Math.max(document.documentElement.scrollHeight, getBody(document).scrollHeight);
  7739. return scrollH - scrolly - windowHeight;
  7740. }
  7741.  
  7742. let scrollHandler, clickToResetHandler, dblclickHandler, keydownHandler, hashchangeHandler, manualModeKeyHandler, pagetualNextHandler, keyupHandler, messageHandler;
  7743. function initListener () {
  7744. document.removeEventListener('scroll', scrollHandler, true);
  7745. document.removeEventListener('wheel', scrollHandler, true);
  7746. document.removeEventListener('dblclick', dblclickHandler);
  7747. document.removeEventListener('keydown', keydownHandler);
  7748. window.removeEventListener('hashchange', hashchangeHandler, false);
  7749. document.removeEventListener('keydown', manualModeKeyHandler);
  7750. document.removeEventListener('pagetual.next', pagetualNextHandler, false);
  7751. document.removeEventListener('keyup', keyupHandler);
  7752. _unsafeWindow.removeEventListener('message', messageHandler, true);
  7753. let loadmoreBtn, loadingMore = true, lastScroll = 0, checkLoadMoreTimes = 0, loadMoreInv;
  7754. if (ruleParser.curSiteRule.smart) {
  7755. loadingMore = false;
  7756. } else if (ruleParser.curSiteRule.loadMore) {
  7757. loadingMore = false;
  7758. }
  7759. clickMode = typeof ruleParser.curSiteRule.clickMode == 'undefined' ? rulesData.clickMode : ruleParser.curSiteRule.clickMode;
  7760. let clickingNext = false;
  7761. let clickNext = async () => {
  7762. if (clickingNext) return;
  7763. clickingNext = true;
  7764. setTimeout(() => {
  7765. clickingNext = false;
  7766. }, 1500);
  7767. let nextLink = ruleParser.nextLinkHref;
  7768. if (!nextLink) return;
  7769. let isJs = ruleParser.hrefIsJs(nextLink);
  7770. if (isJs) {
  7771. let nextBtn = ruleParser.nextLinkEle;
  7772. if (!nextBtn || !nextBtn.offsetParent) nextBtn = await ruleParser.getNextLink(document, true);
  7773. if (nextBtn) emuClick(nextBtn);
  7774. } else {
  7775. window.location.href = nextLink;
  7776. }
  7777. };
  7778. let checkScrollReach = () => {
  7779. let dist = distToBottom();
  7780. if (clickMode) {
  7781. if (dist < 10) {
  7782. clickNext();
  7783. }
  7784. } else if (dist < bottomGap) {
  7785. nextPage();
  7786. }
  7787. };
  7788. messageHandler = e => {
  7789. if (e.data.command === 'pagetual') {
  7790. let action = e.data.action;
  7791. let detail = e.data.detail;
  7792. switch (action) {
  7793. case "config":
  7794. if (!detail || typeof detail !== 'object') return;
  7795. rulesData = {
  7796. ...rulesData,
  7797. ...detail
  7798. }
  7799. storage.setItem("rulesData", rulesData);
  7800. break;
  7801. case "nextPage":
  7802. if (detail === "" || detail === null) return;
  7803. detail = parseInt(detail) || 0;
  7804. if (loadNowNum != detail) {
  7805. loadNowNum = detail;
  7806. }
  7807. autoLoadNum = detail;
  7808. nextPage();
  7809. break;
  7810. case "loadMore":
  7811. clearInterval(loadMoreInv);
  7812. if (detail === -1) return;
  7813. loadmoreBtn = getLoadMore(document, loadmoreBtn);
  7814. loadmoreBtn && emuClick(loadmoreBtn);
  7815. if (detail === 0) {
  7816. loadMoreInv = setInterval(() => {
  7817. loadmoreBtn = getLoadMore(document, loadmoreBtn);
  7818. loadmoreBtn && emuClick(loadmoreBtn);
  7819. }, 500);
  7820. }
  7821. break;
  7822. }
  7823. }
  7824. return true;
  7825. }
  7826. _unsafeWindow.addEventListener('message', messageHandler, true);
  7827. scrollHandler = e => {
  7828. if (urlChanged && !isLoading) {
  7829. ruleParser.initPage(() => {});
  7830. urlChanged = false;
  7831. loadingMore = false;
  7832. return;
  7833. }
  7834. if (isPause) return;
  7835. if (!loadingMore) {
  7836. loadmoreBtn = getLoadMore(document, loadmoreBtn);
  7837. if (loadmoreBtn) {
  7838. if (isInViewPort(loadmoreBtn)) {
  7839. emuClick(loadmoreBtn);
  7840. loadingMore = true;
  7841. setTimeout(() => {loadingMore = false}, 200);
  7842. }
  7843. } else {
  7844. loadingMore = true;
  7845. if (!ruleParser.curSiteRule.smart || checkLoadMoreTimes++ < 3) {
  7846. setTimeout(() => {loadingMore = false}, 200);
  7847. }
  7848. }
  7849. }
  7850. if (!isLoading && !stopScroll) {
  7851. checkScrollReach();
  7852. }
  7853. ruleParser.changeVisibility();
  7854. let curScroll = getBody(document).scrollTop || document.documentElement.scrollTop;
  7855. if (ruleParser.curSiteRule.lockScroll) {
  7856. if (isLoading && Math.abs(lastScroll - curScroll) > 350) {
  7857. getBody(document).scrollTop = lastScroll;
  7858. document.documentElement.scrollTop = lastScroll;
  7859. } else {
  7860. lastScroll = curScroll;
  7861. }
  7862. }
  7863. if (targetY >= 0) {
  7864. if (Math.abs(targetY - curScroll) < 100) {
  7865. targetY = -1;
  7866. }
  7867. }
  7868. if (curScroll <= 20 && curScroll > 0) {
  7869. if (sideController.inited) {
  7870. sideController.pagenum.innerHTML = createHTML("1");
  7871. }
  7872. }
  7873. };
  7874. dblclickHandler = e => {
  7875. if (forceState == 1 || compareNodeName(e.target, ["input", "textarea", "select", "a", "button", "svg", "use", "img", "path"])) return;
  7876. if (!rulesData.dbClick2StopKey) {
  7877. if ((rulesData.dbClick2StopCtrl && !e.ctrlKey) ||
  7878. (rulesData.dbClick2StopAlt && !e.altKey) ||
  7879. (rulesData.dbClick2StopShift && !e.shiftKey) ||
  7880. (rulesData.dbClick2StopMeta && !e.metaKey)) {
  7881. return;
  7882. }
  7883. }
  7884. if (!compareNodeName(e.target, ["body"]) && !e.target.classList.contains('pagetual_pageBar')) {
  7885. try {
  7886. let selection = window.getSelection();
  7887. let selStr = selection.toString().trim();
  7888. if (!selStr) {
  7889. selection = selection.getRangeAt(0);
  7890. selStr = selection && selection.cloneContents().children[0];
  7891. if (selStr && !compareNodeName(selStr, ["img"])) selStr = false;
  7892. }
  7893. if (selStr) {
  7894. return;
  7895. }
  7896. } catch (e) {}
  7897. }
  7898. if (rulesData.dbClick2Stop && (ruleParser.nextLinkHref || loadmoreBtn)) {
  7899. setTimeout(() => {
  7900. if (rulesData.hideBarButNoStop || rulesData.hideBar) {
  7901. changeHideBar(!isHideBar);
  7902. }
  7903. if (!rulesData.hideBarButNoStop) {
  7904. changeStop(!isPause);
  7905. showTips(i18n(isPause ? "disable" : "enable"));
  7906. }
  7907. if (!isPause) {
  7908. checkScrollReach();
  7909. }
  7910. }, 10);
  7911. }
  7912. };
  7913. document.addEventListener('dblclick', dblclickHandler);
  7914. clickToResetHandler = e => {
  7915. if (!ruleParser.nextLinkHref) isLoading = false;
  7916. };
  7917. document.addEventListener('click', clickToResetHandler);
  7918. if (rulesData.dbClick2StopKey) {
  7919. keydownHandler = e => {
  7920. if ((rulesData.dbClick2StopCtrl && !e.ctrlKey) ||
  7921. (rulesData.dbClick2StopAlt && !e.altKey) ||
  7922. (rulesData.dbClick2StopShift && !e.shiftKey) ||
  7923. (rulesData.dbClick2StopMeta && !e.metaKey)) {
  7924. return;
  7925. }
  7926. if (document.activeElement &&
  7927. (compareNodeName(document.activeElement, ["input", "textarea"]) ||
  7928. document.activeElement.contentEditable == 'true')) {
  7929. return;
  7930. }
  7931. var key = e.key.toLowerCase();
  7932. if (rulesData.dbClick2StopKey.toLowerCase() == key) {
  7933. if (forceState == 1) {
  7934. forceState = 0;
  7935. showTips(i18n("enableSiteTips"));
  7936. changeStop(false, true);
  7937. } else {
  7938. forceState = 1;
  7939. showTips(i18n("disableSiteTips"));
  7940. changeStop(true, true);
  7941. sideController.remove();
  7942. }
  7943. if (!ruleParser.curSiteRule.url) {
  7944. setListData("forceState", location.host, forceState);
  7945. setTimeout(() => {
  7946. location.reload();
  7947. }, 500);
  7948. }
  7949. }
  7950. };
  7951. document.addEventListener('keydown', keydownHandler);
  7952. }
  7953. if (ruleParser.curSiteRule.listenHashChange) {
  7954. hashchangeHandler = () => {
  7955. isPause = true;
  7956. ruleParser.urlChanged();
  7957. if (!ruleParser.nextLinkHref) isLoading = false;
  7958. };
  7959. window.addEventListener('hashchange', hashchangeHandler, false);
  7960. }
  7961. let manualMode = typeof ruleParser.curSiteRule.manualMode == 'undefined' ? rulesData.manualMode : ruleParser.curSiteRule.manualMode;
  7962. if (manualMode) {
  7963. manualModeKeyHandler = e => {
  7964. if (document.activeElement &&
  7965. (compareNodeName(document.activeElement, ["input", "textarea"]) ||
  7966. document.activeElement.contentEditable == 'true')) {
  7967. return;
  7968. }
  7969. if (e.keyCode == 39) {
  7970. clickNext();
  7971. } else if (e.keyCode == 37) {
  7972. history.back();
  7973. }
  7974. };
  7975. document.addEventListener('keydown', manualModeKeyHandler);
  7976. pagetualNextHandler = () => {
  7977. clickNext();
  7978. };
  7979. document.addEventListener('pagetual.next', pagetualNextHandler, false);
  7980. return;
  7981. }
  7982. if (rulesData.arrowToScroll) {
  7983. keyupHandler = e => {
  7984. if (document.activeElement &&
  7985. (compareNodeName(document.activeElement, ["input", "textarea"]) ||
  7986. document.activeElement.contentEditable == 'true')) {
  7987. return;
  7988. }
  7989. if (e.keyCode == 39) {
  7990. let nextPageBar=getPageBar().nextBar;
  7991. if (nextPageBar) {
  7992. scrollToPageBar(nextPageBar);
  7993. } else {
  7994. let scrollTop = getBody(document).scrollTop || document.documentElement.scrollTop;
  7995. window.scrollTo({ top: scrollTop + (window.innerHeight || document.documentElement.clientHeight), behavior: 'instant'});
  7996. }
  7997. } else if (e.keyCode == 37) {
  7998. let prePageBar = getPageBar().preBar;
  7999. if (prePageBar) {
  8000. scrollToPageBar(prePageBar);
  8001. } else {
  8002. let scrollTop = getBody(document).scrollTop || document.documentElement.scrollTop;
  8003. window.scrollTo({ top: scrollTop - (window.innerHeight || document.documentElement.clientHeight), behavior: 'instant'});
  8004. }
  8005. }
  8006. };
  8007. document.addEventListener('keyup', keyupHandler);
  8008. }
  8009. if (!ruleParser.curSiteRule.wheel) {
  8010. document.addEventListener('scroll', scrollHandler, true);
  8011. }
  8012. document.addEventListener('wheel', scrollHandler, true);
  8013. }
  8014.  
  8015. let hideTipsTimeout;
  8016. function showTips(content, href, time, wordColor, backColor) {
  8017. initView();
  8018. document.documentElement.appendChild(tipsWords);
  8019. tipsWords.style.color = wordColor || 0xFFFFFF;
  8020. tipsWords.style.backgroundColor = backColor || 0x000;
  8021. let _time = 1500;
  8022. if (href) {
  8023. _time = 3500;
  8024. tipsWords.innerHTML = createHTML(`<a href='${href}' target='_blank'>${content}</a>`);
  8025. tipsWords.style.pointerEvents = 'all';
  8026. } else {
  8027. tipsWords.innerHTML = createHTML(content);
  8028. }
  8029. tipsWords.style.marginLeft = -tipsWords.offsetWidth / 2 + "px";
  8030. setTimeout(() => {
  8031. tipsWords.style.marginLeft = -tipsWords.offsetWidth / 2 + "px";
  8032. }, 0);
  8033. setTimeout(() => {
  8034. tipsWords.style.opacity = 0.8;
  8035. clearTimeout(hideTipsTimeout);
  8036. hideTipsTimeout = setTimeout(() => {
  8037. tipsWords.style.opacity = 0;
  8038. tipsWords.style.pointerEvents = '';
  8039. }, time || _time);
  8040. }, 1);
  8041. }
  8042.  
  8043. const loadmoreReg = /^\s*((点击)?加载更多|(點擊)?加載更多|load\s*more( comments)?|もっと読み込む)[\.…▼\s]*$/i;
  8044. const defaultLoadmoreSel = ".loadMore,.LoadMore,[class*='load-more'],button.show_more,.button-show-more,button[data-testid='more-results-button'],#btn_preview_remain,.view-more-btn";
  8045. function getLoadMore(doc, loadmoreBtn) {
  8046. if (!loadmoreBtn || !getBody(doc).contains(loadmoreBtn) || /less/.test(loadmoreBtn.innerText)) loadmoreBtn = null;
  8047. if (!ruleParser.curSiteRule.smart && !ruleParser.curSiteRule.loadMore) return null;
  8048. if (loadmoreBtn) return loadmoreBtn;
  8049. let btnSel = ruleParser.curSiteRule.loadMore || defaultLoadmoreSel;
  8050. if (btnSel) {
  8051. loadmoreBtn = getElement(btnSel, doc, null, true);
  8052. }
  8053. if (!loadmoreBtn) {
  8054. let buttons = getBody(doc).querySelectorAll("input,button,a,div[onclick]");
  8055. for (let i = 0; i < buttons.length; i++) {
  8056. let button = buttons[i];
  8057. if (!button.innerText || button.innerText.length > 20) continue;
  8058. if (button && loadmoreReg.test(button.innerText)) {
  8059. loadmoreBtn = button;
  8060. break;
  8061. }
  8062. }
  8063. }
  8064. if (loadmoreBtn && !ruleParser.curSiteRule.loadMore && loadmoreBtn.dataset.ajax !== "true") {
  8065. let href = loadmoreBtn.getAttribute("href");
  8066. if (href && href != "/" && !ruleParser.hrefIsJs(href)) {
  8067. loadmoreBtn = null;
  8068. }
  8069. }
  8070. if (loadmoreBtn && /less/.test(loadmoreBtn.innerText)) loadmoreBtn = null;
  8071. if (loadmoreBtn) debug(loadmoreBtn, 'Load more button');
  8072. return loadmoreBtn;
  8073. }
  8074.  
  8075. var targetY = -1;
  8076. function scrollToPageBar(bar) {
  8077. if (window.pageYOffset == 0) {
  8078. bar.scrollIntoView({ behavior: "smooth", block: "start", inline: "nearest" });
  8079. } else {
  8080. let yOffset = -20;
  8081. if (typeof ruleParser.curSiteRule.pageBarTop !== 'undefined') {
  8082. yOffset = -ruleParser.curSiteRule.pageBarTop;
  8083. }
  8084. targetY = bar.getBoundingClientRect().top + window.pageYOffset + yOffset;
  8085. window.scrollTo({ top: targetY, behavior: 'smooth'});
  8086. }
  8087. }
  8088.  
  8089. const pageNumReg=/[&\/\?](p=|page[=\/_-]?)\d+|[_-]\d+\./;
  8090. function createPageBar(url) {
  8091. curPage++;
  8092. sideController.setup();
  8093. let posEle = null;
  8094. let scrollH = Math.max(document.documentElement.scrollHeight, getBody(document).scrollHeight);
  8095. let insert = ruleParser.getInsert();
  8096. if (!insert || !insert.parentNode) return;
  8097. if (forceState == 2) {
  8098. posEle = getBody(document);
  8099. posEle = posEle.children[posEle.children.length - 1];
  8100. } else {
  8101. posEle = insert;
  8102. }
  8103. while (posEle && !posEle.offsetParent) {
  8104. posEle = posEle.previousElementSibling || posEle.parentNode;
  8105. }
  8106. if (posEle) {
  8107. let actualBottom = getElementBottom(posEle);
  8108. bottomGap = scrollH - actualBottom + (window.innerHeight || document.documentElement.clientHeight) * rate;
  8109. if (bottomGap < 100) bottomGap = 100;
  8110. } else {
  8111. bottomGap = 1000;
  8112. }
  8113. if (hidePageBar) return null;
  8114. url = url.replace(/#p{.*/, "");
  8115. let example = (ruleParser.curSiteRule.insertPos == 2 || ruleParser.curSiteRule.insertPos == "in") ? insert.children[0] : (insert.parentNode.children[0] || insert);
  8116. while (example && (compareNodeName(example, ["script", "style"]) || example.className == "pagetual_pageBar")) {
  8117. example = example.nextElementSibling;
  8118. }
  8119. if (!example || !example.parentNode) example = insert;
  8120. if (example.nodeType != 1) {
  8121. example = example.previousElementSibling || example.parentNode;
  8122. if (!example || example.nodeType != 1) return;
  8123. }
  8124. let exampleStyle = _unsafeWindow.getComputedStyle(example);
  8125. let inTable, inLi;
  8126. if (forceState == 2) {
  8127. inTable = inLi = false;
  8128. } else {
  8129. inTable = compareNodeName(example.parentNode, ["table", "tbody"]) ||
  8130. compareNodeName(example, ["tr", "tbody"]) ||
  8131. exampleStyle.display == "table-row" ||
  8132. (example.nextElementSibling && compareNodeName(example.nextElementSibling, ["tr", "tbody"]));
  8133. inLi = compareNodeName(example, ["li"]) || (example.nextElementSibling && compareNodeName(example.nextElementSibling, ["li"]));
  8134. }
  8135. let pageBar = document.createElement(inTable ? "tr" : (inLi ? "li" : "div"));
  8136. let upSpan = document.createElement("span");
  8137. let downSpan = document.createElement("span");
  8138. let pageText = document.createElement("a");
  8139. let pageNum;
  8140. pageBar.className = isHideBar ? "pagetual_pageBar hide" : "pagetual_pageBar";
  8141. pageBar.id = "pagetual_pageBar" + curPage;
  8142. pageBar.setAttribute("translate", "no");
  8143. if (isPause) {
  8144. pageBar.classList.add("stop");
  8145. }
  8146. pageBar.style.cssText = pageBarStyle;
  8147. pageBar.title = i18n(isPause ? "enable" : "disable");
  8148. upSpan.innerHTML = createHTML(upSvg);
  8149. upSpan.children[0].style.cssText = upSvgCSS;
  8150. upSpan.title = i18n("toTop");
  8151. downSpan.innerHTML = createHTML(downSvg);
  8152. downSpan.children[0].style.cssText = downSvgCSS;
  8153. downSpan.title = i18n("toBottom");
  8154. upSpan.style.cssText = initStyle;
  8155. downSpan.style.cssText = initStyle;
  8156. pageText.href = url;
  8157. pageText.style.cssText = pageTextStyle;
  8158. pageText.title = i18n("current");
  8159. if (openInNewTab == 1) pageText.target = "_blank";
  8160. pageBar.appendChild(upSpan);
  8161. pageBar.appendChild(pageText);
  8162. let touched = false;
  8163. let touchBodyHandler = e => {
  8164. touched = false;
  8165. getBody(document).removeEventListener('touchstart', touchBodyHandler, { passive: false, capture: false });
  8166. };
  8167. pageText.addEventListener("touchstart", e => {
  8168. if (touched) return;
  8169. touched = true;
  8170. pageText.style.pointerEvents = 'none';
  8171. setTimeout(() => {
  8172. pageText.style.pointerEvents = 'all';
  8173. }, 250);
  8174. getBody(document).addEventListener("touchstart", touchBodyHandler, { passive: false, capture: false });
  8175. }, { passive: false, capture: false });
  8176. if (ruleParser.nextTitle) {
  8177. pageText.innerHTML = createHTML(ruleParser.nextTitle + " ");
  8178. pageText.title = ruleParser.nextTitle;
  8179. }
  8180. if (ruleParser.curSiteRule.pageNum || pageNumReg.test(url)) {
  8181. pageText.innerHTML = createHTML(pageText.innerHTML + i18n("page"));
  8182. pageNum = document.createElement("span");
  8183. let num = ruleParser.getPageNumFromUrl(url, curPage);
  8184. pageNum.innerHTML = createHTML(num + "<i style='font-size: 0;'>&nbsp;</i>");
  8185. pageNum.className = "pagetual_pageNum";
  8186. pageNum.title = i18n("inputPageNum");
  8187. pageNum.style.cssText = pageTextStyle;
  8188. pageNum.style.cursor = "pointer";
  8189. pageNum.style.color = "";
  8190. pageNum.style.marginLeft = "5px";
  8191. pageNum.addEventListener("click", e => {
  8192. let pageInput = prompt(i18n("inputPageNum"), num || "1");
  8193. if (pageInput) {
  8194. let localPageBar = document.querySelector("#pagetual_pageBar" + pageInput);
  8195. if (localPageBar) {
  8196. scrollToPageBar(localPageBar);
  8197. } else {
  8198. let pageLink = ruleParser.getLinkByPage(url, pageInput);
  8199. if (pageLink) {
  8200. _GM_openInTab(pageLink, {active:true});
  8201. }
  8202. }
  8203. }
  8204. e.preventDefault();
  8205. e.stopPropagation();
  8206. });
  8207. pageBar.appendChild(pageNum);
  8208. } else {
  8209. pageText.innerHTML = createHTML(pageText.innerHTML + i18n("page") + curPage + "<i style='font-size: 0;'>&nbsp;</i>");
  8210. }
  8211. let preBtn = document.createElement("span");
  8212. preBtn.innerHTML = createHTML("∧");
  8213. preBtn.title = i18n("prevPage");
  8214. preBtn.className = "prevScreen";
  8215. 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; ";
  8216. let nextBtn = document.createElement("span");
  8217. nextBtn.innerHTML = createHTML("∨");
  8218. nextBtn.title = i18n("nextPage");
  8219. nextBtn.className = "nextScreen";
  8220. 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; ";
  8221. let localPage = curPage;
  8222. preBtn.addEventListener("click", e => {
  8223. e.stopPropagation();
  8224. e.preventDefault();
  8225. let prePageBar = document.querySelector("#pagetual_pageBar" + (localPage - 1));
  8226. if (prePageBar) {
  8227. scrollToPageBar(prePageBar);
  8228. } else {
  8229. let scrollTop = getBody(document).scrollTop || document.documentElement.scrollTop;
  8230. targetY = scrollTop - (window.innerHeight || document.documentElement.clientHeight);
  8231. window.scrollTo({ top: targetY, behavior: 'smooth'});
  8232. }
  8233. });
  8234. nextBtn.addEventListener("click", e => {
  8235. e.stopPropagation();
  8236. e.preventDefault();
  8237. let nextPageBar = document.querySelector("#pagetual_pageBar" + (localPage + 1));
  8238. if (nextPageBar) {
  8239. scrollToPageBar(nextPageBar);
  8240. } else {
  8241. scrollH = Math.max(document.documentElement.scrollHeight, getBody(document).scrollHeight);
  8242. targetY = scrollH || 9999999;
  8243. window.scrollTo({ top: targetY, behavior: 'smooth'});
  8244. }
  8245. });
  8246. if (!rulesData.hideBarArrow) {
  8247. pageText.insertBefore(preBtn, pageText.firstChild);
  8248. pageText.insertBefore(nextBtn, pageText.firstChild);
  8249. }
  8250. if (curForceIframe) {
  8251. let bgRing = document.createElement("span");
  8252. bgRing.className = "refreshRing";
  8253. bgRing.style.display = "none";
  8254. bgRing.innerHTML = createHTML(upSvg);
  8255. pageText.title = "Refresh";
  8256. pageText.appendChild(bgRing);
  8257. pageText.addEventListener("click", e => {
  8258. e.stopPropagation();
  8259. if (e.ctrlKey || e.altKey || e.shiftKey || e.metaKey) return;
  8260. e.preventDefault();
  8261. let nextEle = pageBar && pageBar.nextElementSibling;
  8262. if (nextEle && nextEle.name == 'pagetual-iframe') {
  8263. if (curForceIframe == nextEle) {
  8264. nextEle.setAttribute("loaded", "refresh");
  8265. }
  8266. nextEle.src = nextEle.src;
  8267. }
  8268. });
  8269. } else if (rulesData.pageBarMenu) {
  8270. pageText.addEventListener("click", e => {
  8271. e.stopPropagation();
  8272. if (e.ctrlKey || e.altKey || e.shiftKey || e.metaKey) return;
  8273. e.preventDefault();
  8274. picker.start();
  8275. });
  8276. }
  8277. pageBar.appendChild(downSpan);
  8278. if (forceState == 2) {
  8279. pageBar.style.width = "99%";
  8280. } else {
  8281. let parentStyle = _unsafeWindow.getComputedStyle(example.parentNode);
  8282. let parentWidth = example.parentNode.offsetWidth || parseInt(parentStyle.width);
  8283. pageBar.style.width = parentWidth - parseInt(parentStyle.paddingLeft) - parseInt(parentStyle.paddingRight) - 10 + "px";
  8284. pageBar.style.margin = '10px 5px';
  8285. if (parentStyle.display == "grid" || parentStyle.display == "inline-grid") {
  8286. pageBar.style.gridColumn = "1/-1";
  8287. }
  8288. if (inTable) {
  8289. example = compareNodeName(example, ["tr", "tbody"]) ? example : example.nextElementSibling || example;
  8290. if (compareNodeName(example, ["tbody"])) example = example.querySelector("tr");
  8291. let nextTr = example;
  8292. while (nextTr && nextTr.children.length == 0) nextTr = nextTr.nextElementSibling;
  8293. if (nextTr) example = nextTr;
  8294. let tdNum = 0;
  8295. if (exampleStyle.display == "table-row") {
  8296. [].forEach.call(example.children, el => {
  8297. tdNum += el.colSpan || 1;
  8298. });
  8299. } else {
  8300. [].forEach.call(example.children, el => {
  8301. if (compareNodeName(el, ["td", "th"])) {
  8302. tdNum += el.colSpan || 1;
  8303. }
  8304. });
  8305. }
  8306. pageBar.style.cssText = "";
  8307. pageBar.style.display = "table-row";
  8308. pageBar.style.backgroundColor = "unset";
  8309. pageBar.style.lineHeight = "20px";
  8310. pageBar.style.boxShadow = "";
  8311. let td = document.createElement("td");
  8312. td.colSpan = tdNum || 1;
  8313. let inTd = document.createElement("div");
  8314. inTd.style.cssText = pageBarStyle;
  8315. inTd.style.display = "";
  8316. inTd.className = pageBar.className;
  8317. pageBar.className = "";
  8318. inTd.appendChild(upSpan);
  8319. inTd.appendChild(pageText);
  8320. if (pageNum) inTd.appendChild(pageNum);
  8321. inTd.appendChild(downSpan);
  8322. td.appendChild(inTd);
  8323. pageBar.appendChild(td);
  8324. } else if (inLi) {
  8325. example = compareNodeName(example, ["li"]) ? example : example.nextElementSibling || example;
  8326. pageBar.style.opacity = 1;
  8327. pageBar.style.display = getComputedStyle(example).display;
  8328. pageBar.style.backgroundColor = "unset";
  8329. pageBar.style.lineHeight = "20px";
  8330. pageBar.style.boxShadow = "";
  8331. pageBar.style.border = "";
  8332. pageBar.style.width = "";
  8333. pageBar.style.maxWidth = "unset";
  8334. pageBar.style.flex = "auto";
  8335. let inTd = document.createElement("div");
  8336. inTd.style.cssText = pageBarStyle;
  8337. inTd.style.display = "";
  8338. inTd.style.margin = "0"
  8339. inTd.style.padding = "0 0";
  8340. inTd.style.textAlign = "center";
  8341. inTd.style.minWidth = "150px";
  8342. inTd.style.width = 'calc(100% - 20px)';
  8343. inTd.className = pageBar.className;
  8344. pageBar.className = "";
  8345. inTd.appendChild(upSpan);
  8346. inTd.appendChild(pageText);
  8347. if (pageNum) inTd.appendChild(pageNum);
  8348. inTd.appendChild(downSpan);
  8349. if (pageBar.style.display === 'table-row') {
  8350. let td = document.createElement("td");
  8351. td.colSpan = example.children.length;
  8352. td.style.width = '100%';
  8353. td.appendChild(inTd);
  8354. pageBar.appendChild(td);
  8355. } else {
  8356. inTd.style.width = '100%';
  8357. pageBar.appendChild(inTd);
  8358. }
  8359. }
  8360. }
  8361.  
  8362. upSpan.addEventListener("click", e => {
  8363. getBody(document).scrollTop = 0;
  8364. document.documentElement.scrollTop = 0;
  8365. e.preventDefault();
  8366. e.stopPropagation();
  8367. });
  8368. downSpan.addEventListener("click", e => {
  8369. if (!e.altKey && !e.ctrlKey && !e.shiftKey && !e.metaKey) {
  8370. changeStop(true);
  8371. }
  8372. pageBar.title = i18n(isPause ? "enable" : "disable");
  8373. scrollH = Math.max(document.documentElement.scrollHeight, getBody(document).scrollHeight);
  8374. getBody(document).scrollTop = scrollH || 9999999;
  8375. document.documentElement.scrollTop = scrollH || 9999999;
  8376. e.preventDefault();
  8377. e.stopPropagation();
  8378. });
  8379. pageBar.addEventListener("click", e => {
  8380. changeStop(!isPause, true);
  8381. pageBar.title = i18n(isPause ? "enable" : "disable");
  8382. });
  8383. ruleParser.insertElement(pageBar);
  8384. ruleParser.runPageBar(pageBar);
  8385.  
  8386. if (sideController.inited) {
  8387. try {
  8388. let observer = new IntersectionObserver(entries => {
  8389. if (entries[0].intersectionRatio > 0) {
  8390. sideController.pagenum.innerHTML = createHTML(localPage);
  8391. }
  8392. });
  8393. observer.observe(pageBar);
  8394. } catch(e) {}
  8395. }
  8396. return pageBar;
  8397. }
  8398.  
  8399. async function waitForElement(sel, doc, maxTime) {
  8400. if (!sel) return null;
  8401. return new Promise((resolve) => {
  8402. let passedTime = 0;
  8403. let checkInv = setInterval(() => {
  8404. let result = getElement(sel, doc, null, true);
  8405. if (result) {
  8406. clearInterval(checkInv);
  8407. resolve(result);
  8408. } else if (maxTime) {
  8409. passedTime += 100;
  8410. if (passedTime >= maxTime) {
  8411. clearInterval(checkInv);
  8412. resolve(result);
  8413. }
  8414. }
  8415. }, 100);
  8416. });
  8417. }
  8418.  
  8419. async function clickAction(sel, doc) {
  8420. let btn = await waitForElement(sel, doc);
  8421. emuClick(btn, doc);
  8422. }
  8423.  
  8424. async function enterAction(sel, doc) {
  8425. let btn = await waitForElement(sel, doc);
  8426. let eventParam = { key: "Enter", keyCode: 13, bubbles: true };
  8427. let event = new KeyboardEvent('keydown', eventParam);
  8428. btn.dispatchEvent(event);
  8429. event = new KeyboardEvent('keyup', eventParam);
  8430. btn.dispatchEvent(event);
  8431. event = new KeyboardEvent('keypress', eventParam);
  8432. btn.dispatchEvent(event);
  8433. }
  8434.  
  8435. async function inputAction(sel, v, doc) {
  8436. let input = await waitForElement(sel, doc);
  8437. let event = new Event('focus', { bubbles: true });
  8438. input.dispatchEvent(event);
  8439. let lastValue = input.value;
  8440. if (input.nodeName.toUpperCase() == "INPUT") {
  8441. var nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value").set;
  8442. nativeInputValueSetter.call(input, v);
  8443. } else if (input.nodeName.toUpperCase() == "TEXTAREA") {
  8444. var nativeTextareaValueSetter = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, "value").set;
  8445. nativeTextareaValueSetter.call(input, v);
  8446. } else {
  8447. input.innerHTML = createHTML(v);
  8448. }
  8449. event = new Event('input', { bubbles: true });
  8450. let tracker = input._valueTracker;
  8451. if (tracker) {
  8452. tracker.setValue(lastValue);
  8453. }
  8454. input.dispatchEvent(event);
  8455. event = new Event('change', { bubbles: true });
  8456. input.dispatchEvent(event);
  8457. debug(input, `input ${sel}`);
  8458. }
  8459.  
  8460. function emuClick(btn, doc) {
  8461. if (!doc) doc = document;
  8462. let curScroll = getBody(doc).scrollTop || doc.documentElement.scrollTop;
  8463. let orgHref = btn.getAttribute('href');
  8464. if (orgHref && orgHref.replace(location.origin + location.pathname, "").indexOf("#") === 0) {
  8465. let hashAction = e => {
  8466. e.preventDefault();
  8467. getBody(doc).scrollTop = curScroll;
  8468. doc.documentElement.scrollTop = curScroll;
  8469. btn.removeEventListener('click', hashAction, false);
  8470. };
  8471. btn.addEventListener('click', hashAction, false);
  8472. }
  8473. if (!PointerEvent) return btn.click();
  8474. let eventParam = {
  8475. isTrusted: true,
  8476. altKey: false,
  8477. azimuthAngle: 0,
  8478. bubbles: true,
  8479. button: 0,
  8480. buttons: 0,
  8481. clientX: 1,
  8482. clientY: 1,
  8483. cancelBubble: false,
  8484. cancelable: true,
  8485. composed: true,
  8486. ctrlKey: false,
  8487. defaultPrevented: false,
  8488. detail: 1,
  8489. eventPhase: 2,
  8490. fromElement: null,
  8491. height: 1,
  8492. isPrimary: false,
  8493. metaKey: false,
  8494. pointerId: 1,
  8495. pointerType: "mouse",
  8496. pressure: 0,
  8497. relatedTarget: null,
  8498. returnValue: true,
  8499. shiftKey: false,
  8500. toElement: null,
  8501. twist: 0,
  8502. which: 1
  8503. };
  8504. let mouseEvent = new PointerEvent("mousedown", eventParam);
  8505. btn.dispatchEvent(mouseEvent);
  8506. mouseEvent = new PointerEvent("mouseup", eventParam);
  8507. btn.dispatchEvent(mouseEvent);
  8508. let dispatchTouchEvent = (ele, type) => {
  8509. let touchEvent;
  8510. try {
  8511. touchEvent = document.createEvent('TouchEvent')
  8512. touchEvent.initTouchEvent(type, true, true)
  8513. } catch (err) {
  8514. try {
  8515. touchEvent = document.createEvent('UIEvent')
  8516. touchEvent.initUIEvent(type, true, true)
  8517. } catch (err) {
  8518. touchEvent = document.createEvent('Event')
  8519. touchEvent.initEvent(type, true, true)
  8520. }
  8521. }
  8522. if (touchEvent) {
  8523. try {
  8524. touchEvent.targetTouches = [{
  8525. pageX: 1,
  8526. pageY: 1,
  8527. clientX: 1,
  8528. clientY: 1,
  8529. target: btn
  8530. }];
  8531. touchEvent.touches = [{
  8532. pageX: 1,
  8533. pageY: 1,
  8534. clientX: 1,
  8535. clientY: 1,
  8536. target: btn
  8537. }];
  8538. touchEvent.changedTouches = [{
  8539. pageX: 1,
  8540. pageY: 1,
  8541. clientX: 1,
  8542. clientY: 1,
  8543. target: btn
  8544. }];
  8545. } catch (err) {}
  8546. ele.dispatchEvent(touchEvent);
  8547. }
  8548. }
  8549. dispatchTouchEvent(btn, "touchstart");
  8550. dispatchTouchEvent(btn, "touchend");
  8551.  
  8552. btn.click();
  8553. }
  8554.  
  8555. function emuInput(input, v) {
  8556. let result = false;
  8557. if (!input) return true;
  8558. let event = new Event('focus', { bubbles: true });
  8559. input.dispatchEvent(event);
  8560. let lastValue = input.value;
  8561. if (input.type == 'file') {
  8562. let file = v;
  8563. let blob = new Blob([file], {
  8564. type: 'text/plain'
  8565. });
  8566. file = new File([blob], 'noname.txt', { type: blob.type });
  8567. let dataTransfer = new DataTransfer();
  8568. dataTransfer.items.add(file);
  8569. input.files = dataTransfer.files;
  8570. v = "c:/fakepath/fakefile";
  8571. } else if (/INPUT/i.test(input.nodeName)) {
  8572. var nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value").set;
  8573. nativeInputValueSetter.call(input, v);
  8574. } else if (/SELECT/i.test(input.nodeName)) {
  8575. var nativeSelectValueSetter = Object.getOwnPropertyDescriptor(window.HTMLSelectElement.prototype, "value").set;
  8576. nativeSelectValueSetter.call(input, v);
  8577. } else if (input.nodeName.toUpperCase() == "TEXTAREA") {
  8578. var nativeTextareaValueSetter = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, "value").set;
  8579. nativeTextareaValueSetter.call(input, v);
  8580. } else {
  8581. input.innerHTML = createHTML(v);
  8582. }
  8583. event = new Event('input', { bubbles: true });
  8584. let tracker = input._valueTracker;
  8585. if (tracker) {
  8586. tracker.setValue(lastValue);
  8587. }
  8588. input.dispatchEvent(event);
  8589. event = new Event('change', { bubbles: true });
  8590. input.dispatchEvent(event);
  8591. return result;
  8592. }
  8593.  
  8594. var failFromIframe = 0;
  8595. var inCors = false;
  8596. var checkRemoveIntv;
  8597. function requestFromIframe(url, callback){
  8598. if (location.protocol === 'https:' && !/^https:/.test(url)) {
  8599. ruleParser.noValidContent(url);
  8600. }
  8601. url = url.indexOf('=') == -1 ? url.replace(/#[^#]*/,"") : url;
  8602. let iframe = document.createElement('iframe');
  8603. iframe.name = 'pagetual-iframe';
  8604. iframe.width = '100%';
  8605. iframe.height = '1000';
  8606. iframe.frameBorder = '0';
  8607. if (ruleParser.curSiteRule.sandbox != false) {
  8608. iframe.sandbox = "allow-same-origin allow-scripts allow-popups allow-forms";
  8609. }
  8610. 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;';
  8611. let waitTime = 100, checkEval;
  8612. ruleParser.runWait((_checkEval, _waitTime) => {
  8613. if (_checkEval) {
  8614. checkEval = _checkEval;
  8615. }
  8616. if (_waitTime) {
  8617. waitTime = _waitTime;
  8618. }
  8619. });
  8620. if (checkRemoveIntv) clearInterval(checkRemoveIntv);
  8621. checkRemoveIntv = setInterval(() => {
  8622. if (!iframe || !getBody(document).contains(iframe)) {
  8623. clearInterval(checkRemoveIntv);
  8624. loadPageOver();
  8625. }
  8626. }, 500);
  8627. let loadedHandler = async e => {
  8628. if (e.data != 'pagetual-iframe:DOMLoaded' && e.type != 'load') return;
  8629. clearInterval(checkRemoveIntv);
  8630. window.removeEventListener('message', loadedHandler, false);
  8631. iframe.removeEventListener('load', loadedHandler, false);
  8632. let pageEleTryTimes = 0;
  8633. async function checkIframe() {
  8634. if (urlChanged || isPause) {
  8635. return callback(false, false);
  8636. }
  8637. try {
  8638. let doc = iframe.contentDocument || iframe.contentWindow.document;
  8639. if (checkEval && !await checkEval(doc)) {
  8640. setTimeout(() => {
  8641. checkIframe();
  8642. }, waitTime);
  8643. return;
  8644. } else {
  8645. let preCode = ruleParser.curSiteRule.pagePre, eles = null;
  8646. if (preCode) {
  8647. try {
  8648. let preResult;
  8649. if (typeof preCode == 'function') {
  8650. preResult = await preCode(doc.documentElement.innerHTML, doc);
  8651. } else if (preCode.length == 2) {
  8652. preResult = doc.documentElement.innerHTML.replace(new RegExp(preCode[0], "gi"), preCode[1]);
  8653. } else {
  8654. preResult = await new AsyncFunction("response", "doc", '"use strict";' + preCode)(doc.documentElement.innerHTML, doc);
  8655. }
  8656. if (typeof preResult !== "undefined") {
  8657. if (typeof preResult === "string") {
  8658. doc.documentElement.innerHTML = preResult;
  8659. } else eles = preResult;
  8660. }
  8661. } catch(e) {
  8662. debug(e);
  8663. }
  8664. }
  8665. let base = doc.querySelector("base");
  8666. ruleParser.basePath = (base && base.href) || url;
  8667. if (eles === null) eles = ruleParser.getPageElement(doc, iframe.contentWindow, pageEleTryTimes < 25);
  8668. if (eles && eles.length > 0) {
  8669. await ruleParser.hookUrl(doc);
  8670. await callback(doc, eles);
  8671. } else if (pageEleTryTimes++ < 100) {
  8672. getBody(doc).scrollTop = 9999999;
  8673. if (doc.documentElement) {
  8674. doc.documentElement.scrollTop = 9999999;
  8675. }
  8676. setTimeout(() => {
  8677. checkIframe();
  8678. }, waitTime);
  8679. return;
  8680. } else {
  8681. if (failFromIframe++ > 2) {
  8682. failFromIframe = 0;
  8683. debug("Stop as failFromIframe");
  8684. changeStop(true);
  8685. callback(false, false);
  8686. } else {
  8687. ruleParser.noValidContent(url);
  8688. callback(false, false);
  8689. }
  8690. }
  8691. }
  8692. } catch(e) {
  8693. inCors = true;
  8694. if (forceState === 3) {
  8695. debug("Stop as cors");
  8696. isPause = true;
  8697. }
  8698. if (!ruleParser.curSiteRule.pageElement) {
  8699. ruleParser.curSiteRule.pageElement = allOfBody;
  8700. ruleParser.getInsert(true);
  8701. }
  8702. ruleParser.curSiteRule.action = 0;
  8703. ruleParser.nextLinkHref = url;
  8704. callback(false, false);
  8705. nextPage();
  8706. }
  8707. if (iframe && iframe.parentNode) iframe.parentNode.removeChild(iframe);
  8708. }
  8709. setTimeout(() => {
  8710. checkIframe();
  8711. }, waitTime);
  8712. };
  8713. let code = ruleParser.curSiteRule.iframeInit;
  8714. if (code) {
  8715. let checkReady = setInterval(() => {
  8716. let doc;
  8717. try {
  8718. doc = iframe.contentDocument || (iframe.contentWindow && iframe.contentWindow.document);
  8719. } catch(e) {
  8720. clearInterval(checkReady);
  8721. return;
  8722. }
  8723. if (doc) {
  8724. clearInterval(checkReady);
  8725. try {
  8726. Function('win', 'iframe', '"use strict";' + code)(iframe.contentWindow, iframe);
  8727. } catch(e) {
  8728. debug(e);
  8729. }
  8730. }
  8731. }, 50);
  8732. }
  8733. window.addEventListener('message', loadedHandler, false);
  8734. iframe.addEventListener('load', loadedHandler, false);
  8735. iframe.src = url;
  8736. try {
  8737. getBody(document).appendChild(iframe);
  8738. } catch (e) {
  8739. return callback(false, false);
  8740. }
  8741. }
  8742.  
  8743. var emuIframe, lastActiveUrl, orgContent, meetCors = false;
  8744. function emuPage(callback) {
  8745. let orgPage = null, preContent = null, iframeDoc, checkTimes = 0, loadmoreBtn, pageEle, nextLink, loadmoreEnd = false, waitTimes = 80, changed = false, checkNext = 0;
  8746. let activeClass = "active";
  8747. if (typeof ruleParser.curSiteRule.activeClass !== 'undefined') {
  8748. activeClass = ruleParser.curSiteRule.activeClass;
  8749. }
  8750. function returnFalse(log) {
  8751. if (curPage > 1) {
  8752. ruleParser.reachedLastPage();
  8753. } else {
  8754. sideController.remove();
  8755. }
  8756. debug(log);
  8757. isPause = true;
  8758. callback(false, false);
  8759. if (emuIframe && emuIframe.parentNode) {
  8760. emuIframe.parentNode.removeChild(emuIframe);
  8761. emuIframe = null;
  8762. }
  8763. }
  8764. async function cloneStatus() {
  8765. if (!iframeDoc) return;
  8766. let inputs = document.querySelectorAll("input:not([type=button],[type=image],[type=reset],[type=submit])");
  8767. let selectOptions = document.querySelectorAll("select>option");
  8768. [...inputs].forEach(input => {
  8769. let sel = geneSelector(input, true, true);
  8770. let mirrorEle = iframeDoc.querySelector(sel);
  8771. if (!mirrorEle) return;
  8772. emuInput(mirrorEle, input.value);
  8773. });
  8774. [...selectOptions].forEach(option => {
  8775. let sel = geneSelector(option, true, true);
  8776. let mirrorEle = iframeDoc.querySelector(sel);
  8777. if (!mirrorEle) return;
  8778. let selected = option.selected;
  8779. mirrorEle.selected = !!selected;
  8780. mirrorEle.parentNode.dispatchEvent(new Event('change'));
  8781. });
  8782. if (activeClass) {
  8783. let actives = document.querySelectorAll("." + activeClass);
  8784. for (let active of actives) {
  8785. let sel = geneSelector(active, true, true).replace("." + activeClass, "");
  8786. let mirrorEle = await waitForElement(sel, iframeDoc, 5000);
  8787. if (!mirrorEle || mirrorEle.classList.contains(activeClass)) {
  8788. continue;
  8789. }
  8790. emuClick(mirrorEle);
  8791. await sleep(300);
  8792. }
  8793. }
  8794. }
  8795. async function checkPage() {
  8796. if (isPause) return loadPageOver();
  8797. try {
  8798. iframeDoc = emuIframe.contentDocument || emuIframe.contentWindow.document;
  8799. } catch(e) {
  8800. returnFalse("Stop as cors");
  8801. return;
  8802. }
  8803. getBody(iframeDoc).scrollTop = 9999999;
  8804. if (iframeDoc.documentElement) {
  8805. iframeDoc.documentElement.scrollTop = 9999999;
  8806. }
  8807.  
  8808. let waitTime = 200, checkEval;
  8809. ruleParser.runWait((_checkEval, _waitTime) => {
  8810. if (_checkEval) {
  8811. checkEval = _checkEval;
  8812. }
  8813. if (_waitTime) {
  8814. waitTime = _waitTime;
  8815. }
  8816. });
  8817.  
  8818. if (!orgPage) {
  8819. if (!loadmoreEnd) {
  8820. loadmoreBtn = getLoadMore(iframeDoc);
  8821. if (loadmoreBtn && isVisible(loadmoreBtn, emuIframe.contentWindow)) {
  8822. emuClick(loadmoreBtn, iframeDoc);
  8823. let intv = setInterval(() => {
  8824. loadmoreBtn = getLoadMore(iframeDoc);
  8825. if (!loadmoreBtn || !getBody(document).contains(loadmoreBtn) || !isVisible(loadmoreBtn, emuIframe.contentWindow)) {
  8826. clearInterval(intv);
  8827. loadmoreEnd = true;
  8828. setTimeout(() => {
  8829. checkPage();
  8830. }, 500);
  8831. } else if (isInViewPort(loadmoreBtn)) {
  8832. emuClick(loadmoreBtn, iframeDoc);
  8833. }
  8834. }, 200);
  8835. return;
  8836. } else {
  8837. loadmoreEnd = true;
  8838. }
  8839. }
  8840. if (checkEval && !await checkEval(iframeDoc)) {
  8841. waitTimes = 50;
  8842. setTimeout(() => {
  8843. checkPage();
  8844. }, waitTime);
  8845. return;
  8846. } else {
  8847. if (!nextLink || !nextLink.offsetParent) nextLink = await ruleParser.getNextLink(iframeDoc, true);
  8848. if (nextLink) pageEle = ruleParser.getPageElement(iframeDoc, emuIframe.contentWindow, true);
  8849. if (!pageEle || pageEle.length == 0 || !nextLink) {
  8850. getBody(iframeDoc).scrollTop = 9999999;
  8851. if (iframeDoc.documentElement) {
  8852. iframeDoc.documentElement.scrollTop = 9999999;
  8853. }
  8854. if (waitTimes-- > 0) {
  8855. setTimeout(() => {
  8856. checkPage();
  8857. }, waitTime);
  8858. return;
  8859. }
  8860. }
  8861. }
  8862. if (!pageEle || pageEle.length == 0) {
  8863. returnFalse("Stop as no page when emu");
  8864. return;
  8865. }
  8866. pageEle = [].filter.call(pageEle, ele => {return ele && !compareNodeName(ele, ["style", "script", "meta"])});
  8867. if (compareNodeName(pageEle[0], ["ul"]) || pageEle.length == 1) pageEle = pageEle[0];
  8868. else if (pageEle[0].parentNode == pageEle[1].parentNode) {
  8869. pageEle = pageEle[0].parentNode;
  8870. } else {
  8871. pageEle = pageEle[0];
  8872. }
  8873. if (ruleParser.curSiteRule.smart && orgContent != pageEle.innerHTML) {
  8874. orgContent = pageEle.innerHTML;
  8875. if (waitTimes-- > 0) {
  8876. setTimeout(() => {
  8877. checkPage();
  8878. }, 500);
  8879. return;
  8880. }
  8881. }
  8882. orgPage = pageEle;
  8883. if (nextLink) {
  8884. if (compareNodeName(orgPage, ["img"])) {
  8885. if (!ruleParser.curSiteRule.lazyImgSrc) ruleParser.curSiteRule.lazyImgSrc = "0";
  8886. if (orgPage.src) {
  8887. orgContent = orgPage.src;
  8888. } else {
  8889. setTimeout(() => {
  8890. checkPage();
  8891. }, 500);
  8892. return;
  8893. }
  8894. } else {
  8895. orgContent = orgPage.innerHTML;
  8896. }
  8897. preContent = orgContent;
  8898. if (!isVisible(nextLink, emuIframe.contentWindow)) {
  8899. returnFalse("Stop as next hide when emu");
  8900. } else {
  8901. emuClick(nextLink, iframeDoc);
  8902. setTimeout(() => {
  8903. checkPage();
  8904. }, 500);
  8905. }
  8906. } else {
  8907. returnFalse("Stop as no next when emu");
  8908. }
  8909. return;
  8910. }
  8911. if (!ruleParser.checkStopSign(nextLink, iframeDoc)) {
  8912. return returnFalse("Stop as stopSign");
  8913. }
  8914. if (checkTimes++ > 200) {
  8915. returnFalse("Stop as timeout when emu");
  8916. return;
  8917. }
  8918. if (checkEval && !await checkEval(iframeDoc)) {
  8919. checkTimes = 0;
  8920. setTimeout(() => {
  8921. checkPage();
  8922. }, waitTime);
  8923. return;
  8924. }
  8925. let eles = ruleParser.getPageElement(iframeDoc, emuIframe.contentWindow, true), checkItem;
  8926. if (eles && eles.length > 0) {
  8927. eles = [].filter.call(eles, ele => {return ele && !compareNodeName(ele, ["style", "script", "meta"])});
  8928. if (compareNodeName(eles[0], ["ul"]) || eles.length == 1) checkItem = eles[0];
  8929. else if (eles[0].parentNode == eles[1].parentNode) {
  8930. checkItem = eles[0].parentNode;
  8931. } else {
  8932. checkItem = eles[0];
  8933. }
  8934. }
  8935. if (!checkItem) {
  8936. setTimeout(() => {
  8937. checkPage();
  8938. }, waitTime);
  8939. } else {
  8940. let checkInner;
  8941. if (compareNodeName(checkItem, ["img"])) {
  8942. if (checkItem.src) {
  8943. checkInner = checkItem.src;
  8944. } else {
  8945. setTimeout(() => {
  8946. checkPage();
  8947. }, waitTime);
  8948. return;
  8949. }
  8950. } else {
  8951. checkInner = checkItem.innerHTML;
  8952. }
  8953. if (orgPage != checkItem || checkInner != preContent) {
  8954. changed = true;
  8955. checkNext = 0;
  8956. orgPage = checkItem;
  8957. preContent = checkInner;
  8958. setTimeout(() => {
  8959. checkPage();
  8960. }, ruleParser.curSiteRule.smart ? 1000 : 500);
  8961. } else if (changed) {
  8962. checkTimes = 0;
  8963. if (orgContent == preContent && (ruleParser.curSiteRule.smart || ruleParser.curSiteRule.stopSame)) {
  8964. returnFalse("Stop as same content");
  8965. } else {
  8966. orgContent = preContent;
  8967. await ruleParser.hookUrl(iframeDoc);
  8968. if (!nextLink || !nextLink.offsetParent) {
  8969. nextLink = await ruleParser.getNextLink(iframeDoc, true);
  8970. }
  8971. if (!nextLink && ++checkNext < 5) {
  8972. setTimeout(() => {
  8973. checkPage();
  8974. }, waitTime);
  8975. }
  8976. callback(iframeDoc, eles);
  8977. }
  8978. } else {
  8979. if (checkTimes % 10 === 5) {
  8980. if (!nextLink || !nextLink.offsetParent) {
  8981. nextLink = await ruleParser.getNextLink(iframeDoc, true);
  8982. }
  8983. if (nextLink) {
  8984. emuClick(nextLink, iframeDoc);
  8985. }
  8986. }
  8987. setTimeout(() => {
  8988. checkPage();
  8989. }, waitTime);
  8990. }
  8991. }
  8992. }
  8993. if (!emuIframe) {
  8994. let loaded = false;
  8995. emuIframe = document.createElement('iframe');
  8996. emuIframe.name = 'pagetual-iframe';
  8997. let notSetSandbox = typeof ruleParser.curSiteRule.sandbox == 'undefined';
  8998. if (notSetSandbox || ruleParser.curSiteRule.sandbox == true) {
  8999. emuIframe.sandbox = "allow-same-origin allow-scripts allow-popups allow-forms";
  9000. } else if (ruleParser.curSiteRule.sandbox) {
  9001. emuIframe.sandbox = ruleParser.curSiteRule.sandbox;
  9002. }
  9003. emuIframe.width = '100%';
  9004. emuIframe.height = '100%';
  9005. emuIframe.frameBorder = '0';
  9006. 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;';
  9007. emuIframe.addEventListener("load", e => {
  9008. try {
  9009. iframeDoc = emuIframe.contentDocument || emuIframe.contentWindow.document;
  9010. } catch(e) {
  9011. if (e.message && e.message.indexOf("cross-origin") != -1 && notSetSandbox && emuIframe.hasAttribute("sandbox")) {
  9012. emuIframe.removeAttribute("sandbox");
  9013. meetCors = true;
  9014. callback(false, false);
  9015. if (ruleParser.curSiteRule.smart) {
  9016. ruleParser.findNoNext();
  9017. }
  9018. } else {
  9019. returnFalse("Stop as cors");
  9020. }
  9021. return;
  9022. }
  9023. setTimeout(async () => {
  9024. if (meetCors && ruleParser.curSiteRule.smart) {
  9025. ruleParser.smartRules = ruleParser.smartRules.filter(item => {return item && item.url !== ruleParser.curSiteRule.url;});
  9026. storage.setItem("smartRules", ruleParser.smartRules);
  9027. }
  9028. meetCors = false;
  9029. let code = ruleParser.curSiteRule.init;
  9030. if (code) {
  9031. try {
  9032. await new AsyncFunction('doc','win','iframe','click', 'enter', 'input', 'sleep', '"use strict";' + code)(iframeDoc, emuIframe.contentWindow, emuIframe, async sel => {await clickAction(sel, iframeDoc)}, async sel => {await enterAction(sel, iframeDoc)}, async (sel, v) =>{await inputAction(sel, v, iframeDoc)}, async time => {await sleep(time)});
  9033. } catch(e) {
  9034. debug(e);
  9035. }
  9036. } else {
  9037. let refreshByClickSel = ruleParser.curSiteRule.refreshByClick;
  9038. if (iframeDoc && refreshByClickSel) {
  9039. let clickBtn = await waitForElement(refreshByClickSel, iframeDoc);
  9040. await sleep(500);
  9041. await cloneStatus();
  9042. emuClick(clickBtn, iframeDoc);
  9043. await sleep(500);
  9044. } else {
  9045. await cloneStatus();
  9046. await sleep(500);
  9047. }
  9048. }
  9049. if (loaded) return;
  9050. loaded = true;
  9051. checkPage();
  9052. }, 500);
  9053. });
  9054. let code = ruleParser.curSiteRule.iframeInit;
  9055. if (code) {
  9056. let checkReady = setInterval(() => {
  9057. try {
  9058. iframeDoc = emuIframe.contentDocument || (emuIframe.contentWindow && emuIframe.contentWindow.document);
  9059. } catch(e) {
  9060. clearInterval(checkReady);
  9061. return;
  9062. }
  9063. if (iframeDoc) {
  9064. clearInterval(checkReady);
  9065. try {
  9066. Function('win', 'iframe', '"use strict";' + code)(emuIframe.contentWindow, emuIframe);
  9067. } catch(e) {
  9068. debug(e);
  9069. }
  9070. }
  9071. }, 50);
  9072. }
  9073. if (!lastActiveUrl) lastActiveUrl = location.href;
  9074. emuIframe.src = lastActiveUrl;
  9075. getBody(document).appendChild(emuIframe);
  9076. } else {
  9077. if (emuIframe.src != lastActiveUrl || meetCors) {
  9078. emuIframe.src = lastActiveUrl;
  9079. return;
  9080. }
  9081. checkPage();
  9082. }
  9083. }
  9084.  
  9085. var scrollToResizeInited = false;
  9086. var resizePool = [];
  9087. var scrollingToResize = false;
  9088.  
  9089. function isTouchViewPort(element) {
  9090. const viewWidth = window.innerWidth || document.documentElement.clientWidth;
  9091. const viewHeight = window.innerHeight || document.documentElement.clientHeight;
  9092. const {
  9093. top,
  9094. right,
  9095. bottom,
  9096. left,
  9097. } = element.getBoundingClientRect();
  9098.  
  9099. return (
  9100. top < viewHeight &&
  9101. left < viewWidth &&
  9102. right > 0 &&
  9103. bottom > 0
  9104. );
  9105. }
  9106.  
  9107. function resizeIframe(iframe, frameDoc, pageEle) {
  9108. if (targetY >= 0) {
  9109. window.scrollTo({ top: targetY, behavior: 'instant'});
  9110. targetY = -1;
  9111. }
  9112. let curScroll = getBody(document).scrollTop || document.documentElement.scrollTop;
  9113. if (ruleParser.curSiteRule.smart || forceState === 2) {
  9114. let height = (getBody(frameDoc).scrollHeight || getBody(frameDoc).offsetHeight || 500);
  9115. if (!iframe.style.height || parseInt(iframe.style.height) === 0 || height - parseInt(iframe.style.height) > window.innerHeight) {
  9116. iframe.style.height = height + "px";
  9117. iframe.style.minHeight = iframe.style.height;
  9118. }
  9119. iframe.style.width = "100%";
  9120. frameDoc.documentElement.scrollTop = 0;
  9121. frameDoc.documentElement.scrollLeft = 0;
  9122. } else {
  9123. if (pageEle) {
  9124. if (document.body.scrollWidth) frameDoc.documentElement.style.width = document.body.scrollWidth + "px";
  9125. let fitWidth = ruleParser.curSiteRule.fitWidth !== false;
  9126. let targetElement = pageEle[0];
  9127. if (!targetElement) return;
  9128. if (pageEle.length > 1) {
  9129. targetElement = targetElement.parentNode;
  9130. }
  9131. let scrollHeight = targetElement.scrollHeight || targetElement.offsetHeight || 500;
  9132. iframe.style.height = scrollHeight + "px";
  9133. let scrollTop = 0, scrollLeft = 0;
  9134. getBody(frameDoc).scrollTop = 0;
  9135. getBody(frameDoc).scrollLeft = 0;
  9136. while (targetElement && targetElement.offsetParent) {
  9137. targetElement.offsetParent.scrollTop = targetElement.offsetTop;
  9138. if (targetElement.offsetParent.scrollTop == 0) {
  9139. scrollTop += targetElement.offsetTop;
  9140. }
  9141. if (fitWidth) {
  9142. targetElement.offsetParent.scrollLeft = targetElement.offsetLeft;
  9143. if (targetElement.offsetParent.scrollLeft == 0) {
  9144. scrollLeft += targetElement.offsetLeft;
  9145. }
  9146. }
  9147. targetElement = targetElement.offsetParent;
  9148. }
  9149. frameDoc.documentElement.scrollTop = scrollTop;
  9150. frameDoc.documentElement.scrollLeft = scrollLeft;
  9151. if (frameDoc.documentElement.scrollTop == 0 && frameDoc.documentElement.scrollLeft == 0) {
  9152. getBody(frameDoc).scrollTop += scrollTop;
  9153. getBody(frameDoc).scrollLeft += scrollLeft;
  9154. }
  9155. if (!fitWidth && iframe.style.marginLeft == '0px') {
  9156. iframe.style.width = "100vw";
  9157. iframe.style.maxWidth = "100vw";
  9158. iframe.style.minWidth = "100vw";
  9159. var cWidth = document.body.clientWidth || document.documentElement.clientWidth;
  9160. var iWidth = window.innerWidth;
  9161. iframe.style.marginLeft = -iframe.getBoundingClientRect().left - (iWidth - cWidth) / 2 + "px";
  9162. }
  9163. }
  9164. }
  9165. let newScroll = getBody(document).scrollTop || document.documentElement.scrollTop;
  9166. if (newScroll != curScroll) {
  9167. getBody(document).scrollTop = curScroll;
  9168. document.documentElement.scrollTop = curScroll;
  9169. }
  9170. }
  9171.  
  9172. function scrollToResize(e) {
  9173. if (scrollingToResize) return;
  9174. else {
  9175. scrollingToResize = true;
  9176. let resizeHandler = () => {
  9177. let touched = 0;
  9178. for (let i = 0; i < resizePool.length; i++) {
  9179. let resizeArr = resizePool[i];
  9180. let iframe = resizeArr[1]();
  9181. if (isTouchViewPort(iframe)) {
  9182. touched++;
  9183. let pageEle = resizeArr[0]();
  9184. let frameDoc = resizeArr[2]();
  9185. resizeIframe(iframe, frameDoc, pageEle);
  9186. } else if (touched) {
  9187. if (touched == 1) {
  9188. let pageEle = resizeArr[0]();
  9189. let frameDoc = resizeArr[2]();
  9190. resizeIframe(iframe, frameDoc, pageEle);
  9191. }
  9192. break;
  9193. } else if (!iframe.parentNode) {
  9194. resizePool.splice(i, 1);
  9195. break;
  9196. }
  9197. }
  9198. };
  9199. setTimeout(() => {
  9200. scrollingToResize = false;
  9201. }, 300);
  9202. resizeHandler();
  9203. }
  9204. }
  9205.  
  9206. var curForceIframe;
  9207. function forceIframe(url, callback) {
  9208. url = url.indexOf('=') == -1 ? url.replace(/#[^#]*/,"") : url;
  9209. let curIframe = document.createElement('iframe'), iframeDoc, pageElement = null, inAction = true;
  9210. let loadedHandler = () => {
  9211. let getPageEle = () => {
  9212. if (ruleParser.curSiteRule.smart) {
  9213. return null;
  9214. } else {
  9215. if (!pageElement || pageElement.length === 0 || !pageElement[0].offsetParent) {
  9216. pageElement = ruleParser.getPageElement(iframeDoc, curIframe.contentWindow);
  9217. }
  9218. return pageElement;
  9219. }
  9220. };
  9221. resizeIframe(curIframe, iframeDoc, getPageEle());
  9222. let loaded = curIframe.getAttribute("loaded");
  9223. if (loaded == "true") {
  9224. return;
  9225. }
  9226. curIframe.setAttribute("loaded", "true");
  9227. let getIframe = () => {
  9228. return curIframe;
  9229. };
  9230. let getFrameDoc = () => {
  9231. return iframeDoc;
  9232. };
  9233. ruleParser.insertPage(iframeDoc, [], url, ele => {
  9234. callback(curIframe, loaded == "refresh");
  9235. inAction = false;
  9236. }, true);
  9237. if (!loaded) {
  9238. resizePool.push([getPageEle, getIframe, getFrameDoc]);
  9239. }
  9240. };
  9241. let checkIframeTimer = setInterval(() => {
  9242. if (!curIframe.parentNode) {
  9243. clearInterval(checkIframeTimer);
  9244. return curIframe.getAttribute("loaded") == "true" || callback(false);
  9245. }
  9246. }, 500);
  9247. let code = ruleParser.curSiteRule.iframeInit;
  9248. if (code) {
  9249. let checkReady = setInterval(() => {
  9250. try {
  9251. iframeDoc = curIframe.contentDocument || (curIframe.contentWindow && curIframe.contentWindow.document);
  9252. } catch(e) {
  9253. clearInterval(checkReady);
  9254. return;
  9255. }
  9256. if (iframeDoc) {
  9257. clearInterval(checkReady);
  9258. try {
  9259. Function('win', 'iframe', '"use strict";' + code)(curIframe.contentWindow, curIframe);
  9260. } catch(e) {
  9261. debug(e);
  9262. }
  9263. }
  9264. }, 50);
  9265. }
  9266. let waitTime = 300, checkEval;
  9267. ruleParser.runWait((_checkEval, _waitTime) => {
  9268. if (_checkEval) {
  9269. checkEval = _checkEval;
  9270. }
  9271. if (_waitTime) {
  9272. waitTime = _waitTime;
  9273. }
  9274. });
  9275. async function checkIframe() {
  9276. if (checkEval && !await checkEval(iframeDoc)) {
  9277. setTimeout(() => {
  9278. checkIframe();
  9279. }, waitTime);
  9280. return;
  9281. }
  9282. loadedHandler();
  9283. }
  9284. curIframe.name = 'pagetual-iframe';
  9285. curIframe.sandbox = "allow-same-origin allow-scripts allow-popups allow-forms";
  9286. curIframe.frameBorder = '0';
  9287. curIframe.scrolling = "no";
  9288. curIframe.style.cssText = 'display: block; visibility: visible; float: none; clear: both; width: 100%; height: 0; background: initial; border: 0px; border-radius: 0px; margin: 0px; padding: 0px; z-index: 2147483645;content-visibility: auto;contain-intrinsic-size: auto 300px;';
  9289. curIframe.addEventListener("load", async e => {
  9290. clearInterval(checkIframeTimer);
  9291. if (isPause) return callback(false);
  9292. try {
  9293. iframeDoc = curIframe.contentDocument || curIframe.contentWindow.document;
  9294. } catch(e) {
  9295. debug("Stop as cors");
  9296. isPause = true;
  9297. callback(false);
  9298. return;
  9299. }
  9300. let css;
  9301. if (rulesData.customCss && ruleParser.curSiteRule.css) {
  9302. let globalCssArr = rulesData.customCss.split("inIframe:");
  9303. let ruleCssArr = ruleParser.curSiteRule.css.split("inIframe:");
  9304. let mainCss = globalCssArr[0] + ruleCssArr[0], inCss = (globalCssArr[1] || "") + (ruleCssArr[1] || "");
  9305. css = mainCss + (inCss ? ("inIframe:" + inCss) : "");
  9306. } else {
  9307. css = ruleParser.curSiteRule.css || rulesData.customCss;
  9308. }
  9309. if (css) {
  9310. let cssArr = css.split("inIframe:");
  9311. if (cssArr && cssArr.length > 1) {
  9312. let styleEle = iframeDoc.createElement("style");
  9313. styleEle.innerHTML = cssArr[1];
  9314. iframeDoc.head.appendChild(styleEle);
  9315. }
  9316. }
  9317. curIframe.style.height = "";
  9318. checkIframe();
  9319. iframeDoc.addEventListener('wheel', e => {
  9320. document.dispatchEvent(new Event('wheel'));
  9321. }, true);
  9322. });
  9323. let checkTimes = 0, findPageEle = false;
  9324. let forceRefresh = e => {
  9325. if (inAction || !iframeDoc) return;
  9326. inAction = true;
  9327. let foundNext = () => {
  9328. document.removeEventListener("scroll", forceRefresh);
  9329. }
  9330. setTimeout(async () => {
  9331. inAction = false;
  9332. if (!ruleParser.nextLinkHref && !isPause) {
  9333. checkTimes++;
  9334. await ruleParser.getNextLink(iframeDoc, true);
  9335. if (ruleParser.nextLinkHref) {
  9336. foundNext();
  9337. if (isLoading) isLoading = false;
  9338. } else if (checkTimes >= 10) {
  9339. foundNext();
  9340. } else if (checkTimes >= 3 && !findPageEle) {
  9341. if (!pageElement) pageElement = ruleParser.getPageElement(iframeDoc, curIframe.contentWindow);
  9342. if (!pageElement) {
  9343. inAction = true;
  9344. curIframe.contentWindow.location.reload();
  9345. } else {
  9346. findPageEle = true;
  9347. }
  9348. }
  9349. } else {
  9350. foundNext();
  9351. }
  9352. }, 100);
  9353. };
  9354. document.addEventListener("scroll", forceRefresh);
  9355. curIframe.src = url;
  9356. curForceIframe = curIframe;
  9357. let insert = ruleParser.getInsert();
  9358. let body = getBody(document);
  9359. let curScroll = body.scrollTop || document.documentElement.scrollTop;
  9360. if (forceState == 2) {
  9361. document.documentElement.appendChild(loadingDiv);
  9362. body.appendChild(curIframe);
  9363. let bodyStyle = getComputedStyle(body);
  9364. if (bodyStyle.display == "flex" || bodyStyle.display == "inline-flex") {
  9365. body.style.flexDirection = "column";
  9366. }
  9367. } else {
  9368. ruleParser.insertElement(curIframe);
  9369. }
  9370. body.scrollTop = curScroll;
  9371. document.documentElement.scrollTop = curScroll;
  9372.  
  9373. if (!scrollToResizeInited) {
  9374. scrollToResizeInited = true;
  9375. document.addEventListener("scroll", scrollToResize);
  9376. }
  9377. return curIframe;
  9378. }
  9379.  
  9380. function loadPageOver() {
  9381. isLoading = false;
  9382. stopScroll = true;
  9383. setTimeout(() => {stopScroll = false;}, 300);
  9384. if (loadingDiv.parentNode) {
  9385. loadingDiv.parentNode.removeChild(loadingDiv);
  9386. }
  9387. if (rate !== 1 && !clickMode) {
  9388. setTimeout(() => {
  9389. if (distToBottom() < bottomGap) {
  9390. nextPage();
  9391. }
  9392. }, 1);
  9393. }
  9394. if (sideController.inited) {
  9395. sideController.frame.classList.remove("loading");
  9396. }
  9397. }
  9398.  
  9399. function checkAutoLoadNum() {
  9400. if (autoLoadNum >= 0) {
  9401. if (autoLoadNum !== 0 && --autoLoadNum === 0) {
  9402. autoLoadNum = -1;
  9403. } else {
  9404. setTimeout(() => nextPage(), 1);
  9405. }
  9406. }
  9407. }
  9408.  
  9409. async function nextPage() {
  9410. if (isPause || isLoading || forceState === 1) return;
  9411. if (ruleParser.curSiteRule.delay) {
  9412. try {
  9413. let checkDelay = ((typeof ruleParser.curSiteRule.delay === 'function') ? ruleParser.curSiteRule.delay : Function('"use strict";' + ruleParser.curSiteRule.delay))();
  9414. if (!checkDelay) return;
  9415. } catch(e) {
  9416. debug(e);
  9417. }
  9418. }
  9419. let nextLink = ruleParser.nextLinkHref;
  9420. if (!nextLink) {
  9421. isLoading = true;
  9422. if (curPage === 1) {
  9423. await ruleParser.getNextLink(document, true);
  9424. nextLink = ruleParser.nextLinkHref;
  9425. }
  9426. if (!nextLink) {
  9427. if (curPage === 1) {
  9428. if (ruleParser.curSiteRule.pinUrl) {
  9429. setTimeout(() => {isLoading = false;}, 500);
  9430. } else if (tryTimes++ < 5) {
  9431. setTimeout(() => {isLoading = false;}, 1000);
  9432. } else {
  9433. ruleParser.findNoNext();
  9434. }
  9435. } else if (!showedLastPageTips) {
  9436. ruleParser.reachedLastPage();
  9437. showedLastPageTips = true;
  9438. }
  9439. return;
  9440. }
  9441. isLoading = false;
  9442. }
  9443. showedLastPageTips = false;
  9444. let pvGallery = document.querySelector("span.pv-gallery-container");
  9445. if (pvGallery && pvGallery.style.display !== "none") return;
  9446. let insert = ruleParser.getInsert();
  9447. if (insert) {
  9448. if (curPage === 1) {
  9449. initView();
  9450. }
  9451. /*if (curPage == 1) {
  9452. window.postMessage({
  9453. command: 'pagetual.insert'
  9454. }, '*');
  9455. }*/
  9456. let isJs = ruleParser.curSiteRule.action == 3 || ruleParser.hrefIsJs(nextLink);
  9457. if (!isJs) {
  9458. emuIframe = null;
  9459. lastActiveUrl = nextLink;
  9460. if (location.protocol === "https:" && /^http:/.test(nextLink)) {
  9461. nextLink = nextLink.replace(/^http/, "https");
  9462. }
  9463. }
  9464. isLoading = true;
  9465. if (curPage !== 1 || !isJs || !ruleParser.curSiteRule.smart) {
  9466. ruleParser.beginLoading(loadingDiv);
  9467. } else {
  9468. if (sideController.inited) {
  9469. sideController.frame.classList.add("loading");
  9470. }
  9471. }
  9472. let sleep = ruleParser.curSiteRule.sleep || 0;
  9473. setTimeout(() => {
  9474. if (ruleParser.curSiteRule.pageElementByJs) {
  9475. var over = eles => {
  9476. if (urlChanged || isPause) {
  9477. loadPageOver();
  9478. return;
  9479. }
  9480. if (eles) {
  9481. ruleParser.insertPage(document, eles, nextLink, () => {
  9482. createPageBar(nextLink);
  9483. checkAutoLoadNum();
  9484. }, true);
  9485. } else {
  9486. debug("Stop as no page when get by js");
  9487. isPause = true;
  9488. loadPageOver();
  9489. }
  9490. };
  9491. try {
  9492. ((typeof ruleParser.curSiteRule.pageElementByJs === 'function') ? ruleParser.curSiteRule.pageElementByJs : Function("over", "pageNum",'"use strict";' + ruleParser.curSiteRule.pageElementByJs))(over, curPage);
  9493. } catch(e) {
  9494. debug(e);
  9495. }
  9496. } else if ((forceState === 2 || ruleParser.curSiteRule.action == 2) && !isJs) {
  9497. forceIframe(nextLink, (iframe, refresh) => {
  9498. if (urlChanged || isPause) {
  9499. loadPageOver();
  9500. return;
  9501. }
  9502. if (!refresh) {
  9503. let pageBar = createPageBar(nextLink);
  9504. if (pageBar && iframe && iframe.parentNode) iframe.parentNode.insertBefore(pageBar, iframe);
  9505. }
  9506. loadPageOver();
  9507. checkAutoLoadNum();
  9508. });
  9509. } else if ((forceState === 3 || ruleParser.curSiteRule.action == 1) && !isJs) {
  9510. requestFromIframe(nextLink, async (doc, eles) => {
  9511. if (urlChanged || isPause) {
  9512. loadPageOver();
  9513. return;
  9514. }
  9515. if (eles) {
  9516. await ruleParser.insertPage(doc, eles, nextLink, () => {
  9517. createPageBar(nextLink);
  9518. checkAutoLoadNum();
  9519. }, true);
  9520. } else {
  9521. loadPageOver();
  9522. if (autoLoadNum >= 0) {
  9523. setTimeout(() => nextPage(), 2000);
  9524. }
  9525. }
  9526. });
  9527. } else {
  9528. if (!isJs) {
  9529. requestDoc(nextLink, (eles) => {
  9530. if (urlChanged || isPause) {
  9531. loadPageOver();
  9532. return;
  9533. }
  9534. if (eles) {
  9535. createPageBar(nextLink);
  9536. checkAutoLoadNum();
  9537. } else {
  9538. loadPageOver();
  9539. if (autoLoadNum >= 0) {
  9540. setTimeout(() => nextPage(), 2000);
  9541. }
  9542. }
  9543. });
  9544. } else {
  9545. emuPage((doc, eles) => {
  9546. if (urlChanged || isPause) {
  9547. loadPageOver();
  9548. return;
  9549. }
  9550. if (eles) {
  9551. ruleParser.insertPage(doc, eles, "", () => {
  9552. createPageBar(nextLink);
  9553. checkAutoLoadNum();
  9554. }, true);
  9555. } else {
  9556. loadPageOver();
  9557. if (autoLoadNum >= 0) {
  9558. setTimeout(() => nextPage(), 2000);
  9559. }
  9560. }
  9561. });
  9562. }
  9563. }
  9564. }, sleep);
  9565. }
  9566. }
  9567.  
  9568. function init() {
  9569. if (document.readyState === 'loading' || document.readyState === 'uninitialized') {
  9570. let domReady = e => {
  9571. initRules(() => {
  9572. initPage();
  9573. });
  9574. document.removeEventListener("DOMContentLoaded", domReady, false);
  9575. };
  9576. document.addEventListener("DOMContentLoaded", domReady, false);
  9577. } else {
  9578. initRules(() => {
  9579. initPage();
  9580. });
  9581. }
  9582. }
  9583.  
  9584. function visibilitychangeHandler() {
  9585. document.removeEventListener('visibilitychange', visibilitychangeHandler);
  9586. init();
  9587. }
  9588.  
  9589. setTimeout(() => {
  9590. if (document.hidden) {
  9591. document.addEventListener('visibilitychange', visibilitychangeHandler);
  9592. } else {
  9593. init();
  9594. }
  9595. }, 300);
  9596. })();