东方永页机

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

目前为 2024-08-10 提交的版本。查看 最新版本

  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.90
  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 prevReg = new RegExp("\u005e\u005c\u0073\u002a\u0028\u005b\u4e0a\u524d\u9996\u5c3e\u005d\u007c\u0070\u0072\u0065\u0076\u0069\u006f\u0075\u0073\u007c\u0065\u006e\u0064\u0029", "i");
  1174. 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"];
  1175. var rulesData = {uninited: true, firstRun: true, sideController: !isMobile}, ruleUrls, updateDate, loadNowNum = 5, autoScrollRate = 50;
  1176. 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;
  1177. var tryTimes = 0, showedLastPageTips = false, rate = 1, author = '';
  1178.  
  1179. function getBody(doc) {
  1180. return doc.body || doc.querySelector('body') || doc;
  1181. }
  1182.  
  1183. function getElementByXpath(xpath, doc, contextNode) {
  1184. if (doc && doc.ownerDocument) doc = doc.ownerDocument;
  1185. doc = (doc && doc.evaluate) ? doc : document;
  1186. contextNode = contextNode || doc;
  1187. try {
  1188. let xpathNode = (s, d, n) => {
  1189. let result = d.evaluate(s, n, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null);
  1190. return result.singleNodeValue && result.singleNodeValue.nodeType === 1 && result.singleNodeValue;
  1191. };
  1192. let selSplit = xpath.split(" =>> ");
  1193. if (selSplit.length === 2) {
  1194. let ele = xpathNode(selSplit[0], doc, contextNode);
  1195. if (ele && ele.shadowRoot) {
  1196. return xpathNode(selSplit[1], ele.shadowRoot, ele.shadowRoot);
  1197. }
  1198. } else {
  1199. return xpathNode(xpath, doc, contextNode);
  1200. }
  1201. } catch (err) {
  1202. debug(`Invalid xpath: ${xpath}`);
  1203. }
  1204. return null;
  1205. }
  1206.  
  1207. function getAllElementsByXpath(xpath, contextNode, doc) {
  1208. if (doc && doc.ownerDocument) doc = doc.ownerDocument;
  1209. doc = (doc && doc.evaluate) ? doc : document;
  1210. contextNode = contextNode || doc;
  1211. var result = [];
  1212. try {
  1213. var query = doc.evaluate(xpath, contextNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  1214. for (var i = 0; i < query.snapshotLength; i++) {
  1215. var node = query.snapshotItem(i);
  1216. if (node.nodeType === 1) {
  1217. result.push(node);
  1218. }
  1219. }
  1220. } catch (err) {
  1221. debug(`Invalid xpath: ${xpath}`);
  1222. }
  1223. return result;
  1224. }
  1225.  
  1226. function isXPath(xpath) {
  1227. if (!xpath) {
  1228. return false;
  1229. }
  1230. return /^\(*(descendant::|\.\/|\/|id\()/.test(xpath);
  1231. }
  1232.  
  1233. function getAllElements(sel, doc, contextNode) {
  1234. try {
  1235. if (sel.indexOf(" =>> ") !== -1) {
  1236. let result = getElement(sel, doc, contextNode);
  1237. return result && [result];
  1238. }
  1239. if (!isXPath(sel)) {
  1240. return doc.querySelectorAll(sel);
  1241. }
  1242. } catch(e) {
  1243. debug(e, 'Error selector');
  1244. }
  1245. return getAllElementsByXpath(sel, contextNode, doc);
  1246. }
  1247.  
  1248. function getElement(sel, doc, contextNode, bySort) {
  1249. try {
  1250. if (!isXPath(sel)) {
  1251. let checkShadow = s => {
  1252. let selSplit = s.split(" =>> ");
  1253. if (selSplit.length === 2) {
  1254. let ele = doc.querySelector(selSplit[0]);
  1255. return ele && ele.shadowRoot && ele.shadowRoot.querySelector(selSplit[1]);
  1256. } else return doc.querySelector(s);
  1257. };
  1258. if (!bySort) {
  1259. return checkShadow(sel);
  1260. } else {
  1261. let selArr = sel.split(",");
  1262. try {
  1263. for (let i = 0; i < selArr.length; i++) {
  1264. let ele = checkShadow(selArr[i].trim());
  1265. if (ele) {
  1266. return ele;
  1267. }
  1268. }
  1269. } catch(e) {
  1270. return checkShadow(sel);
  1271. }
  1272. return null;
  1273. }
  1274. }
  1275. } catch(e) {
  1276. debug(e, 'Error selector');
  1277. }
  1278. return getElementByXpath(sel, doc, contextNode);
  1279. }
  1280.  
  1281. function compareNodeName(node, names) {
  1282. if (!node || !node.nodeName || !node.nodeName.toLowerCase) {
  1283. return false;
  1284. }
  1285. let nodeName = node.nodeName.toLowerCase();
  1286. for (let i = 0; i < names.length; i++) {
  1287. if (names[i] === nodeName) {
  1288. return true;
  1289. }
  1290. }
  1291. return false;
  1292. }
  1293.  
  1294. function geneSelector(ele, addID, exact) {
  1295. let selector = ele.nodeName.toLowerCase();
  1296. //Google id class都是隨機。百度更過分,style script順序都是隨機的
  1297. if (selector !== "html" && selector !== "body") {
  1298. let hasId = false;
  1299. if (addID && ele.id && /^[a-z_][\w\-_]*$/i.test(ele.id)) {
  1300. if (ele.ownerDocument && ele.ownerDocument.querySelectorAll("#" + ele.id).length === 1) {
  1301. hasId = true;
  1302. selector = '#' + ele.id;
  1303. }
  1304. }
  1305. if (!hasId) {
  1306. let className = "";
  1307. if (ele.className) {
  1308. let classList = ele.classList;
  1309. for (let i = 0; i < classList.length; i++) {
  1310. let c = classList[i];
  1311. if (c !== 'scrolling' && /^[a-z_][\w\-_]*$/.test(c) && !/\d{4,}/.test(c)) {
  1312. className += '.' + c;
  1313. }
  1314. }
  1315. selector += className;
  1316. }
  1317. let parent = ele.parentElement;
  1318. if (parent) {
  1319. if (exact) {
  1320. let i, nth = 0, all = 0;
  1321. for (i = 0; i < parent.children.length; i++) {
  1322. if (parent.children[i].nodeName === ele.nodeName) {
  1323. all++;
  1324. if (parent.children[i] === ele) {
  1325. nth = all;
  1326. }
  1327. if (nth > 0 && all > 1) {
  1328. break;
  1329. }
  1330. }
  1331. }
  1332. selector += (all === 1 ? "" : `:nth-of-type(${nth})`);
  1333. } else if (!className && !hasId && parent.children.length > 1 && !compareNodeName(parent, ["html"])) {
  1334. let prevE = ele.previousElementSibling;
  1335. if (prevE && prevE.className) {
  1336. let classList = prevE.classList;
  1337. for (let i = 0; i < classList.length; i++) {
  1338. let c = classList[i];
  1339. if (c !== 'scrolling' && /^[a-z_][\w\-_]*$/.test(c) && !/\d{4,}/.test(c)) {
  1340. className += '.' + c;
  1341. }
  1342. }
  1343. if (className) {
  1344. selector = prevE.nodeName.toLowerCase() + className + "+" + selector;
  1345. }
  1346. }
  1347. if (!className) {
  1348. let i, nth = 0, all = 0;
  1349. for (i = 0; i < parent.children.length; i++) {
  1350. if (parent.children[i].nodeName === ele.nodeName) {
  1351. all++;
  1352. if (parent.children[i] === ele) {
  1353. nth = all;
  1354. }
  1355. if (nth > 0 && all > 1) {
  1356. break;
  1357. }
  1358. }
  1359. }
  1360. selector += (all === 1 ? "" : `:nth-of-type(${nth})`);
  1361. }
  1362. }
  1363. selector = geneSelector(parent, addID, exact) + ' > ' + selector;
  1364. }
  1365. }
  1366. }
  1367. return selector;
  1368. }
  1369.  
  1370. function createXPathFromElement(elm) {
  1371. let allNodes = document.getElementsByTagName('*'), segs;
  1372. for (segs = []; elm && elm.nodeType === 1; elm = elm.parentNode) {
  1373. if (compareNodeName(elm, ["body", "html"])) {
  1374. segs.unshift(elm.localName.toLowerCase());
  1375. continue;
  1376. }
  1377. if (elm.hasAttribute && elm.hasAttribute('id')) {
  1378. var uniqueIdCount = 0;
  1379. for (var n = 0; n < allNodes.length; n++) {
  1380. if (allNodes[n].hasAttribute('id') && allNodes[n].id === elm.id) {
  1381. uniqueIdCount++;
  1382. }
  1383. if (uniqueIdCount > 1) {
  1384. break;
  1385. }
  1386. }
  1387. if ( uniqueIdCount === 1) {
  1388. segs.unshift('id("' + elm.getAttribute('id') + '")');
  1389. return segs.join('/');
  1390. } else {
  1391. segs.unshift(elm.localName.toLowerCase() + '[@id="' + elm.getAttribute('id') + '"]');
  1392. }
  1393. } else if (elm.hasAttribute && elm.hasAttribute('class')) {
  1394. segs.unshift(elm.localName.toLowerCase() + '[@class="' + elm.getAttribute('class') + '"]');
  1395. } else {
  1396. let i, sib;
  1397. for (i = 1, sib = elm.previousSibling; sib; sib = sib.previousSibling) {
  1398. if (sib.localName === elm.localName) {
  1399. i++;
  1400. }
  1401. }
  1402. segs.unshift(elm.localName.toLowerCase() + '[' + i + ']');
  1403. }
  1404. }
  1405. return segs.length ? '/' + segs.join('/') : null;
  1406. }
  1407.  
  1408. const escapeHTMLPolicy = (_unsafeWindow.trustedTypes && _unsafeWindow.trustedTypes.createPolicy) ? _unsafeWindow.trustedTypes.createPolicy('pagetual_default', {
  1409. createHTML: (string, sink) => string
  1410. }) : null;
  1411.  
  1412. function createHTML(html) {
  1413. return escapeHTMLPolicy ? escapeHTMLPolicy.createHTML(html) : html;
  1414. }
  1415.  
  1416. const AsyncFunction = Object.getPrototypeOf(async function(){}).constructor;
  1417.  
  1418. async function sleep(time) {
  1419. await new Promise((resolve) => {
  1420. setTimeout(() => {
  1421. resolve();
  1422. }, time);
  1423. });
  1424. }
  1425.  
  1426. class RuleParser {
  1427. constructor() {
  1428. this.hpRules = [];
  1429. this.smartRules = [];
  1430. this.customRules = [];
  1431. this.rules = [];
  1432. this.pageDoc = document;
  1433. this.nextLinkHref = null;
  1434. this.nextTitle = "";
  1435. this.oldUrl = "";
  1436. this.curUrl = location.href;
  1437. this.curSiteRule = {};
  1438. }
  1439.  
  1440. async initSavedRules(callback) {
  1441. var self = this;
  1442. let smartRules = await getData("smartRules");
  1443. if (smartRules) self.smartRules = smartRules;
  1444. let hpRules = await getData("hpRules");
  1445. if (hpRules) self.hpRules = hpRules;
  1446. let customRules = await getData("customRules");
  1447. if (customRules) self.customRules = customRules;
  1448. if (_unsafeWindow.pagetualRules && _unsafeWindow.pagetualRules.length) {
  1449. _unsafeWindow.pagetualRules.forEach(rule => {
  1450. rule.isScript = true;
  1451. });
  1452. self.customRules = _unsafeWindow.pagetualRules.concat(self.customRules);
  1453. }
  1454. let rules = await getData("rules");
  1455. if (rules) self.rules = rules;
  1456. callback();
  1457. }
  1458.  
  1459. saveCurSiteRule() {
  1460. /*if(!this.curSiteRule || !this.curSiteRule.url || this.curSiteRule.smart || this.curSiteRule.url.length<13)return;
  1461. this.hpRules=this.hpRules.filter(item=>{return item&&item.url!=this.curSiteRule.url});
  1462. this.hpRules.unshift(this.curSiteRule);
  1463. if(this.hpRules.length>30){
  1464. this.hpRules.pop();
  1465. }
  1466. storage.setItem("hpRules", this.hpRules);*/
  1467. }
  1468.  
  1469. requestJSON(url, callback) {
  1470. _GM_xmlhttpRequest({
  1471. url: url,
  1472. method: 'GET',
  1473. timeout: 1000000,
  1474. headers: {
  1475. 'accept': 'application/json,text/html',
  1476. 'Referer': url,
  1477. },
  1478. onload: function(res) {
  1479. let json = null;
  1480. try {
  1481. json = JSON.parse(res.response || res.responseText);
  1482. } catch(e) {
  1483. debug(e, 'Error json');
  1484. }
  1485. callback(json);
  1486. },
  1487. onerror: function(e) {
  1488. callback(null, e);
  1489. },
  1490. ontimeout: function(e) {
  1491. callback(null, e);
  1492. }
  1493. });
  1494. }
  1495.  
  1496. formatRule(item, from) {
  1497. if (item.data && item.data.url) {
  1498. let result = {
  1499. name: item.name,
  1500. from: from,
  1501. action: item.data.forceIframe === "true" ? 1 : undefined,
  1502. url: item.data.url,
  1503. pageElement: item.data.pageElement,
  1504. nextLink: item.data.nextLink,
  1505. insert: item.data.insertBefore||undefined,
  1506. updatedAt: item.updated_at
  1507. };
  1508. let _css = (item.data.Stylus || '') + (item.data.CSS || '');
  1509. if (_css) result.css = _css;
  1510. if (item.data.bookmarklet) result.pageAction = item.data.bookmarklet;
  1511. return result;
  1512. } else {
  1513. item.from = from;
  1514. return item;
  1515. }
  1516. return null;
  1517. }
  1518.  
  1519. addRuleByUrl(url, from, callback) {
  1520. if (url.indexOf("?") === -1) {
  1521. url = url + "?" + Date.now();
  1522. } else {
  1523. url = url + "&" + Date.now();
  1524. }
  1525. this.requestJSON(url, (json,err) => {
  1526. if (!json) {
  1527. debug(err, "Failed to update " + url + " rules!");
  1528. }
  1529. this.addRules(json, from);
  1530. callback(json, err);
  1531. });
  1532. }
  1533.  
  1534. addRules(rules, from) {
  1535. if (rules && rules.length > 0) {
  1536. let first = -1;
  1537. this.rules = this.rules.filter((item, i) => {
  1538. if (item.from === from) {
  1539. if (first === -1) first = i;
  1540. return false;
  1541. } else return true;
  1542. });
  1543. if (first === -1) first = 0;
  1544. rules.forEach(item => {
  1545. let rule = this.formatRule(item, from);
  1546. if (rule) {
  1547. this.rules.splice(first, 0, rule)
  1548. }
  1549. });
  1550. }
  1551. }
  1552.  
  1553. ruleMatchPre(r) {
  1554. if (r.include) {
  1555. let include;
  1556. if (Array && Array.isArray && Array.isArray(r.include)) {
  1557. include = r.include.every((sel, i) => {
  1558. let ele = getElement(sel, document);
  1559. return !!ele;
  1560. });
  1561. } else include = getElement(r.include, document);
  1562. if (!include) return false;
  1563. }
  1564. if (r.exclude) {
  1565. let exclude;
  1566. if (Array && Array.isArray && Array.isArray(r.exclude)) {
  1567. exclude = !r.exclude.every((sel, i) => {
  1568. let ele = getElement(sel, document);
  1569. return !ele;
  1570. });
  1571. } else exclude = getElement(r.exclude, document);
  1572. if (exclude) return false;
  1573. }
  1574. return true;
  1575. }
  1576.  
  1577. ruleMatchReady(r) {
  1578. let findIndex = 0;
  1579. if (r.nextLink && r.nextLink !== 0) {
  1580. let nextLinkSel = r.nextLink, nextLink;
  1581. if (Array && Array.isArray && Array.isArray(nextLinkSel)) {
  1582. nextLink = !nextLinkSel.every((sel, i) => {
  1583. let ele = getElement(sel, document);
  1584. if (ele) findIndex = i;
  1585. return !ele;
  1586. });
  1587. } else nextLink = getElement(nextLinkSel, document);
  1588. if (!nextLink) return false;
  1589. }
  1590. if (r.pageElement) {
  1591. let pageElementSel = r.pageElement, pageElement;
  1592. if (Array && Array.isArray && Array.isArray(pageElementSel)) {
  1593. pageElementSel = pageElementSel[findIndex];
  1594. }
  1595. pageElement = getElement(pageElementSel, document);
  1596. if (!pageElement) return false;
  1597. }
  1598. if (r.insert) {
  1599. let insertSel = r.insert, insert;
  1600. if (Array && Array.isArray && Array.isArray(insertSel)) {
  1601. insertSel = insertSel[findIndex];
  1602. }
  1603. insert = getElement(insertSel, document);
  1604. if (!insert) return false;
  1605. }
  1606. //if (findIndex !== 0) nextIndex = findIndex;
  1607. return true;
  1608. }
  1609.  
  1610. ruleMatch(r) {
  1611. return this.ruleMatchPre(r) && this.ruleMatchReady(r);
  1612. }
  1613.  
  1614. scrollToShow(sel, doc) {
  1615. let exclude = getElement(sel, doc);
  1616. if (exclude) {
  1617. var actualTop = exclude.offsetTop;
  1618. var current = exclude.offsetParent;
  1619. while (current !== null) {
  1620. actualTop += current.offsetTop;
  1621. current = current.offsetParent;
  1622. }
  1623. getBody(doc).scrollTop = 0;
  1624. doc.documentElement.scrollTop = 0;
  1625. let maxHeight = Math.max(getBody(doc).scrollHeight, doc.documentElement.scrollHeight);
  1626. getBody(doc).scrollTop = actualTop - 10;
  1627. doc.documentElement.scrollTop = actualTop - 10;
  1628. setTimeout(() => {
  1629. while (actualTop < maxHeight) {
  1630. actualTop += 200;
  1631. getBody(doc).scrollTop = actualTop;
  1632. doc.documentElement.scrollTop = actualTop;
  1633. }
  1634. }, 0);
  1635. return false;
  1636. }
  1637. return true;
  1638. }
  1639.  
  1640. waitElement(doc, selArr) {
  1641. if (!selArr) selArr = this.curSiteRule.waitElement;
  1642. if (!Array.isArray(selArr)) {
  1643. selArr = [selArr];
  1644. }
  1645. let includeSel = selArr[0].trim(), excludeSel;
  1646. if (selArr.length === 2) {
  1647. excludeSel = selArr[1].trim().replace(/^!/, '');
  1648. } else if (includeSel.indexOf('!') === 0) {
  1649. excludeSel = includeSel.replace(/^!/, '');
  1650. includeSel = '';
  1651. }
  1652. if (includeSel) {
  1653. let include = getElement(includeSel, doc);
  1654. if (!include) {
  1655. if (doc !== document) {
  1656. getBody(doc).scrollTop = 9999999;
  1657. if (doc.documentElement) {
  1658. doc.documentElement.scrollTop = 9999999;
  1659. }
  1660. }
  1661. return false;
  1662. }
  1663. }
  1664. if (doc === document) return true;
  1665. if (excludeSel) {
  1666. if (!this.scrollToShow(excludeSel, doc)) {
  1667. if (!loadingDiv.offsetParent && this.insert.parentNode) {
  1668. this.insertElement(loadingDiv);
  1669. }
  1670. return false;
  1671. }
  1672. }
  1673. return true;
  1674. }
  1675.  
  1676. runPageBar(pageBar) {
  1677. if (this.curSiteRule.pageBar && this.curSiteRule.pageBar !== 0) {
  1678. try {
  1679. ((typeof this.curSiteRule.pageBar === 'function') ? this.curSiteRule.pageBar : Function("pageBar",'"use strict";' + this.curSiteRule.pageBar))(pageBar);
  1680. } catch(e) {
  1681. debug(e);
  1682. }
  1683. }
  1684. }
  1685.  
  1686. runWait(cb) {
  1687. let checkEval = null, waitTime = 0;
  1688. if (this.curSiteRule.waitElement) {
  1689. checkEval = async doc => {
  1690. return await this.waitElement(doc);
  1691. };
  1692. } else if(this.curSiteRule.wait) {
  1693. if (isNaN(this.curSiteRule.wait)) {
  1694. try {
  1695. checkEval = (typeof this.curSiteRule.wait === 'function') ? this.curSiteRule.wait : new AsyncFunction("doc", '"use strict";' + this.curSiteRule.wait);
  1696. } catch(e) {
  1697. debug(e);
  1698. }
  1699. } else {
  1700. waitTime = this.curSiteRule.wait;
  1701. }
  1702. }
  1703. cb(checkEval, waitTime);
  1704. }
  1705.  
  1706. findNoNext() {
  1707. if (!this.curSiteRule || !this.curSiteRule.smart || this.curSiteRule.nextLink === 0 || this.possibleRule) return;
  1708. let self = this;
  1709. self.curSiteRule.nextLink = 0;
  1710. self.smartRules = self.smartRules.filter(item => {return item && item.url !== self.curSiteRule.url;});
  1711. self.smartRules.unshift(self.curSiteRule);
  1712. storage.setItem("smartRules", self.smartRules);
  1713. }
  1714.  
  1715. async getRule(callback) {
  1716. var href = location.href.slice(0, 500);
  1717. if (noRuleTest) {
  1718. this.curSiteRule = {};
  1719. this.curSiteRule.url = href;
  1720. this.curSiteRule.smart = true;
  1721. callback();
  1722. return;
  1723. }
  1724. if (_unsafeWindow.pagetualRule) {
  1725. this.curSiteRule = _unsafeWindow.pagetualRule;
  1726. if (!this.curSiteRule.url) this.curSiteRule.url = ".";
  1727. this.curSiteRule.isScript = true;
  1728. }
  1729. if (this.curSiteRule && this.curSiteRule.url && !this.curSiteRule.smart) {
  1730. let urlReg = new RegExp(this.curSiteRule.url, "i");
  1731. if (urlReg.test(href) && this.ruleMatch(this.curSiteRule)) {
  1732. return callback();
  1733. }
  1734. }
  1735. if (this.possibleRule) {
  1736. let urlReg = new RegExp(this.possibleRule.url, "i");
  1737. if (urlReg.test(href) && this.ruleMatch(this.possibleRule)) {
  1738. this.curSiteRule = this.possibleRule;
  1739. debug(this.curSiteRule, 'Match');
  1740. return callback();
  1741. }
  1742. }
  1743. this.curSiteRule = {};
  1744. var self = this;
  1745.  
  1746. function setRule(r) {
  1747. if (self.preSiteRule) {
  1748. href = location.href.slice(0, 500);
  1749. let urlReg = new RegExp(self.preSiteRule.url, "i");
  1750. if (urlReg.test(href) && self.ruleMatch(self.preSiteRule)) {
  1751. self.curSiteRule = self.preSiteRule;
  1752. return callback();
  1753. }
  1754. }
  1755. if (r.from === 2) {
  1756. delete r.autoLoadNum;
  1757. delete r.history;
  1758. delete r.sideController;
  1759. if (r.pageBar === 0) delete r.pageBar;
  1760. }
  1761. if (!r.smart) {
  1762. self.insert = null;
  1763. self.curSiteRule = r;
  1764. self.preSiteRule = r;
  1765. if (r.enable !== 0) debug(r, 'Match');
  1766. } else if (!self.curSiteRule || !self.curSiteRule.smart) self.curSiteRule = r;
  1767. callback();
  1768. }
  1769.  
  1770. function checkRule(r) {
  1771. if (r.from === 1 && r.url.length <= 13) return false;
  1772. let urlReg = new RegExp(r.url, "i");
  1773. if (urlReg.test(href)) {
  1774. if (!self.ruleMatchPre(r)) return false;
  1775. if (r.url.length > 15 && r.from !== 1) {
  1776. self.possibleRule = r;
  1777. }
  1778. if (r.waitElement) {
  1779. let waitTime = 500;
  1780. let checkReady = () => {
  1781. setTimeout(() => {
  1782. if (!self.waitElement(document, r.waitElement) || !self.ruleMatchReady(r)) {
  1783. checkReady();
  1784. } else {
  1785. setRule(r);
  1786. }
  1787. }, parseInt(waitTime));
  1788. };
  1789. checkReady();
  1790. debug(r, 'Wait for');
  1791. return true;
  1792. } else if (r.wait) {
  1793. let waitTime = 500, checkEval, maxCheckTimes = 50;
  1794. if (isNaN(r.wait)) {
  1795. try {
  1796. checkEval = (typeof r.wait === 'function') ? r.wait : AsyncFunction("doc",'"use strict";' + r.wait);
  1797. } catch(e) {
  1798. debug(e, 'Error when checkeval');
  1799. }
  1800. } else {
  1801. waitTime = r.wait;
  1802. }
  1803. let checkReady = () => {
  1804. if (maxCheckTimes-- <= 0) {
  1805. debug("Wait for rule ready but failed");
  1806. setRule(r);
  1807. return;
  1808. }
  1809. setTimeout(async() => {
  1810. if (!self.ruleMatchReady(r) || (checkEval && !await checkEval(document))) {
  1811. checkReady();
  1812. } else {
  1813. setRule(r);
  1814. }
  1815. }, parseInt(waitTime));
  1816. };
  1817. checkReady();
  1818. debug(r, 'Wait for');
  1819. return true;
  1820. }
  1821. if (r.pinUrl) {
  1822. setRule(r);
  1823. return true;
  1824. }
  1825. if (!self.ruleMatchReady(r)) {
  1826. return false;
  1827. }
  1828. setRule(r);
  1829. return true;
  1830. }
  1831. return false;
  1832. }
  1833.  
  1834. function checkHpRules() {
  1835. for (let i in self.hpRules) {
  1836. let rule = self.hpRules[i];
  1837. if (!rule || !rule.url || rule.smart) continue;
  1838. if (checkRule(rule)) return true;
  1839. }
  1840. return false;
  1841. }
  1842.  
  1843. function checkCustomRules() {
  1844. for (let i in self.customRules) {
  1845. let rule = self.customRules[i];
  1846. if (!rule || !rule.url) continue;
  1847. if (checkRule(rule)) return true;
  1848. }
  1849. return false;
  1850. }
  1851.  
  1852. if (rulesData.customFirst) {
  1853. if (checkCustomRules()) return;
  1854. await sleep(1);
  1855. if (checkHpRules()) return;
  1856. } else {
  1857. if (checkHpRules()) return;
  1858. await sleep(1);
  1859. if (checkCustomRules()) return;
  1860. }
  1861. await sleep(1);
  1862.  
  1863. for (let i in this.smartRules) {
  1864. let rule = this.smartRules[i];
  1865. if (!rule || !rule.url || !rule.smart) continue;
  1866. if (href === rule.url) {
  1867. setRule(rule);
  1868. return;
  1869. } else if (rule.listenUrlChange === false && href.replace(/[^\/]+$/, "") === rule.url) {
  1870. setRule(rule);
  1871. return;
  1872. }
  1873. }
  1874. let r = 0;
  1875. async function searchByTime() {
  1876. while (document.hidden) {
  1877. await sleep(1000);
  1878. }
  1879. setTimeout(() => {
  1880. let end = r + 20;
  1881. end = end > self.rules.length ? self.rules.length : end;
  1882. for (; r < end; r++) {
  1883. let rule = self.rules[r];
  1884. if (checkRule(rule)) return;
  1885. }
  1886. if (end >= self.rules.length) {
  1887. if (document.documentElement && document.documentElement.className && document.documentElement.className.indexOf && document.documentElement.className.indexOf('discourse') !== -1) {
  1888. setRule({url: href.replace(/[^\/]+$/, ""), smart: true, nextLink: 0, listenUrlChange: false});
  1889. } else {
  1890. setRule({url: href, smart: true});
  1891. }
  1892. return;
  1893. } else {
  1894. searchByTime();
  1895. }
  1896. }, 1);
  1897. }
  1898. searchByTime();
  1899. }
  1900.  
  1901. addToHpRules(instead) {
  1902. try {
  1903. if (this.curSiteRule.isScript) return;
  1904. if (!this.hpRules) this.hpRules = [];
  1905. let url = this.curSiteRule && this.curSiteRule.url, self = this;
  1906. let href = location.href.slice(0, 500);
  1907. let matchedRules = this.hpRules.filter(rule => rule != self.curSiteRule && new RegExp(rule.url, "i").test(href) && self.ruleMatch(rule));
  1908. if (url) matchedRules.unshift(this.curSiteRule);
  1909. matchedRules.sort((a, b) => {
  1910. if ((a.include || a.exclude) && (!b.include && !b.exclude)) {
  1911. return -1;
  1912. } else if ((b.include || b.exclude) && (!a.include && !a.exclude)) {
  1913. return 1;
  1914. } else {
  1915. if ((a.nextLink || a.pageElement) && (!b.nextLink && !b.pageElement)) {
  1916. return -1;
  1917. } else if ((b.nextLink || b.pageElement) && (!a.nextLink && !a.pageElement)) {
  1918. return 1;
  1919. } else {
  1920. if (a.url.length > b.url.length) {
  1921. return -1;
  1922. } else if (a.url.length < b.url.length) {
  1923. return 1;
  1924. } else {
  1925. return 0;
  1926. }
  1927. }
  1928. }
  1929. });
  1930. this.hpRules = this.hpRules.filter(item => {
  1931. return item && !matchedRules.find(rule => item.url == rule.url && JSON.stringify(item) == JSON.stringify(rule));
  1932. });
  1933. if (instead) {
  1934. if (url) {
  1935. this.hpRules.unshift(this.curSiteRule);
  1936. matchedRules = [];
  1937. }
  1938. } else {
  1939. this.hpRules = matchedRules.concat(this.hpRules);
  1940. }
  1941. if (matchedRules && matchedRules.length) this.curSiteRule = matchedRules[0];
  1942. if (this.hpRules.length > 30) {
  1943. this.hpRules.pop();
  1944. }
  1945. if (!rulesData.sort) rulesData.sort = [1];
  1946. this.hpRules.sort((a, b) => {
  1947. let aSort = -1, bSort = -1;
  1948. for (let s = 0; s < rulesData.sort.length; s++) {
  1949. if (a.from == rulesData.sort[s]) aSort = s;
  1950. if (b.from == rulesData.sort[s]) bSort = s;
  1951. if (aSort > -1 && bSort > -1) break;
  1952. }
  1953. return aSort - bSort;
  1954. });
  1955. storage.setItem("hpRules", this.hpRules);
  1956. } catch (e) {
  1957. debug(e);
  1958. }
  1959. }
  1960.  
  1961. replaceElement(doc) {
  1962. if (!doc || doc === document) return;
  1963. let replaceElementSel = this.curSiteRule.replaceElement;
  1964. if (replaceElementSel) {
  1965. if (!Array.isArray(replaceElementSel)) {
  1966. replaceElementSel = [replaceElementSel];
  1967. }
  1968. replaceElementSel.forEach(sel => {
  1969. let pageEles = getAllElements(sel, document);
  1970. let replaceEles = getAllElements(sel, doc);
  1971. for (let i = 0; i < pageEles.length; i++) {
  1972. let replaceEle = replaceEles[i];
  1973. let pageEle = pageEles[i];
  1974. if (replaceEle) {
  1975. pageEle.parentNode.replaceChild(replaceEle.cloneNode(true), pageEle);
  1976. } else break;
  1977. }
  1978. });
  1979. }
  1980. }
  1981.  
  1982. refreshByClick() {
  1983. let refreshByClickSel = this.curSiteRule.refreshByClick;
  1984. if (refreshByClickSel) {
  1985. let self = this;
  1986. if (!this.refreshByClickHandler) {
  1987. this.refreshByClickHandler = e => {
  1988. if (!self.refreshing) {
  1989. self.refreshing = true;
  1990. setTimeout(() => {
  1991. self.refreshing = false;
  1992. let checkEles = getAllElements(refreshByClickSel, document);
  1993. for (let i = 0; i < checkEles.length; i++) {
  1994. let curEle = checkEles[i];
  1995. if (curEle === e.target || curEle.contains(e.target)) {
  1996. ruleParser.urlChanged();
  1997. isPause = true;
  1998. if (!ruleParser.nextLinkHref) isLoading = false;
  1999. break;
  2000. }
  2001. }
  2002. }, 300);
  2003. }
  2004. }
  2005. }
  2006. document.removeEventListener("click", this.refreshByClickHandler);
  2007. document.addEventListener("click", this.refreshByClickHandler);
  2008. }
  2009. }
  2010.  
  2011. getValidSize(ele, win) {
  2012. if (!win) return {h: 0, w: 0};
  2013. let eleStyle = win.getComputedStyle(ele);
  2014. if (!ele.offsetParent && eleStyle.display !== "contents" && (eleStyle.position !== "fixed" || eleStyle.opacity === 0)) {
  2015. return {h: 0, w: 0};
  2016. }
  2017. if (ele.children && ele.children.length === 1 && (ele.offsetWidth === 0 || ele.offsetHeight === 0)) {
  2018. ele = ele.children[0];
  2019. }
  2020. let h = ele.scrollHeight, w;
  2021. if (eleStyle.overflow === "hidden") {
  2022. h = ele.offsetHeight;
  2023. w = ele.offsetWidth;
  2024. } else w = parseInt(ele.offsetWidth || ele.scrollWidth);
  2025. if (h === 0 && ele.parentNode && ele.parentNode.children.length === 1) {
  2026. h = ele.parentNode.scrollHeight;
  2027. }
  2028. while (h === 0 && ele.children && ele.children.length === 1) {
  2029. ele = ele.children[0];
  2030. h = ele.scrollHeight;
  2031. }
  2032. if (h === 0 && ele.children && ele.children.length) {
  2033. let maxChildSize = {h: 0}, self = this;
  2034. [].forEach.call(ele.children, el => {
  2035. let childSize = self.getValidSize(el, win);
  2036. if (childSize.h > maxChildSize.h) maxChildSize = childSize;
  2037. });
  2038. if (maxChildSize.h !== 0) return maxChildSize;
  2039. }
  2040. const maxNum = 2147483647;
  2041. let moreChild = ele.children[0], minOffsetTop = maxNum;
  2042. while (moreChild) {
  2043. if ((moreChild.offsetParent === ele || moreChild.offsetParent === ele.offsetParent)) {
  2044. let curOffsetTop = moreChild.offsetParent === ele.offsetParent ? moreChild.offsetTop - ele.offsetTop : moreChild.offsetTop;
  2045. if (curOffsetTop < minOffsetTop) {
  2046. minOffsetTop = curOffsetTop;
  2047. }
  2048. }
  2049. moreChild = moreChild.nextElementSibling;
  2050. }
  2051. if (h && minOffsetTop !== maxNum && minOffsetTop > 0) {
  2052. h -= minOffsetTop;
  2053. }
  2054. return {h: h, w: w};
  2055. }
  2056.  
  2057. checkTargetChildren(ele, curWin, articleNum, curHeight) {
  2058. let pf = false;
  2059. if (ele.parentNode) {
  2060. let paStyle = curWin.getComputedStyle(ele.parentNode);
  2061. let paDisplay = paStyle.display;
  2062. let paOverflow = paStyle.overflow;
  2063. pf = (paDisplay.indexOf('flex') !== -1 && paStyle.flexDirection.indexOf("row") === 0 && paStyle.flexWrap !== "wrap") || compareNodeName(ele.parentNode, ["ul"]) || paDisplay.indexOf('grid') !== -1 || paOverflow === "hidden";
  2064. }
  2065. let curStyle = curWin.getComputedStyle(ele);
  2066. if (ele.children.length > 1) {
  2067. if (articleNum > 1) {
  2068. return ">article";
  2069. } else {
  2070. let hasText = false;
  2071. for (let i in ele.childNodes) {
  2072. let child = ele.childNodes[i];
  2073. if (child.nodeType === 3 && child.nodeValue.trim() !== '') {
  2074. hasText = true;
  2075. break;
  2076. }
  2077. }
  2078. let gridArea = curStyle.gridArea;
  2079. if (gridArea && gridArea !== "auto" && gridArea !== "auto / auto / auto / auto") {
  2080. return ">*";
  2081. } else {
  2082. let middleChild = ele.children[parseInt(ele.children.length / 2)];
  2083. if ((curStyle.display === 'flex' && curStyle.flexDirection.indexOf("row") === 0 && curStyle.flexWrap !== "wrap") || (curStyle.float === "none" && curStyle.display !== "table-cell" && (rulesData.opacity !== 0 || hasText) && !pf)) {
  2084. return "";
  2085. } else if ((middleChild.style && middleChild.style.position === "absolute" && middleChild.style.left && middleChild.style.top) || compareNodeName(ele, ["ul"]) || curHeight === 0) {
  2086. return "";
  2087. } else {
  2088. return ">*";
  2089. }
  2090. }
  2091. }
  2092. } else if (pf || curStyle.position === "absolute") {
  2093. return ">*";
  2094. }
  2095. return "";
  2096. }
  2097.  
  2098. getPageElement(doc, curWin, dontFind) {
  2099. if (doc === document && this.docElementValid()) {
  2100. return this.docPageElement;
  2101. }
  2102. let pageElement = null;
  2103. let self = this;
  2104. let body = getBody(doc);
  2105. if (this.curSiteRule.pageElement) {
  2106. let pageElementSel = this.curSiteRule.pageElement;
  2107. if (Array && Array.isArray && Array.isArray(pageElementSel)) {
  2108. pageElementSel = pageElementSel[nextIndex < pageElementSel.length ? nextIndex : 0];
  2109. }
  2110. pageElement = getAllElements(pageElementSel, doc);
  2111. if (this.curSiteRule.smart && (!pageElement || pageElement.length === 0)) {
  2112. const childSelMatch = />\s*\*$/;
  2113. const targetChild = childSelMatch.test(pageElementSel);
  2114. if (targetChild) pageElementSel = pageElementSel.replace(childSelMatch, "");
  2115. let pageElementSelSplit = pageElementSel.split(">");
  2116. while(pageElementSelSplit && pageElementSelSplit.length > 5) {
  2117. pageElementSelSplit.shift();
  2118. let tempSel = pageElementSelSplit.join(">");
  2119. pageElement = getAllElements(tempSel, doc);
  2120. if (pageElement && pageElement.length === 1) {
  2121. if (targetChild) {
  2122. pageElement = pageElement.children;
  2123. }
  2124. this.curSiteRule.pageElement = tempSel + (targetChild ? ">*" : "");
  2125. break;
  2126. }
  2127. }
  2128. if (!pageElement || pageElement.length === 0) {
  2129. pageElementSel = pageElementSel.replace(/:nth-of-type\(\d+\)/g, "");
  2130. pageElement = getAllElements(pageElementSel, doc);
  2131. if (pageElement && pageElement.length === 1) {
  2132. if (targetChild) {
  2133. pageElement = pageElement.children;
  2134. }
  2135. this.curSiteRule.pageElement = pageElementSel + (targetChild ? ">*" : "");
  2136. }
  2137. }
  2138. }
  2139. if (this.curSiteRule.smart && pageElement && pageElement.length) {
  2140. if (pageElement.length === 1 && !pageElement[0].src && pageElement[0].innerHTML.trim() === "") {
  2141. pageElement = null;
  2142. } else if (curWin && curWin !== _unsafeWindow) {
  2143. let parent = pageElement[0].parentNode;
  2144. let loading = parent.querySelector('[class*=loading]');
  2145. if (loading && loading.offsetParent && loading.offsetHeight > parent.offsetHeight>>2) {
  2146. pageElement = null;
  2147. }
  2148. }
  2149. }
  2150. }
  2151. if (pageElement && pageElement.length === 1 && pageElement[0].style.display === 'none') {
  2152. pageElement = [body];
  2153. }
  2154. if (this.curSiteRule.smart && pageElement && pageElement.length > 0 && compareNodeName(pageElement[0], ["tr"])) {
  2155. let mainTr = this.insert.parentNode.querySelectorAll('tr'), mainTdNum = 0, newTdNum = 0;
  2156. mainTr = mainTr[mainTr.length - 1];
  2157. [].forEach.call(mainTr.children, el => {
  2158. if (compareNodeName(el, ["td", "th"])) {
  2159. mainTdNum += el.colSpan || 1;
  2160. }
  2161. });
  2162. [].forEach.call(pageElement[0].children, el => {
  2163. if (compareNodeName(el, ["td", "th"])) {
  2164. newTdNum += el.colSpan || 1;
  2165. }
  2166. });
  2167. if (mainTdNum !== newTdNum) {
  2168. this.curSiteRule.pageElement = this.curSiteRule.pageElement.replace(/> *table.*/, ">table");
  2169. this.getInsert(true);
  2170. return this.getPageElement(doc, curWin, dontFind);
  2171. }
  2172. }
  2173. if ((this.curSiteRule.smart || !this.curSiteRule.pageElement) && (!pageElement || pageElement.length == 0) && curWin && !dontFind) {
  2174. if (!body) return null;
  2175. let bodyHeight = parseInt(body.offsetHeight || body.scrollHeight);
  2176. let curHeight = bodyHeight, curWidth = 0;
  2177. let windowHeight = window.innerHeight || document.documentElement.clientHeight;
  2178. let windowWidth = window.innerWidth || document.documentElement.clientWidth;
  2179. let needCheckNext = (doc == document && this.initNext), nextLeftPos = 0;
  2180. if (needCheckNext && this.initNext.getBoundingClientRect) {
  2181. nextLeftPos = this.initNext.getBoundingClientRect().left;
  2182. }
  2183. function checkElement(ele) {
  2184. if (compareNodeName(ele, ["pre", "code"])) {
  2185. self.curSiteRule.pageElement = geneSelector(ele.parentNode);
  2186. debug(self.curSiteRule.pageElement, 'Page element');
  2187. return [ele.parentNode];
  2188. }
  2189. if (ele.children && ele.children.length === 1) {
  2190. let hasText = false;
  2191. for (let i in ele.childNodes) {
  2192. let child = ele.childNodes[i];
  2193. if (child.nodeType === 3 && child.nodeValue.trim() !== '') {
  2194. hasText = true;
  2195. break;
  2196. }
  2197. }
  2198. if (!hasText) {
  2199. ele = ele.children[0];
  2200. let validSize = self.getValidSize(ele, curWin);
  2201. curHeight = validSize.h;
  2202. curWidth = validSize.w;
  2203. }
  2204. }
  2205. if (compareNodeName(ele, ["picture"]) || !ele.innerText || ele.innerText.trim() === '') {
  2206. self.curSiteRule.pageElement = geneSelector(ele.parentNode) + ">" + ele.nodeName.toLowerCase();
  2207. debug(self.curSiteRule.pageElement, 'Page element');
  2208. let eles = [];
  2209. for (let i = 0; i < ele.parentNode.children.length; i++) {
  2210. let curNode = ele.parentNode.children[i];
  2211. if (curNode.nodeName === ele.nodeName && curNode.id === ele.id && curNode.className === ele.className) {
  2212. eles.push(curNode);
  2213. }
  2214. }
  2215. return eles;
  2216. }
  2217. if (compareNodeName(ele, ["form"]) && ele.parentNode !== getBody(document)) {
  2218. self.curSiteRule.pageElement = geneSelector(ele) + ">*";
  2219. debug(self.curSiteRule.pageElement, 'Page element');
  2220. return ele.children;
  2221. }
  2222. if (ele.children.length === 0 && !self.curSiteRule.pageElement) {
  2223. if (compareNodeName(ele.parentNode, ["p"])) ele = ele.parentNode;
  2224. self.curSiteRule.pageElement = geneSelector(ele.parentNode) + ">" + ele.nodeName.toLowerCase();
  2225. debug(self.curSiteRule.pageElement, 'Page element');
  2226. return getAllElements(self.curSiteRule.pageElement, doc);
  2227. }
  2228. let i, minHeight = curHeight * 0.52, curMaxEle = null, curMaxArea = 0, minWidth = Math.min(curWidth * 0.38, 500);
  2229. let isHori, preOffsetTop = -1;
  2230. let articleNum = 0;
  2231. for (i = 0; i < ele.children.length; i++) {
  2232. let curNode = ele.children[i];
  2233. if (ele !== body && /^H\d$/i.test(curNode.nodeName) && curNode.offsetParent) {
  2234. curMaxEle = null;
  2235. break;
  2236. }
  2237. if (compareNodeName(curNode, ["canvas", "nav"])) continue;
  2238. let curStyle = curWin.getComputedStyle(curNode);
  2239. if (!curNode.offsetParent && curStyle.display !== "contents" && (curStyle.position !== "fixed" || curStyle.opacity === 0)) {
  2240. continue;
  2241. }
  2242. if (!compareNodeName(curNode, ["img"]) && curNode.querySelector('img') === null && /^\s*$/.test(curNode.innerText)) continue;
  2243. if (needCheckNext && !curNode.contains(self.initNext) && getElementTop(curNode) > windowHeight) {
  2244. continue;
  2245. }
  2246. if (compareNodeName(curNode, ["article"])) articleNum++;
  2247. let validSize = self.getValidSize(curNode, curWin);
  2248. let h = validSize.h;
  2249. let w = validSize.w;
  2250. if (isNaN(h) || isNaN(w) || !h || !w) continue;
  2251. isHori = Math.abs(preOffsetTop - curNode.offsetTop) <= 20 ? true : (preOffsetTop === -1 && curNode.nextElementSibling && curNode.nextElementSibling.offsetTop === curNode.offsetTop);
  2252. if (isHori && h <= 50) continue;
  2253. /*if (isHori && nextLeftPos && curMaxEle && curWidth > 500 && curHeight > 500) {
  2254. let curRect = curNode.getBoundingClientRect();
  2255. if (curRect.left > windowWidth>>2 && curRect.left <= nextLeftPos && curRect.right > nextLeftPos) {
  2256. continue;
  2257. }
  2258. }*/
  2259. let a = h * w, moreChild = curNode.children[0];
  2260. while (moreChild) {
  2261. let validSize = self.getValidSize(moreChild, curWin);
  2262. let ch = validSize.h;
  2263. let cw = validSize.w;
  2264. if (h < ch) {
  2265. h = ch;
  2266. }
  2267. if (moreChild.innerText !== "" && ch && cw) {
  2268. a += ch * cw;
  2269. }
  2270. moreChild = moreChild.nextElementSibling;
  2271. }
  2272. let isMax = false;
  2273. if (isHori) {
  2274. if (curMaxEle) {
  2275. if (w > curWidth && (windowWidth>>1) > curWidth) {
  2276. isMax = true;
  2277. } else if (w + 300 > curWidth && a > curMaxArea) {
  2278. isMax = true;
  2279. }
  2280. }
  2281. } else {
  2282. if (curMaxEle && curMaxEle.offsetParent === curNode.offsetParent && curMaxEle.offsetTop === curNode.offsetTop) {
  2283. if (curMaxArea * 2 > a) continue;
  2284. }
  2285. isMax = curMaxArea < a;
  2286. }
  2287. if (curMaxEle === null || isMax) {
  2288. if (isHori) {
  2289. if (w < minWidth) {
  2290. continue;
  2291. }
  2292. }
  2293. if (h < minHeight) {
  2294. if (!needCheckNext || h < (minHeight>>1)) {
  2295. continue;
  2296. }
  2297. if (!ele.contains(self.initNext)) {
  2298. continue;
  2299. } else if (!curNode.contains(self.initNext) && h < curHeight >> 1) {
  2300. continue;
  2301. }
  2302. }
  2303. curHeight = h;
  2304. curMaxArea = a;
  2305. curWidth = w;
  2306. curMaxEle = curNode;
  2307. preOffsetTop = curNode.offsetTop;
  2308. }
  2309. }
  2310. let curHeightPercent = curHeight / bodyHeight;
  2311. if (curMaxEle && curHeightPercent <= 0.18) {
  2312. let article;
  2313. for (let i = 0; i < mainSel.length; i++) {
  2314. article = doc.querySelectorAll(mainSel[i]);
  2315. if (article && article.length === 1) break;
  2316. }
  2317. if (article && article.length === 1) {
  2318. article = article[0];
  2319. let childrenEnd = self.checkTargetChildren(article, curWin, articleNum, curHeight);
  2320. self.curSiteRule.pageElement = article.nodeName.toLowerCase() + (article.id ? "#" + article.id : "") + (article.className ? "." + article.className.replace(/ /g, ".") : "") + childrenEnd;
  2321. debug(self.curSiteRule.pageElement, 'Page element');
  2322. return childrenEnd ? article.children : [article];
  2323. }
  2324. curMaxEle = null;
  2325. }
  2326. if (curMaxEle && (!compareNodeName(curMaxEle, ["ul"]) || curHeightPercent > 0.8)) {
  2327. let sameClassNum = 0, hasDifferent = false;
  2328. if (curMaxEle.className) {
  2329. for(i = 0; i < ele.children.length; i++) {
  2330. let curNode = ele.children[i];
  2331. if (curMaxEle !== curNode && curNode.style.display !== 'none' && curMaxEle.className === curNode.className && curMaxEle.nodeName === curNode.nodeName){
  2332. sameClassNum++;
  2333. } else if (curMaxEle.className !== curNode.className) {
  2334. hasDifferent = true;
  2335. }
  2336. }
  2337. }
  2338. if (sameClassNum < 2 || (sameClassNum < 5 && hasDifferent)) {
  2339. return checkElement(curMaxEle);
  2340. }
  2341. }
  2342. if (ele.nodeName === "APP-ROOT") {
  2343. isPause = true;
  2344. debug(ele, "Angular root");
  2345. return null;
  2346. }
  2347. while (compareNodeName(ele, ["p", "br", "td"])) {
  2348. ele = ele.parentNode;
  2349. }
  2350. if (compareNodeName(ele, ["tbody"])) {
  2351. self.curSiteRule.pageElement = geneSelector(ele) + ">*";
  2352. if (ele.children.length > 0 && ele.children[0].querySelector("th")) {
  2353. self.curSiteRule.pageElement += ":not(:first-child)";
  2354. }
  2355. debug(self.curSiteRule.pageElement, 'Page element');
  2356. return ele.children;
  2357. }
  2358. let imgs = ele.querySelectorAll('img');
  2359. if (imgs.length === 1) {
  2360. let img = imgs[0];
  2361. if (img.offsetWidth > ele.offsetWidth / 3 * 2 && img.offsetHeight > ele.offsetHeight / 2) {
  2362. ele = img;
  2363. }
  2364. }
  2365. let childrenEnd = self.checkTargetChildren(ele, curWin, articleNum, curHeight);
  2366. if (childrenEnd) {
  2367. self.curSiteRule.pageElement = geneSelector(ele) + childrenEnd;
  2368. ele = ele.children;
  2369. } else {
  2370. if (ele.scrollHeight === 0 && ele.parentNode.children.length === 1) {
  2371. ele = ele.parentNode;
  2372. }
  2373. self.curSiteRule.pageElement = geneSelector(ele);
  2374. ele = [ele];
  2375. }
  2376. debug(self.curSiteRule.pageElement, 'Page element');
  2377. return ele;
  2378. }
  2379. pageElement = checkElement(body);
  2380. if (doc === document && pageElement && pageElement.length > 0 && self.initNext) {
  2381. let posEle = pageElement[pageElement.length - 1];
  2382. while (posEle && !posEle.offsetParent) {
  2383. posEle = posEle.previousElementSibling || posEle.parentNode;
  2384. }
  2385. if (posEle && posEle.lastElementChild) {
  2386. if (posEle.scrollHeight === 0) posEle = posEle.lastElementChild;
  2387. else if (posEle.lastElementChild.offsetTop > 500) {
  2388. posEle = posEle.lastElementChild;
  2389. }
  2390. }
  2391. let lastBottom = forceState !== 2 && forceState !== 3 && posEle && getElementBottom(posEle);
  2392. if (lastBottom && getElementTop(self.initNext) - lastBottom > 1000) {
  2393. debug("Stop as too long between next & page element, try to enable Force-Join mode.");
  2394. isPause = true;
  2395. pageElement = [];
  2396. sideController.remove();
  2397. } else {
  2398. if (pageElement.length === 1 && compareNodeName(pageElement[0], ["img"])) {
  2399. self.curSiteRule.pageBar = 0;
  2400. }
  2401. }
  2402. }
  2403. //if(pageElement)this.saveCurSiteRule();
  2404. }
  2405.  
  2406. if (doc !== document) {
  2407. this.setPageElementCss(pageElement);
  2408. this.lazyImgAction(pageElement, doc);
  2409. this.filterEles(doc, pageElement);
  2410. } else if (!this.docPageElement) {
  2411. this.setPageElementCss(pageElement, true);
  2412. this.docPageElement = pageElement;
  2413. this.filterEles(doc, pageElement);
  2414. if (this.nextLinkHref) {
  2415. this.openInNewTab(pageElement);
  2416. }
  2417. }
  2418. return pageElement;
  2419. }
  2420.  
  2421. showAddedElements() {
  2422. if (!this.addedElementsIsHide) return;
  2423. if (this.addedElePool && this.addedElePool.length) {
  2424. this.addedElePool.forEach(ele => {
  2425. ele.classList && ele.classList.remove("pagetual-hide");
  2426. });
  2427. }
  2428. this.addedElementsIsHide = false;
  2429. }
  2430.  
  2431. hideAddedElements() {
  2432. if (this.addedElePool && this.addedElePool.length) {
  2433. this.addedElePool.forEach(ele => {
  2434. ele.classList && ele.classList.add("pagetual-hide");
  2435. });
  2436. }
  2437. this.addedElementsIsHide = true;
  2438. }
  2439.  
  2440. toggleAddedElements() {
  2441. if (this.addedElementsIsHide) {
  2442. this.showAddedElements();
  2443. } else {
  2444. this.hideAddedElements();
  2445. }
  2446. }
  2447.  
  2448. changeVisibility() {
  2449. let contentVisibility = this.curSiteRule.contentVisibility || rulesData.contentVisibility;
  2450. if (!contentVisibility) return;
  2451. if (!this.changingVisibility) {
  2452. clearTimeout(this.changeVisibilityTimer);
  2453. this.changeVisibilityTimer = setTimeout(() => {
  2454. this.changingVisibility = true;
  2455. this.changeVisibility();
  2456. }, 300);
  2457. return;
  2458. }
  2459. this.changingVisibility = false;
  2460. if (!this.visibilityItems || !this.visibilityItems.length || this.visibleIndex < 0) return;
  2461. let tempIndex = this.visibleIndex, findVisible = false, lastVisible = 0;
  2462. let viewPortHeight = window.innerHeight || document.documentElement.clientHeight || getBody(document).clientHeight;
  2463. let checkItem = this.visibilityItems[tempIndex];
  2464. while(checkItem) {
  2465. if (checkItem.offsetParent) {
  2466. if (!checkItem.style.containIntrinsicSize) return;
  2467. let clientRect = checkItem.getBoundingClientRect();
  2468. let top = clientRect && clientRect.top;
  2469. let bottom = clientRect && clientRect.bottom;
  2470. if (bottom > 0 && top < viewPortHeight) {
  2471. if (!findVisible) {
  2472. findVisible = true;
  2473. lastVisible = tempIndex;
  2474. }
  2475. checkItem.style.contentVisibility = "visible";
  2476. } else {
  2477. if (top < viewPortHeight && checkItem.style.contentVisibility === "auto") {
  2478. break;
  2479. } else checkItem.style.contentVisibility = "auto";
  2480. }
  2481. }
  2482. if (tempIndex === 0) break;
  2483. tempIndex--;
  2484. checkItem = this.visibilityItems[tempIndex];
  2485. }
  2486. tempIndex = this.visibleIndex + 1;
  2487. if (findVisible) {
  2488. this.visibleIndex = lastVisible;
  2489. }
  2490. checkItem = this.visibilityItems[tempIndex];
  2491. while(checkItem) {
  2492. if (checkItem.offsetParent) {
  2493. if (!checkItem.style.containIntrinsicSize) return;
  2494. let clientRect = checkItem.getBoundingClientRect();
  2495. let top = clientRect && clientRect.top;
  2496. let bottom = clientRect && clientRect.bottom;
  2497. if (bottom > 0 && top < viewPortHeight) {
  2498. findVisible = true;
  2499. lastVisible = tempIndex;
  2500. checkItem.style.contentVisibility = "visible";
  2501. } else {
  2502. if (findVisible && checkItem.style.contentVisibility === "auto") {
  2503. break;
  2504. } else checkItem.style.contentVisibility = "auto";
  2505. }
  2506. }
  2507. if (tempIndex === this.visibilityItems.length - 1) break;
  2508. tempIndex++;
  2509. checkItem = this.visibilityItems[tempIndex];
  2510. }
  2511. if (findVisible) {
  2512. this.visibleIndex = lastVisible;
  2513. }
  2514. }
  2515.  
  2516. setPageElementCss(pageElement, init) {
  2517. let self = this;
  2518. if (pageElement && pageElement.length > 0) {
  2519. let pageElementCss = this.curSiteRule.pageElementCss || rulesData.pageElementCss;
  2520. if (!pageElementCss && init && !this.nextLinkHref) return;
  2521. let contentVisibility = this.curSiteRule.contentVisibility || rulesData.contentVisibility;
  2522. if (!contentVisibility && !pageElementCss) return;
  2523. [].forEach.call(pageElement, (ele, i) => {
  2524. if (!compareNodeName(ele, ["link", "meta", "style", "script"])) {
  2525. if (pageElementCss) {
  2526. if (pageElementCss !== '0' && !ele.dataset.pagetualPageElement) {
  2527. ele.style.cssText = (ele.style.cssText || '') + pageElementCss;
  2528. ele.dataset.pagetualPageElement = 1;
  2529. }
  2530. }
  2531. if (contentVisibility) {
  2532. ele.style.containIntrinsicSize = `auto ${ele.offsetHeight || self.preVisibleHeight || 100}px`;
  2533. if (ele.style.containIntrinsicSize) {
  2534. if (ele.offsetHeight) self.preVisibleHeight = ele.offsetHeight;
  2535. if (init) {
  2536. ele.style.contentVisibility = "visible";
  2537. self.visibilityItems.push(ele);
  2538. self.visibleIndex++;
  2539. } else {
  2540. ele.style.contentVisibility = emuIframe ? "visible" : "auto";
  2541. }
  2542. }
  2543. }
  2544. }
  2545. });
  2546. }
  2547. }
  2548.  
  2549. clearAddedElements() {
  2550. if (this.addedElePool && this.addedElePool.length) {
  2551. this.addedElePool.forEach(ele => {
  2552. if (ele.parentNode) ele.parentNode.removeChild(ele);
  2553. });
  2554. }
  2555. this.addedElePool = [];
  2556. sideController.remove();
  2557. }
  2558.  
  2559. linkHasHref(link) {
  2560. return link && link.href && link.href.replace && !this.hrefIsJs(link.href);
  2561. }
  2562.  
  2563. hrefIsJs(href) {
  2564. return /^(javascript|#|$)/.test(href.trim().replace("#p{", "").replace(location.href, ""));
  2565. }
  2566.  
  2567. async querySelectorList(source, list, defaultView) {
  2568. for (let i = 0; i < list.length; i++) {
  2569. await sleep(1);
  2570. let sel = list[i];
  2571. let result = getAllElements(sel, source);
  2572. if (result.length > 0) {
  2573. for (let i = result.length - 1; i >= 0; i--) {
  2574. let ele = result[i];
  2575. if (prevReg.test(ele.innerText)) continue;
  2576. if (!defaultView || isVisible(ele, defaultView)) return ele;
  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. ".pagination>.active+a",
  2652. "a[data-pagination=next]",
  2653. ".pageButtonsCurrent+a",
  2654. "a[class*=nextpage]",
  2655. "li.page-current+li>a",
  2656. "[class^=pag] a[rel=next]",
  2657. "[class^=Pag] [aria-label=next]",
  2658. "[aria-label='Next Page']",
  2659. "[aria-label='Next page']",
  2660. "[aria-label='next page']",
  2661. ".pagination-nav__item--next>a",
  2662. "a.pageright",
  2663. ".page-numbers.current+a",
  2664. "a.page-numbers.next",
  2665. "body [class*=pagination] li.active+span+li>a",
  2666. "body [class*=pagination] li.active+li>a",
  2667. "body [class^=pag] .current+a",
  2668. ".page_current+a",
  2669. "input[value='next']",
  2670. "input[value='Next page']",
  2671. "input[value='下一页']",
  2672. "input[value='下一頁']",
  2673. "a#pb_next",
  2674. "a#rightFix",
  2675. "a#btnPreGn",
  2676. "a.page-next",
  2677. "a.pages-next",
  2678. "a.page.right",
  2679. ".paging>.active+.item",
  2680. "a#next",
  2681. ".next>a",
  2682. ".next>button",
  2683. "a[alt=next]",
  2684. ".pg_area>em+a",
  2685. "button.next:not([disabled])",
  2686. ".btn_next:not([disabled])",
  2687. ".btn-next:not([disabled])",
  2688. "a#linkNext",
  2689. "body a[class*=page__next]",
  2690. "body [class*=pager]>a.next",
  2691. "body [class*=pagination-next]>a",
  2692. "body [class*=pagination-next]>button",
  2693. "body [class*=page--current]+li>a",
  2694. "body [class*=Pages]>.curr+a",
  2695. "body [class*=page]>.cur+a",
  2696. "body [class*=pagination] [class*=next]",
  2697. ".page>em+a",
  2698. "[name*=nextPage]",
  2699. '//button[contains(@class, "Page")][text()="Next"]',
  2700. '//button[contains(@class, "page")][text()="next"]'
  2701. ];
  2702. let next = await this.querySelectorList(body, selectorList, doc.defaultView);
  2703. if (!next) {
  2704. await sleep(1);
  2705. let nexts = body.querySelectorAll("a.next");
  2706. for (i = 0; i < nexts.length; i++) {
  2707. let n = nexts[i];
  2708. if (this.verifyElement(n) && this.linkHasHref(n) && !prevReg.test(n.innerText.trim())) {
  2709. next = n;
  2710. break;
  2711. }
  2712. }
  2713. }
  2714. if (next) {
  2715. let innerText = next.innerText;
  2716. let isJs = !this.linkHasHref(next);
  2717. if (innerText && nextTextReg2.test(innerText.trim())) {
  2718. if (isJs) {
  2719. if (this.verifyElement(next)) {
  2720. nextJs2 = next;
  2721. }
  2722. } else {
  2723. next2 = next;
  2724. }
  2725. next = null;
  2726. } else {
  2727. if (isJs) {
  2728. if (this.verifyElement(next)) {
  2729. jsNext = next;
  2730. }
  2731. next = null;
  2732. }
  2733. }
  2734. }
  2735. if (!next) {
  2736. await sleep(1);
  2737. next = body.querySelector("a.curr+a") ||
  2738. body.querySelector("div.wp-pagenavi>span.current+a,div.page-nav>span.current+a,div.article-paging>span+a") ||
  2739. body.querySelector(".number>ul>li.active+li>a,.pager a.next");
  2740. }
  2741. if (!next) {
  2742. await sleep(1);
  2743. let pageDiv = body.querySelector(".pages>ul,.page_no>ul");
  2744. if (pageDiv) {
  2745. cur = pageDiv.querySelector("li>b,li>strong");
  2746. if (cur) next = cur.parentNode.nextElementSibling;
  2747. if (next) next = next.querySelector("a");
  2748. }
  2749. }
  2750. if (!next) {
  2751. await sleep(1);
  2752. next = body.querySelector(".pages>a[href='javascript:;']+a");
  2753. if (next && (next.href === "javascript:;" || next.getAttribute("href") === "#")) next = null;
  2754. }
  2755. if (!next) {
  2756. await sleep(1);
  2757. let pageDiv = body.querySelector(".pagination,.pagination-list");
  2758. if (pageDiv) {
  2759. cur = pageDiv.querySelector("[class*=current],.page-selected");
  2760. if (cur) next = cur.parentNode.nextElementSibling;
  2761. if (next) next = next.querySelector("a");
  2762. }
  2763. }
  2764. if (!next) {
  2765. await sleep(1);
  2766. cur = body.querySelector(".paginator td strong");
  2767. if (cur) {
  2768. while (cur && !compareNodeName(cur, ["td"])) {
  2769. cur = cur.parentNode;
  2770. }
  2771. next = cur && cur.nextElementSibling;
  2772. if (next) next = next.querySelector("a");
  2773. }
  2774. }
  2775. if (!next) {
  2776. await sleep(1);
  2777. let pageDivs = body.querySelectorAll("[class*=pagination],[class*=Pagination]");
  2778. if (pageDivs && pageDivs.length) {
  2779. for (let i = pageDivs.length - 1; i >= 0; i--) {
  2780. let p = pageDivs[i];
  2781. if (/(next\s*(»|>>|>|›|→|❯)?|&gt;|▶|>|›|→|❯)/i.test(p.title || p.value || '')) {
  2782. next = p.querySelector("a,button,[type='button']") || p;
  2783. break;
  2784. } else if (/^(next\s*(»|>>|>|›|→|❯)?|&gt;|▶|>|›|→|❯)$/i.test((p.innerText || '').trim())) {
  2785. next = p.querySelector("a,button,[type='button']") || p;
  2786. break;
  2787. }
  2788. }
  2789. if (next && !this.linkHasHref(next)) {
  2790. if (!jsNext) jsNext = next;
  2791. next = null;
  2792. }
  2793. }
  2794. }
  2795. if (!next) {
  2796. let isApp = !!body.querySelector("main#app");
  2797. let aTags = body.querySelectorAll("a,button,[type='button'],.btn-action");
  2798. for (i = aTags.length - 1; i >= 0; i--) {
  2799. if (next1) break;
  2800. if (i % 100 === 0) {
  2801. await sleep(1);
  2802. }
  2803. let aTag = aTags[i];
  2804. let title = aTag.title || "";
  2805. let value = aTag.value || "";
  2806. let innerText = aTag.innerText || "";
  2807. if (innerText === "" || (title !== "" && title.length < innerText.length)) {
  2808. innerText = title;
  2809. }
  2810. if (innerText === "" || (value !== "" && value.length < innerText.length)) {
  2811. innerText = value;
  2812. }
  2813. if (innerText !== "") {
  2814. if (innerText === "§") continue;
  2815. innerText = innerText.trim();
  2816. if (innerText.length > 80) continue;
  2817. }
  2818. if (!this.verifyElement(aTag)) continue;
  2819. if (aTag.dataset && aTag.dataset.preview) continue;
  2820. let availableHref = aTag.href && aTag.href.length < 250 && !/^(javascript:|#)/.test(aTag.href);
  2821. if (availableHref && /next\-?(page)?$|\/video\/|\/vod\/play\//i.test(aTag.href)) continue;
  2822. if (compareNodeName(aTag.parentNode, ["blockquote"])) continue;
  2823. if (aTag.previousElementSibling && /\b(play|volume)\b/.test(aTag.previousElementSibling.className)) continue;
  2824. if (aTag.nextElementSibling && /\b(play|volume)\b/.test(aTag.nextElementSibling.className)) continue;
  2825. let isJs = !this.linkHasHref(aTag);
  2826. if (exist && isJs && !aTag.offsetParent) continue;
  2827. if (innerText) {
  2828. innerText = innerText.split(/\n/)[0].replace(/ /g, '');
  2829. if (isJs && /^(»|>>|>|›|→|❯)$/.test(innerText)) continue;
  2830. if (innerText && innerText.length <= 25) {
  2831. if (!next1) {
  2832. if (nextTextReg1.test(innerText)) {
  2833. if (isJs) {
  2834. if (!nextJs1) nextJs1 = aTag;
  2835. } else {
  2836. next1 = aTag;
  2837. }
  2838. }
  2839. }
  2840. if (!next4) {
  2841. if (!next2) {
  2842. if (nextTextReg2.test(innerText) || /nextpage|pager\-older|next.chap/i.test(aTag.className) || /^(»|>>)$/.test(innerText)) {
  2843. if (isJs) {
  2844. if (!nextJs2) nextJs2 = aTag;
  2845. } else {
  2846. next2 = aTag;
  2847. }
  2848. }
  2849. }
  2850. if (!isApp && !next3 && !isJs) {
  2851. if (/^(next\s*(»|>>|>|›|→|❯)?|&gt;|▶|>|›|→|❯)$/i.test(aTag.textContent) && aTag.parentNode.hasAttribute && !aTag.parentNode.hasAttribute("jsaction")) {
  2852. next3 = aTag;
  2853. }
  2854. }
  2855. }
  2856. }
  2857. }
  2858. if (isJs) continue;
  2859. if (!next4) {
  2860. let prevEle = aTag.previousElementSibling;
  2861. if (prevEle && compareNodeName(prevEle, ["b", "span", "strong"])) {
  2862. if (/^\d+$/.test(aTag.innerText.trim()) && /^\d+$/.test(prevEle.innerText.trim()) && parseInt(aTag.innerText) === parseInt(prevEle.innerText) + 1) {
  2863. next4 = aTag;
  2864. }
  2865. }
  2866. }
  2867. if (urlWillChange) continue;
  2868. if (!next4 && availableHref) {
  2869. let aHref = aTag.href.indexOf("http") === 0 ? aTag.href : this.canonicalUri(aTag.href);
  2870. if (aHref.indexOf(location.hostname) === -1) continue;
  2871. let _aHref = aHref.replace("?&", "?").replace("index.php?", "?");
  2872. if (preStr || afterStr) {
  2873. let _aHrefTrim = _aHref;
  2874. if (preStr) _aHrefTrim = _aHrefTrim.replace(preStr, "");
  2875. if (afterStr) _aHrefTrim = _aHrefTrim.replace(afterStr, "");
  2876. if (_aHrefTrim == pageNum + 1) {
  2877. next4 = aTag;
  2878. }
  2879. } else if (this.curUrl !== aHref) {
  2880. _aHref = _aHref.replace(/\.s?html?$/i, "").toLowerCase();
  2881. if (_aHref.indexOf(_url) !== -1) {
  2882. let pageTwoMatch = _aHref.replace(_url, "").match(pageTwoReg);
  2883. if (pageTwoMatch) {
  2884. afterStr = pageTwoMatch[2];
  2885. next4 = aTag;
  2886. }
  2887. }
  2888. }
  2889. if (next4 && !/page/.test(next4.href)) {
  2890. let curHref = next4.getAttribute("href");
  2891. let curPageReg = new RegExp("(.*)" + (pageNum + 1) + afterStr.replace(/([\.\?])/g, '\\$1'));
  2892. let otherPageHref = curHref.replace(curPageReg, `$1${pageNum}${afterStr}`);
  2893. let otherPageEle = body.querySelector(`a[href='${otherPageHref}']`);
  2894. if (!otherPageEle) {
  2895. otherPageHref = curHref.replace(curPageReg, `$1${pageNum + 2}${afterStr}`);
  2896. otherPageEle = body.querySelector(`a[href='${otherPageHref}']`);
  2897. }
  2898. if (otherPageEle) {
  2899. let parent = otherPageEle.parentNode;
  2900. if (parent && parent.parentNode) {
  2901. parent = parent.parentNode;
  2902. if (parent.parentNode) {
  2903. parent = parent.parentNode;
  2904. }
  2905. }
  2906. if (parent && parent.contains(next4) && !/^\d+$/.test(next4.innerText.trim())) {
  2907. next4 = null;
  2908. }
  2909. }
  2910. }
  2911. }
  2912. }
  2913. if (next2 && doubtTextReg.test(next2.innerText)) {
  2914. next2 = this.verifyNext(next2, doc, false);
  2915. }
  2916. if (nextJs2 && doubtTextReg.test(nextJs2.innerText)) {
  2917. nextJs2 = this.verifyNext(nextJs2, doc, true);
  2918. }
  2919. if (next3) {
  2920. next3 = this.verifyNext(next3, doc, false);
  2921. }
  2922. }
  2923. if (!next) next = next1 || next4 || next3 || next2;
  2924. if (!next && location.pathname + location.search !== "/") {
  2925. next = jsNext || nextJs1 || nextJs2;
  2926. if (next && next.parentNode.className && next.parentNode.className.indexOf && next.parentNode.className.indexOf('tab') !== -1) next = null;
  2927. }
  2928. if (next && next.classList && (next.classList.contains("results-more") || next.classList.contains("no"))) next = null;
  2929. if (next && next.hasAttribute && next.hasAttribute("disabled")) next = null;
  2930. if (next && next.parentNode.href && compareNodeName(next.parentNode, ["a"])) next = next.parentNode;
  2931. return {next:next, canSave:canSave};
  2932. }
  2933.  
  2934. verifyNext(next, doc, isJs) {
  2935. if (!next) return null;
  2936. if (!isJs) {
  2937. let href = next.getAttribute("href");
  2938. if (href && !/\d/.test(next.getAttribute("href"))) {
  2939. return null;
  2940. }
  2941. }
  2942. if (next.previousElementSibling && compareNodeName(next.previousElementSibling, ["br"])) return null;
  2943. let eles = [];
  2944. if (next.innerText && next.innerText.indexOf("\n") === -1) {
  2945. eles = getAllElements(`//${next.nodeName}[text()='${next.innerText}']`, doc);
  2946. }
  2947. if (eles.length >= 2 && eles[0].href !== eles[1].href) {
  2948. next = null;
  2949. } else if (doc === document) {
  2950. let left = getElementLeft(next);
  2951. if (left < 20 || (document.documentElement.scrollWidth > 500 && left < 250)) {
  2952. next = null;
  2953. } else {
  2954. let top = getElementTop(next);
  2955. if (top < 20 || (left < window.innerWidth / 3 && top < window.innerHeight / 3)) {
  2956. next = null;
  2957. } else {
  2958. let bottom = top + next.offsetHeight || 0;
  2959. let scrollH = Math.max(document.documentElement.scrollHeight, getBody(document).scrollHeight);
  2960. if (scrollH - bottom < 10) next = null;
  2961. }
  2962. }
  2963. }
  2964. return next;
  2965. }
  2966.  
  2967. canonicalUri(src) {
  2968. if (!src) {
  2969. return "";
  2970. }
  2971. if (src.charAt(0) === "#") return this.curUrl + src;
  2972. if (src.charAt(0) === "?") return this.curUrl.replace(/^([^\?#]+).*/, "$1" + src);
  2973. let origin = location.protocol + '//' + location.host;
  2974. let url = this.basePath || origin;
  2975. url = url.replace(/(\?|#).*/, "");
  2976. if (/https?:\/\/[^\/]+$/.test(url)) url = url + '/';
  2977. if (url.indexOf("http") !== 0) url = origin + url;
  2978. var root_page = /^[^\?#]*\//.exec(url)[0],
  2979. root_domain = /^\w+\:\/\/\/?[^\/]+/.exec(root_page)[0],
  2980. absolute_regex = /^\w+\:\/\//;
  2981. this.updateUrl = false;
  2982. while (src.indexOf("../") === 0) {
  2983. src = src.substr(3);
  2984. root_page = root_page.replace(/\/[^\/]+\/$/, "/");
  2985. this.updateUrl = true;
  2986. }
  2987. src = src.replace(/\.\//, "");
  2988. if (/^\/\/\/?/.test(src)) {
  2989. src = location.protocol + src;
  2990. }
  2991. return (absolute_regex.test(src) ? src : ((src.charAt(0) === "/" ? root_domain : root_page) + src));
  2992. }
  2993.  
  2994. getLinkByPage(url, pageNum) {
  2995. if (!url) return null;
  2996. if (this.curSiteRule.pageNum) {
  2997. let result = this.curSiteRule.pageNum;
  2998. let strMatch = result.match(/\{.*?}/);
  2999. if (!strMatch) return null;
  3000. let urlReg = new RegExp("(" + result.replace(strMatch[0], ")\\d+(") + ")", "i");
  3001. let code = strMatch[0].replace(/^{/, "").replace(/}$/, "").replace(/\$p/g, pageNum);
  3002. if (code === pageNum) {
  3003. result = url.replace(urlReg, "$1" + code + "$2");
  3004. } else {
  3005. try {
  3006. code = Function('"use strict";return ' + code)();
  3007. if (code && code % 1 == 0) {
  3008. result = url.replace(urlReg, "$1" + code + "$2");
  3009. } else return null;
  3010. } catch(e) {
  3011. debug(e);
  3012. }
  3013. }
  3014. if (result != url) {
  3015. return result;
  3016. }
  3017. }
  3018. return url.replace(/([&\/\?](p=|page[=\/_-]?))\d+/i, "$1" + pageNum).replace(/([_-])\d+\./i, "$1" + pageNum + ".");
  3019. }
  3020.  
  3021. getPageNumFromUrl(url, defaultPage) {
  3022. if (!url) return defaultPage;
  3023. if (this.curSiteRule.pageNum) {
  3024. let result = this.curSiteRule.pageNum;
  3025. let strMatch = result.match(/\{.*?}/);
  3026. if (!strMatch) return defaultPage;
  3027. let urlReg = new RegExp(".*" + result.replace(strMatch[0], "(\\d+)") + ".*", "i");
  3028. let curShowNum = url.replace(urlReg, "$1");
  3029. if (curShowNum !== url) {
  3030. let code = strMatch[0].replace(/^{/, "").replace(/}$/, "");
  3031. if (code === "$p") {
  3032. return curShowNum;
  3033. } else {
  3034. try {
  3035. let page1 = parseInt(Function('"use strict";return ' + code.replace("$p", "0"))());
  3036. let page2 = parseInt(Function('"use strict";return ' + code.replace("$p", "1"))());
  3037. let numGap = page2 - page1;
  3038. let _page = (parseInt(curShowNum) - page1) / numGap;
  3039. if (_page && _page % 1 === 0) return _page;
  3040. else {
  3041. this.curSiteRule.pageNum = null;
  3042. return defaultPage;
  3043. }
  3044. } catch(e) {
  3045. debug(e);
  3046. }
  3047. }
  3048. } else {
  3049. return defaultPage;
  3050. }
  3051. }
  3052. let pageNum = url.replace(/.*[&\/\?](p=|page[=\/_-]?)(\d+).*/i, "$2");
  3053. return pageNum === url ? defaultPage : (pageNum.length > 4 ? defaultPage : pageNum);
  3054. }
  3055.  
  3056. reachedLastPage() {
  3057. if (rulesData.lastPageTips) {
  3058. showTips(i18n("lastPage"), "", 800);
  3059. }
  3060. _unsafeWindow.postMessage({
  3061. action: "lastPage",
  3062. command: 'pagetual'
  3063. }, '*');
  3064. if (sideController.inited) {
  3065. sideController.frame.classList.add("end");
  3066. }
  3067. }
  3068.  
  3069. async getNextLink(doc, exist) {
  3070. let nextLink = null, page, href;
  3071. let getNextLinkByForm = (form, submitBtn, n) => {
  3072. let params = [];
  3073. let formData = new FormData(form);
  3074. if (submitBtn && submitBtn.getAttribute) {
  3075. let btnValue, btnName;
  3076. btnName = submitBtn.getAttribute("name");
  3077. btnValue = submitBtn.getAttribute("value");
  3078. if (btnName && btnValue) params = [btnName + "=" + encodeURIComponent(btnValue)];
  3079. }
  3080. for (let [key, value] of formData) {
  3081. if (n && /^(p|page)$/i.test(key)) {
  3082. params.push(key + '=' + n);
  3083. } else {
  3084. params.push(key + '=' + encodeURIComponent(value));
  3085. }
  3086. }
  3087. params = params.join('&');
  3088. return form.action + (form.action.indexOf('?') === -1 ? '?' : '&') + params + (form.method === 'post' ? '#p{' + params + '}' : '');
  3089. };
  3090. if (this.curSiteRule.pageElementByJs) {
  3091. this.nextLinkHref = "#";
  3092. return true;
  3093. } else if (this.curSiteRule.nextLinkByJs) {
  3094. try {
  3095. let over = _url => {};
  3096. let targetUrl = await ((typeof this.curSiteRule.nextLinkByJs === 'function') ? this.curSiteRule.nextLinkByJs : new AsyncFunction("doc", '"use strict";' + this.curSiteRule.nextLinkByJs))(doc);
  3097. if (targetUrl) nextLink = {href: targetUrl};
  3098. } catch(e) {
  3099. debug(e);
  3100. }
  3101. } else if (this.curSiteRule.nextLinkByUrl) {
  3102. let targetUrl = this.curUrl.replace(new RegExp(this.curSiteRule.nextLinkByUrl[0], "i"), this.curSiteRule.nextLinkByUrl[1]);
  3103. if (targetUrl !== this.curUrl) {
  3104. let includeSel = this.curSiteRule.nextLinkByUrl[2];
  3105. let excludeSel = this.curSiteRule.nextLinkByUrl[3];
  3106. if (includeSel) {
  3107. includeSel = includeSel.trim();
  3108. if (!getElement(includeSel, doc)) {
  3109. this.nextLinkHref=false;
  3110. return null;
  3111. }
  3112. }
  3113. if (excludeSel) {
  3114. excludeSel = excludeSel.trim();
  3115. if (getElement(excludeSel, doc)) {
  3116. this.nextLinkHref=false;
  3117. return null;
  3118. }
  3119. }
  3120. let reps = targetUrl.match(/{.*?}/g);
  3121. if (reps) {
  3122. reps.forEach(rep => {
  3123. let code = rep.replace("{", "").replace("}", "").replace(/\(\)/g, "0");
  3124. let result = code.match(/^(\d*)\+1$/);
  3125. if (result) {
  3126. result = parseInt(result[1] || 1) + 1;
  3127. } else {
  3128. try {
  3129. result = Function('"use strict";return ' + code)();
  3130. } catch(e) {
  3131. debug(e);
  3132. }
  3133. }
  3134. targetUrl = targetUrl.replace(rep, result);
  3135. });
  3136. }
  3137. }
  3138. nextLink = {href: targetUrl};
  3139. } else if (typeof this.curSiteRule.nextLink !== 'undefined') {
  3140. let nextLinkSel = this.curSiteRule.nextLink;
  3141. if (nextLinkSel != 0) {
  3142. if (Array && Array.isArray && Array.isArray(nextLinkSel)) {
  3143. nextLink = getElement(nextLinkSel[nextIndex], doc, null, true);
  3144. if (!nextLink && curPage === 1 && nextIndex !== 0) {
  3145. nextIndex = 0;
  3146. nextLink = getElement(nextLinkSel[nextIndex], doc, null, true);
  3147. }
  3148. } else nextLink = getElement(nextLinkSel, doc, null, true);
  3149. }
  3150. if (nextLink && (this.curSiteRule.action == 0 || this.curSiteRule.action == 1 || this.curSiteRule.action == 2)) {
  3151. let form = doc.querySelector('#search-form');
  3152. if (!nextLink.href && nextLink.hasAttribute && nextLink.hasAttribute("onclick") && form) {
  3153. if (/^\d+$/.test(nextLink.innerText)) {
  3154. nextLink.href = getNextLinkByForm(form, nextLink, nextLink.innerText);
  3155. }
  3156. } else if (compareNodeName(nextLink, ["input"]) || nextLink.type === "submit") {
  3157. form = nextLink.parentNode;
  3158. while (form) {
  3159. if (compareNodeName(form, ["form"])) break;
  3160. else form = form.parentNode;
  3161. }
  3162. if (form) {
  3163. nextLink.href = getNextLinkByForm(form, nextLink);
  3164. }
  3165. }
  3166. if (nextLink.href && this.curSiteRule.action != 0) {
  3167. nextLink.href = nextLink.href.replace(/#p{.*/, "");
  3168. }
  3169. }
  3170. } else {
  3171. page = await this.getPage(doc, exist);
  3172. nextLink = page.next;
  3173. if (nextLink) {
  3174. if (compareNodeName(nextLink, ["input"]) || nextLink.type === "submit") {
  3175. if (!/next/i.test(nextLink.getAttribute("onclick"))) {
  3176. let form = nextLink.parentNode;
  3177. while (form) {
  3178. if (compareNodeName(form, ["form"])) break;
  3179. else form = form.parentNode;
  3180. }
  3181. if (form) {
  3182. nextLink.href = getNextLinkByForm(form, nextLink);
  3183. }
  3184. }
  3185. }
  3186. let parent = nextLink;
  3187. while (parent && !compareNodeName(parent, ["body"])) {
  3188. if (parent.hasAttribute && parent.hasAttribute("disabled")) {
  3189. this.nextLinkHref = false;
  3190. return null;
  3191. }
  3192. if (parent.className && parent.classList) {
  3193. if (parent.classList.contains("noClick") || parent.classList.contains("no-pages") || parent.classList.contains("disabled")) {
  3194. this.nextLinkHref = false;
  3195. return null;
  3196. }
  3197. }
  3198. if (parent.style && parent.style.display === "none") {
  3199. this.nextLinkHref = false;
  3200. return null;
  3201. }
  3202. parent = parent.parentNode;
  3203. }
  3204. if (doc === document) {
  3205. if (!this.linkHasHref(nextLink)) {
  3206. if (!isVisible(nextLink, _unsafeWindow)) {
  3207. this.nextLinkHref = false;
  3208. return null;
  3209. }
  3210. let video = document.querySelector("video,iframe[id*=play],[id*=play]>iframe,iframe[src*=player],iframe[src*=m3u8]");
  3211. if (video) {
  3212. if (video.offsetParent && video.name !== 'pagetual-iframe') {
  3213. let scrollWidth = video.scrollWidth || video.offsetWidth;
  3214. let scrollHeight = video.scrollHeight || video.offsetHeight;
  3215. if (compareNodeName(video, ["iframe"])) {
  3216. } else if (scrollWidth > 100 && scrollHeight > 100) {
  3217. let winWidth = window.innerWidth || document.documentElement.clientWidth;
  3218. let winHeight = window.innerHeight || document.documentElement.clientHeight;
  3219. if (scrollWidth > winWidth>>1 && scrollHeight > winHeight>>1) {
  3220. debug("Disable when large media found");
  3221. } else {
  3222. video = null;
  3223. }
  3224. } else {
  3225. video = null;
  3226. }
  3227. } else {
  3228. video = null;
  3229. }
  3230. }
  3231. if (video) {
  3232. isPause = true;
  3233. this.clearAddedElements();
  3234. this.nextLinkHref = false;
  3235. return null;
  3236. }
  3237. }
  3238.  
  3239. let nextLinkCs = _unsafeWindow.getComputedStyle(nextLink);
  3240. if (nextLinkCs.cursor === "not-allowed") {
  3241. this.nextLinkHref = false;
  3242. return null;
  3243. }
  3244. this.initNext = nextLink;
  3245. }
  3246. let form = doc.querySelector('#search-form');
  3247. if (!nextLink.href && nextLink.hasAttribute("onclick") && form) {
  3248. if (form && /^\d+$/.test(nextLink.innerText)) {
  3249. href = getNextLinkByForm(form, nextLink, nextLink.innerText);
  3250. }
  3251. }
  3252. }
  3253. }
  3254. if (nextLink) {
  3255. if (doc === document && nextLink.offsetParent) {
  3256. let scrollH = Math.max(document.documentElement.scrollHeight, getBody(document).scrollHeight);
  3257. let actualBottom = getElementBottom(nextLink);
  3258. bottomGap = scrollH - actualBottom + (window.innerHeight || document.documentElement.clientHeight) * rate;
  3259. if (bottomGap < 100) bottomGap = 100;
  3260. }
  3261. if (!this.checkStopSign(nextLink, doc)) {
  3262. if (curPage > 1) {
  3263. this.reachedLastPage();
  3264. }
  3265. return null;
  3266. }
  3267. if (this.curSiteRule.action == 3) {
  3268. if (doc == document) debug(nextLink, 'Next link');
  3269. this.nextLinkHref = '#';
  3270. } else {
  3271. let needUrl = (this.curSiteRule.action == 0 || this.curSiteRule.action == 1 || this.curSiteRule.action == 2);
  3272. if (!href) href = nextLink.href;
  3273. if (href && nextLink.getAttribute) {
  3274. let _href = nextLink.getAttribute("href");
  3275. if (_href) {
  3276. let realHref = _href.replace(location.href, "");
  3277. if (realHref.charAt(0) === "#" || realHref === "?"){
  3278. href = "#";
  3279. } else {
  3280. href = _href;
  3281. }
  3282. } else if (_href === "") {
  3283. href = _href;
  3284. }
  3285. }
  3286.  
  3287. if (needUrl && (href === "" || href === null)) {
  3288. this.nextLinkHref = false;
  3289. } else if (needUrl && /^(javascript:|#)/.test(href)) {
  3290. this.nextLinkHref = false;
  3291. } else {
  3292. this.nextLinkHref = (href && !/^(javascript:|#)/.test(href)) ? this.canonicalUri(href) : "#";
  3293. let tempUrl = this.nextLinkHref;
  3294. 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 + "#"))) {
  3295. this.nextLinkHref = false;
  3296. } else if (doc === document) {
  3297. debug(nextLink, 'Next link');
  3298. }
  3299. }
  3300. }
  3301. } else {
  3302. this.nextLinkHref = false;
  3303. }
  3304. this.nextLinkEle = nextLink;
  3305. this.preload();
  3306. return nextLink;
  3307. }
  3308.  
  3309. compareUrl(url1, url2) {
  3310. if (url1 === url2) return true;
  3311. if (!url1 || !url2) return false;
  3312. let url1Arr = url1.split("?");
  3313. let url2Arr = url2.split("?");
  3314. if (url1Arr[0] != url2Arr[0]) return false;
  3315. if (!url1Arr[1] || !url2Arr[1]) return false;
  3316. url1Arr = url1Arr[1].split("&").sort().join("&");
  3317. url2Arr = url2Arr[1].split("&").sort().join("&");
  3318. return url1Arr === url2Arr;
  3319. }
  3320.  
  3321. filterEles(doc, eles) {
  3322. let filter = this.curSiteRule.filter;
  3323. if (!filter || !eles || eles.length === 0) return;
  3324. if (eles.length === 1) {
  3325. eles = eles[0].children;
  3326. if (eles.length === 1) {
  3327. eles = eles[0].children;
  3328. }
  3329. }
  3330. if (typeof filter === "string") {
  3331. if (/^\d+$/.test(filter)) {
  3332. filter = {count: parseInt(filter)};
  3333. } else filter = {words: filter};
  3334. }
  3335. [].forEach.call(eles, ele => {
  3336. if (!ele.parentNode) return;
  3337. let canKeep = (() => {
  3338. let innerText = (ele.innerText && ele.innerText.trim()) || "";
  3339. if (filter.count) {
  3340. if (innerText.length < filter.count) return false;
  3341. }
  3342. if (filter.words) {
  3343. let wordsRegExp = new RegExp(filter.words, "i");
  3344. if (innerText && wordsRegExp.test(innerText)) return false;
  3345. }
  3346. if (filter.link) {
  3347. let linkRegExp = new RegExp(filter.link, "i");
  3348. if (compareNodeName(ele, ["a"]) && linkRegExp.test(ele.href)) return false;
  3349. let aChildren = ele.querySelectorAll("a");
  3350. for (let i = 0; i < aChildren.length; i++) {
  3351. let child = aChildren[i];
  3352. if (linkRegExp.test(child.href)) return false;
  3353. }
  3354. }
  3355. if (filter.selector) {
  3356. if (getElement(filter.selector, doc, ele)) return false;
  3357. }
  3358. return true;
  3359. })();
  3360. if (!canKeep) {
  3361. ele.parentNode.removeChild(ele);
  3362. }
  3363. });
  3364. }
  3365.  
  3366. checkStopSign(nextLink, doc) {
  3367. if (this.curSiteRule.stopSign) {
  3368. let typeArray = Array && Array.isArray && Array.isArray(this.curSiteRule.stopSign);
  3369. let typeObject = !typeArray && (this.curSiteRule.stopSign.include || this.curSiteRule.stopSign.exclude || this.curSiteRule.stopSign.pageNum);
  3370. if (typeArray || typeObject) {
  3371. let includeSel, excludeSel, curSign, maxSign;
  3372. if (typeArray) {
  3373. includeSel = this.curSiteRule.stopSign[0];
  3374. excludeSel = this.curSiteRule.stopSign[1];
  3375. curSign = this.curSiteRule.stopSign[2];
  3376. maxSign = this.curSiteRule.stopSign[3];
  3377. if (Array && Array.isArray && Array.isArray(includeSel) && !curSign) {
  3378. curSign = includeSel;
  3379. includeSel = false;
  3380. }
  3381. if (excludeSel && Array && Array.isArray && Array.isArray(excludeSel) && !maxSign) {
  3382. maxSign = excludeSel;
  3383. excludeSel = false;
  3384. }
  3385. } else {
  3386. includeSel = this.curSiteRule.stopSign.include;
  3387. excludeSel = this.curSiteRule.stopSign.exclude;
  3388. curSign = this.curSiteRule.stopSign.pageNum;
  3389. }
  3390. if (includeSel) {
  3391. includeSel = includeSel.trim();
  3392. if (!getElement(includeSel, doc)) {
  3393. isPause = true;
  3394. this.nextLinkHref = false;
  3395. return false;
  3396. }
  3397. }
  3398. if (excludeSel) {
  3399. excludeSel = excludeSel.trim();
  3400. if (getElement(excludeSel, doc)) {
  3401. isPause = true;
  3402. this.nextLinkHref = false;
  3403. return false;
  3404. }
  3405. }
  3406. if (curSign) {
  3407. if (!maxSign) maxSign = curSign.slice(2);
  3408. let currentEle = getElement(curSign[0], doc);
  3409. let maxEle = getElement(maxSign[0], doc);
  3410. if (currentEle && maxEle) {
  3411. let currentSignNum, maxSignNum;
  3412. if (/\(.*\)/.test(curSign[1])) {
  3413. currentSignNum = currentEle.innerText.match(new RegExp(curSign[1]));
  3414. if (currentSignNum) currentSignNum = currentSignNum[1];
  3415. } else if (currentEle.getAttribute) {
  3416. currentSignNum = currentEle.getAttribute(curSign[1]);
  3417. }
  3418. if (/\(.*\)/.test(maxSign[1])) {
  3419. maxSignNum = maxEle.innerText.match(new RegExp(maxSign[1]));
  3420. if (maxSignNum) maxSignNum = maxSignNum[1];
  3421. } else if (maxEle.getAttribute) {
  3422. maxSignNum = maxEle.getAttribute(maxSign[1]);
  3423. }
  3424. if (currentSignNum && maxSignNum && currentSignNum == maxSignNum) {
  3425. isPause = true;
  3426. this.nextLinkHref = false;
  3427. return false;
  3428. }
  3429. }
  3430. }
  3431. } else {
  3432. try {
  3433. let stopSign = ((typeof this.curSiteRule.stopSign === 'function') ? this.curSiteRule.stopSign : Function("doc", "nextLink", '"use strict";' + this.curSiteRule.stopSign))(doc, nextLink);
  3434. if (stopSign) {
  3435. isPause = true;
  3436. this.nextLinkHref = false;
  3437. return false;
  3438. }
  3439. } catch(e) {
  3440. debug(e);
  3441. }
  3442. }
  3443. }
  3444. return true;
  3445. }
  3446.  
  3447. preloadImageHandler() {
  3448. if (this.preloadingImage || !this.unCheckedImgs.length) return;
  3449. this.preloadingImage = true;
  3450. setTimeout(() => {
  3451. this.preloadingImage = false;
  3452. this.preloadImageHandler();
  3453. }, 10);
  3454. let iSrc = this.unCheckedImgs.shift();
  3455. let img = document.createElement('img');
  3456. img.src = iSrc;
  3457. this.preloadDiv.appendChild(img);
  3458. }
  3459.  
  3460. preload() {
  3461. if (!rulesData.preload) return;
  3462. if (this.curSiteRule.preload === 0) return;
  3463. if (!this.nextLinkHref || this.nextLinkHref == "#") return;
  3464. if (this.readyStateUnComplete) return;
  3465. if (document.readyState !== 'complete') {
  3466. this.readyStateUnComplete = true;
  3467. let self = this;
  3468. window.addEventListener("load", e => {
  3469. self.readyStateUnComplete = false;
  3470. self.preload();
  3471. });
  3472. return;
  3473. }
  3474. let self = this, url = this.nextLinkHref;
  3475. let postParams = url.match(/#p{(.*)}$/);
  3476. if (postParams) {
  3477. postParams = postParams[1];
  3478. url = url.replace(/#p{.*/, "");
  3479. }
  3480. _GM_xmlhttpRequest({
  3481. url: url,
  3482. method: postParams ? 'POST' : 'GET',
  3483. data: postParams,
  3484. overrideMimeType: 'text/html;charset=' + charset,
  3485. headers: {
  3486. 'Referer': location.href,
  3487. 'User-Agent': navigator.userAgent,
  3488. "Content-Type": (postParams ? "application/x-www-form-urlencoded" : "text/html") + ";charset=" + charset,
  3489. },
  3490. timeout: 10000,
  3491. onload: function(res) {
  3492. var doc = null;
  3493. try {
  3494. doc = document.implementation.createHTMLDocument('');
  3495. doc.documentElement.innerHTML = createHTML(res.response);
  3496. var body = getBody(doc);
  3497. if (!self.preloadDiv) {
  3498. self.preloadDiv = document.createElement('div');
  3499. self.preloadDiv.id = "pagetual-preload";
  3500. self.preloadDiv.style.cssText = 'display:none!important;';
  3501. getBody(document).appendChild(self.preloadDiv);
  3502. self.checkedImgs = {};
  3503. self.unCheckedImgs = [];
  3504. }
  3505. let code = self.curSiteRule.preloadImages;
  3506. if (code) {
  3507. let imgSrcArr = new Function("doc", '"use strict";' + code)(doc);
  3508. if (imgSrcArr && imgSrcArr.length) {
  3509. imgSrcArr.forEach(imgSrc => {
  3510. if (imgSrc && !self.checkedImgs[imgSrc]) {
  3511. self.checkedImgs[imgSrc] = true;
  3512. self.unCheckedImgs.push(imgSrc);
  3513. }
  3514. });
  3515. }
  3516. self.preloadImageHandler();
  3517. } else if (code !== 0 && code !== false) {
  3518. if (body && body.firstChild) {
  3519. self.lazyImgAction(body.children, doc);
  3520. }
  3521. [].forEach.call(doc.images, i => {
  3522. let iSrc = i.src;
  3523. if (iSrc && !self.checkedImgs[iSrc]) {
  3524. self.checkedImgs[iSrc] = true;
  3525. self.unCheckedImgs.push(iSrc);
  3526. }
  3527. });
  3528. self.preloadImageHandler();
  3529. }
  3530. }
  3531. catch(e) {
  3532. debug(e);
  3533. return;
  3534. }
  3535. }
  3536. });
  3537. }
  3538.  
  3539. getInsert(refresh) {
  3540. if (refresh) {
  3541. this.insert = null;
  3542. }
  3543. if (this.insert && this.insert.parentNode && document.documentElement.contains(this.insert)) {
  3544. return this.insert;
  3545. }
  3546. if (this.curSiteRule.insert) {
  3547. let insertSel = this.curSiteRule.insert;
  3548. if (Array && Array.isArray && Array.isArray(insertSel)) {
  3549. insertSel = insertSel[nextIndex < insertSel.length ? nextIndex : 0];
  3550. }
  3551. this.insert = getElement(insertSel, document, null, true);
  3552. } else {
  3553. this.docPageElement = null;
  3554. let pageElement = this.getPageElement(document, _unsafeWindow);
  3555. if (this.curSiteRule.smart && this.nextLinkHref == "#" && this.curSiteRule.pageElement === 'body') {
  3556. debug("Stop as jsNext & whole body");
  3557. isPause = true;
  3558. return null;
  3559. }
  3560. if (pageElement && pageElement.length > 0) {
  3561. let pEIndex = pageElement.length - 1;
  3562. let pELast = pageElement[pEIndex];
  3563. while(pELast && compareNodeName(pELast, ["link", "meta", "style", "script"])) {
  3564. pEIndex--;
  3565. pELast = pageElement[pEIndex];
  3566. }
  3567. this.insert = pELast.nextSibling ? pELast.nextSibling : pELast.parentNode.appendChild(document.createTextNode(' '));
  3568. }
  3569. }
  3570. return this.insert;
  3571. }
  3572.  
  3573. pageInit(doc, eles) {
  3574. let code = this.curSiteRule.pageInit;
  3575. if (code) {
  3576. let initFunc = ((typeof code == 'function') ? code : Function("doc", "eles", '"use strict";' + code));
  3577. let checkInit = (resolve) => {
  3578. try {
  3579. if (initFunc(doc, eles) === false) {
  3580. setTimeout(() => {
  3581. checkInit(resolve);
  3582. }, 100);
  3583. } else {
  3584. resolve(true);
  3585. }
  3586. } catch(e) {
  3587. resolve(false);
  3588. debug(e);
  3589. }
  3590. };
  3591. return new Promise((resolve) => {
  3592. checkInit(function(e) {
  3593. resolve(e)
  3594. });
  3595. })
  3596. }
  3597. }
  3598.  
  3599. pageAction(doc, eles) {
  3600. let code = this.curSiteRule.pageAction;
  3601. if (code) {
  3602. try {
  3603. ((typeof code == 'function') ? code : Function("doc", "eles", '"use strict";' + code))(doc, eles);
  3604. } catch(e) {
  3605. debug(e);
  3606. }
  3607. }
  3608. this.openInNewTab(eles);
  3609. this.replaceElement(doc);
  3610. }
  3611.  
  3612. openInNewTab(eles) {
  3613. if (openInNewTab) {
  3614. [].forEach.call(eles, ele => {
  3615. if (compareNodeName(ele, ["a"]) && ele.href && !/^(mailto:|javascript:)|#/.test(ele.href)) {
  3616. ele.setAttribute('target', openInNewTab == 1 ? '_blank' : '_self');
  3617. } else {
  3618. [].forEach.call(ele.querySelectorAll('a[href]:not([href^="mailto:"]):not([href^="javascript:"]):not([href^="#"])'), a => {
  3619. if (openInNewTab == 1) {
  3620. a.setAttribute('target', '_blank');
  3621. if (a.getAttribute('onclick') == 'atarget(this)') {
  3622. a.removeAttribute('onclick');
  3623. }
  3624. } else a.setAttribute('target', '_self');
  3625. });
  3626. }
  3627. });
  3628. }
  3629. }
  3630.  
  3631. lazyImgAction(eles, doc) {
  3632. if (!eles || eles.length == 0) return;
  3633. let lazyImgSrc = this.curSiteRule.lazyImgSrc;
  3634. if (lazyImgSrc === 0 || lazyImgSrc === '0') return;
  3635. let imgLazyAttrs = [];
  3636. 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"];
  3637. let removeProps = [];
  3638. let setLazyImg = img => {
  3639. let realSrc;
  3640. imgLazyAttrs.forEach(attr => {
  3641. realSrc = img.getAttribute(lazyImgSrc[0]);
  3642. if (realSrc) {
  3643. removeProps.forEach(prop => {
  3644. img.removeAttribute(prop.trim());
  3645. });
  3646. img.src = realSrc;
  3647. return;
  3648. }
  3649. })
  3650. if (!realSrc) {
  3651. let lazyAttr = "";
  3652. if (img.getAttribute("_src") && !img.src) {
  3653. lazyAttr = "_src";
  3654. realSrc = img.getAttribute(lazyAttr);
  3655. } else {
  3656. for (let i in lazyImgAttr) {
  3657. lazyAttr = lazyImgAttr[i];
  3658. let attrValue = img.getAttribute(lazyAttr);
  3659. if (attrValue) {
  3660. realSrc = attrValue;
  3661. break;
  3662. }
  3663. }
  3664. }
  3665. if (!realSrc && img._lazyrias && img._lazyrias.srcset) {
  3666. realSrc = img._lazyrias.srcset[img._lazyrias.srcset.length - 1];
  3667. lazyAttr = "_lazyrias";
  3668. }
  3669. if (!realSrc && img.srcset) {
  3670. lazyAttr = "srcset";
  3671. var srcs = img.srcset.split(/[xw],/i), largeSize = 0;
  3672. srcs.forEach(srci => {
  3673. let srcInfo = srci.trim().split(" "), curSize = parseInt(srcInfo[1]);
  3674. if (srcInfo[1] && curSize > largeSize) {
  3675. largeSize = curSize;
  3676. realSrc = srcInfo[0];
  3677. }
  3678. });
  3679. }
  3680. if (realSrc) {
  3681. img.src = realSrc;
  3682. img.removeAttribute("srcset");
  3683. img.removeAttribute(lazyAttr);
  3684. if (img.classList && img.classList.contains && img.classList.contains("lazy")) {
  3685. img.classList.remove("lazy");
  3686. }
  3687. if (img.style.display == "none") {
  3688. img.style.display = "";
  3689. }
  3690. if (img.style.visibility == "hidden") {
  3691. img.style.visibility = "";
  3692. }
  3693. if (img.style.opacity == 0) {
  3694. img.style.opacity = "";
  3695. }
  3696. }
  3697. }
  3698. };
  3699. if (lazyImgSrc) {
  3700. if (!Array.isArray(lazyImgSrc)) {
  3701. lazyAttrs = lazyImgSrc.split(",");
  3702. } else {
  3703. lazyAttrs = lazyImgSrc[0].split(",");
  3704. removeProps = lazyImgSrc[1].split(",");
  3705. }
  3706. }
  3707. lazyAttrs.forEach(attr => {
  3708. let attrArr = attr.split("|");
  3709. if (attrArr.length !== 2) {
  3710. imgLazyAttrs.push(attr.trim());
  3711. } else {
  3712. let selector = attrArr[0].trim();
  3713. let lazyAttr = attrArr[1].trim();
  3714. if (selector == "img") {
  3715. imgLazyAttrs.push(lazyAttr);
  3716. } else {
  3717. selector += "[" + lazyAttr + "]";
  3718. [].forEach.call(doc.querySelectorAll(selector), ele => {
  3719. ele.style.setProperty("background-image", "url(" + ele.getAttribute(lazyAttr) + ")", "important");
  3720. removeProps.forEach(prop => {
  3721. ele.removeAttribute(prop.trim());
  3722. });
  3723. });
  3724. }
  3725. }
  3726. });
  3727. [].forEach.call(doc.querySelectorAll("img,picture>source"), img => {
  3728. setLazyImg(img);
  3729. });
  3730. }
  3731.  
  3732. canListenUrlChange() {
  3733. if (this.curSiteRule) {
  3734. if (this.curSiteRule.listenUrlChange === true) return true;
  3735. if (this.curSiteRule.listenUrlChange === false) return false;
  3736. if (this.docElementValid()) {
  3737. return false;
  3738. }
  3739. }
  3740. return true;
  3741. }
  3742.  
  3743. checkClickHref() {
  3744. if (this.curSiteRule.smart && this.nextLinkEle && !this.linkHasHref(this.nextLinkEle)) {
  3745. this.urlChanged();
  3746. isPause = true;
  3747. if (!this.nextLinkHref) isLoading = false;
  3748. }
  3749. }
  3750.  
  3751. docElementValid() {
  3752. if (!this.docPageElement || this.docPageElement.length == 0) return false;
  3753. if (!this.checkPageEle) {
  3754. let ele;
  3755. if (this.docPageElement.length == 1) {
  3756. ele = this.docPageElement[0];
  3757. } else {
  3758. ele = this.docPageElement[Math.floor(this.docPageElement.length / 2)];
  3759. }
  3760. if (ele.children.length) {
  3761. ele = ele.children[Math.floor(ele.children.length / 2)];
  3762. }
  3763. this.checkPageEle = ele;
  3764. }
  3765. return document.documentElement.contains(this.checkPageEle);
  3766. }
  3767.  
  3768. urlChanged() {
  3769. urlChanged = true;
  3770. this.clearAddedElements();
  3771. }
  3772.  
  3773. initPage(callback) {
  3774. let self = this;
  3775. if (self.initing) return;
  3776. self.initing = true;
  3777. setTimeout(() => {
  3778. self.initing = false;
  3779. }, 100);
  3780. curPage = 1;
  3781. urlChanged = false;
  3782. tryTimes = 0;
  3783. this.clearAddedElements();
  3784. this.insert = null;
  3785. this.visibilityItems = [];
  3786. this.visibleIndex = -1;
  3787. this.pageDoc = document;
  3788. this.nextLinkHref = null;
  3789. this.curUrl = location.href;
  3790. this.oldUrl = "";
  3791. this.initUrl = location.href;
  3792. this.historyUrl = "";
  3793. this.possibleCheck = 0;
  3794. let base = document.querySelector("base");
  3795. this.basePath = (base && base.href) || location.href;
  3796. this.getRule(async () => {
  3797. if (self.curSiteRule.sideController === true || (self.curSiteRule.sideController !== false && rulesData.sideController)) {
  3798. isPause = manualPause;
  3799. }
  3800. hidePageBar = rulesData.opacity == 0 || self.curSiteRule.pageBar === 0;
  3801. if (typeof(self.curSiteRule.rate) !== "undefined") {
  3802. rate = self.curSiteRule.rate;
  3803. }
  3804. if (self.curSiteRule.enable == 0) {
  3805. debug("Stop as rule disable");
  3806. isPause = true;
  3807. _GM_registerMenuCommand(i18n("enable"), () => {
  3808. showTips(i18n("enableSiteTips"));
  3809. if(!self.customRules) {
  3810. self.customRules = [];
  3811. }
  3812. for (let i in self.customRules) {
  3813. if (self.customRules[i].url == self.curSiteRule.url) {
  3814. self.customRules.splice(i, 1);
  3815. break;
  3816. }
  3817. }
  3818. self.curSiteRule.enable = 1;
  3819. self.customRules.unshift(self.curSiteRule);
  3820. storage.setItem("customRules", self.customRules);
  3821. location.reload();
  3822. });
  3823. return;
  3824. }
  3825. if (rulesData.sideControllerAlways) {
  3826. sideController.setup();
  3827. }
  3828. //若是再亂匹配就不緩存wedata,或者只在找完本地規則之後再考慮wedata的緩存
  3829. if (self.curSiteRule.smart) {
  3830. delete self.curSiteRule.pageElement;
  3831. if (!self.possibleRule) {
  3832. self.smartRules = self.smartRules.filter(item => {return item && item.url != self.curSiteRule.url});
  3833. self.smartRules.unshift(self.curSiteRule);
  3834. if (self.smartRules.length > 100) {
  3835. self.smartRules.pop();
  3836. }
  3837. storage.setItem("smartRules", self.smartRules);
  3838. }
  3839. } else if (self.curSiteRule && self.curSiteRule.url.length > 13) {
  3840. self.addToHpRules();
  3841. }
  3842. let css;
  3843. if (rulesData.customCss && self.curSiteRule.css) {
  3844. let globalCssArr = rulesData.customCss.split("inIframe:");
  3845. let ruleCssArr = self.curSiteRule.css.split("inIframe:");
  3846. let mainCss = globalCssArr[0] + ruleCssArr[0], inCss = (globalCssArr[1] || "") + (ruleCssArr[1] || "");
  3847. css = mainCss + (inCss ? ("inIframe:" + inCss) : "");
  3848. } else {
  3849. css = self.curSiteRule.css || rulesData.customCss;
  3850. }
  3851. if (css) {
  3852. let cssArr = css.split("inIframe:");
  3853. if (cssArr && cssArr.length) {
  3854. _GM_addStyle(cssArr[0]);
  3855. }
  3856. }
  3857. if (/sidesearch=(1|true)$/.test(self.curUrl)) {
  3858. openInNewTab = 0;
  3859. } else if (typeof self.curSiteRule.openInNewTab !== 'undefined') {
  3860. openInNewTab = self.curSiteRule.openInNewTab ? 1 : 2;
  3861. }
  3862. let autoClick = self.curSiteRule.autoClick;
  3863. if (autoClick) {
  3864. let autoClickBtn;
  3865. autoClickBtn = getElement(autoClick, document, null, true);
  3866. if (autoClickBtn) {
  3867. emuClick(autoClickBtn);
  3868. }
  3869. }
  3870. let code = self.curSiteRule.init;
  3871. if (code) {
  3872. try {
  3873. 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)});
  3874. } catch(e) {
  3875. debug(e);
  3876. }
  3877. }
  3878. await self.getNextLink(document, true);
  3879. if (self.curSiteRule.pageNum && self.nextLinkHref && self.nextLinkHref != "#") {
  3880. let num1st = self.getPageNumFromUrl(location.href, 1);
  3881. let num2nd = self.getPageNumFromUrl(self.nextLinkHref, 1);
  3882. if (parseInt(num2nd) != parseInt(num1st) + 1) {
  3883. self.curSiteRule.pageNum = null;
  3884. }
  3885. }
  3886. if (self.curSiteRule.smart && self.nextLinkHref == false && self.possibleRule) {
  3887. let urlReg = new RegExp(self.possibleRule.url, "i");
  3888. function checkPossible () {
  3889. if (self.possibleCheck++ < 3) {
  3890. setTimeout(() => {
  3891. if (self.curSiteRule.smart) {
  3892. var href = location.href.slice(0, 500);
  3893. if (urlReg.test(href) && self.ruleMatch(self.possibleRule)) {
  3894. self.initPage(() => {});
  3895. } else checkPossible();
  3896. }
  3897. }, 3000);
  3898. }
  3899. }
  3900. checkPossible();
  3901. }
  3902. self.refreshByClick();
  3903. if (emuIframe && emuIframe.parentNode) {
  3904. emuIframe.parentNode.removeChild(emuIframe);
  3905. emuIframe = null;
  3906. }
  3907.  
  3908. let pageElementCss = self.curSiteRule.pageElementCss || rulesData.pageElementCss;
  3909. if (pageElementCss && pageElementCss !== '0') {
  3910. self.getPageElement(document, _unsafeWindow);
  3911. }
  3912. callback();
  3913. let initRun = typeof self.curSiteRule.initRun == 'undefined' ? rulesData.initRun : self.curSiteRule.initRun;
  3914. if (self.nextLinkHref) {
  3915. sideController.setup();
  3916. if (initRun && initRun != false) {
  3917. setTimeout(() => {
  3918. nextPage();
  3919. }, 300);
  3920. }
  3921. } else isPause = false;
  3922. });
  3923. }
  3924.  
  3925. async hookUrlSetEle(ele, doc) {
  3926. let self = this;
  3927. return new Promise((resolve) => {
  3928. let catchUrl = e => {
  3929. ele.dataset.url = self.catchedUrl;
  3930. ele.setAttribute('onclick', 'window.open(this.dataset.url)');
  3931. window.removeEventListener('pagetual_openUrl', catchUrl);
  3932. resolve();
  3933. };
  3934. window.addEventListener('pagetual_openUrl', catchUrl);
  3935. emuClick(ele, doc);
  3936. });
  3937. }
  3938.  
  3939. async hookUrl(doc) {
  3940. let sel = this.curSiteRule.hookUrl;
  3941. if (!sel) return;
  3942. let self = this;
  3943. if (!this.initHook) {
  3944. this.initHook = true;
  3945. Object.defineProperty(doc.defaultView, 'open', {
  3946. get: function () {
  3947. return (s) => {
  3948. self.catchedUrl = s;
  3949. var e = new CustomEvent('pagetual_openUrl');
  3950. window.dispatchEvent(e);
  3951. }
  3952. }
  3953. });
  3954. }
  3955. let eles = getAllElements(sel, doc);
  3956. for (let i = 0; i < eles.length; i++) {
  3957. await sleep(1);
  3958. let ele = eles[i];
  3959. if (!ele.dataset.url) {
  3960. await this.hookUrlSetEle(ele, doc);
  3961. }
  3962. }
  3963. }
  3964.  
  3965. beginLoading() {
  3966. isLoading = true;
  3967. if (targetY >= 0) {
  3968. window.scrollTo({ top: targetY, behavior: 'instant'});
  3969. targetY = -1;
  3970. }
  3971. let lastScrollTop = getBody(document).scrollTop || document.documentElement.scrollTop;
  3972. ruleParser.insertElement(loadingDiv);
  3973. if (forceState == 2) {
  3974. getBody(document).appendChild(loadingDiv);
  3975. } else {
  3976. let parent = loadingDiv.parentNode;
  3977. if (compareNodeName(parent, ["tbody"])) {
  3978. parent = parent.parentNode;
  3979. }
  3980. if (compareNodeName(parent, ["table"])) {
  3981. parent.parentNode.appendChild(loadingDiv);
  3982. }
  3983. }
  3984. getBody(document).scrollTop = lastScrollTop;
  3985. document.documentElement.scrollTop = lastScrollTop;
  3986. if (sideController.inited) {
  3987. sideController.frame.classList.add("loading");
  3988. }
  3989. }
  3990.  
  3991. insertElement(ele) {
  3992. if (!this.insert || !this.insert.parentNode) {
  3993. this.getInsert();
  3994. }
  3995. if (this.insert && this.insert.parentNode) {
  3996. let self = this;
  3997. if (ele.nodeName == "#document-fragment") {
  3998. [].forEach.call(ele.children, el => {
  3999. self.addedElePool.push(el);
  4000. });
  4001. } else {
  4002. this.addedElePool.push(ele);
  4003. }
  4004. if (this.curSiteRule.insertPos == 2 || this.curSiteRule.insertPos == "in") {
  4005. this.insert.appendChild(ele);
  4006. } else {
  4007. this.insert.parentNode.insertBefore(ele, this.insert);
  4008. }
  4009. }
  4010. }
  4011.  
  4012. noValidContent(url) {
  4013. if (!this.curSiteRule.nextLinkByUrl) showTips(i18n("noValidContent"), url);
  4014. }
  4015.  
  4016. async insertPage(doc, eles, url, callback, tried) {
  4017. this.oldUrl = this.curUrl;
  4018. let oldTitle = document.title;
  4019. try {
  4020. let oldTitle = this.pageDoc.title;
  4021. } catch (e) {}
  4022. this.pageDoc = doc;
  4023. this.curUrl = url;
  4024. isLoading = true;
  4025. let nextLink = await this.getNextLink(doc);
  4026. this.nextTitle = "";
  4027. if (this.curSiteRule.pageBarText) {
  4028. if (this.curSiteRule.pageBarText == 1 || this.curSiteRule.pageBarText == true) {
  4029. this.nextTitle = doc.title;
  4030. } else {
  4031. try {
  4032. this.nextTitle = ((typeof this.curSiteRule.pageBarText == 'function') ? this.curSiteRule.pageBarText : Function("doc",'"use strict";' + this.curSiteRule.pageBarText))(doc);
  4033. } catch(e) {
  4034. debug(e);
  4035. }
  4036. }
  4037. }
  4038. if (curPage == 1 && !tried && !nextLink && this.curSiteRule.smart && this.curSiteRule.pageElement && this.curSiteRule.action != 0) {
  4039. this.curSiteRule.action = 1;
  4040. this.curUrl = location.href;
  4041. isLoading = false;
  4042. return false;
  4043. }
  4044.  
  4045. if (targetY >= 0) {
  4046. window.scrollTo({ top: targetY, behavior: 'instant'});
  4047. targetY = -1;
  4048. }
  4049. let lastScrollTop = getBody(document).scrollTop || document.documentElement.scrollTop;
  4050. this.getInsert();
  4051. await this.pageInit(doc, eles);
  4052. var self = this, newEles = [];
  4053. if (!eles || eles.length == 0 || !self.insert || !self.insert.parentNode) {
  4054. if (callback) callback(eles);
  4055. loadPageOver();
  4056. } else {
  4057. if (callback) callback(eles);
  4058. loadPageOver();
  4059. const collection = document.createDocumentFragment();
  4060. [].forEach.call(eles, ele => {
  4061. let newEle = ele.cloneNode(true);
  4062. let oldCanvass = ele.querySelectorAll("canvas");
  4063. let newCanvass = newEle.querySelectorAll("canvas");
  4064. if (self.updateUrl) {
  4065. [].forEach.call(newEle.querySelectorAll("img"), img => {
  4066. if (img.getAttribute("src")) img.src = self.canonicalUri(img.getAttribute("src"));
  4067. });
  4068. [].forEach.call(newEle.querySelectorAll("a"), a => {
  4069. if (a.getAttribute("href")) a.href = self.canonicalUri(a.getAttribute("href"));
  4070. });
  4071. }
  4072. for (let i = 0; i < oldCanvass.length; i++) {
  4073. let oldCanvas = oldCanvass[i];
  4074. let newCanvas = newCanvass[i];
  4075. newCanvas.getContext('2d').drawImage(oldCanvas, 0, 0);
  4076. }
  4077. if (!compareNodeName(newEle, ["style", "script"])) self.visibilityItems.push(newEle);
  4078. collection.appendChild(newEle);
  4079. newEles.push(newEle);
  4080. });
  4081. let css = this.curSiteRule.css;
  4082. let addCss = (parent) => {
  4083. if (css) {
  4084. let cssArr = css.split("inIframe:");
  4085. if (cssArr && cssArr.length == 2) {
  4086. let styleEle = document.createElement("style");
  4087. styleEle.innerHTML = cssArr[1];
  4088. parent.appendChild(styleEle);
  4089. }
  4090. }
  4091. };
  4092. if (this.curSiteRule.surround === "iframe") {
  4093. let ele = document.createElement("iframe");
  4094. ele.style.border = "unset";
  4095. ele.style.maxWidth = "100%";
  4096. ele.style.width = "100vw";
  4097. self.insertElement(ele);
  4098. try {
  4099. let doc = ele.contentDocument || ele.contentWindow.document;
  4100. doc.body.appendChild(collection);
  4101. ele.style.width = doc.body.scrollWidth + "px";
  4102. ele.style.height = doc.body.scrollHeight + "px";
  4103. doc.documentElement.style.overflow = "hidden";
  4104. doc.body.style.overflow = "hidden";
  4105. addCss(doc.body);
  4106. } catch(e) {
  4107. console.log(e);
  4108. }
  4109. } else if (this.curSiteRule.surround === "shadowDom") {
  4110. let ele = document.createElement("div");
  4111. self.insertElement(ele);
  4112. let shadowRoot = ele.attachShadow({ mode: "open" });
  4113. shadowRoot.appendChild(collection);
  4114. addCss(shadowRoot);
  4115. } else {
  4116. self.insertElement(collection);
  4117. }
  4118. }
  4119. getBody(document).scrollTop = lastScrollTop;
  4120. document.documentElement.scrollTop = lastScrollTop;
  4121. this.pageAction(doc, newEles);
  4122. let enableHistory = this.curSiteRule.history;
  4123. let enableHistoryAfterInsert = false;
  4124. if (enableHistory == 1) {
  4125. enableHistory = true;
  4126. } else if (enableHistory == 2) {
  4127. enableHistory = true;
  4128. enableHistoryAfterInsert = true;
  4129. } else if (enableHistory == 0) {
  4130. enableHistory = false;
  4131. } else {
  4132. enableHistory = rulesData.enableHistory;
  4133. enableHistoryAfterInsert = rulesData.enableHistoryAfterInsert;
  4134. }
  4135. if (enableHistory) {
  4136. this.historyUrl = enableHistoryAfterInsert ? this.curUrl : this.oldUrl;
  4137. if(this.historyUrl != location.href) {
  4138. let isJs = this.hrefIsJs(this.historyUrl);
  4139. if (!isJs) {
  4140. let historyTitle = enableHistoryAfterInsert ? doc.title : oldTitle;
  4141. _unsafeWindow.history.replaceState(undefined, historyTitle, this.historyUrl);
  4142. document.title = historyTitle;
  4143. }
  4144. }
  4145. }
  4146. isLoading = false;
  4147. _unsafeWindow.postMessage({
  4148. action: "insert",
  4149. command: 'pagetual'
  4150. }, '*');
  4151. return true;
  4152. }
  4153. }
  4154. var ruleParser = new RuleParser();
  4155.  
  4156. class SideController {
  4157. //static controller;
  4158. constructor() {
  4159. this.inited = false;
  4160. }
  4161.  
  4162. /*static getInstance() {
  4163. if (!SideController.controller) {
  4164. SideController.controller = new SideController();
  4165. }
  4166. return SideController.controller;
  4167. }*/
  4168.  
  4169. setup() {
  4170. if (ruleParser.curSiteRule.sideController === false) return;
  4171. if (!rulesData.sideController && !ruleParser.curSiteRule.sideController) return;
  4172. this.addToStage();
  4173. }
  4174.  
  4175. init() {
  4176. if (this.inited) return;
  4177. this.inited = true;
  4178. let self = this;
  4179. this.cssText = `
  4180. #pagetual-sideController {
  4181. position: fixed;
  4182. top: calc(50% - 83px);
  4183. left: calc(99% - 40px);
  4184. width: 40px;
  4185. border-radius: 20px;
  4186. box-shadow: rgb(0 0 0) 0px 0px 10px;
  4187. text-align: center;
  4188. background: #ffffffd0!important;
  4189. user-select: none;
  4190. z-index: 2147483646!important;
  4191. padding: 0!important;
  4192. opacity: 0.5;
  4193. transition: opacity .5s ease, background .5s, box-shadow .5s;
  4194. }
  4195. #pagetual-sideController.end {
  4196. opacity: 0.3;
  4197. }
  4198. #pagetual-sideController * {
  4199. font-weight: bold;
  4200. font-family: arial;
  4201. font-style: normal;
  4202. font-size: 20px!important;
  4203. color: black!important;
  4204. line-height: normal;
  4205. float: none;
  4206. text-align: center;
  4207. }
  4208. #pagetual-sideController.stop {
  4209. -webkit-filter: invert(100%);
  4210. filter: invert(100%);
  4211. }
  4212. .pagetual-sideController-btn {
  4213. padding: 5px 0;
  4214. cursor: pointer;
  4215. transition: transform .15s ease-in-out, opacity .3s ease;
  4216. }
  4217. #pagetual-sideController .pagetual-sideController-btn:hover {
  4218. transform: scale(1.5);
  4219. color: red!important;
  4220. }
  4221. #pagetual-sideController #pagetual-sideController-move > svg {
  4222. transition: transform .3s ease;
  4223. }
  4224. #pagetual-sideController #pagetual-sideController-move > svg:hover {
  4225. transform: scale(1.2);
  4226. }
  4227. ${rulesData.hideLoadingIcon ? '' : `
  4228. #pagetual-sideController.minSize #pagetual-sideController-move::before {
  4229. content: '';
  4230. position: absolute;
  4231. width: 34px;
  4232. height: 34px;
  4233. background-color: #1a232a;
  4234. background-repeat: no-repeat;
  4235. background-position: 0 0;
  4236. z-index: -1;
  4237. margin: -2px;
  4238. border-radius: 50%;
  4239. }
  4240. #pagetual-sideController.minSize.loading #pagetual-sideController-move::before {
  4241. background-image: conic-gradient(transparent, #a8efff, transparent 30%);
  4242. -webkit-animation: siderotate 1s linear infinite;
  4243. animation: siderotate 1s linear infinite;
  4244. }
  4245. @keyframes siderotate {
  4246. 100% {
  4247. transform: rotate(1turn);
  4248. }
  4249. }`}
  4250. #pagetual-sideController.minSize #pagetual-sideController-move > svg {
  4251. background: white;
  4252. opacity: 0;
  4253. }
  4254. #pagetual-sideController #pagetual-sideController-move > img,
  4255. #pagetual-sideController #pagetual-sideController-move > span {
  4256. width: 35px;
  4257. height: 35px;
  4258. cursor: pointer;
  4259. }
  4260. #pagetual-sideController.minSize #pagetual-sideController-move > img,
  4261. #pagetual-sideController.minSize #pagetual-sideController-move > span {
  4262. border-radius: 50px;
  4263. text-shadow: rgb(255 255 255) 0px 0px 10px;
  4264. }
  4265. #pagetual-sideController #pagetual-sideController-pagenum {
  4266. font-size: 15px!important;
  4267. line-height: 30px;
  4268. text-align: center;
  4269. position: absolute;
  4270. right: calc(50% - 15px);
  4271. top: calc(50% - 15px);
  4272. border: 1px solid #00000099;
  4273. display: inline-block;
  4274. width: 30px;
  4275. height: 30px;
  4276. box-sizing: border-box;
  4277. border-radius: 50%;
  4278. background: white;
  4279. opacity: 0;
  4280. transition: opacity .5s ease;
  4281. pointer-events: none;
  4282. }
  4283. #pagetual-sideController.minSize #pagetual-sideController-pagenum {
  4284. opacity: 1;
  4285. }
  4286. #pagetual-sideController:hover {
  4287. opacity: 1;
  4288. }
  4289. #pagetual-sideController>.extra {
  4290. bottom: 170px;
  4291. left: 0px;
  4292. width: 40px;
  4293. position: absolute;
  4294. }
  4295. #pagetual-sideController>.extra>svg {
  4296. width: 40px;
  4297. height: 30px;
  4298. opacity: 0.1;
  4299. cursor: pointer;
  4300. margin: 0 0 5px 0;
  4301. transition: opacity .3s ease;
  4302. }
  4303. #pagetual-sideController.minSize>.extra>svg {
  4304. opacity: 0;
  4305. }
  4306. #pagetual-sideController>.extra>svg:hover {
  4307. opacity: 1;
  4308. }
  4309. #pagetual-sideController.minSize {
  4310. box-shadow: rgb(0 0 0 / 0%) 0px 0px 0px;
  4311. background: #00000000!important;
  4312. pointer-events: none;
  4313. }
  4314. #pagetual-sideController.minSize #pagetual-sideController-move {
  4315. pointer-events: all;
  4316. height: 30px;
  4317. }
  4318. #pagetual-sideController.minSize .pagetual-sideController-btn {
  4319. opacity: 0;
  4320. }
  4321. `;
  4322. let frame = document.createElement("div");
  4323. frame.id = "pagetual-sideController";
  4324. frame.innerHTML = createHTML(`
  4325. <div class="extra">
  4326. <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>
  4327. <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>
  4328. </div>
  4329. <div id="pagetual-sideController-top" class="pagetual-sideController-btn">⊼</div>
  4330. <div>
  4331. <div id="pagetual-sideController-pre" class="pagetual-sideController-btn">∧</div>
  4332. <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>
  4333. <div id="pagetual-sideController-next" class="pagetual-sideController-btn">∨</div>
  4334. </div>
  4335. <div id="pagetual-sideController-bottom" class="pagetual-sideController-btn">⊻</div>
  4336. `);
  4337. frame.classList.add("stop");
  4338. let top = frame.querySelector("#pagetual-sideController-top");
  4339. let pre = frame.querySelector("#pagetual-sideController-pre");
  4340. let move = frame.querySelector("#pagetual-sideController-move");
  4341. let next = frame.querySelector("#pagetual-sideController-next");
  4342. let bottom = frame.querySelector("#pagetual-sideController-bottom");
  4343. let pagenum = frame.querySelector("#pagetual-sideController-pagenum");
  4344. let scroll = frame.querySelector("#scroll");
  4345. let loadNow = frame.querySelector("#loadNow");
  4346. if (rulesData.sideControllerScroll === false) {
  4347. scroll.style.display = "none";
  4348. }
  4349. if (rulesData.sideControllerLoadNow === false) {
  4350. loadNow.style.display = "none";
  4351. }
  4352. if (sideControllerIcon) move.innerHTML = sideControllerIcon;
  4353.  
  4354. frame.addEventListener("dblclick", e => {
  4355. e.preventDefault();
  4356. e.stopPropagation();
  4357. });
  4358.  
  4359. frame.addEventListener("mouseenter", e => {
  4360. clearTimeout(self.hideTimer);
  4361. frame.classList.remove("minSize");
  4362. });
  4363.  
  4364. frame.addEventListener("mouseleave", e => {
  4365. clearTimeout(self.hideTimer);
  4366. self.hideTimer = setTimeout(() => {
  4367. frame.classList.add("minSize");
  4368. }, 800);
  4369. });
  4370.  
  4371. document.body.addEventListener('touchstart', e => {
  4372. if (e.target === frame || frame.contains(e.target)) {
  4373. frame.classList.remove("minSize");
  4374. } else {
  4375. frame.classList.add("minSize");
  4376. }
  4377. });
  4378.  
  4379. scroll.addEventListener("click", e => {
  4380. autoScroll = (autoScroll ? 0 : prompt(i18n("autoScrollRate"), autoScrollRate)) || 0;
  4381. autoScroll = parseInt(autoScroll) || 0;
  4382. if (autoScroll < 0) autoScroll = 0;
  4383. if (autoScroll && autoScroll != autoScrollRate) {
  4384. autoScrollRate = autoScroll;
  4385. storage.setItem("autoScrollRate", autoScrollRate);
  4386. }
  4387. setListData("autoScroll", location.host + location.pathname, autoScroll);
  4388. startAutoScroll();
  4389. }, true);
  4390.  
  4391. loadNow.addEventListener("click", e => {
  4392. if (autoLoadNum != -1) {
  4393. autoLoadNum = -1;
  4394. return;
  4395. }
  4396. let loadNum = window.prompt(i18n("loadConfirm"), loadNowNum);
  4397. if (loadNum === "" || loadNum === null) return;
  4398. loadNum = Math.abs(parseInt(loadNum)) || 0;
  4399. if (loadNowNum != loadNum) {
  4400. loadNowNum = loadNum;
  4401. storage.setItem("loadNowNum", loadNowNum);
  4402. }
  4403. autoLoadNum = loadNum;
  4404. nextPage();
  4405. }, true);
  4406.  
  4407. pre.addEventListener("click", e => {
  4408. let prePageBar = getPageBar().preBar;
  4409. if (prePageBar) {
  4410. scrollToPageBar(prePageBar);
  4411. } else {
  4412. let scrollTop = getBody(document).scrollTop || document.documentElement.scrollTop;
  4413. targetY = scrollTop - (window.innerHeight || document.documentElement.clientHeight);
  4414. window.scrollTo({ top: targetY, behavior: 'smooth'});
  4415. }
  4416. }, true);
  4417.  
  4418. next.addEventListener("click", e => {
  4419. let pageBarObj = getPageBar();
  4420. let nextPageBar = pageBarObj.nextBar;
  4421. if (nextPageBar) {
  4422. scrollToPageBar(nextPageBar);
  4423. } else {
  4424. if (pageBarObj.preBar) {
  4425. let scrollH = Math.max(document.documentElement.scrollHeight, getBody(document).scrollHeight);
  4426. targetY = scrollH || 9999999;
  4427. window.scrollTo({ top: targetY, behavior: 'smooth'});
  4428. } else {
  4429. let scrollTop = getBody(document).scrollTop || document.documentElement.scrollTop;
  4430. targetY = scrollTop + (window.innerHeight || document.documentElement.clientHeight);
  4431. window.scrollTo({ top: targetY, behavior: 'smooth'});
  4432. }
  4433. }
  4434. }, true);
  4435.  
  4436. top.addEventListener("click", e => {
  4437. getBody(document).scrollTop = 0;
  4438. document.documentElement.scrollTop = 0;
  4439. e.preventDefault();
  4440. e.stopPropagation();
  4441. }, true);
  4442.  
  4443. bottom.addEventListener("click", e => {
  4444. if (!e.altKey && !e.ctrlKey && !e.shiftKey && !e.metaKey) {
  4445. changeStop(true);
  4446. }
  4447. let scrollH = Math.max(document.documentElement.scrollHeight, getBody(document).scrollHeight);
  4448. getBody(document).scrollTop = scrollH || 9999999;
  4449. document.documentElement.scrollTop = scrollH || 9999999;
  4450. e.preventDefault();
  4451. e.stopPropagation();
  4452. }, true);
  4453.  
  4454. let initX, initY, moving = false;
  4455. let removeTimer;
  4456. move.addEventListener("click", e => {
  4457. if (!moving) {
  4458. changeStop(!isPause, true);
  4459. }
  4460. }, true);
  4461. move.addEventListener("dblclick", e => {
  4462. clearTimeout(removeTimer);
  4463. document.removeEventListener("mousemove", mouseMoveHandler, true);
  4464. document.removeEventListener("mouseup", mouseUpHandler, true);
  4465. changeStop(!isPause, true);
  4466. if (isPause) {
  4467. ruleParser.hideAddedElements();
  4468. } else {
  4469. ruleParser.showAddedElements();
  4470. }
  4471. }, true);
  4472.  
  4473. move.oncontextmenu = e => {
  4474. e.preventDefault();
  4475. picker.start();
  4476. };
  4477.  
  4478. let clientX = e => {
  4479. if (e.type.indexOf('mouse') === 0) {
  4480. return e.clientX;
  4481. } else {
  4482. return e.changedTouches[0].clientX;
  4483. }
  4484. };
  4485.  
  4486. let clientY = e => {
  4487. if (e.type.indexOf('mouse') === 0) {
  4488. return e.clientY;
  4489. } else {
  4490. return e.changedTouches[0].clientY;
  4491. }
  4492. };
  4493.  
  4494. let mouseMoveHandler = e => {
  4495. if (moving) {
  4496. let windowHeight = window.innerHeight || document.documentElement.clientHeight;
  4497. let windowWidth = window.innerWidth || document.documentElement.clientWidth;
  4498. initX = (clientX(e) - 10 + 40) / windowWidth * 100;
  4499. initY = (clientY(e) - 83 + 83) / windowHeight * 100;
  4500. this.frame.style.top = `calc(${initY}% - 83px)`;
  4501. this.frame.style.left = `calc(${initX}% - 40px)`;
  4502. } else if (Math.abs(clientX(e) - initX) + Math.abs(clientY(e) - initY) > 5) {
  4503. moving = true;
  4504. clearTimeout(removeTimer);
  4505. }
  4506. };
  4507. let mouseUpHandler = e => {
  4508. clearTimeout(removeTimer);
  4509. document.removeEventListener("mousemove", mouseMoveHandler, true);
  4510. document.removeEventListener("mouseup", mouseUpHandler, true);
  4511. document.removeEventListener("touchmove", mouseMoveHandler, true);
  4512. document.removeEventListener("touchend", mouseUpHandler, true);
  4513. if (moving) {
  4514. rulesData.sideControllerPos = {x: parseInt(initX), y: parseInt(initY)};
  4515. storage.setItem("rulesData", rulesData);
  4516. }
  4517. };
  4518. let mouseDownHandler = e => {
  4519. initX = clientX(e);
  4520. initY = clientY(e);
  4521. moving = false;
  4522. clearTimeout(removeTimer);
  4523. removeTimer = setTimeout(() => {
  4524. if (e.type === "touchstart") {
  4525. picker.start();
  4526. } else {
  4527. self.remove();
  4528. }
  4529. }, 1500);
  4530. document.addEventListener("mousemove", mouseMoveHandler, true);
  4531. document.addEventListener("mouseup", mouseUpHandler, true);
  4532. document.addEventListener("touchmove", mouseMoveHandler, true);
  4533. document.addEventListener("touchend", mouseUpHandler, true);
  4534. e.stopPropagation();
  4535. e.preventDefault();
  4536. };
  4537.  
  4538. move.addEventListener("mousedown", mouseDownHandler, true);
  4539. move.addEventListener("touchstart", mouseDownHandler, { passive: false, capture: true });
  4540.  
  4541. this.frame = frame;
  4542. this.pagenum = pagenum;
  4543. if (rulesData.sideControllerPos) {
  4544. this.frame.style.top = `calc(${rulesData.sideControllerPos.y}% - 83px)`;
  4545. this.frame.style.left = `calc(${rulesData.sideControllerPos.x}% - 40px)`;
  4546. }
  4547. }
  4548.  
  4549. addToStage() {
  4550. this.init();
  4551. if (!this.styleEle || !this.styleEle.parentNode) {
  4552. this.styleEle = _GM_addStyle(this.cssText);
  4553. }
  4554. if (!isPause) {
  4555. this.frame.classList.remove("stop");
  4556. }
  4557. this.pagenum.innerHTML = createHTML(curPage);
  4558. this.frame.title = i18n("page") + curPage;
  4559. if (this.frame.parentNode) return;
  4560. getBody(document).appendChild(this.frame);
  4561. clearTimeout(this.hideTimer);
  4562. this.frame.classList.add("minSize");
  4563. }
  4564.  
  4565. remove() {
  4566. if (this.frame && this.frame.parentNode) this.frame.parentNode.removeChild(this.frame);
  4567. }
  4568. }
  4569. const sideController = new SideController();
  4570.  
  4571. class NextSwitch {
  4572. //static nextSwitch;
  4573. constructor() {
  4574. this.inited = false;
  4575. }
  4576.  
  4577. /*static getInstance() {
  4578. if (!NextSwitch.nextSwitch) {
  4579. NextSwitch.nextSwitch = new NextSwitch();
  4580. }
  4581. return NextSwitch.nextSwitch;
  4582. }*/
  4583.  
  4584. init() {
  4585. if (this.inited) return;
  4586. this.inited = true;
  4587. let self = this;
  4588. this.cssText = `
  4589. #pagetual-nextSwitch {
  4590. position: fixed;
  4591. top: 10px;
  4592. left: calc(50% - 160px);
  4593. background: aliceblue;
  4594. padding: 10px;
  4595. border-radius: 5px;
  4596. text-align: center;
  4597. opacity: 0.95;
  4598. color: #161616;
  4599. z-index: 2147483647;
  4600. font-size: 16px;
  4601. box-shadow: rgb(0 0 0) 0px 0px 10px;
  4602. }
  4603. #pagetual-nextSwitch>.title {
  4604. margin: -5px 45px 10px 45px;
  4605. font-size: 20px;
  4606. font-weight: bold;
  4607. border-bottom: 1px solid black;
  4608. user-select: none;
  4609. color: orangered;
  4610. }
  4611. #pagetual-nextSwitch>.group {
  4612. display: flex;
  4613. flex-direction: column;
  4614. }
  4615. #pagetual-nextSwitch>.group>span {
  4616. color: #161616;
  4617. cursor: pointer;
  4618. margin: 3px;
  4619. font-size: larger;
  4620. }
  4621. #pagetual-nextSwitch>.group>span:hover {
  4622. color: red;
  4623. }
  4624. #pagetual-nextSwitch>.group>span.current {
  4625. border: 2px dotted red;
  4626. border-radius: 10px;
  4627. }
  4628. #pagetual-nextSwitch>.closeSwitch {
  4629. position: absolute;
  4630. top: 3px;
  4631. right: 10px;
  4632. background: none;
  4633. border: none;
  4634. vertical-align: top;
  4635. transition: transform .15s ease-in-out;
  4636. float: right;
  4637. cursor: pointer;
  4638. }
  4639. #pagetual-nextSwitch svg {
  4640. width: 30px;
  4641. height: 30px;
  4642. vertical-align: middle;
  4643. fill: #161616;
  4644. overflow: hidden;
  4645. }
  4646. #pagetual-nextSwitch button:hover {
  4647. transform: scale(1.2);
  4648. }
  4649. `;
  4650. let frame = document.createElement("div");
  4651. frame.id = "pagetual-nextSwitch";
  4652. frame.innerHTML = createHTML(`
  4653. <div class="title">${i18n("nextSwitch")}</div>
  4654. <button type="button" class="closeSwitch">
  4655. <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2754">
  4656. <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">
  4657. </path>
  4658. </svg>
  4659. </button>
  4660. <div class="group"></div>
  4661. `);
  4662. let group = frame.querySelector(".group");
  4663. let closeBtn = frame.querySelector(".closeSwitch");
  4664. closeBtn.addEventListener("click", e => {
  4665. self.close();
  4666. }, true);
  4667. this.frame = frame;
  4668. let currentSpan;
  4669. ruleParser.curSiteRule.nextLink.forEach((link, i) => {
  4670. let span = document.createElement("span");
  4671. let target = getElement(link, document);
  4672. let index = "<b>" + (i + 1) + "</b>: ";
  4673. if (target) {
  4674. let targetInner = target.innerText.trim();
  4675. span.innerHTML = index + (targetInner || link);
  4676. } else {
  4677. span.innerHTML = index + "Not Found";
  4678. }
  4679. span.title = link;
  4680. span.addEventListener("click", e => {
  4681. if (currentSpan) currentSpan.classList.remove("current");
  4682. span.classList.add("current");
  4683. currentSpan = span;
  4684. nextIndex = i;
  4685. setListData("nextSwitch", location.host, nextIndex === 0 ? "" : nextIndex);
  4686. ruleParser.curUrl += "#pagetual";
  4687. ruleParser.oldUrl = ruleParser.curUrl;
  4688. autoLoadNum = -1;
  4689. if (!ruleParser.nextLinkHref) {
  4690. isLoading = false;
  4691. }
  4692. ruleParser.getNextLink(ruleParser.pageDoc || document);
  4693. self.close();
  4694. }, true);
  4695. if (i == nextIndex) {
  4696. span.classList.add("current");
  4697. currentSpan = span;
  4698. }
  4699. group.appendChild(span);
  4700. });
  4701. }
  4702.  
  4703. start() {
  4704. this.init();
  4705. if (!this.styleEle || !this.styleEle.parentNode) {
  4706. this.styleEle = _GM_addStyle(this.cssText);
  4707. }
  4708. document.documentElement.appendChild(this.frame);
  4709. }
  4710.  
  4711. close() {
  4712. if (this.frame.parentNode) this.frame.parentNode.removeChild(this.frame);
  4713. }
  4714. }
  4715. const nextSwitch = new NextSwitch();
  4716.  
  4717. class Picker {
  4718. //static picker;
  4719. constructor() {
  4720. this.inited = false;
  4721. }
  4722.  
  4723. /*static getInstance() {
  4724. if (!Picker.picker) {
  4725. Picker.picker = new Picker();
  4726. }
  4727. return Picker.picker;
  4728. }*/
  4729.  
  4730. init() {
  4731. if (this.inited) return;
  4732. this.inited = true;
  4733. let self = this;
  4734. this.signList = [];
  4735. this.cssText = `
  4736. body.pagetual-picker,
  4737. body.pagetual-picker *:hover,
  4738. body.pagetual-picker a:hover {
  4739. cursor: crosshair !important;
  4740. }
  4741. #pagetual-picker {
  4742. position: fixed;
  4743. top: 10px;
  4744. left: calc(50% - 178px);
  4745. background: aliceblue;
  4746. padding: 10px;
  4747. border-radius: 5px;
  4748. text-align: center;
  4749. opacity: 0.95;
  4750. color: #161616;
  4751. z-index: 2147483646;
  4752. font-size: 16px;
  4753. overflow: hidden;
  4754. box-shadow: rgb(0 0 0) 0px 0px 10px;
  4755. }
  4756. #pagetual-picker * {
  4757. margin: 0;
  4758. padding: 0;
  4759. font-family: Times New Roman;
  4760. overflow: initial;
  4761. user-select: none;
  4762. line-height: unset;
  4763. min-width: unset;
  4764. min-height: unset;
  4765. }
  4766. #pagetual-picker>.title {
  4767. margin: -5px 45px 10px 45px;
  4768. font-size: 20px;
  4769. font-weight: bold;
  4770. cursor: pointer;
  4771. border-bottom: 1px solid black;
  4772. user-select: none;
  4773. color: orangered;
  4774. height: initial;
  4775. width: initial;
  4776. position: initial;
  4777. transition: transform .3s ease;
  4778. }
  4779. #pagetual-picker>.title:hover {
  4780. transform: scale(1.1);
  4781. }
  4782. #pagetual-picker button {
  4783. background: none;
  4784. border: none;
  4785. vertical-align: top;
  4786. transition: transform .15s ease-in-out;
  4787. float: right;
  4788. cursor: pointer;
  4789. overflow: hidden;
  4790. background-color: unset!important;
  4791. }
  4792. #pagetual-picker button:hover {
  4793. transform: scale(1.2);
  4794. }
  4795. #pagetual-picker>.closePicker {
  4796. position: absolute;
  4797. top: 3px;
  4798. right: 10px;
  4799. }
  4800. #pagetual-picker>.logoIcon {
  4801. position: absolute;
  4802. top: 3px;
  4803. left: 10px;
  4804. }
  4805. #pagetual-picker>.logoIcon.showSign>svg>path {
  4806. fill: gray!important;
  4807. }
  4808. #pagetual-picker textarea{
  4809. display: inline-block;
  4810. width: calc(100% - 65px);
  4811. height: 20px;
  4812. min-width: 250px;
  4813. max-width: calc(65vw - 50px);
  4814. min-height: unset;
  4815. max-height: unset;
  4816. padding: 6px 12px;
  4817. font-size: 16px;
  4818. font-weight: 400;
  4819. line-height: 1.5;
  4820. color: #495057;
  4821. background-color: #fff;
  4822. background-clip: padding-box;
  4823. border: 1px solid #ced4da;
  4824. border-radius: 4px;
  4825. transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out;
  4826. box-sizing: content-box;
  4827. margin-right: 5px;
  4828. resize: both;
  4829. box-shadow: 0 1px 5px 1px #ddd;
  4830. overflow-wrap: anywhere;
  4831. }
  4832. #pagetual-picker textarea:focus {
  4833. color: black;
  4834. background-color: #fff;
  4835. border-color: #80bdff;
  4836. outline: 0;
  4837. box-shadow: 0 0 0 3.2px rgb(0 123 255 / 25%);
  4838. }
  4839. #pagetual-picker [type=checkbox],
  4840. #pagetual-picker [type=radio] {
  4841. line-height: 20px;
  4842. height: 25px;
  4843. width: 25px;
  4844. margin-left: 5px;
  4845. vertical-align: middle;
  4846. appearance: auto;
  4847. display: inline-block;
  4848. position: initial;
  4849. }
  4850. #pagetual-picker [type=checkbox]:after,
  4851. #pagetual-picker [type=radio]:after,
  4852. #pagetual-picker [type=checkbox]:before,
  4853. #pagetual-picker [type=radio]:before {
  4854. border: none;
  4855. background: none;
  4856. }
  4857. #pagetual-picker label {
  4858. font-size: 18px;
  4859. line-height: 25px;
  4860. vertical-align: middle;
  4861. display: inline-block;
  4862. color: black;
  4863. position: initial;
  4864. cursor: pointer;
  4865. }
  4866. #pagetual-picker .bottom {
  4867. text-align: left;
  4868. margin: 10px 0;
  4869. width: 100%;
  4870. }
  4871. #pagetual-picker .bottom>button {
  4872. float: right;
  4873. }
  4874. #pagetual-picker svg {
  4875. width: 30px;
  4876. height: 30px;
  4877. vertical-align: middle;
  4878. fill: #161616;
  4879. overflow: hidden;
  4880. }
  4881. #pagetual-picker svg * {
  4882. pointer-events: none;
  4883. }
  4884. #pagetual-picker .allpath {
  4885. font-size: 18px;
  4886. margin: 10px auto;
  4887. max-width: 330px;
  4888. word-break: break-all;
  4889. cursor: context-menu;
  4890. overflow: hidden;
  4891. max-height: 42px;
  4892. -moz-transition:max-height 1s ease-in;
  4893. -webkit-transition:max-height 1s ease-in;
  4894. transition:max-height 1s ease-in;
  4895. color: black;
  4896. }
  4897. #pagetual-picker .allpath:hover {
  4898. max-height: calc(100vh - 130px);
  4899. overflow: auto;
  4900. }
  4901. #pagetual-picker .allpath>span.path {
  4902. cursor: pointer;
  4903. }
  4904. #pagetual-picker .allpath>span.path:hover {
  4905. opacity: 0.6;
  4906. }
  4907. #pagetual-picker .allpath>span.path:hover,
  4908. #pagetual-picker .allpath>span.path.checked {
  4909. color: orangered;
  4910. }
  4911. #pagetual-picker .moreConfig {
  4912. display: flex;
  4913. justify-content: space-between;
  4914. border-top: 1px solid;
  4915. padding-top: 10px;
  4916. width: 100%;
  4917. }
  4918. #pagetual-picker .command {
  4919. width: 100%;
  4920. color: black!important;
  4921. text-align: center;
  4922. font-size: large;
  4923. margin-top: 10px;
  4924. box-shadow: 0 1px 6px 0 rgba(0, 0, 0, 0.12);
  4925. border-radius: 5px;
  4926. }
  4927. #pagetual-picker .command:hover {
  4928. color: orangered;
  4929. }
  4930. #pagetual-picker #showDetail {
  4931. float: initial;
  4932. margin-top: 10px;
  4933. }
  4934. #pagetual-picker.showDetail #showDetail {
  4935. float: right;
  4936. }
  4937. #pagetual-picker #showDetail>svg {
  4938. -moz-transition:transform 0.3s ease;
  4939. -webkit-transition:transform 0.3s ease;
  4940. transition:transform 0.3 ease;
  4941. }
  4942. #pagetual-picker.showDetail #showDetail>svg {
  4943. transform: rotate(180deg);
  4944. }
  4945. #pagetual-picker .tempRule {
  4946. display: none;
  4947. margin-top: 10px;
  4948. height: 300px;
  4949. min-height: 150px;
  4950. }
  4951. #pagetual-picker.showDetail .tempRule {
  4952. display: inline-block;
  4953. word-break: break-all;
  4954. }
  4955. #pagetual-picker #saveDetail {
  4956. display: none;
  4957. position: absolute;
  4958. bottom: 10px;
  4959. right: 8px;
  4960. }
  4961. #pagetual-picker.showDetail #saveDetail {
  4962. display: inline-block;
  4963. }
  4964. #pagetual-picker #saveDetail svg {
  4965. width: 35px;
  4966. height: 35px;
  4967. }
  4968. #pagetual-picker .addProp {
  4969. display: none;
  4970. flex-direction: column;
  4971. position: absolute;
  4972. bottom: 45px;
  4973. right: 12px;
  4974. }
  4975. #pagetual-picker.showDetail .addProp {
  4976. display: flex;
  4977. }
  4978. #pagetual-picker .addProp>button {
  4979. font-size: 30px;
  4980. font-family: Arial,sans-serif;
  4981. line-height: 35px;
  4982. color: #161616;
  4983. }
  4984. #pagetual-picker #edit{
  4985. -webkit-animation: jumpAnimation .6s 5;
  4986. animation: jumpAnimation .6s 5;
  4987. }
  4988. @keyframes jumpAnimation {
  4989. 0% {
  4990. transform: scale(1) translateY(0);
  4991. animation-timing-function: ease-out;
  4992. }
  4993. 50% {
  4994. transform: scale(1.2) translateY(-5px);
  4995. animation-timing-function: ease-in;
  4996. }
  4997. 100% {
  4998. transform: scale(1) translateY(0);
  4999. animation-timing-function: ease-out;
  5000. }
  5001. }
  5002. @-webkit-keyframes jumpAnimation {
  5003. 0% {
  5004. -webkit-transform: scale(1) translateY(0);
  5005. animation-timing-function: ease-out;
  5006. }
  5007. 50% {
  5008. -webkit-transform: scale(1.2) translateY(-5px);
  5009. animation-timing-function: ease-in;
  5010. }
  5011. 100% {
  5012. -webkit-transform: scale(1) translateY(0);
  5013. animation-timing-function: ease-out;
  5014. }
  5015. }
  5016. `;
  5017. this.mainSignDiv = this.createSignDiv();
  5018. this.allSignDiv = [];
  5019. let frame = document.createElement("div");
  5020. frame.id = "pagetual-picker";
  5021. frame.innerHTML = createHTML(`
  5022. <button title="Pagetual" type="button" class="logoIcon">
  5023. <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>
  5024. </button>
  5025. <div class="title" title="${i18n("configure")}">${i18n("picker")}</div>
  5026. <button title="${i18n("closePicker")}" type="button" class="closePicker">
  5027. <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>
  5028. </button>
  5029. <div class="allpath" title="${i18n("switchSelector")}"></div>
  5030. <div>
  5031. <textarea class="selector" spellcheck="false" name="selector" placeholder="${i18n("pickerPlaceholder")}"></textarea>
  5032. <button id="check" title="${i18n("pickerCheck")}" type="button">
  5033. <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>
  5034. </button>
  5035. </div>
  5036. <div class="bottom">
  5037. <input name="xpath" id="checkbox_id" type="checkbox" />
  5038. <label for="checkbox_id">XPath</label>
  5039. <button id="edit" title="${i18n("gotoEdit")}" type="button">
  5040. <svg viewBox="0 0 1024 1024" style="color: orangered;fill: orangered;" version="1.1" xmlns="http://www.w3.org/2000/svg">
  5041. <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">
  5042. </path>
  5043. </svg>
  5044. </button>
  5045. </div>
  5046. <div class="moreConfig">
  5047. <div title="${i18n('forceStateIframe')}">
  5048. <input name="forceState" id="forceStateIframe" type="radio" />
  5049. <label for="forceStateIframe">${i18n('iframe')}</label>
  5050. </div>
  5051. <div title="${i18n('forceStateDynamic')}">
  5052. <input name="forceState" id="forceStateDynamic" type="radio" />
  5053. <label for="forceStateDynamic">${i18n('dynamic')}</label>
  5054. </div>
  5055. <div title="${i18n('forceStateDisable')}">
  5056. <input name="forceState" id="forceStateDisable" type="radio" />
  5057. <label for="forceStateDisable">${i18n('disable')}</label>
  5058. </div>
  5059. </div>
  5060. <button id="nextSwitch" class="command" title="${i18n("nextSwitch")}" type="button">${i18n("nextSwitch")}</button>
  5061. <button id="loadNow" class="command" title="${i18n("loadNow")}" type="button">${i18n("loadNow")}</button>
  5062. <button id="autoScroll" class="command" title="${i18n("toggleAutoScroll")}" type="button"></button>
  5063. <button id="ruleRequest" class="command" title="${i18n("ruleRequest")}" type="button">${i18n("ruleRequest")}</button>
  5064. <div>
  5065. <textarea class="tempRule" spellcheck="false" placeholder="{Rule object}" title="Rule for current site"></textarea>
  5066. <button id="showDetail" title="" type="button">
  5067. <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>
  5068. </button>
  5069. <div class="addProp">
  5070. <button id="addOtherProp" title="${i18n("addOtherProp")}" type="button">+</button>
  5071. <button id="addNextSelector" title="${i18n("addNextSelector")}" type="button">></button>
  5072. <button id="addPageSelector" title="${i18n("addPageSelector")}" type="button">❏</button>
  5073. </div>
  5074. <button id="saveDetail" title="${i18n("save")}" type="button">
  5075. <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>
  5076. </button>
  5077. </div>
  5078. `);
  5079. let forceStateIframe = frame.querySelector("#forceStateIframe");//forceState 1 禁用 2 强嵌 3 动态
  5080. let forceStateDynamic = frame.querySelector("#forceStateDynamic");
  5081. let forceStateDisable = frame.querySelector("#forceStateDisable");
  5082. let clickRadio = e => {
  5083. let radio = e.currentTarget.querySelector('input');
  5084. if (radio.checked) {
  5085. forceState = "";
  5086. } else {
  5087. switch (radio.id) {
  5088. case "forceStateIframe":
  5089. forceState = 2;
  5090. break;
  5091. case "forceStateDynamic":
  5092. forceState = 3;
  5093. break;
  5094. case "forceStateDisable":
  5095. forceState = 1;
  5096. break;
  5097. default:
  5098. return;
  5099. }
  5100. }
  5101. setListData("forceState", location.host, forceState);
  5102. self.close();
  5103. setTimeout(() => {
  5104. location.reload();
  5105. }, 500);
  5106. };
  5107. forceStateIframe.parentNode.addEventListener("mousedown", clickRadio);
  5108. forceStateDynamic.parentNode.addEventListener("mousedown", clickRadio);
  5109. forceStateDisable.parentNode.addEventListener("mousedown", clickRadio);
  5110. if (forceState == 1) forceStateDisable.checked = true;
  5111. else if (forceState == 2) forceStateIframe.checked = true;
  5112. else if (forceState == 3) forceStateDynamic.checked = true;
  5113. let closeBtn = frame.querySelector(".closePicker");
  5114. let logoBtn = frame.querySelector(".logoIcon");
  5115. let title = frame.querySelector(".title");
  5116. let allpath = frame.querySelector(".allpath");
  5117. let selectorInput = frame.querySelector(".selector");
  5118. let xpath = frame.querySelector("#checkbox_id");
  5119. let checkBtn = frame.querySelector("#check");
  5120. let editBtn = frame.querySelector("#edit");
  5121. let nextSwitchBtn = frame.querySelector("#nextSwitch");
  5122. let autoScrollBtn = frame.querySelector("#autoScroll");
  5123. let loadNow = frame.querySelector("#loadNow");
  5124. let tempRule = frame.querySelector(".tempRule");
  5125. let showDetailBtn = frame.querySelector("#showDetail");
  5126. let saveDetailBtn = frame.querySelector("#saveDetail");
  5127. let addOtherProp = frame.querySelector("#addOtherProp");
  5128. let addNextSelector = frame.querySelector("#addNextSelector");
  5129. let addPageSelector = frame.querySelector("#addPageSelector");
  5130. let ruleRequestBtn = frame.querySelector("#ruleRequest");
  5131. ruleRequestBtn.addEventListener("click", e => {
  5132. _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});
  5133. }, true);
  5134. autoScrollBtn.addEventListener("click", e => {
  5135. self.close();
  5136. autoScroll = (autoScroll ? 0 : prompt(i18n("autoScrollRate"), autoScrollRate)) || 0;
  5137. autoScroll = parseInt(autoScroll) || 0;
  5138. if (autoScroll < 0) autoScroll = 0;
  5139. if (autoScroll && autoScroll != autoScrollRate) {
  5140. autoScrollRate = autoScroll;
  5141. storage.setItem("autoScrollRate", autoScrollRate);
  5142. }
  5143. setListData("autoScroll", location.host + location.pathname, autoScroll);
  5144. startAutoScroll();
  5145. }, true);
  5146. addOtherProp.addEventListener("click", e => {
  5147. let propName = prompt(i18n("propName"), "author");
  5148. if (!propName) return;
  5149. let propValue = prompt(i18n("propValue"));
  5150. if (!propValue) return;
  5151. if (propValue === "true") propValue = true;
  5152. else if (propValue === "false") propValue = false;
  5153. else if (/^\d+$/.test(propValue)) propValue = parseInt(propValue);
  5154. if (propName === "author" && propValue) {
  5155. author = propValue;
  5156. storage.setItem("author", propValue);
  5157. }
  5158. let editTemp = self.getTempRule();
  5159. if (!editTemp) return;
  5160. editTemp[propName] = propValue;
  5161. self.tempRule.value = JSON.stringify(editTemp, null, 4);
  5162. }, true);
  5163. addNextSelector.addEventListener("click", e => {
  5164. let editTemp = self.getTempRule();
  5165. if (!editTemp) return;
  5166. let selector = self.selectorInput.value;
  5167. if (selector) {
  5168. editTemp.nextLink = selector;
  5169. }
  5170. self.tempRule.value = JSON.stringify(editTemp, null, 4);
  5171. }, true);
  5172. addPageSelector.addEventListener("click", e => {
  5173. let editTemp = self.getTempRule();
  5174. if (!editTemp) return;
  5175. let selector = self.selectorInput.value;
  5176. if (selector) {
  5177. editTemp.pageElement = selector;
  5178. }
  5179. self.tempRule.value = JSON.stringify(editTemp, null, 4);
  5180. }, true);
  5181. showDetailBtn.addEventListener("click", e => {
  5182. frame.classList.toggle("showDetail");
  5183. }, true);
  5184. saveDetailBtn.addEventListener("click", e => {
  5185. let editTemp = self.getTempRule(true);
  5186. if (tempRule.value && !editTemp) {
  5187. return;
  5188. }
  5189. if(!ruleParser.customRules) {
  5190. ruleParser.customRules = [];
  5191. }
  5192. ruleParser.customRules = ruleParser.customRules.filter(item => {return item.url != editTemp.url || item.name != editTemp.name});
  5193. if (tempRule.value) {
  5194. ruleParser.customRules.unshift(editTemp);
  5195. ruleParser.curSiteRule = editTemp;
  5196. } else {
  5197. ruleParser.curSiteRule = {};
  5198. isPause = true;
  5199. }
  5200. storage.setItem("customRules", ruleParser.customRules);
  5201. if (ruleParser.hpRules && ruleParser.curSiteRule && !ruleParser.curSiteRule.smart) {
  5202. ruleParser.addToHpRules(true);
  5203. }
  5204. if (window.confirm(i18n("reloadPage"))) {
  5205. setTimeout(() => {location.reload()}, 100);
  5206. }
  5207. }, true);
  5208. nextSwitchBtn.addEventListener("click", e => {
  5209. self.close();
  5210. nextSwitch.start();
  5211. }, true);
  5212. loadNow.addEventListener("click", e => {
  5213. self.close();
  5214. let loadNum = window.prompt(i18n("loadConfirm"), "1");
  5215. if (loadNum === "" || loadNum === null) return;
  5216. autoLoadNum = Math.abs(parseInt(loadNum));
  5217. nextPage();
  5218. }, true);
  5219. closeBtn.addEventListener("click", e => {
  5220. self.close();
  5221. }, true);
  5222. this.showSign = true;
  5223. logoBtn.addEventListener("click", e => {
  5224. logoBtn.classList.toggle("showSign");
  5225. self.showSign = !self.showSign;
  5226. getBody(document).classList.toggle("pagetual-picker");
  5227. }, true);
  5228. let moving = false;
  5229. let initX = 0, initY = 0, initPos = {x: 0, y: 0};
  5230. let moveHanlder = e => {
  5231. if (moving) {
  5232. frame.style.left = e.clientX - initX + "px";
  5233. frame.style.top = e.clientY - initY + "px";
  5234. e.stopPropagation();
  5235. e.preventDefault();
  5236. } else if(Math.abs(e.clientX - initPos.x) + Math.abs(e.clientY - initPos.y) > 20) {
  5237. moving = true;
  5238. }
  5239. };
  5240. let upHanlder = e => {
  5241. if (moving) {
  5242. moving = false;
  5243. } else {
  5244. _GM_openInTab(rulesData.configPage || configPage[0], {active: true});
  5245. }
  5246. document.removeEventListener("mousemove", moveHanlder, true);
  5247. title.removeEventListener("mouseup", upHanlder, true);
  5248. e.stopPropagation();
  5249. e.preventDefault();
  5250. };
  5251. title.addEventListener("mousedown", e => {
  5252. initPos = {x: e.clientX, y: e.clientY};
  5253. initX = e.clientX - parseInt(getComputedStyle(frame).left);
  5254. initY = e.clientY - parseInt(getComputedStyle(frame).top);
  5255. document.addEventListener("mousemove", moveHanlder, true);
  5256. title.addEventListener("mouseup", upHanlder, true);
  5257. });
  5258. frame.addEventListener("mouseenter", e => {
  5259. if (!self.showSign || moving) return;
  5260. if (self.mainSignDiv.parentNode) self.mainSignDiv.parentNode.removeChild(self.mainSignDiv);
  5261. self.checkInputSelector(false);
  5262. });
  5263. frame.addEventListener("mouseleave", e => {
  5264. if (!self.showSign) {
  5265. if (self.mainSignDiv.parentNode) self.mainSignDiv.parentNode.removeChild(self.mainSignDiv);
  5266. self.clearSigns();
  5267. return;
  5268. }
  5269. if (moving) return;
  5270. document.documentElement.appendChild(self.mainSignDiv);
  5271. self.clearSigns();
  5272. });
  5273. checkBtn.addEventListener("click", e => {
  5274. self.checkInputSelector();
  5275. if (this.selectorInput.value && self.foundEle) {
  5276. debug(self.foundEle);
  5277. self.foundEle[0].scrollIntoView({ behavior: "smooth" });
  5278. _GM_setClipboard(this.selectorInput.value);
  5279. showTips(i18n("copied"));
  5280. } else showTips("Null");
  5281. });
  5282. xpath.addEventListener("click", e => {
  5283. if (!selectorInput.value) {
  5284. self.setSelectorDiv("");
  5285. return;
  5286. }
  5287. let element = getElement(selectorInput.value, document);
  5288. let selector = self.getSelectorFromEle(element);
  5289. selectorInput.value = selector;
  5290. self.setSelectorDiv(selector);
  5291. });
  5292. editBtn.addEventListener("click", e => {
  5293. rulesData.editTemp = self.getTempRule();
  5294. storage.setItem("rulesData", rulesData);
  5295. _GM_openInTab(rulesData.configPage || configPage[0], {active: true});
  5296. });
  5297. editBtn.oncontextmenu = e => {
  5298. e.preventDefault();
  5299. _GM_openInTab(rulesData.configPage || configPage[0], {active: true});
  5300. };
  5301. this.frame = frame;
  5302. this.xpath = xpath;
  5303. this.allpath = allpath;
  5304. this.selectorInput = selectorInput;
  5305. this.nextSwitchBtn = nextSwitchBtn;
  5306. this.autoScrollBtn = autoScrollBtn;
  5307. this.loadNow = loadNow;
  5308. this.tempRule = tempRule;
  5309. this.logoBtn = logoBtn;
  5310. let setTitleTimer;
  5311. this.moveHandler = e => {
  5312. if (!self.showSign || e.target === document) return;
  5313. let target = self.getTarget(e.target);
  5314. self.adjustSignDiv(self.mainSignDiv, target);
  5315. clearTimeout(setTitleTimer);
  5316. setTitleTimer = setTimeout(() => {
  5317. if (self.inPicker && target.hasAttributes()) {
  5318. let title = target.nodeName.toLowerCase() + "\n";
  5319. for (const attr of target.attributes) {
  5320. title += `【${attr.name}】${attr.value ? " ➡️ " + attr.value : ""}\n`;
  5321. }
  5322. getBody(document).title = title;
  5323. }
  5324. }, 100);
  5325. };
  5326. this.clickHandler = e => {
  5327. if (!self.showSign || !e.isTrusted) return;
  5328. if (self.inPicker) {
  5329. e.stopPropagation();
  5330. e.preventDefault();
  5331. }
  5332. let target = self.getTarget(e.target);
  5333. let selector = self.getSelectorFromEle(target);
  5334. selectorInput.value = selector;
  5335. self.setSelectorDiv(selector);
  5336. };
  5337. }
  5338.  
  5339. getTempRule(detail) {
  5340. if (this.tempRule.value) {
  5341. try {
  5342. this.editTemp = JSON.parse(this.tempRule.value);
  5343. } catch (e) {
  5344. this.editTemp = null;
  5345. if (detail) {
  5346. let pos = e && e.message && e.message.match(/position (\d+)/);
  5347. if (pos) {
  5348. pos = parseInt(pos[1]);
  5349. this.tempRule.value = this.tempRule.value.slice(0, pos) + "➡️" + this.tempRule.value.slice(pos);
  5350. }
  5351. showTips(i18n("errorJson"));
  5352. return null;
  5353. }
  5354. }
  5355. }
  5356. if (!this.editTemp) {
  5357. if (ruleParser.curSiteRule.url && !ruleParser.curSiteRule.smart) {
  5358. this.editTemp = ruleParser.curSiteRule;
  5359. } else {
  5360. this.editTemp = {
  5361. name: document.title,
  5362. url: "^" + (location.origin + location.pathname).replace(/[^\/]*$/, "").replace(/^https?/, "https?").replace(/\./g, "\\."),
  5363. example: location.href
  5364. };
  5365. if (author) this.editTemp.author = author;
  5366. }
  5367. delete this.editTemp.from;
  5368. delete this.editTemp.type;
  5369. delete this.editTemp.updatedAt;
  5370. }
  5371. if (this.selectorInput.value && (!this.frame.classList.contains("showDetail") || !this.editTemp || !this.editTemp.pageElement)) {
  5372. if (this.foundEle && this.foundEle.length === 1) {
  5373. let foundEleRect = this.foundEle[0].getBoundingClientRect();
  5374. if (foundEleRect.height < 100) {
  5375. showTips("Next Link", "", 500);
  5376. this.editTemp.nextLink = this.selectorInput.value;
  5377. return this.editTemp;
  5378. }
  5379. }
  5380. showTips("Page Element", "", 500);
  5381. this.editTemp.pageElement = this.selectorInput.value;
  5382. }
  5383. return this.editTemp;
  5384. }
  5385.  
  5386. getTarget(ele) {
  5387. while (ele.parentNode && (ele.offsetWidth === 0 || ele.offsetHeight === 0)) {
  5388. ele = ele.parentNode;
  5389. }
  5390. return ele;
  5391. }
  5392.  
  5393. close() {
  5394. this.clearSigns();
  5395. if (this.frame.parentNode) this.frame.parentNode.removeChild(this.frame);
  5396. if (this.mainSignDiv.parentNode) this.mainSignDiv.parentNode.removeChild(this.mainSignDiv);
  5397. getBody(document).classList.remove("pagetual-picker");
  5398. getBody(document).removeEventListener("mousemove", this.moveHandler, true);
  5399. getBody(document).removeEventListener("click", this.clickHandler, true);
  5400. getBody(document).title = "";
  5401. this.inPicker = false;
  5402. }
  5403.  
  5404. setImportant(ele, prop, value) {
  5405. ele.style.setProperty(prop, value, "important");
  5406. }
  5407.  
  5408. createSignDiv() {
  5409. let signDiv = document.createElement("div");
  5410. this.setImportant(signDiv, "position", "absolute");
  5411. this.setImportant(signDiv, "pointer-events", "none");
  5412. this.setImportant(signDiv, "z-index", "2147483645");
  5413. this.setImportant(signDiv, "background", "rgba(120, 170, 210, 0.6)");
  5414. this.setImportant(signDiv, "transition", "all 0.15s ease-out");
  5415. this.setImportant(signDiv, "box-shadow", "rgb(0 0 0) 0px 0px 3px 0px");
  5416. return signDiv;
  5417. }
  5418.  
  5419. adjustSignDiv(div, target) {
  5420. let rect = target.getBoundingClientRect();
  5421. this.setImportant(div, "width", rect.width + "px");
  5422. this.setImportant(div, "height", rect.height + "px");
  5423. this.setImportant(div, "left", rect.left + window.scrollX + "px");
  5424. this.setImportant(div, "top", rect.top + window.scrollY + "px");
  5425. }
  5426.  
  5427. getSelectorFromEle(ele) {
  5428. return this.xpath.checked ? createXPathFromElement(ele) : geneSelector(ele, true);
  5429. }
  5430.  
  5431. fillTempRuleTextarea() {
  5432. if (!this.frame.classList.contains("showDetail") || !this.editTemp || !this.editTemp.pageElement) this.tempRule.value = JSON.stringify(this.getTempRule(), null, 4);
  5433. }
  5434.  
  5435. setSelectorDiv(selector) {
  5436. let self = this;
  5437. this.allpath.innerHTML = createHTML("");
  5438. if (selector) {
  5439. if (this.xpath.checked) {
  5440. let span = document.createElement("span");
  5441. span.innerText = selector;
  5442. span.addEventListener("click", e => {
  5443. self.selectorInput.value = selector;
  5444. self.checkInputSelector();
  5445. }, true);
  5446. this.allpath.appendChild(span);
  5447. } else {
  5448. selector.split(">").forEach((item, index) => self.geneSelectorItem(item, index));
  5449. }
  5450. }
  5451. this.checkInputSelector();
  5452. }
  5453.  
  5454. geneSelectorItem(item, index) {
  5455. let self = this;
  5456. item = item.trim();
  5457. if (!item) return;
  5458. if (index !== 0) {
  5459. let span = document.createElement("span");
  5460. span.innerText = " > ";
  5461. this.allpath.appendChild(span);
  5462. }
  5463. let span = document.createElement("span");
  5464. span.className = "path";
  5465. span.innerText = item;
  5466. span.addEventListener("click", e => {
  5467. let selector = "";
  5468. let target = e.target;
  5469. while (target) {
  5470. selector = target.innerText + selector;
  5471. target = target.previousElementSibling;
  5472. }
  5473. self.selectorInput.value = selector;
  5474. self.checkInputSelector();
  5475. if (self.checkedPath) {
  5476. self.checkedPath.classList.remove("checked");
  5477. }
  5478. span.classList.add("checked");
  5479. self.checkedPath = span;
  5480. }, true);
  5481. this.allpath.appendChild(span);
  5482. }
  5483.  
  5484. checkInputSelector(fill = true) {
  5485. let self = this;
  5486. this.clearSigns();
  5487. if (!this.selectorInput.value) return;
  5488. let eles = getAllElements(this.selectorInput.value, document);
  5489. this.foundEle = null;
  5490. if (eles && eles.length > 0) {
  5491. this.foundEle = eles;
  5492. eles.forEach(ele => {
  5493. let sign = self.createSignDiv();
  5494. document.documentElement.appendChild(sign);
  5495. self.adjustSignDiv(sign, ele);
  5496. self.signList.push(sign);
  5497. });
  5498. if (fill) this.fillTempRuleTextarea();
  5499. }
  5500. }
  5501.  
  5502. clearSigns() {
  5503. this.signList.forEach(sign => {
  5504. if (sign.parentNode) sign.parentNode.removeChild(sign);
  5505. });
  5506. this.signList = [];
  5507. }
  5508.  
  5509. start() {
  5510. this.init();
  5511. if (this.inPicker) return;
  5512. this.inPicker = true;
  5513. if (!this.styleEle || !this.styleEle.parentNode) {
  5514. this.styleEle = _GM_addStyle(this.cssText);
  5515. }
  5516. document.documentElement.appendChild(this.frame);
  5517. document.documentElement.appendChild(this.mainSignDiv);
  5518. getBody(document).classList.add("pagetual-picker");
  5519.  
  5520. this.logoBtn.classList.remove("showSign");
  5521. this.showSign = true;
  5522.  
  5523. getBody(document).addEventListener("mousemove", this.moveHandler, true);
  5524. getBody(document).addEventListener("click", this.clickHandler, true);
  5525. this.xpath.checked = isXPath(ruleParser.curSiteRule.pageElement);
  5526. this.tempRule.value = "";
  5527. this.editTemp = null;
  5528. this.frame.classList.remove("showDetail");
  5529.  
  5530. this.loadNow.style.display = ruleParser.nextLinkHref ? "block" : "none";
  5531. if (ruleParser.curSiteRule.nextLink && Array && Array.isArray && Array.isArray(ruleParser.curSiteRule.nextLink)) {
  5532. this.nextSwitchBtn.style.display = "block";
  5533. } else {
  5534. this.nextSwitchBtn.style.display = "none";
  5535. }
  5536. this.autoScrollBtn.innerText = i18n(autoScroll ? "disableAutoScroll" : "enableAutoScroll");
  5537.  
  5538. let pageElementSel = ruleParser.curSiteRule.pageElement || "";
  5539. if (Array && Array.isArray && Array.isArray(pageElementSel)) {
  5540. pageElementSel = pageElementSel[nextIndex < pageElementSel.length ? nextIndex : 0];
  5541. }
  5542. this.setSelectorDiv(pageElementSel);
  5543. this.fillTempRuleTextarea();
  5544. }
  5545. }
  5546. const picker = new Picker();
  5547.  
  5548. var editor, editorChanged = false, customRulesInput;
  5549. function createEdit() {
  5550. var options = {
  5551. mode: 'code',
  5552. modes: ['code', 'tree'],
  5553. templates: [
  5554. {
  5555. text: 'New site',
  5556. title: 'Insert a new site',
  5557. className: 'jsoneditor-type-object',
  5558. field: 'SiteTemplate',
  5559. value: {
  5560. 'name': 'Site name',
  5561. 'url': 'Site url'
  5562. }
  5563. }
  5564. ],
  5565. schema: {
  5566. "title": "Sites data",
  5567. "description": "Object containing site config",
  5568. "type": "array",
  5569. "items": {
  5570. "type": 'object',
  5571. "properties": {
  5572. "name": {
  5573. "title": "Site Name",
  5574. "description": "The site's name.",
  5575. "examples": [
  5576. "Google"
  5577. ],
  5578. "type": "string"
  5579. },
  5580. "url": {
  5581. "title": "Site Url",
  5582. "description": "The Regexp of site's url.",
  5583. "examples": [
  5584. "^https:\/\/yande\\.re\/"
  5585. ],
  5586. "type": "string"
  5587. }
  5588. },
  5589. "required": ["name", "url"]
  5590. }
  5591. },
  5592. onChange: () => {
  5593. editorChanged = true;
  5594. }
  5595. };
  5596. setTimeout(() => {
  5597. var container = document.getElementById("jsoneditor");
  5598. if (!container) {
  5599. container = document.createElement("div");
  5600. configCon.appendChild(container);
  5601. }
  5602. container.style.height = '800px';
  5603. container.innerHTML = "";
  5604. try {
  5605. editor = new _unsafeWindow.JSONEditor(container, options);
  5606. editor.set(ruleParser.customRules);
  5607. } catch (e) {
  5608. editor = null;
  5609. container.style.display = 'none';
  5610. customRulesInput.style.display = "";
  5611. }
  5612. }, 500);
  5613. }
  5614.  
  5615. function checkGuidePage(href) {
  5616. if (guidePage.test(href)) {
  5617. if (typeof _unsafeWindow.JSONEditor !== 'undefined') {
  5618. createEdit();
  5619. } else {
  5620. let timeout = 30;
  5621. let checkEditorReady = setInterval(() => {
  5622. if (typeof _unsafeWindow.JSONEditor !== 'undefined') {
  5623. createEdit();
  5624. clearInterval(checkEditorReady);
  5625. } else if (timeout-- <= 0) {
  5626. editor = null;
  5627. customRulesInput.style.display = "";
  5628. clearInterval(checkEditorReady);
  5629. }
  5630. }, 100);
  5631. }
  5632. return true;
  5633. }
  5634. return false;
  5635. }
  5636.  
  5637. function startAutoScroll() {
  5638. clearInterval(autoScrollInterval);
  5639. if (autoScroll <= 0) return;
  5640. let scrollRange_o = 1;
  5641. if (autoScroll > 1000) {
  5642. scrollRange_o = parseInt(autoScroll / 1000);
  5643. }
  5644. let devicePixelRatio = window.devicePixelRatio;
  5645. let scrollRange = Math.ceil(scrollRange_o / devicePixelRatio);
  5646.  
  5647. let scrollTarget, body = getBody(document);
  5648. let checkOverflow = ele => {
  5649. return ele.scrollHeight !== ele.clientHeight && getComputedStyle(ele).overflowY !== "hidden";
  5650. };
  5651. if (document.documentElement.scrollTop || checkOverflow(document.documentElement)) {
  5652. scrollTarget = document.documentElement;
  5653. } else if (body.scrollTop || checkOverflow(body)) {
  5654. scrollTarget = body;
  5655. } else {
  5656. let tempEle;
  5657. let img = body.querySelector('img');
  5658. if (img) {
  5659. tempEle = img;
  5660. while (tempEle && !checkOverflow(tempEle)) {
  5661. tempEle = tempEle.parentNode;
  5662. }
  5663. }
  5664. if (!tempEle && document.activeElement) {
  5665. let tempEle = document.activeElement;
  5666. while (tempEle && !checkOverflow(tempEle)) {
  5667. tempEle = tempEle.parentNode;
  5668. }
  5669. }
  5670. if (tempEle) scrollTarget = tempEle;
  5671. }
  5672. scrollTarget = scrollTarget || document.documentElement;
  5673.  
  5674. autoScrollInterval = setInterval(() => {
  5675. if (isPause && !urlChanging) return;
  5676. if (devicePixelRatio !== window.devicePixelRatio) {
  5677. devicePixelRatio = window.devicePixelRatio;
  5678. scrollRange = Math.ceil(scrollRange_o / devicePixelRatio);
  5679. }
  5680. scrollTarget.scrollTop += scrollRange;
  5681. }, parseInt(1000 / autoScroll));
  5682. }
  5683.  
  5684. var inUpdate = false;
  5685. var importHandler, configCon;
  5686. function initConfig(href) {
  5687. if (location.hostname === "github.com") {
  5688. 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) {
  5689. let issue_body = document.getElementById("issue_body");
  5690. if (!issue_body) return true;
  5691. issue_body.value = issue_body.value.replace("\n", "\n" + location.hash.slice(1) + "\n");
  5692. let starButton = document.createElement("a");
  5693. starButton.href = "https://github.com/hoothin/UserScripts#star";
  5694. starButton.className = "js-toggler-target rounded-left-2 btn-with-aria-count btn-sm btn";
  5695. 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>');
  5696. starButton.style.float = "right";
  5697. document.querySelector(".Layout-main>h2").appendChild(starButton);
  5698. return true;
  5699. } else if (location.href === "https://github.com/hoothin/UserScripts#star") {
  5700. let starButton = document.querySelector(".starring-container:not(.on)>.unstarred>form>button");
  5701. if (starButton) emuClick(starButton);
  5702. return true;
  5703. }
  5704. }
  5705. let isGuidePage = checkGuidePage(href);
  5706.  
  5707. var click2import, importUrlPres;
  5708.  
  5709. let inConfig = isGuidePage;
  5710. if (!inConfig) {
  5711. for (let i = 0; i < configPage.length; i++) {
  5712. if (configPage[i] == location.href) {
  5713. inConfig = true;
  5714. break;
  5715. }
  5716. }
  5717. }
  5718. if (!isGuidePage) {
  5719. if (location.hostname === "hoothin.github.io" || location.hostname === "pagetual.hoothin.com") isGuidePage = true;
  5720. }
  5721. configCon = document.getElementById("configCon");
  5722. if (configCon) {
  5723. configCon.parentNode.removeChild(configCon);
  5724. }
  5725. if (ruleImportUrlReg.test(href) || inConfig) {
  5726. let importing = false;
  5727. if (!inUpdate && rulesData.uninited) {
  5728. setTimeout(() => {
  5729. if (!inUpdate && !importing) showTips(i18n("firstAlert"));
  5730. }, 3000);
  5731. showTips(i18n("firstAlert"));
  5732. }
  5733. let defaultOption = document.querySelector('#discussion_rating_4');
  5734. if (defaultOption) defaultOption.checked = true;
  5735. let createImportBtn = (pre) => {
  5736. let importBtn = document.createElement("button");
  5737. importBtn.id = "pagetualImport";
  5738. importBtn.innerText = i18n("import");
  5739. importBtn.style.marginTop = "100px";
  5740. importBtn.style.float = "right";
  5741. importBtn.style.position = "relative";
  5742. importBtn.style.display = "block";
  5743. importBtn.style.fontSize = "20px";
  5744. importBtn.addEventListener("click", e => {
  5745. let parentNode = importBtn.parentNode;
  5746. if (!parentNode) return;
  5747. parentNode.removeChild(importBtn);
  5748. try {
  5749. let rules = parentNode.innerText.trim();
  5750. let isContent = /['"]name['"]/i.test(rules);
  5751. if (isContent) {
  5752. let ruleList = JSON.parse(`[${rules}]`);
  5753. for (let i in ruleList) {
  5754. let hasRule = false;
  5755. let r = ruleList[i];
  5756. for (let j in ruleParser.customRules) {
  5757. if (ruleParser.customRules[j].name == r.name) {
  5758. ruleParser.customRules[j] = r;
  5759. hasRule = true;
  5760. break;
  5761. }
  5762. }
  5763. if (!hasRule) ruleParser.customRules.push(r);
  5764. ruleParser.hpRules.unshift(r);
  5765. }
  5766. storage.setItem("customRules", ruleParser.customRules);
  5767. storage.setItem("hpRules", ruleParser.hpRules);
  5768. storage.setItem("smartRules", []);
  5769. showTips(i18n("importSucc"));
  5770. } else {
  5771. rules = rules.split("\n");
  5772. let diff = false;
  5773. for (let c = 0; c < rules.length; c++) {
  5774. let urlArr = rules[c].split("|"), url, type = 1;
  5775. if (urlArr.length == 1) {
  5776. url = urlArr[0].trim();
  5777. if (!/^http/.test(url)) {
  5778. showTips(i18n("errorWrongUrl"));
  5779. return;
  5780. }
  5781. } else if (urlArr.length == 2) {
  5782. type = urlArr[0].trim();
  5783. url = urlArr[1].trim();
  5784. if (!/^http/.test(url)) {
  5785. showTips(i18n("errorWrongUrl"));
  5786. return;
  5787. }
  5788. } else {
  5789. break;
  5790. }
  5791. let maxId = 1, hasUrl = false;
  5792. if (!rulesData.urls) {
  5793. rulesData.urls = [];
  5794. maxId = 1;
  5795. } else {
  5796. rulesData.urls.forEach(u => {
  5797. if (maxId < u.id) {
  5798. maxId = u.id;
  5799. }
  5800. if (u.url == url) {
  5801. hasUrl = true;
  5802. }
  5803. });
  5804. if (hasUrl) break;
  5805. }
  5806. diff = true;
  5807. if (!rulesData.sort) rulesData.sort = [1];
  5808. rulesData.urls.push({id: maxId + 1, url: url, type: type});
  5809. rulesData.sort.unshift(maxId + 1);
  5810. }
  5811. if (!diff) {
  5812. showTips(i18n("errorAlreadyExists"));
  5813. setTimeout(() => {
  5814. showTips(i18n("beginUpdate"), "", 50000);
  5815. updateRules(() => {
  5816. showTips(i18n("updateSucc"));
  5817. location.reload();
  5818. }, (rule, err) => {
  5819. showTips(`Failed to update ${rule.url} rules!`);
  5820. debug(err);
  5821. });
  5822. }, 500);
  5823. return;
  5824. }
  5825. storage.setItem("rulesData", rulesData);
  5826.  
  5827. if (rulesData.urls) ruleUrls = ruleUrls.concat(rulesData.urls);
  5828. if (rulesData.sort) {
  5829. let urls = [];
  5830. rulesData.sort.forEach(id => {
  5831. for (let s = 0; s < ruleUrls.length; s++) {
  5832. if (id == ruleUrls[s].id) {
  5833. urls.push(ruleUrls[s]);
  5834. break;
  5835. }
  5836. }
  5837. });
  5838. ruleUrls = urls;
  5839. }
  5840. showTips(i18n("beginUpdate"), "", 30000);
  5841. updateRules(() => {
  5842. showTips(i18n("updateSucc"));
  5843. location.reload();
  5844. }, (rule, err) => {
  5845. showTips(`Failed to update ${rule.url} rules!`);
  5846. debug(err);
  5847. });
  5848. importing = true;
  5849. }
  5850. } catch (e) {
  5851. _GM_notification(e.toString());
  5852. }
  5853. });
  5854. if (pre) {
  5855. let clientHeight = 35 - pre.clientHeight;
  5856. if (clientHeight > -20) clientHeight = -20;
  5857. importBtn.style.marginTop = `${clientHeight}px`;
  5858. pre.appendChild(importBtn);
  5859. }
  5860. return importBtn;
  5861. };
  5862. [].forEach.call(document.querySelectorAll('pre[name=pagetual],pre[name=user-content-pagetual]'), pre => {
  5863. let importBtn = createImportBtn(pre);
  5864. if (rulesData.uninited) {
  5865. pre.style.display = "";
  5866. }
  5867. });
  5868. click2import = document.querySelector("[name='user-content-click2import'],[name='click2import']");
  5869. if (click2import) {
  5870. click2import.innerText = i18n("click2ImportRule");
  5871. click2import.style.display = rulesData.uninited ? "block" : "none";
  5872. }
  5873. if (!importHandler) {
  5874. importHandler = e => {
  5875. if (compareNodeName(e.target, ["pre"])) {
  5876. let nameAttr = e.target.getAttribute("name");
  5877. if (nameAttr == "pagetual" || nameAttr == "user-content-pagetual") {
  5878. if (e.target.querySelector('#pagetualImport')) return;
  5879. let importBtn = createImportBtn(e.target);
  5880. }
  5881. }
  5882. };
  5883. }
  5884. document.removeEventListener("mouseover", importHandler);
  5885. document.addEventListener("mouseover", importHandler);
  5886.  
  5887. if (inConfig) {
  5888. if (!inUpdate && _GM_info.script && _GM_info.script.version && _GM_info.script.version !== '1.0.0') {
  5889. let versionEle = document.querySelector('.markdown-body>h1[id],article>h1');
  5890. let latestVer = versionEle && versionEle.innerText.match(/\d[\d\.]+/)[0];
  5891. if (latestVer && latestVer != _GM_info.script.version) {
  5892. showTips(i18n('outOfDate'), "", 3000);
  5893. }
  5894. }
  5895. _GM_addStyle(`
  5896. p>span:nth-child(1),p>span:nth-child(2),p>span:nth-child(3){
  5897. cursor: pointer;
  5898. user-select: none;
  5899. display: inline-block;
  5900. margin-right: 5px;
  5901. -moz-transition:color 0.3s ease, transform 0.3s;
  5902. -webkit-transition:color 0.3s ease, transform 0.3s;
  5903. transition:color 0.3s ease, transform 0.3s;
  5904. }
  5905. p>span:nth-child(1):hover,p>span:nth-child(2):hover,p>span:nth-child(3):hover{
  5906. color:red;
  5907. transform: scale(1.5);
  5908. -webkit-transform: scale(1.5);
  5909. }
  5910. .updateDate{
  5911. cursor: pointer;
  5912. user-select: none;
  5913. -moz-transition:color 0.3s ease, transform 0.3s;
  5914. -webkit-transition:color 0.3s ease, transform 0.3s;
  5915. transition:color 0.3s ease, transform 0.3s;
  5916. transform-origin: left;
  5917. -webkit-transform-origin: left;
  5918. }
  5919. .updateDate:hover{
  5920. color:red;
  5921. transform: scale(1.1);
  5922. -webkit-transform: scale(1.1);
  5923. }
  5924. input[type=number]::-webkit-inner-spin-button,
  5925. input[type=number]::-webkit-outer-spin-button {
  5926. -webkit-appearance: none;
  5927. margin: 0;
  5928. }
  5929. input[type=number] {
  5930. -moz-appearance:textfield;
  5931. }
  5932. table td>h3 {
  5933. margin: 16px!important;
  5934. padding: 0!important;
  5935. }
  5936. table td>h4 {
  5937. padding: 0!important;
  5938. }
  5939. #saveBtn {
  5940. width: 60vw;
  5941. position: fixed;
  5942. z-index: 999;
  5943. bottom: 0;
  5944. left: 20vw;
  5945. font-size: xx-large;
  5946. opacity: 0.6;
  5947. cursor: pointer;
  5948. -moz-transition:all 0.3s ease;
  5949. -webkit-transition:all 0.3s ease;
  5950. transition:all 0.3s ease;
  5951. }
  5952. #configCon #saveBtn:hover {
  5953. opacity: 1;
  5954. margin-bottom: 0px;
  5955. }
  5956. #configCon #saveBtn {
  5957. margin-bottom: -30px;
  5958. }
  5959. #configCon.showSave #saveBtn {
  5960. margin-bottom: 0px;
  5961. }
  5962. `);
  5963. configCon = document.querySelector(".markdown-body,.theme-default-content");
  5964. if (!configCon) {
  5965. setTimeout(() => {
  5966. location.reload();
  5967. }, 1000);
  5968. return true;
  5969. }
  5970. let insertPos = configCon.querySelector("hr,#jsoneditor");
  5971. configCon = document.createElement("div");
  5972. configCon.id = "configCon";
  5973. insertPos.parentNode.insertBefore(configCon, insertPos);
  5974.  
  5975. importUrlPres = document.querySelectorAll("pre[name='user-content-pagetual'],pre[name='pagetual']");
  5976. if (importUrlPres) {
  5977. [].forEach.call(importUrlPres, importUrlPre => {
  5978. importUrlPre.style.overflow = "hidden";
  5979. importUrlPre.style.display = rulesData.uninited ? "block" : "none";
  5980. });
  5981. }
  5982. let otherconfig = document.querySelector("a[name='user-content-otherconfig'],a[name='otherconfig']");
  5983. if (otherconfig) otherconfig.parentNode.removeChild(otherconfig);
  5984. let rulesExample = document.querySelector("#user-content-rules-example+a,#rules-example>a");
  5985. if (rulesExample) {
  5986. rulesExample.innerText = i18n("rulesExample");
  5987. if (lang == "zh-CN") {
  5988. rulesExample.href = rulesExample.href.replace("en", "cn");
  5989. } else if (lang == "zh-TW" || lang == "zh-HK") {
  5990. rulesExample.href = rulesExample.href.replace("/en", "");
  5991. }
  5992. }
  5993. document.documentElement.scrollTop = 0;
  5994.  
  5995. let newPos, lastPos = 0;
  5996. window.addEventListener('scroll', function(e) {
  5997. newPos = window.scrollY;
  5998. if (newPos > lastPos) {
  5999. configCon.classList.add("showSave");
  6000. } else {
  6001. configCon.classList.remove("showSave");
  6002. }
  6003. lastPos = newPos;
  6004. });
  6005. } else return isGuidePage;
  6006. } else return isGuidePage;
  6007. let ruleBarInsertPos = document.createTextNode(' ');
  6008. configCon.appendChild(ruleBarInsertPos);
  6009. class Rulebar {
  6010. init(ruleUrl) {
  6011. let id = ruleUrl.id;
  6012. this.ruleUrl = ruleUrl;
  6013. this.item = document.createElement("p");
  6014. this.item.dataset.id = id;
  6015. let url = document.createElement("a");
  6016. url.href = ruleUrl.url;
  6017. url.innerHTML = ruleUrl.url;
  6018. url.title = ruleUrl.url;
  6019. let up = document.createElement("span");
  6020. up.innerHTML = "↑ ";
  6021. up.title = i18n("sortTitle");
  6022. let down = document.createElement("span");
  6023. down.innerHTML = "↓ ";
  6024. down.title = i18n("sortTitle");
  6025. let del = document.createElement("span");
  6026. del.innerHTML = "× ";
  6027. up.onclick = e => {
  6028. this.moveUp();
  6029. };
  6030. down.onclick = e => {
  6031. this.moveDown();
  6032. };
  6033. del.onclick = e => {
  6034. this.del();
  6035. };
  6036. this.item.appendChild(up);
  6037. this.item.appendChild(down);
  6038. this.item.appendChild(del);
  6039. this.item.appendChild(url);
  6040. if (ruleParser.rules) {
  6041. url.style.maxWidth = "calc(100% - 150px)";
  6042. url.style.overflow = "hidden";
  6043. url.style.display = "inline-block";
  6044. url.style.textOverflow = "ellipsis";
  6045. url.style.verticalAlign = "bottom";
  6046. url.style.whiteSpace = "nowrap";
  6047. let rulesLength = ruleParser.rules.reduce((acc, cur) => acc + (cur.from == id ? 1 : 0), 0);
  6048. let idSpan = document.createElement("span");
  6049. idSpan.style.float = "right";
  6050. idSpan.innerHTML = `[rules: ${rulesLength}]`;
  6051. this.item.appendChild(idSpan);
  6052. this.idSpan = idSpan;
  6053. }
  6054. configCon.insertBefore(this.item, ruleBarInsertPos);
  6055. }
  6056. updateNum() {
  6057. if (ruleParser.rules) {
  6058. let rulesLength = ruleParser.rules.reduce((acc, cur) => acc + (cur.from == this.item.dataset.id ? 1 : 0), 0);
  6059. this.idSpan.innerHTML = `[rules: ${rulesLength}]`;
  6060. }
  6061. }
  6062. saveSort() {
  6063. let sort = [];
  6064. [].forEach.call(this.item.parentNode.querySelectorAll("p[data-id]"), i => {
  6065. sort.push(i.dataset.id);
  6066. });
  6067. rulesData.sort = sort;
  6068. let urls = [];
  6069. sort.forEach(id => {
  6070. for (let s = 0; s < ruleUrls.length; s++) {
  6071. if (id == ruleUrls[s].id) {
  6072. urls.push(ruleUrls[s]);
  6073. break;
  6074. }
  6075. }
  6076. });
  6077. ruleUrls = urls;
  6078. storage.setItem("rulesData", rulesData);
  6079. showTips(i18n("sortTitle"));
  6080. }
  6081. moveUp() {
  6082. let preE = this.item.previousElementSibling;
  6083. if (compareNodeName(preE, ["p"]) && preE.children.length > 1) {
  6084. this.item.parentNode.insertBefore(this.item, preE);
  6085. this.saveSort();
  6086. }
  6087. }
  6088. moveDown() {
  6089. let nextE = this.item.nextElementSibling;
  6090. if (compareNodeName(nextE, ["p"]) && nextE.children.length > 1) {
  6091. this.item.parentNode.insertBefore(nextE, this.item);
  6092. this.saveSort();
  6093. }
  6094. }
  6095. del() {
  6096. if (this.ruleUrl.id < 2) {
  6097. showTips(i18n("cantDel"));
  6098. } else if (window.confirm(i18n("confirmDel"))) {
  6099. for (let u = 0; u < rulesData.urls.length; u++) {
  6100. if (this.ruleUrl.id == rulesData.urls[u].id) {
  6101. rulesData.urls.splice(u, 1);
  6102. break;
  6103. }
  6104. }
  6105. for (let u = 0; u < ruleUrls.length; u++) {
  6106. if (this.ruleUrl.id == ruleUrls[u].id) {
  6107. ruleUrls.splice(u, 1);
  6108. break;
  6109. }
  6110. }
  6111. for (let u = 0; u < rulesData.sort.length; u++) {
  6112. if (this.ruleUrl.id == rulesData.sort[u]) {
  6113. rulesData.sort.splice(u, 1);
  6114. break;
  6115. }
  6116. }
  6117. rulesData.ruleVersion = 0;
  6118. storage.setItem("rulesData", rulesData);
  6119. ruleParser.rules = ruleParser.rules.filter(item => {return item.from != this.ruleUrl.id});
  6120. storage.setItem("rules", ruleParser.rules);
  6121. this.item.parentNode.removeChild(this.item);
  6122. //location.reload();
  6123. }
  6124. }
  6125. }
  6126. let langSelect = document.createElement("select");
  6127. langSelect.style.float = "right";
  6128. langSelect.style.position = "relative";
  6129. langSelect.style.zIndex = "1";
  6130. let option = document.createElement("option");
  6131. option.value = "";
  6132. option.innerText = "Language";
  6133. langSelect.appendChild(option);
  6134. for (let key in langList) {
  6135. let option = document.createElement("option");
  6136. option.value = key;
  6137. option.innerText = langList[key];
  6138. langSelect.appendChild(option);
  6139. }
  6140. langSelect.value = rulesData.lang || "";
  6141. configCon.appendChild(langSelect);
  6142.  
  6143. let updateP = document.createElement("p"), i = 0;
  6144. let now = new Date().getTime();
  6145.  
  6146.  
  6147. let pastDate = (new Date(updateDate)).toString(), passStr;
  6148. let passTime = (now - updateDate) / 1000;
  6149. if (isNaN(passTime)) {
  6150. passStr = i18n("firstUpdate");
  6151. } else {
  6152. if (passTime < 60) {
  6153. passStr = i18n("passSec", parseInt(passTime));
  6154. } else if (passTime < 60 * 60) {
  6155. passStr = i18n("passMin", parseInt(passTime / 60));
  6156. } else if (passTime < 60 * 60 * 24) {
  6157. passStr = i18n("passHour", parseInt(passTime / 3600));
  6158. } else {
  6159. passStr = i18n("passDay", parseInt(passTime / 86400));
  6160. }
  6161. passStr += " 🖱 " + i18n("click2update");
  6162. }
  6163.  
  6164. let rulebarList = [], updateFail = false;
  6165. updateP.className = "updateDate";
  6166. updateP.innerHTML = passStr;
  6167. updateP.title = i18n("update") + " - " + pastDate;
  6168. configCon.appendChild(updateP);
  6169. if (ruleUrls) {
  6170. ruleUrls.forEach(ruleUrl => {
  6171. let rulebar = new Rulebar();
  6172. rulebar.init(ruleUrl);
  6173. rulebarList.push(rulebar);
  6174. });
  6175. }
  6176. let customUrlsTitle = document.createElement("h2");
  6177. customUrlsTitle.innerHTML = i18n("customUrls");
  6178. configCon.appendChild(customUrlsTitle);
  6179. let customUrlsInput = document.createElement("textarea");
  6180. customUrlsInput.style.width = "100%";
  6181. customUrlsInput.style.position = "relative";
  6182. customUrlsInput.placeholder = "http://wedata.net/databases/AutoPagerize/items_all.json \nhttps://hoothin.github.io/UserScripts/Pagetual/pagetualRules.json";
  6183. customUrlsInput.spellcheck = false;
  6184. configCon.appendChild(customUrlsInput);
  6185.  
  6186. let btns = document.createElement("div");
  6187. btns.style.display = "flex";
  6188. configCon.appendChild(btns);
  6189. let upBtnImg = document.createElement("div");
  6190. upBtnImg.style.width = "33%";
  6191. let upBtnImgTitle = document.createElement("h2");
  6192. upBtnImgTitle.style.whiteSpace = "nowrap";
  6193. upBtnImgTitle.style.overflow = "auto";
  6194. upBtnImgTitle.innerHTML = i18n("upBtnImg");
  6195. upBtnImg.appendChild(upBtnImgTitle);
  6196. let upBtnImgInput = document.createElement("input");
  6197. upBtnImgInput.style.width = "100%";
  6198. upBtnImgInput.style.position = "relative";
  6199. upBtnImgInput.placeholder = "data:image/png;base64,UpBtn";
  6200. upBtnImgInput.value = rulesData.upBtnImg || '';
  6201. upBtnImgInput.spellcheck = false;
  6202. upBtnImg.appendChild(upBtnImgInput);
  6203. btns.appendChild(upBtnImg);
  6204.  
  6205. let downBtnImg = document.createElement("div");
  6206. downBtnImg.style.width = "33%";
  6207. let downBtnImgTitle = document.createElement("h2");
  6208. downBtnImgTitle.style.whiteSpace = "nowrap";
  6209. downBtnImgTitle.style.overflow = "auto";
  6210. downBtnImgTitle.innerHTML = i18n("downBtnImg");
  6211. downBtnImg.appendChild(downBtnImgTitle);
  6212. let downBtnImgInput = document.createElement("input");
  6213. downBtnImgInput.style.width = "100%";
  6214. downBtnImgInput.style.position = "relative";
  6215. downBtnImgInput.placeholder = "data:image/png;base64,DownBtn";
  6216. downBtnImgInput.value = rulesData.downBtnImg || '';
  6217. downBtnImgInput.spellcheck = false;
  6218. downBtnImg.appendChild(downBtnImgInput);
  6219. btns.appendChild(downBtnImg);
  6220.  
  6221. let sideControllerIconDiv = document.createElement("div");
  6222. sideControllerIconDiv.style.width = "33%";
  6223. let sideControllerIconTitle = document.createElement("h2");
  6224. sideControllerIconTitle.style.whiteSpace = "nowrap";
  6225. sideControllerIconTitle.style.overflow = "auto";
  6226. sideControllerIconTitle.innerHTML = i18n("sideControllerIcon");
  6227. sideControllerIconDiv.appendChild(sideControllerIconTitle);
  6228. let sideControllerIconInput = document.createElement("input");
  6229. sideControllerIconInput.style.width = "100%";
  6230. sideControllerIconInput.style.position = "relative";
  6231. sideControllerIconInput.placeholder = "📄";
  6232. sideControllerIconInput.value = rulesData.sideControllerIcon || '';
  6233. sideControllerIconInput.spellcheck = false;
  6234. sideControllerIconDiv.appendChild(sideControllerIconInput);
  6235. btns.appendChild(sideControllerIconDiv);
  6236.  
  6237. let otherBtns = document.createElement("div");
  6238. otherBtns.style.display = "flex";
  6239. configCon.appendChild(otherBtns);
  6240. let loadingText = document.createElement("div");
  6241. loadingText.style.width = "100%";
  6242. let loadingTextTitle = document.createElement("h2");
  6243. loadingTextTitle.style.whiteSpace = "nowrap";
  6244. loadingTextTitle.style.overflow = "auto";
  6245. loadingTextTitle.innerHTML = i18n("loadingTextTitle");
  6246. loadingText.appendChild(loadingTextTitle);
  6247. let loadingTextInput = document.createElement("input");
  6248. loadingTextInput.value = rulesData.loadingText || '';
  6249. loadingTextInput.placeholder = i18n("loadingText");
  6250. loadingTextInput.style.width = "100%";
  6251. loadingTextInput.style.position = "relative";
  6252. loadingTextInput.style.margin = "0";
  6253. loadingTextInput.spellcheck = false;
  6254. loadingText.appendChild(loadingTextInput);
  6255. otherBtns.appendChild(loadingText);
  6256.  
  6257. let opacity = document.createElement("div");
  6258. let opacityTitle = document.createElement("h2");
  6259. opacityTitle.style.whiteSpace = "nowrap";
  6260. opacityTitle.style.overflow = "visible";
  6261. opacityTitle.innerHTML = i18n("opacity");
  6262. opacity.appendChild(opacityTitle);
  6263. let opacityInput = document.createElement("input");
  6264. opacityInput.value = rulesData.opacity * 100;
  6265. opacityInput.type = "number";
  6266. opacityInput.min = 0;
  6267. opacityInput.max = 100;
  6268. opacityInput.style.width = "110px";
  6269. opacityInput.style.position = "relative";
  6270. opacityInput.style.margin = "0";
  6271. opacityInput.placeholder = i18n("opacityPlaceholder");
  6272. opacityInput.spellcheck = false;
  6273. opacityInput.oninput = e => {
  6274. if (opacityInput.value > 100) opacityInput.value = 100;
  6275. else if (opacityInput.value < 0) opacityInput.value = 0;
  6276. };
  6277. opacity.appendChild(opacityInput);
  6278. otherBtns.appendChild(opacity);
  6279.  
  6280. let pageElementCss = document.createElement("div");
  6281. pageElementCss.style.marginBottom = "30px";
  6282. let pageElementCssTitle = document.createElement("h2");
  6283. pageElementCssTitle.innerHTML = i18n("pageElementCss");
  6284. pageElementCss.appendChild(pageElementCssTitle);
  6285. let pageElementCssInput = document.createElement("input");
  6286. pageElementCssInput.value = rulesData.pageElementCss || '';
  6287. pageElementCssInput.style.width = "100%";
  6288. pageElementCssInput.style.position = "relative";
  6289. pageElementCssInput.style.margin = "0";
  6290. pageElementCssInput.placeholder = "font-size: xx-large;";
  6291. pageElementCssInput.spellcheck = false;
  6292. pageElementCss.appendChild(pageElementCssInput);
  6293. configCon.appendChild(pageElementCss);
  6294.  
  6295. let customCss = document.createElement("div");
  6296. customCss.style.marginBottom = "50px";
  6297. let customCssTitle = document.createElement("h2");
  6298. customCssTitle.innerHTML = i18n("customCss");
  6299. customCss.appendChild(customCssTitle);
  6300. let customCssInput = document.createElement("textarea");
  6301. customCssInput.value = rulesData.customCss || '';
  6302. customCssInput.style.width = "100%";
  6303. customCssInput.style.position = "relative";
  6304. customCssInput.style.margin = "0";
  6305. customCssInput.placeholder = ".pagetual {\n}";
  6306. customCssInput.spellcheck = false;
  6307. customCss.appendChild(customCssInput);
  6308. configCon.appendChild(customCss);
  6309.  
  6310. let configTable = document.createElement("table");
  6311. configTable.style.width = "100%";
  6312. let configTbody = document.createElement("tbody");
  6313. configTbody.style.width = "99%";
  6314. configTbody.style.display = "inline-table";
  6315. configTable.appendChild(configTbody);
  6316. configCon.appendChild(configTable);
  6317. function createCheckbox(innerText, val, tag, parentCheck, otherType, alwaysShow) {
  6318. if (typeof val == 'undefined') val = "";
  6319. let title = document.createElement(tag || "h3");
  6320. title.innerHTML = innerText;
  6321. title.style.overflowWrap = "normal";
  6322. let input = document.createElement("input");
  6323. if (otherType === 'key') {
  6324. input.type = 'text';
  6325. input.setAttribute('readOnly', 'readonly');
  6326. input.addEventListener("keydown", e => {
  6327. if (e.key === 'Escape' || e.key === 'Backspace') input.value = '';
  6328. else input.value = e.key;
  6329. e.stopPropagation();
  6330. e.preventDefault();
  6331. });
  6332. } else {
  6333. input.type = otherType || "checkbox";
  6334. }
  6335. input.style.width = "35px";
  6336. input.style.height = "20px";
  6337. input.style.float = "left";
  6338. input.style.margin = "0 2px";
  6339. input.value = val;
  6340. input.checked = val;
  6341. let td = document.createElement("td");
  6342. td.appendChild(input);
  6343. if (parentCheck) {
  6344. title.appendChild(input);
  6345. title.style.margin = "0";
  6346. td.appendChild(title);
  6347. let parent = parentCheck.parentNode.nextElementSibling;
  6348. let tr = parent.querySelector("tr");
  6349. if (!tr) {
  6350. tr = document.createElement("tr");
  6351. parent.appendChild(tr);
  6352. }
  6353. tr.appendChild(td);
  6354. if (!alwaysShow) {
  6355. if (!parentCheck.checked) {
  6356. td.style.display = "none";
  6357. }
  6358. parentCheck.addEventListener("click", e => {
  6359. td.style.display = parentCheck.checked ? "" : "none";
  6360. });
  6361. }
  6362. } else {
  6363. let tr = document.createElement("tr");
  6364. tr.appendChild(td);
  6365. td = document.createElement("td");
  6366. td.appendChild(title);
  6367. tr.appendChild(td);
  6368. configTable.children[0].appendChild(tr);
  6369. }
  6370. let xNodePos = innerText.indexOf('【X】');
  6371. if (xNodePos !== -1) {
  6372. input.style.float = "";
  6373. let xNode = title.firstChild.splitText(xNodePos);
  6374. xNode.splitText(3);
  6375. xNode.parentNode.replaceChild(input, xNode);
  6376. }
  6377. return input;
  6378. }
  6379.  
  6380. let setConfigPageInput = createCheckbox(i18n("setConfigPage"), false);
  6381. let enableWhiteListInput = createCheckbox(i18n("autoRun"), rulesData.enableWhiteList != true);
  6382. let sideControllerInput = createCheckbox(i18n("sideController"), rulesData.sideController);
  6383. let sideControllerAlwaysInput = createCheckbox(i18n("sideControllerAlways"), rulesData.sideControllerAlways, "h4", sideControllerInput);
  6384. let sideControllerScrollInput = createCheckbox(i18n("sideControllerScroll"), rulesData.sideControllerScroll !== false, "h4", sideControllerInput);
  6385. let sideControllerLoadNowInput = createCheckbox(i18n("loadNow"), rulesData.sideControllerLoadNow !== false, "h4", sideControllerInput);
  6386. let enableDebugInput = createCheckbox(i18n("enableDebug"), rulesData.enableDebug != false);
  6387. let enableHistoryInput = createCheckbox(i18n("enableHistory"), rulesData.enableHistory === true);
  6388. let enableHistoryAfterInsertInput = createCheckbox(i18n("enableHistoryAfterInsert"), rulesData.enableHistoryAfterInsert === true, "h4", enableHistoryInput);
  6389. let openInNewTabInput = createCheckbox(i18n("openInNewTab"), rulesData.openInNewTab != false);
  6390. let hidePageBarInput = createCheckbox(i18n("hideBarTips"), rulesData.opacity == 0);
  6391. let hidePageBarArrowInput = createCheckbox(i18n("hideBarArrow"), rulesData.hideBarArrow);
  6392. let hideLoadingIconInput = createCheckbox(i18n("hideLoadingIcon"), rulesData.hideLoadingIcon != false);
  6393. let initRunInput = createCheckbox(i18n("initRun"), rulesData.initRun != false);
  6394. let autoLoadNumInput = createCheckbox(i18n("autoLoadNum"), rulesData.autoLoadNum, "h4", initRunInput, "number");
  6395. let preloadInput = createCheckbox(i18n("preload"), rulesData.preload);
  6396. let rateInput = createCheckbox(i18n("turnRate"), rulesData.rate, "h4", preloadInput, "number", true);
  6397. let dbClick2StopInput = createCheckbox(i18n("dbClick2Stop"), rulesData.dbClick2Stop);
  6398. let manualModeInput = createCheckbox(i18n("manualMode"), rulesData.manualMode);
  6399. let clickModeInput = createCheckbox(i18n("clickMode"), rulesData.clickMode);
  6400. let pageBarMenuInput = createCheckbox(i18n("pageBarMenu"), rulesData.pageBarMenu != false);
  6401. let arrowToScrollInput = createCheckbox(i18n("arrowToScroll"), rulesData.arrowToScroll);
  6402. let contentVisibilityInput = createCheckbox(i18n("contentVisibility"), rulesData.contentVisibility);
  6403. let wedata2githubInput = createCheckbox(i18n("wedata2github"), rulesData.wedata2github);
  6404. let customFirstInput = createCheckbox(i18n("customFirst"), rulesData.customFirst);
  6405. let lastPageTipsInput = createCheckbox(i18n("lastPageTips"), rulesData.lastPageTips);
  6406. let updateNotificationInput = createCheckbox(i18n("updateNotification"), rulesData.updateNotification != false);
  6407.  
  6408. let hideBarInput = createCheckbox(i18n("hideBar"), rulesData.hideBar && !rulesData.hideBarButNoStop, "h4", dbClick2StopInput, 'radio');
  6409. hideBarInput.name = 'hideBar';
  6410. let hideBarButNoStopInput = createCheckbox(i18n("hideBarButNoStop"), rulesData.hideBarButNoStop, "h4", dbClick2StopInput, 'radio');
  6411. hideBarButNoStopInput.name = 'hideBar';
  6412. hideBarInput.addEventListener('mouseup', e => {
  6413. if (hideBarInput.checked) {
  6414. setTimeout(() => {hideBarInput.checked = false}, 0);
  6415. }
  6416. });
  6417. hideBarButNoStopInput.addEventListener('mouseup', e => {
  6418. if (hideBarButNoStopInput.checked) {
  6419. setTimeout(() => {hideBarButNoStopInput.checked = false}, 0);
  6420. }
  6421. });
  6422. hidePageBarInput.addEventListener('click', e => {
  6423. opacityInput.value = hidePageBarInput.checked ? 0 : 100;
  6424. });
  6425.  
  6426. let dbClick2StopCtrlInput = createCheckbox(i18n("dbClick2StopCtrl"), rulesData.dbClick2StopCtrl, "h4", dbClick2StopInput);
  6427. let dbClick2StopAltInput = createCheckbox(i18n("dbClick2StopAlt"), rulesData.dbClick2StopAlt, "h4", dbClick2StopInput);
  6428. let dbClick2StopShiftInput = createCheckbox(i18n("dbClick2StopShift"), rulesData.dbClick2StopShift, "h4", dbClick2StopInput);
  6429. let dbClick2StopMetaInput = createCheckbox(i18n("dbClick2StopMeta"), rulesData.dbClick2StopMeta, "h4", dbClick2StopInput);
  6430. let dbClick2StopKeyInput = createCheckbox(i18n("dbClick2StopKey"), rulesData.dbClick2StopKey, "h4", dbClick2StopInput, "key");
  6431.  
  6432. let otherConfigPage = (rulesData.configPage || configPage[0]) != location.href.replace(/#.*/, "");
  6433. if (!otherConfigPage) {
  6434. setConfigPageInput.parentNode.parentNode.style.display = "none";
  6435. }
  6436.  
  6437. updateP.onclick = e => {
  6438. updateFail = false;
  6439. //ruleParser.rules = [];
  6440. showTips(i18n("beginUpdate"), "", 30000);
  6441. updateRules(() => {
  6442. if (!updateFail) {
  6443. showTips(i18n("updateSucc"));
  6444. if (importUrlPres) {
  6445. [].forEach.call(importUrlPres, importUrlPre => {
  6446. importUrlPre.style.display = "none";
  6447. });
  6448. }
  6449. if (click2import) click2import.style.display = "none";
  6450. }
  6451. updateP.innerHTML = i18n("passSec", 0);
  6452. updateP.title = i18n("update");
  6453. rulebarList.forEach(rulebar => {
  6454. rulebar.updateNum();
  6455. });
  6456. }, (rule, err) => {
  6457. if (rule.id == 1) {
  6458. showTips(`Failed to update wedata rules! Try to switch to wedata mirror!`);
  6459. wedata2githubInput.scrollIntoView({ behavior: "smooth" });
  6460. } else {
  6461. showTips(`Failed to update ${rule.url} rules!`);
  6462. }
  6463. debug(err);
  6464. updateFail = true;
  6465. });
  6466. };
  6467. let customRulesTitle = document.createElement("h2");
  6468. 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');
  6469. configCon.appendChild(customRulesTitle);
  6470. customRulesInput = document.createElement("textarea");
  6471. customRulesInput.spellcheck = false;
  6472. configCon.appendChild(customRulesInput);
  6473. if (rulesData.editTemp) {
  6474. if (!ruleParser.customRules) {
  6475. ruleParser.customRules = [];
  6476. }
  6477. for (let i in ruleParser.customRules) {
  6478. if (ruleParser.customRules[i].url == rulesData.editTemp.url) {
  6479. ruleParser.customRules.splice(i, 1);
  6480. break;
  6481. }
  6482. }
  6483. ruleParser.customRules.unshift(rulesData.editTemp);
  6484. rulesData.editTemp = null;
  6485. storage.setItem("rulesData", rulesData);
  6486. customRulesInput.previousElementSibling.scrollIntoView();
  6487. }
  6488. customRulesInput.style.width = "100%";
  6489. customRulesInput.style.height = "800px";
  6490. 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]`;
  6491. let preCustom = getFormatJSON(ruleParser.customRules);
  6492. customRulesInput.value = preCustom;
  6493. if (isGuidePage) customRulesInput.style.display = "none";
  6494. let blacklistInput = document.createElement("textarea");
  6495. blacklistInput.style.width = "100%";
  6496. blacklistInput.style.height = "500px";
  6497. blacklistInput.style.display = "none";
  6498. blacklistInput.spellcheck = false;
  6499. 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";
  6500. blacklistInput.value = rulesData.blacklist ? rulesData.blacklist.join("\n") : "";
  6501. let blacklistBtn = document.createElement("button");
  6502. blacklistBtn.innerText = i18n("editBlacklist");
  6503. blacklistBtn.style.width = "100%";
  6504. blacklistBtn.onclick = e => {
  6505. blacklistInput.style.display = blacklistInput.style.display == "none" ? "" : "none";
  6506. };
  6507. configCon.appendChild(blacklistBtn);
  6508. configCon.appendChild(blacklistInput);
  6509. let saveBtn = document.createElement("button");
  6510. saveBtn.innerHTML = i18n("save");
  6511. saveBtn.id = "saveBtn";
  6512. configCon.appendChild(saveBtn);
  6513. saveBtn.onclick = e => {
  6514. try {
  6515. let customRules;
  6516. if (editor) {
  6517. if (editorChanged) {
  6518. editorChanged = false;
  6519. storage.setItem("hpRules", []);
  6520. storage.setItem("smartRules", []);
  6521. }
  6522. customRules = editor.get();
  6523. if (!customRules) {
  6524. customRules = "";
  6525. } else {
  6526. if (Array && Array.isArray && !Array.isArray(customRules)) {
  6527. showTips(i18n("errorRulesMustBeArray"));
  6528. return;
  6529. }
  6530. }
  6531. } else {
  6532. if (customRulesInput.value != preCustom) {
  6533. storage.setItem("hpRules", []);
  6534. storage.setItem("smartRules", []);
  6535. }
  6536. if (customRulesInput.value == "") {
  6537. customRules = "";
  6538. } else {
  6539. customRules = JSON.parse(customRulesInput.value);
  6540. if (Array && Array.isArray && !Array.isArray(customRules)) {
  6541. showTips(i18n("errorRulesMustBeArray"));
  6542. return;
  6543. }
  6544. customRulesInput.value = JSON.stringify(customRules, null, 4);
  6545. }
  6546. }
  6547. debug(customRules);
  6548. storage.setItem("customRules", customRules);
  6549. } catch(e) {
  6550. debug(e);
  6551. let pos = e && e.message && e.message.match(/position (\d+)/);
  6552. if (pos && !editor) {
  6553. pos = parseInt(pos[1]);
  6554. customRulesInput.value = customRulesInput.value.slice(0, pos) + "➡️" + customRulesInput.value.slice(pos);
  6555. }
  6556. showTips(i18n("errorJson"));
  6557. return;
  6558. }
  6559. rulesData.lang = langSelect.value || "";
  6560. if (setConfigPageInput.checked) rulesData.configPage = location.href;
  6561. rulesData.wedata2github = wedata2githubInput.checked;
  6562. let opacity = parseInt(opacityInput.value) || 0;
  6563. if (opacity > 100) opacity = 100;
  6564. else if (opacity < 0) opacity = 0;
  6565. rulesData.opacity = opacity / 100;
  6566. rulesData.blacklist = blacklistInput.value ? blacklistInput.value.trim().split("\n") : "";
  6567. rulesData.hideBar = hideBarInput.checked;
  6568. rulesData.hideBarButNoStop = hideBarButNoStopInput.checked;
  6569. rulesData.dbClick2Stop = dbClick2StopInput.checked;
  6570. rulesData.enableWhiteList = !enableWhiteListInput.checked;
  6571. rulesData.enableDebug = enableDebugInput.checked;
  6572. rulesData.updateNotification = updateNotificationInput.checked;
  6573. rulesData.enableHistory = enableHistoryInput.checked;
  6574. rulesData.enableHistoryAfterInsert = enableHistoryAfterInsertInput.checked;
  6575. rulesData.openInNewTab = openInNewTabInput.checked;
  6576. rulesData.hideLoadingIcon = hideLoadingIconInput.checked;
  6577. rulesData.hideBarArrow = hidePageBarArrowInput.checked;
  6578. rulesData.customFirst = customFirstInput.checked;
  6579. rulesData.lastPageTips = lastPageTipsInput.checked;
  6580. rulesData.initRun = initRunInput.checked;
  6581. rulesData.autoLoadNum = autoLoadNumInput.value !== "0" ? autoLoadNumInput.value : '';
  6582. rulesData.rate = parseFloat(rateInput.value) || 0;
  6583. rulesData.preload = preloadInput.checked;
  6584. rulesData.manualMode = manualModeInput.checked;
  6585. rulesData.clickMode = clickModeInput.checked;
  6586. rulesData.pageBarMenu = pageBarMenuInput.checked;
  6587. rulesData.arrowToScroll = arrowToScrollInput.checked;
  6588. rulesData.contentVisibility = contentVisibilityInput.checked;
  6589. if (rulesData.sideController != sideControllerInput.checked) {
  6590. rulesData.sideControllerPos = false;
  6591. }
  6592. rulesData.sideController = sideControllerInput.checked;
  6593. rulesData.sideControllerScroll = sideControllerScrollInput.checked;
  6594. rulesData.sideControllerLoadNow = sideControllerLoadNowInput.checked;
  6595. rulesData.sideControllerAlways = sideControllerAlwaysInput.checked;
  6596. rulesData.pageElementCss = pageElementCssInput.value;
  6597. rulesData.customCss = customCssInput.value;
  6598. rulesData.upBtnImg = upBtnImgInput.value;
  6599. rulesData.downBtnImg = downBtnImgInput.value;
  6600. rulesData.sideControllerIcon = sideControllerIconInput.value;
  6601. rulesData.loadingText = loadingTextInput.value;
  6602. rulesData.dbClick2StopCtrl = dbClick2StopCtrlInput.checked;
  6603. rulesData.dbClick2StopAlt = dbClick2StopAltInput.checked;
  6604. rulesData.dbClick2StopShift = dbClick2StopShiftInput.checked;
  6605. rulesData.dbClick2StopMeta = dbClick2StopMetaInput.checked;
  6606. rulesData.dbClick2StopKey = dbClick2StopKeyInput.value;
  6607. storage.setItem("rulesData", rulesData);
  6608. let customUrls = customUrlsInput.value.trim(), urlImported = false;
  6609. if (customUrls) {
  6610. customUrls = customUrls.split(/\n/);
  6611. for (let c = 0; c < customUrls.length; c++) {
  6612. let url;
  6613. if (/^0\s*\|/.test(customUrls[c])) {
  6614. url = customUrls[c].replace(/^0\s*\|\s*/, "").trim();
  6615. if (!/^http/.test(url)) {
  6616. showTips(i18n("errorWrongUrl"));
  6617. return;
  6618. }
  6619. } else {
  6620. url = customUrls[c].trim();
  6621. if (!/^http/.test(url)) {
  6622. showTips(i18n("errorWrongUrl"));
  6623. return;
  6624. }
  6625. }
  6626. let maxId = 1, hasUrl = false;
  6627. if (!rulesData.urls) {
  6628. rulesData.urls = [];
  6629. }
  6630. ruleUrls.forEach(u => {
  6631. if (maxId < u.id) {
  6632. maxId = u.id;
  6633. }
  6634. if (u.url == url) {
  6635. hasUrl = true;
  6636. }
  6637. });
  6638. if (hasUrl) break;
  6639. if (!rulesData.sort) rulesData.sort = [1];
  6640. let newRule = {id: maxId + 1, url: url};
  6641. ruleUrls.push(newRule);
  6642. rulesData.urls.push(newRule);
  6643. rulesData.sort.push(maxId + 1);
  6644. storage.setItem("rulesData", rulesData);
  6645. let rulebar = new Rulebar();
  6646. rulebar.init(newRule);
  6647. rulebarList.push(rulebar);
  6648. }
  6649. }
  6650. showTips(i18n("settingsSaved"));
  6651. };
  6652. return true;
  6653. }
  6654.  
  6655. function updateRules (success, fail, keepCache) {
  6656. if (!storage.supportCrossSave()) {
  6657. fail({url:''}, "Not support cross storage");
  6658. showTips("Current platform do not support cross storage!");
  6659. return;
  6660. }
  6661. if (inUpdate) return;
  6662. inUpdate = true;
  6663. let ruleIndex = ruleUrls.length - 1;
  6664. if (!keepCache) {
  6665. storage.setItem("hpRules", []);
  6666. storage.setItem("smartRules", []);
  6667. }
  6668. let allOk = true;
  6669. let preLength = ruleParser.rules.length;
  6670. let fetchVersion = -1;
  6671. async function needUpdate(url, id) {
  6672. if (!/^https:\/\/hoothin\.github\.io\/|\/hoothin\/UserScripts\/.*\/Pagetual\/pagetualRules\.json/i.test(url)) {
  6673. return true;
  6674. }
  6675. let rulesLength = ruleParser.rules.reduce((acc, cur) => acc + (cur.from == id ? 1 : 0), 0);
  6676. if (rulesLength === 0) return true;
  6677. if (fetchVersion >= 0) {
  6678. return fetchVersion > (rulesData.ruleVersion || 0);
  6679. }
  6680. fetchVersion = await new Promise(resolve => {
  6681. _GM_xmlhttpRequest({
  6682. url: url.replace(/\/\w+\.json/i, "/version"),
  6683. method: 'GET',
  6684. timeout: 20000,
  6685. headers: {
  6686. 'accept': 'application/json,text/html'
  6687. },
  6688. onload: function(res) {
  6689. let version = parseInt(res.response || res.responseText);
  6690. resolve(version || -1);
  6691. },
  6692. onerror: function(e) {
  6693. resolve(-1);
  6694. },
  6695. ontimeout: function(e) {
  6696. resolve(-1);
  6697. }
  6698. });
  6699. });
  6700. return fetchVersion > (rulesData.ruleVersion || 0);
  6701. }
  6702. async function addNextRule() {
  6703. if (ruleIndex < 0) {
  6704. let now = new Date().getTime();
  6705. storage.setItem("ruleLastUpdate", now);
  6706. storage.setItem("rules", ruleParser.rules);
  6707. let curLength = ruleParser.rules.length;
  6708. if (curLength !== preLength && rulesData.updateNotification) {
  6709. _GM_notification({
  6710. text: `Rules has updated( ${preLength} => ${curLength} )`,
  6711. title: "Pagetual rules updated",
  6712. onclick: (event) => {
  6713. event.preventDefault();
  6714. _GM_openInTab(rulesData.configPage || configPage[0], {active: true});
  6715. }
  6716. });
  6717. }
  6718. inUpdate = false;
  6719. let rulesDataChanged = false;
  6720. if (fetchVersion >= 0 && rulesData.ruleVersion !== fetchVersion) {
  6721. rulesData.ruleVersion = fetchVersion;
  6722. rulesDataChanged = true;
  6723. }
  6724. if (rulesData.uninited && allOk && ruleUrls.length > 1) {
  6725. rulesData.uninited = false;
  6726. rulesDataChanged = true;
  6727. }
  6728. if (rulesDataChanged) {
  6729. storage.setItem("rulesData", rulesData);
  6730. }
  6731. success();
  6732. } else {
  6733. let rule = ruleUrls[ruleIndex--];
  6734. if (await needUpdate(rule.url, rule.id)) {
  6735. ruleParser.addRuleByUrl(rule.url, rule.id, (json, err) => {
  6736. if (!json) {
  6737. allOk = false;
  6738. fail(rule, err);
  6739. }
  6740. addNextRule();
  6741. });
  6742. } else {
  6743. addNextRule();
  6744. }
  6745. }
  6746. }
  6747. addNextRule();
  6748. }
  6749.  
  6750. function objIsArr(obj) {
  6751. return obj &&
  6752. typeof obj === 'object' &&
  6753. typeof obj.length === 'number' &&
  6754. !(obj.propertyIsEnumerable('length'));
  6755. }
  6756.  
  6757. function isVisible(el, win) {
  6758. if(!el || !el.offsetParent)return false;
  6759. var loopable = true,
  6760. visible = el.nodeName && win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  6761. while(loopable && visible) {
  6762. el = el.parentNode;
  6763.  
  6764. if(el && el.nodeType === 1 && !compareNodeName(el, ["body"])) {
  6765. visible = win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  6766. }else {
  6767. loopable = false;
  6768. }
  6769. }
  6770. return visible;
  6771. }
  6772.  
  6773. function getElementTop(ele) {
  6774. if (!ele) return 0;
  6775. if (ele.getBoundingClientRect) {
  6776. return ele.getBoundingClientRect().top + document.documentElement.scrollTop;
  6777. }
  6778. var actualTop = ele.offsetTop;
  6779. var current = ele.offsetParent;
  6780. while (current) {
  6781. actualTop += current.offsetTop;
  6782. current = current.offsetParent;
  6783. }
  6784. return actualTop;
  6785. }
  6786.  
  6787. function getElementLeft(ele) {
  6788. if (!ele) return 0;
  6789. if (ele.getBoundingClientRect) {
  6790. return ele.getBoundingClientRect().left + document.documentElement.scrollLeft;
  6791. }
  6792. var actualLeft = ele.offsetLeft;
  6793. var current = ele.offsetParent;
  6794. while (current) {
  6795. actualLeft += current.offsetLeft;
  6796. current = current.offsetParent;
  6797. }
  6798. return actualLeft;
  6799. }
  6800.  
  6801. function getElementBottom(ele) {
  6802. return getElementTop(ele) + (ele.offsetHeight || ele.scrollHeight);
  6803. }
  6804.  
  6805. function getFormatJSON(obj){
  6806. if(!objIsArr(obj) || obj.length === 0)return "";
  6807. return JSON.stringify(obj, null, 4);
  6808. }
  6809.  
  6810. function globMatch(first, second) {
  6811. if (first === '*') {
  6812. return true;
  6813. }
  6814. if (first.length == 0 && second.length == 0){
  6815. return true;
  6816. }
  6817.  
  6818. if (first.length > 1 && first[0] == '*' &&
  6819. second.length == 0){
  6820. return false;
  6821. }
  6822.  
  6823. if ((first.length > 1 && first[0] == '?') ||
  6824. (first.length != 0 && second.length != 0 &&
  6825. first[0] == second[0])){
  6826. return globMatch(first.substring(1),
  6827. second.substring(1));
  6828. }
  6829.  
  6830. if (first.length > 0 && first[0] == '*'){
  6831. return globMatch(first.substring(1), second) ||
  6832. globMatch(first, second.substring(1));
  6833. }
  6834.  
  6835. return false;
  6836. }
  6837.  
  6838. let pageReady = false;
  6839. function initRules(callback) {
  6840. charset = (document.characterSet || document.charset || document.inputEncoding);
  6841. let equiv = document.querySelector('[http-equiv="Content-Type"]');
  6842. if (equiv && equiv.content) {
  6843. let innerCharSet = equiv.content.match(/charset\=([^;]+)/);
  6844. if (!innerCharSet) {
  6845. charsetValid = false;
  6846. } else if (innerCharSet[1].replace("-", "").toLowerCase() != charset.replace("-", "").toLowerCase()) {
  6847. charsetValid = false;
  6848. }
  6849. } else charsetValid = false;
  6850. storage.getItem("rulesData", data => {
  6851. /*0 wedata格式,1 pagetual格式*/
  6852. ruleUrls = [{
  6853. id: 1,
  6854. url: data && data.wedata2github ? 'https://hoothin.github.io/UserScripts/Pagetual/items_all.json' : 'http://wedata.net/databases/AutoPagerize/items_all.json',
  6855. type: 0,
  6856. }];
  6857. if (data) {
  6858. rulesData = data;
  6859. if (data.urls) ruleUrls = ruleUrls.concat(data.urls);
  6860. if (data.sort) {
  6861. let urls = [];
  6862. data.sort.forEach(id => {
  6863. for (let s = 0; s < ruleUrls.length; s++) {
  6864. if (id == ruleUrls[s].id) {
  6865. urls.push(ruleUrls[s]);
  6866. break;
  6867. }
  6868. }
  6869. });
  6870. ruleUrls = urls;
  6871. }
  6872. }
  6873. if (rulesData.lang) {
  6874. setLang(rulesData.lang);
  6875. }
  6876. if (rulesData.firstRun) {
  6877. rulesData.firstRun = false;
  6878. storage.setItem("rulesData", rulesData);
  6879. setTimeout(() => {
  6880. storage.getItem("rulesData", data => {
  6881. if (data.firstRun === false) {
  6882. _GM_openInTab(firstRunPage, {active: true});
  6883. }
  6884. });
  6885. }, 100);
  6886. }
  6887. _GM_registerMenuCommand(i18n("configure"), () => {
  6888. _GM_openInTab(rulesData.configPage || configPage[0], {active: true});
  6889. });
  6890. if (rulesData.blacklist && rulesData.blacklist.length > 0) {
  6891. let href = location.href.slice(0, 500);
  6892. let commentStart = false;
  6893. for (let i = 0; i < rulesData.blacklist.length; i++) {
  6894. let curGlob = rulesData.blacklist[i];
  6895. if (!curGlob) continue;
  6896. if (curGlob.indexOf("//") == 0) continue;
  6897. if (commentStart) {
  6898. if (/\*\/$/.test(curGlob)) {
  6899. commentStart = false;
  6900. }
  6901. continue;
  6902. }
  6903. if (curGlob.indexOf("/*") == 0) {
  6904. commentStart = true;
  6905. continue;
  6906. }
  6907. if (curGlob.indexOf("/") == 0) {
  6908. let regMatch = curGlob.match(/^\/(.*)\/(\w*)$/);
  6909. if (regMatch && new RegExp(regMatch[1], regMatch[2]).test(href)) {
  6910. forceState == 1;
  6911. return;
  6912. }
  6913. } else if (globMatch(curGlob, href)) {
  6914. forceState == 1;
  6915. return;
  6916. }
  6917. }
  6918. }
  6919. _GM_registerMenuCommand(i18n("editCurrent"), () => {
  6920. picker.start();
  6921. });
  6922. ruleParser.initSavedRules(async () => {
  6923. let upBtnImg = rulesData.upBtnImg, downBtnImg = rulesData.downBtnImg, _sideControllerIcon = rulesData.sideControllerIcon;
  6924. if (upBtnImg && downBtnImg) {
  6925. downSvgCSS = downSvgCSS.replace("transform: rotate(180deg);", "");
  6926. } else if (upBtnImg && !downBtnImg) {
  6927. downBtnImg = upBtnImg;
  6928. } else if(downBtnImg && !upBtnImg) {
  6929. upBtnImg = downBtnImg;
  6930. }
  6931. if (upBtnImg) {
  6932. upSvg = /https?:|data/.test(upBtnImg) ? `<img class="pagetual" src="${upBtnImg}"/>` : `<span>${upBtnImg}</span>`;
  6933. }
  6934. if (downBtnImg) {
  6935. downSvg = /https?:|data/.test(downBtnImg) ? `<img class="pagetual" src="${downBtnImg}"/>` : `<span>${downBtnImg}</span>`;
  6936. }
  6937. if (_sideControllerIcon) {
  6938. sideControllerIcon = /https?:|data/.test(_sideControllerIcon) ? `<img class="pagetual" src="${_sideControllerIcon}"/>` : `<span>${_sideControllerIcon}</span>`;
  6939. }
  6940. setLoadingDiv(rulesData.loadingText || i18n("loadingText"));
  6941. if (typeof(rulesData.opacity) == "undefined") {
  6942. rulesData.opacity = 1;
  6943. }
  6944. if (typeof(rulesData.hideBar) == "undefined") {
  6945. rulesData.hideBar = false;
  6946. }
  6947. if (typeof(rulesData.dbClick2Stop) == "undefined") {
  6948. rulesData.dbClick2Stop = true;
  6949. }
  6950. if (typeof(rulesData.enableWhiteList) == "undefined") {
  6951. rulesData.enableWhiteList = false;
  6952. }
  6953. if (typeof(rulesData.enableHistory) == "undefined") {
  6954. rulesData.enableHistory = false;
  6955. }
  6956. if (typeof(rulesData.openInNewTab) == "undefined") {
  6957. rulesData.openInNewTab = false;
  6958. }
  6959. if (typeof(rulesData.enableDebug) == "undefined") {
  6960. rulesData.enableDebug = true;
  6961. }
  6962. if (typeof(rulesData.updateNotification) == "undefined") {
  6963. rulesData.updateNotification = true;
  6964. }
  6965. if (typeof(rulesData.initRun) == "undefined") {
  6966. rulesData.initRun = true;
  6967. }
  6968. if (typeof(rulesData.preload) == "undefined") {
  6969. rulesData.preload = false;
  6970. }
  6971. if (typeof(rulesData.customFirst) == "undefined") {
  6972. rulesData.customFirst = false;
  6973. }
  6974. if (typeof(rulesData.manualMode) == "undefined") {
  6975. rulesData.manualMode = false;
  6976. }
  6977. if (typeof(rulesData.clickMode) == "undefined") {
  6978. rulesData.clickMode = false;
  6979. }
  6980. if (typeof(rulesData.pageBarMenu) == "undefined") {
  6981. rulesData.pageBarMenu = true;
  6982. }
  6983. if (typeof(rulesData.arrowToScroll) == "undefined") {
  6984. rulesData.arrowToScroll = false;
  6985. }
  6986. if (typeof(rulesData.hideLoadingIcon) == "undefined") {
  6987. rulesData.hideLoadingIcon = false;
  6988. }
  6989. if (typeof(rulesData.hideBarArrow) == "undefined") {
  6990. rulesData.hideBarArrow = false;
  6991. }
  6992. if (typeof(rulesData.lastPageTips) == "undefined") {
  6993. rulesData.lastPageTips = true;
  6994. }
  6995. if (typeof(rulesData.rate) == "undefined") {
  6996. rulesData.rate = 1;
  6997. }
  6998. rate = rulesData.rate;
  6999. if (rulesData.autoLoadNum && rulesData.initRun) {
  7000. autoLoadNum = parseInt(rulesData.autoLoadNum);
  7001. }
  7002. openInNewTab = rulesData.openInNewTab ? 1 : 0;
  7003. enableDebug = rulesData.enableDebug;
  7004.  
  7005. let _nextSwitch = await getListData("nextSwitch", location.host);
  7006. if (typeof(_nextSwitch) !== "undefined") {
  7007. nextIndex = _nextSwitch || 0;
  7008. }
  7009.  
  7010. let _forceState = await getListData("forceState", location.host);
  7011. if (typeof(_forceState) == "undefined") {
  7012. _forceState = await getData("forceState_" + location.host);
  7013. }
  7014. if (typeof(_forceState) == "undefined") {
  7015. _forceState = (rulesData.enableWhiteList ? 1 : 0);
  7016. }
  7017. forceState = _forceState;
  7018.  
  7019. autoScroll = await getListData("autoScroll", location.host + location.pathname) || 0;
  7020.  
  7021. updateDate = await getData("ruleLastUpdate");
  7022.  
  7023. let _loadNowNum = await getData("loadNowNum");
  7024. if (typeof(_loadNowNum) != "undefined") {
  7025. loadNowNum = _loadNowNum;
  7026. }
  7027. let _autoScrollRate = await getData("autoScrollRate");
  7028. if (_autoScrollRate) {
  7029. autoScrollRate = _autoScrollRate;
  7030. }
  7031.  
  7032. author = await getData("author") || "";
  7033.  
  7034. manualPause = !!await getListData("pauseState", location.host);
  7035.  
  7036. let href = location.href.slice(0, 100);
  7037. try {
  7038. if (_unsafeWindow.initedPagetual) {
  7039. if (ruleImportUrlReg.test(href)) {
  7040. showTips(i18n('duplicate'));
  7041. }
  7042. return;
  7043. }
  7044. _unsafeWindow.initedPagetual = true;
  7045. } catch(e) {showTips(e)}
  7046. listenUrl();
  7047. _GM_registerMenuCommand(i18n("update"), () => {
  7048. showTips(i18n("beginUpdate"), "", 60000);
  7049. updateRules(() => {
  7050. showTips(i18n("updateSucc"));
  7051. location.reload();
  7052. },(rule, err) => {
  7053. showTips(`Failed to update ${rule.url} rules!`);
  7054. debug(err);
  7055. });
  7056. });
  7057. _GM_registerMenuCommand(i18n(forceState == 1 ? "enable" : "disableSite"), () => {
  7058. if (forceState == 1) {
  7059. forceState = 0;
  7060. showTips(i18n("enableSiteTips"));
  7061. changeStop(false, true);
  7062. } else {
  7063. forceState = 1;
  7064. showTips(i18n("disableSiteTips"));
  7065. changeStop(true, true);
  7066. sideController.remove();
  7067. }
  7068. setListData("forceState", location.host, forceState);
  7069. if (!ruleParser.curSiteRule.url) {
  7070. setTimeout(() => {
  7071. location.reload();
  7072. }, 500);
  7073. }
  7074. });
  7075. _GM_registerMenuCommand(i18n("toggleAutoScroll"), () => {
  7076. autoScroll = (autoScroll ? 0 : prompt(i18n("autoScrollRate"), autoScrollRate)) || 0;
  7077. autoScroll = parseInt(autoScroll) || 0;
  7078. if (autoScroll < 0) autoScroll = 0;
  7079. if (autoScroll && autoScroll != autoScrollRate) {
  7080. autoScrollRate = autoScroll;
  7081. storage.setItem("autoScrollRate", autoScrollRate);
  7082. }
  7083. setListData("autoScroll", location.host + location.pathname, autoScroll);
  7084. startAutoScroll();
  7085. });
  7086. startAutoScroll();
  7087.  
  7088.  
  7089. if (initConfig(href)) {
  7090. document.addEventListener("click", e => {
  7091. if (e.target && typeof e.target.dataset.pagetualPicker !== 'undefined') {
  7092. e.preventDefault();
  7093. e.stopPropagation();
  7094. picker.start();
  7095. }
  7096. });
  7097. return;
  7098. }
  7099. pageReady = true;
  7100. if (forceState == 1) return;
  7101. let now = new Date().getTime();
  7102. if (!updateDate || now - updateDate > 2 * 24 * 60 * 60 * 1000) {
  7103. updateRules(() => {
  7104. }, (rule, err) => {}, true);
  7105. storage.setItem("ruleLastUpdate", now);
  7106. }
  7107. callback();
  7108. });
  7109. });
  7110. }
  7111.  
  7112. let xhrFailed = false;
  7113. function requestDoc(url, callback) {
  7114. let postParams = url.match(/#p{(.*)}$/);
  7115. if (postParams) {
  7116. postParams = postParams[1];
  7117. url = url.replace(/#p{.*/, "");
  7118. }
  7119. let ruleHeaders = ruleParser.curSiteRule.headers;
  7120. let headers = {
  7121. 'Referer': location.href,
  7122. 'User-Agent': navigator.userAgent,
  7123. 'accept': 'text/html,application/xhtml+xml,application/xml',
  7124. "Content-Type": (postParams ? "application/x-www-form-urlencoded" : "text/html") + ";charset=" + charset,
  7125. };
  7126. if (ruleHeaders) {
  7127. if (ruleHeaders.referer) {
  7128. headers.referer = ruleHeaders.referer;
  7129. }
  7130. if (ruleHeaders.userAgent) {
  7131. headers.userAgent = ruleHeaders.userAgent;
  7132. }
  7133. if (ruleHeaders.accept) {
  7134. headers.accept = ruleHeaders.accept;
  7135. }
  7136. if (ruleHeaders.contentType) {
  7137. headers.contentType = ruleHeaders.contentType;
  7138. let ruleCharset = ruleHeaders.contentType.match(/charset\=([^;]+)/);
  7139. if (ruleCharset) charset = ruleCharset[1];
  7140. }
  7141. if (ruleHeaders.cookie) {
  7142. headers.cookie = ruleHeaders.cookie;
  7143. }
  7144. }
  7145. _GM_xmlhttpRequest({
  7146. url: url,
  7147. method: postParams ? 'POST' : 'GET',
  7148. data: postParams,
  7149. overrideMimeType: 'text/html;charset=' + charset,
  7150. headers: headers,
  7151. timeout: 50000,
  7152. onload: async function(res) {
  7153. if (isPause) return callback(false);
  7154. var doc = null, response = res.response;
  7155. try {
  7156. doc = document.implementation.createHTMLDocument('');
  7157. doc.documentElement.innerHTML = response;
  7158. } catch (e) {
  7159. debug('parse error:' + e.toString());
  7160. }
  7161. let pageElement = null;
  7162. let preCode = ruleParser.curSiteRule.pagePre;
  7163. if (preCode) {
  7164. try {
  7165. let preResult;
  7166. if (typeof preCode == 'function') {
  7167. preResult = await preCode(response, doc);
  7168. } else if (preCode.length == 2) {
  7169. preResult = response.replace(new RegExp(preCode[0], "gi"), preCode[1]);
  7170. } else {
  7171. preResult = await new AsyncFunction("response", "doc", '"use strict";' + preCode)(response, doc);
  7172. }
  7173. if (typeof preResult !== "undefined") {
  7174. if (typeof preResult === "string") {
  7175. doc.documentElement.innerHTML = preResult;
  7176. } else pageElement = preResult;
  7177. }
  7178. } catch(e) {
  7179. debug(e);
  7180. }
  7181. }
  7182. let base = doc.querySelector("base");
  7183. ruleParser.basePath = (base && base.href) || url;
  7184. if (charsetValid && !ruleHeaders) {
  7185. let equiv = doc.querySelector('[http-equiv="Content-Type"]');
  7186. if (equiv && equiv.content) {
  7187. let innerCharSet = equiv.content.match(/charset\=([^;]+)/);
  7188. if (innerCharSet && innerCharSet[1].replace("-", "").toLowerCase() != charset.replace("-", "").toLowerCase()) {
  7189. charset = innerCharSet[1];
  7190. return requestDoc(url, callback);
  7191. }
  7192. }
  7193. }
  7194. if (pageElement === null) {
  7195. pageElement = ruleParser.getPageElement(doc);
  7196. }
  7197. if ((!pageElement || pageElement.length == 0) && res.status >= 400) {
  7198. debug(res.status + " " + url + " " + response, "Error status");
  7199. if (!ruleParser.curSiteRule.smart || !xhrFailed) {
  7200. xhrFailed = true;
  7201. return callback(false);
  7202. }
  7203. }
  7204. if (inCors && (!pageElement || pageElement.length == 0) && ruleParser.curSiteRule.smart) {
  7205. let article;
  7206. for (let i = 0; i < mainSel.length; i++) {
  7207. article = doc.querySelectorAll(mainSel[i]);
  7208. if (article && article.length === 1) break;
  7209. }
  7210. if (article && article.length == 1) {
  7211. article = article[0];
  7212. ruleParser.curSiteRule.pageElement = article.nodeName.toLowerCase() + (article.id ? "#" + article.id : "") + (article.className ? "." + article.className.replace(/ /g, ".") : "") + ">*";
  7213. pageElement = article.children;
  7214. } else {
  7215. ruleParser.curSiteRule.pageElement = allOfBody;
  7216. pageElement = ruleParser.getPageElement(doc);
  7217. }
  7218. ruleParser.getInsert(true);
  7219. }
  7220. //只有1的話怕不是圖片哦
  7221. if (pageElement && (pageElement.length > 1 || (pageElement.length == 1 && !compareNodeName(pageElement[0], ["img"])))) {
  7222. await ruleParser.insertPage(doc, pageElement, url, callback, false);
  7223. if (ruleParser.curSiteRule.action == 1) {
  7224. isLoading = true;
  7225. requestFromIframe(url, async (doc, eles) => {
  7226. if (eles) {
  7227. await ruleParser.insertPage(doc, eles, url, callback, true);
  7228. } else isLoading = false;
  7229. });
  7230. } else ruleParser.curSiteRule.action = 0;
  7231. } else if ((ruleParser.curSiteRule.smart || curPage == 1) && !inCors) {
  7232. ruleParser.curSiteRule.action = 1;
  7233. requestFromIframe(url, async (doc, eles) => {
  7234. if (eles) {
  7235. await ruleParser.insertPage(doc, eles, url, callback, true);
  7236. } else isLoading = false;
  7237. });
  7238. } else {
  7239. debug("Stop as no page element");
  7240. ruleParser.noValidContent(url);
  7241. changeStop(true);
  7242. callback(false);
  7243. }
  7244. },
  7245. onerror: function(e) {
  7246. debug(e, "NetError");
  7247. callback(false);
  7248. },
  7249. ontimeout: function(e) {
  7250. debug(e, "NetTimeout");
  7251. callback(false);
  7252. }
  7253. });
  7254. }
  7255.  
  7256. function initPage() {
  7257. ruleParser.initPage(() => {
  7258. if (ruleParser.curSiteRule.autoLoadNum) {
  7259. autoLoadNum = ruleParser.curSiteRule.autoLoadNum;
  7260. }
  7261. if (ruleParser.curSiteRule.nextLink && Array && Array.isArray && Array.isArray(ruleParser.curSiteRule.nextLink)) {
  7262. _GM_registerMenuCommand(i18n("nextSwitch"), () => {
  7263. nextSwitch.start();
  7264. });
  7265. }
  7266. if (ruleParser.nextLinkHref) {
  7267. let isJs = ruleParser.hrefIsJs(ruleParser.nextLinkHref);
  7268. if (!isJs) {
  7269. let inForce = (forceState == 2 || forceState == 3);
  7270. _GM_registerMenuCommand(i18n(inForce ? "cancelForceIframe" : "forceIframe"), () => {
  7271. if (inForce) {
  7272. setListData("forceState", location.host, "");
  7273. } else {
  7274. let _state = ruleParser.curSiteRule.action > 0 || confirm(i18n("forceAllBody")) ? 2 : 3;
  7275. setListData("forceState", location.host, _state);
  7276. }
  7277. setTimeout(() => {
  7278. location.reload();
  7279. }, 500);
  7280. });
  7281. }
  7282. _GM_registerMenuCommand(i18n("loadNow"), () => {
  7283. if (autoLoadNum != -1) {
  7284. autoLoadNum = -1;
  7285. return;
  7286. }
  7287. let loadNum = window.prompt(i18n("loadConfirm"), loadNowNum);
  7288. if (loadNum === "" || loadNum === null) return;
  7289. loadNum = Math.abs(parseInt(loadNum)) || 0;
  7290. if (loadNowNum != loadNum) {
  7291. loadNowNum = loadNum;
  7292. storage.setItem("loadNowNum", loadNowNum);
  7293. }
  7294. autoLoadNum = loadNum;
  7295. nextPage();
  7296. });
  7297. }
  7298. initListener();
  7299. });
  7300. }
  7301.  
  7302. var pageBarStyle, mainStyleEle, mainStyleStyle;
  7303. function initView() {
  7304. if (!mainStyleStyle) {
  7305. mainStyleStyle = `
  7306. .pagetual_pageBar{
  7307. -moz-transition:all 0.3s ease-in-out 0s;
  7308. -webkit-transition:all 0.3s ease-in-out 0s;
  7309. transition:all 0.3s ease-in-out 0s;
  7310. font-family: Arial,sans-serif !important;
  7311. text-align: center !important;
  7312. }
  7313. .pagetual_pageBar.stop {
  7314. -webkit-filter: invert(100%);
  7315. filter: invert(100%);
  7316. opacity: 1!important;
  7317. }
  7318. .pagetual_pageBar.hide {
  7319. display: none!important;
  7320. }
  7321. .pagetual-hide {
  7322. display: none!important;
  7323. }
  7324. .pagetual_pageBar:hover {
  7325. opacity: 1!important;
  7326. box-shadow: 0px 0px 10px 0px #000000aa;
  7327. border-radius: 20px;
  7328. background-color: rgb(240 240 240 / 80%);
  7329. border-color: transparent!important;
  7330. }
  7331. .pagetual_pageBar span {
  7332. vertical-align: super;
  7333. }
  7334. .pagetual_pageBar a::before,
  7335. .pagetual_pageBar a::after {
  7336. content: none;
  7337. }
  7338. .pagetual_pageBar a>span {
  7339. margin-top: 0!important;
  7340. pointer-events: none;
  7341. padding: unset;
  7342. opacity: 0;
  7343. -moz-transition:margin-top 0.3s ease-in-out 0s, opacity .3s;
  7344. -webkit-transition:margin-top 0.3s ease-in-out 0s, opacity .3s;
  7345. transition:margin-top 0.3s ease-in-out 0s, opacity .3s;
  7346. transform: none;
  7347. left: 0;
  7348. margin-left: calc(50% - 20px);
  7349. }
  7350. .pagetual_pageBar a>span:hover {
  7351. color: red;
  7352. }
  7353. .pagetual_pageBar a:hover>span {
  7354. opacity: 1!important;
  7355. }
  7356. .pagetual_pageBar span.prevScreen,
  7357. .pagetual_pageBar span.nextScreen {
  7358. display: block!important;
  7359. top: unset !important;
  7360. padding: unset !important;
  7361. opacity: 0!important;
  7362. }
  7363. .pagetual_pageBar a:hover>span.prevScreen {
  7364. margin-top: -${rulesData.opacity == 1 ? 31 : 30}px!important;
  7365. pointer-events: all;
  7366. }
  7367. .pagetual_pageBar span.refreshRing {
  7368. position: absolute;
  7369. top: 0;
  7370. opacity: 0;
  7371. height: 30px;
  7372. margin-left: calc(50% - 23px);
  7373. display: block!important;
  7374. }
  7375. .pagetual_pageBar span.refreshRing>svg {
  7376. background: white;
  7377. border-radius: 50%;
  7378. }
  7379. .pagetual_pageBar a:hover>span.refreshRing {
  7380. opacity: 0.3;
  7381. -webkit-animation: pagetual_ring 2.0s infinite linear;
  7382. animation: pagetual_ring 2.0s infinite linear;
  7383. }
  7384. @-webkit-keyframes pagetual_ring {
  7385. 0% { -webkit-transform: rotate(0deg) }
  7386. 100% {
  7387. -webkit-transform: rotate(360deg);
  7388. }
  7389. }
  7390. @keyframes pagetual_ring {
  7391. 0% {
  7392. transform: rotate(0deg);
  7393. -webkit-transform: rotate(0deg);
  7394. } 100% {
  7395. transform: rotate(360deg);
  7396. -webkit-transform: rotate(360deg);
  7397. }
  7398. }
  7399. .pagetual_pageBar a:hover>span.nextScreen {
  7400. margin-top: 30px!important;
  7401. pointer-events: all;
  7402. }
  7403. .pagetual_pageBar span>svg {
  7404. -moz-transition:transform 0.5s ease, opacity 0.3s ease;
  7405. -webkit-transition:transform 0.5s ease, opacity 0.3s ease;
  7406. transition:transform 0.5 ease, opacity 0.3s ease;
  7407. opacity: 0;
  7408. }
  7409. .pagetual_pageBar.stop span>svg{
  7410. opacity: 1;
  7411. }
  7412. .pagetual_pageBar.stop span>svg>path{
  7413. transform: scale(.8);
  7414. transform-origin: center;
  7415. -moz-transition:transform 0.3s ease;
  7416. -webkit-transition:transform 0.3s ease;
  7417. transition:transform 0.3 ease;
  7418. }
  7419. .pagetual_pageBar.stop:hover span>svg>path{
  7420. transform: unset;
  7421. }
  7422. .pagetual_pageBar:hover span>svg {
  7423. opacity: 1;
  7424. }
  7425. .pagetual_pageBar span>svg.upSvg:hover {
  7426. transform: rotate(360deg) scale3d(1.2, 1.2, 1.2);
  7427. }
  7428. .pagetual_pageBar span>svg.downSvg:hover {
  7429. transform: rotate(540deg) scale3d(1.2, 1.2, 1.2)!important;
  7430. }
  7431. .pagetual_pageBar .pagetual_pageNum{
  7432. color: #55555f;
  7433. }
  7434. .pagetual_pageBar .pagetual_pageNum:hover{
  7435. color: #ff6464;
  7436. }
  7437. .pagetual_tipsWords {
  7438. font-size: 50px;
  7439. font-weight: bold;
  7440. font-family: "黑体", -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto",
  7441. "Oxygen", "Ubuntu", "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji",
  7442. "Segoe UI Emoji", "Segoe UI Symbol";
  7443. color: #ffffff;
  7444. min-height: 70px;
  7445. max-width: 80%;
  7446. line-height: 1.5;
  7447. position: fixed;
  7448. left: 50%;
  7449. top: 10%;
  7450. margin-left: -99999px;
  7451. padding: 0 15px;
  7452. z-index: 2147483647;
  7453. background-color: #000;
  7454. border: 1px solid #303030;
  7455. border-radius: 10px;
  7456. opacity: 0;
  7457. filter: alpha(opacity=65);
  7458. box-shadow: 5px 5px 20px 0px #000;
  7459. -moz-transition:opacity 0.3s ease-in-out 0s;
  7460. -webkit-transition:opacity 0.3s ease-in-out 0s;
  7461. transition:opacity 0.3s ease-in-out 0s;
  7462. pointer-events: none;
  7463. word-break: break-all;
  7464. }
  7465. .pagetual_tipsWords>a {
  7466. color: #ffffff;
  7467. }
  7468. .pagetual_loading {
  7469. width: 50px;
  7470. height: 50px;
  7471. margin: 10px auto;
  7472. border-radius: 100%;
  7473. display: flex;
  7474. -webkit-animation: pagetual_loading_scaleout 1.0s infinite ease-in-out;
  7475. animation: pagetual_loading_scaleout 1.0s infinite ease-in-out;
  7476. }
  7477. @-webkit-keyframes pagetual_loading_scaleout {
  7478. 0% { -webkit-transform: scale(0.0) }
  7479. 100% {
  7480. -webkit-transform: scale(1.0);
  7481. opacity: 0;
  7482. }
  7483. }
  7484. @keyframes pagetual_loading_scaleout {
  7485. 0% {
  7486. transform: scale(0.0);
  7487. -webkit-transform: scale(0.0);
  7488. } 100% {
  7489. transform: scale(1.0);
  7490. -webkit-transform: scale(1.0);
  7491. opacity: 0;
  7492. }
  7493. }
  7494. .pagetual_loading_text {
  7495. white-space: nowrap;
  7496. -webkit-animation: pagetual_loading_opacity 2.6s infinite ease-in-out;
  7497. animation: pagetual_loading_opacity 2.6s infinite ease-in-out;
  7498. }
  7499. @-webkit-keyframes pagetual_loading_opacity {
  7500. 0% { opacity: 1 }
  7501. 50% { opacity: 0.2 }
  7502. 100% { opacity: 1 }
  7503. }
  7504. @keyframes pagetual_loading_opacity {
  7505. 0% { opacity: 1 }
  7506. 50% { opacity: 0.2 }
  7507. 100% { opacity: 1 }
  7508. }
  7509. `;
  7510. 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%);"}`;
  7511. }
  7512. if (!mainStyleEle || !mainStyleEle.parentNode) {
  7513. mainStyleEle = _GM_addStyle(mainStyleStyle);
  7514. }
  7515. }
  7516. var loadingDiv = document.createElement("div");
  7517. 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;";
  7518.  
  7519. 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;`;
  7520. function setLoadingDiv(loadingText) {
  7521. 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>`}`);
  7522. }
  7523.  
  7524. 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>`;
  7525. 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;`;
  7526. 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>`;
  7527. 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);`;
  7528.  
  7529. 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;`;
  7530. 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;`;
  7531. var sideControllerIcon = '';
  7532.  
  7533. var tipsWords = document.createElement("div");
  7534. tipsWords.className = "pagetual_tipsWords";
  7535.  
  7536. function changeStop(stop, save) {
  7537. isPause = stop;
  7538. [].forEach.call(getBody(document).querySelectorAll(".pagetual_pageBar,#pagetual-sideController"), bar => {
  7539. if (isPause) {
  7540. bar.classList.add("stop");
  7541. } else {
  7542. bar.classList.remove("stop");
  7543. }
  7544. });
  7545. if (!isPause) ruleParser.showAddedElements();
  7546. manualPause = isPause;
  7547. if (save && sideController.inited) setListData("pauseState", location.host, isPause ? true : "");
  7548. }
  7549.  
  7550. function changeHideBar(hide) {
  7551. isHideBar = hide;
  7552. [].forEach.call(getBody(document).querySelectorAll(".pagetual_pageBar"), bar => {
  7553. if (isHideBar) {
  7554. bar.classList.add("hide");
  7555. } else {
  7556. bar.classList.remove("hide");
  7557. }
  7558. });
  7559. }
  7560.  
  7561. function isInViewPort(element) {
  7562. const viewWidth = window.innerWidth || document.documentElement.clientWidth;
  7563. const viewHeight = window.innerHeight || document.documentElement.clientHeight;
  7564. const {
  7565. top,
  7566. right,
  7567. bottom,
  7568. left,
  7569. } = element.getBoundingClientRect();
  7570.  
  7571. return (
  7572. top >= 0 &&
  7573. left >= 0 &&
  7574. right <= viewWidth + 1 &&
  7575. top <= viewHeight * rate &&
  7576. isVisible(element, _unsafeWindow)
  7577. );
  7578. }
  7579.  
  7580. function getPageBar() {
  7581. let preBar = null, nextBar = null;
  7582. let pageBars = [].slice.call(document.querySelectorAll(".pagetual_pageBar"));
  7583. for (let i = 0; i < pageBars.length; i++) {
  7584. let pageBar = pageBars[i];
  7585. if (!pageBar || !getBody(document).contains(pageBar)) continue;
  7586. let {
  7587. top,
  7588. right,
  7589. bottom,
  7590. left,
  7591. } = pageBar.getBoundingClientRect();
  7592. if (top > 500) {
  7593. nextBar = pageBar;
  7594. preBar = (i - 1 >= 0 ? pageBars[i - 1] : null);
  7595. if (pageBar && getBody(document).contains(pageBar)) {
  7596. let {
  7597. top,
  7598. right,
  7599. bottom,
  7600. left,
  7601. } = pageBar.getBoundingClientRect();
  7602. if (top < -500) {
  7603. preBar = pageBar;
  7604. } else preBar = (i - 2 >= 0 ? pageBars[i - 2] : null);
  7605. }
  7606. break;
  7607. }
  7608. }
  7609. if (!nextBar) preBar = pageBars[pageBars.length - 2];
  7610. return {preBar: preBar, nextBar: nextBar};
  7611. }
  7612.  
  7613. var urlChanged = false;
  7614. var urlChanging = false;
  7615. var urlchangeHandler = e => {
  7616. if (ruleParser && ruleParser.curSiteRule && ruleParser.curSiteRule.listenUrlChange == false) return;
  7617. isPause = true;
  7618. setTimeout(() => {
  7619. lastActiveUrl = location.href;
  7620. if (urlChanging) return;
  7621. urlChanging = true;
  7622. let href = location.href.slice(0, 60);
  7623. if (href == configPage[1]) {
  7624. setTimeout(() => {
  7625. initConfig(href);
  7626. urlChanging = false;
  7627. }, 1000);
  7628. } else {
  7629. setTimeout(() => {
  7630. if (guidePage.test(href)) {
  7631. setTimeout(() => {
  7632. initConfig(href);
  7633. urlChanging = false;
  7634. }, 1000);
  7635. } else {
  7636. ruleParser.urlChanged();
  7637. if (!ruleParser.nextLinkHref) {
  7638. isLoading = false;
  7639. }
  7640. urlChanging = false;
  7641. //if (!pageReady && !ruleImportUrlReg.test(href)) location.reload();
  7642. }
  7643. }, 500);
  7644. }
  7645. }, 1);
  7646. };
  7647. window.addEventListener('pagetual_pushState', urlchangeHandler);
  7648. /*var _wr = function(type) {
  7649. var orig = history[type];
  7650. return function() {
  7651. var rv = orig.apply(this, arguments);
  7652. var e = new Event('pagetual_' + type);
  7653. e.arguments = arguments;
  7654. window.dispatchEvent(e);
  7655. return rv;
  7656. };
  7657. };
  7658. history.pushState = _wr('pushState');*/
  7659.  
  7660. function listenUrl() {
  7661. var prevPathname = window.location.pathname;
  7662. var prevSearch = window.location.search;
  7663. var checkUrlTime = 100;
  7664. var checkUrlTimer;
  7665. var checkClickedEle = null;
  7666. var clickedSth = false;
  7667. var checkFunc = () => {
  7668. if (forceState == 1) return;
  7669. if (checkClickedEle) {
  7670. if (typeof ruleParser.curSiteRule.refreshByClick !== "undefined") {
  7671. } else if (!clickedSth && checkClickedEle && checkClickedEle.nodeName) {
  7672. if (compareNodeName(checkClickedEle, ["a", "button"])) {
  7673. clickedSth = true;
  7674. } else {
  7675. let targetStyle = _unsafeWindow.getComputedStyle(checkClickedEle);
  7676. if (targetStyle.cursor == "pointer") clickedSth = true;
  7677. }
  7678. }
  7679. checkClickedEle = null;
  7680. }
  7681. if (checkUrlTime < 5000) {
  7682. checkUrlTime += checkUrlTime>>1;
  7683. }
  7684. clearTimeout(checkUrlTimer);
  7685. checkUrlTimer = setTimeout(checkFunc, checkUrlTime);
  7686. if (document.hidden) return;
  7687. if (clickedSth) {
  7688. ruleParser.checkClickHref();
  7689. clickedSth = false;
  7690. } else if (!ruleParser.canListenUrlChange()) {
  7691. return;
  7692. }
  7693. if ((prevPathname !== window.location.pathname || prevSearch !== window.location.search) && window.location.href != ruleParser.historyUrl) {
  7694. checkUrlTime = 2000;
  7695. urlWillChange = true;
  7696. var e = new Event('pagetual_pushState');
  7697. e.arguments = arguments;
  7698. window.dispatchEvent(e);
  7699. clickedSth = false;
  7700. }
  7701. prevPathname = window.location.pathname;
  7702. prevSearch = window.location.search;
  7703. };
  7704. checkUrlTimer = setTimeout(checkFunc, checkUrlTime);
  7705.  
  7706. document.addEventListener("click", e => {
  7707. if (!checkClickedEle) {
  7708. checkClickedEle = e.target;
  7709. checkUrlTime = 300;
  7710. clearTimeout(checkUrlTimer);
  7711. checkUrlTimer = setTimeout(checkFunc, checkUrlTime);
  7712. }
  7713. });
  7714. }
  7715.  
  7716. let scrollContainer;
  7717. function distToBottom () {
  7718. let scrolly = window.scrollY;
  7719. let windowHeight = window.innerHeight || document.documentElement.clientHeight;
  7720. if (!scrollContainer || !document.documentElement.contains(scrollContainer)) {
  7721. if (curPage > 1 || ruleParser.nextLinkHref) {
  7722. let pageEle = ruleParser.getPageElement(document);
  7723. if (pageEle && pageEle.length) {
  7724. let parent = pageEle[0].parentNode, pageScrollY = parent.scrollTop;
  7725. while (parent && pageScrollY == 0) {
  7726. parent = parent.parentNode;
  7727. pageScrollY = parent.scrollTop;
  7728. }
  7729. if (pageScrollY) {
  7730. scrollContainer = parent;
  7731. return scrollContainer.scrollHeight - pageScrollY - windowHeight;
  7732. }
  7733. }
  7734. }
  7735. }
  7736. if (scrollContainer) {
  7737. return scrollContainer.scrollHeight - scrollContainer.scrollTop - windowHeight;
  7738. }
  7739.  
  7740. let scrollH = Math.max(document.documentElement.scrollHeight, getBody(document).scrollHeight);
  7741. return scrollH - scrolly - windowHeight;
  7742. }
  7743.  
  7744. let scrollHandler, clickToResetHandler, dblclickHandler, keydownHandler, hashchangeHandler, manualModeKeyHandler, pagetualNextHandler, keyupHandler, messageHandler;
  7745. function initListener () {
  7746. document.removeEventListener('scroll', scrollHandler, true);
  7747. document.removeEventListener('wheel', scrollHandler, true);
  7748. document.removeEventListener('dblclick', dblclickHandler);
  7749. document.removeEventListener('keydown', keydownHandler);
  7750. window.removeEventListener('hashchange', hashchangeHandler, false);
  7751. document.removeEventListener('keydown', manualModeKeyHandler);
  7752. document.removeEventListener('pagetual.next', pagetualNextHandler, false);
  7753. document.removeEventListener('keyup', keyupHandler);
  7754. _unsafeWindow.removeEventListener('message', messageHandler, true);
  7755. let loadmoreBtn, loadingMore = true, lastScroll = 0, checkLoadMoreTimes = 0, loadMoreInv;
  7756. if (ruleParser.curSiteRule.smart) {
  7757. loadingMore = false;
  7758. } else if (ruleParser.curSiteRule.loadMore) {
  7759. loadingMore = false;
  7760. }
  7761. clickMode = typeof ruleParser.curSiteRule.clickMode == 'undefined' ? rulesData.clickMode : ruleParser.curSiteRule.clickMode;
  7762. let clickingNext = false;
  7763. let clickNext = async () => {
  7764. if (clickingNext) return;
  7765. clickingNext = true;
  7766. setTimeout(() => {
  7767. clickingNext = false;
  7768. }, 1500);
  7769. let nextLink = ruleParser.nextLinkHref;
  7770. if (!nextLink) return;
  7771. let isJs = ruleParser.hrefIsJs(nextLink);
  7772. if (isJs) {
  7773. let nextBtn = ruleParser.nextLinkEle;
  7774. if (!nextBtn || !nextBtn.offsetParent) nextBtn = await ruleParser.getNextLink(document, true);
  7775. if (nextBtn) emuClick(nextBtn);
  7776. } else {
  7777. window.location.href = nextLink;
  7778. }
  7779. };
  7780. let checkScrollReach = () => {
  7781. let dist = distToBottom();
  7782. if (clickMode) {
  7783. if (dist < 10) {
  7784. clickNext();
  7785. }
  7786. } else if (dist < bottomGap) {
  7787. nextPage();
  7788. }
  7789. };
  7790. messageHandler = e => {
  7791. if (e.data.command === 'pagetual') {
  7792. let action = e.data.action;
  7793. let detail = e.data.detail;
  7794. switch (action) {
  7795. case "config":
  7796. if (!detail || typeof detail !== 'object') return;
  7797. rulesData = {
  7798. ...rulesData,
  7799. ...detail
  7800. }
  7801. storage.setItem("rulesData", rulesData);
  7802. break;
  7803. case "nextPage":
  7804. if (detail === "" || detail === null) return;
  7805. detail = parseInt(detail) || 0;
  7806. if (loadNowNum != detail) {
  7807. loadNowNum = detail;
  7808. }
  7809. autoLoadNum = detail;
  7810. nextPage();
  7811. break;
  7812. case "loadMore":
  7813. clearInterval(loadMoreInv);
  7814. if (detail === -1) return;
  7815. loadmoreBtn = getLoadMore(document, loadmoreBtn);
  7816. loadmoreBtn && emuClick(loadmoreBtn);
  7817. if (detail === 0) {
  7818. loadMoreInv = setInterval(() => {
  7819. loadmoreBtn = getLoadMore(document, loadmoreBtn);
  7820. loadmoreBtn && emuClick(loadmoreBtn);
  7821. }, 500);
  7822. }
  7823. break;
  7824. }
  7825. }
  7826. return true;
  7827. }
  7828. _unsafeWindow.addEventListener('message', messageHandler, true);
  7829. scrollHandler = e => {
  7830. if (urlChanged && !isLoading) {
  7831. ruleParser.initPage(() => {});
  7832. urlChanged = false;
  7833. loadingMore = false;
  7834. return;
  7835. }
  7836. if (isPause) return;
  7837. if (!loadingMore) {
  7838. loadmoreBtn = getLoadMore(document, loadmoreBtn);
  7839. if (loadmoreBtn) {
  7840. if (isInViewPort(loadmoreBtn)) {
  7841. emuClick(loadmoreBtn);
  7842. loadingMore = true;
  7843. setTimeout(() => {loadingMore = false}, 200);
  7844. }
  7845. } else {
  7846. loadingMore = true;
  7847. if (!ruleParser.curSiteRule.smart || checkLoadMoreTimes++ < 3) {
  7848. setTimeout(() => {loadingMore = false}, 200);
  7849. }
  7850. }
  7851. }
  7852. if (!isLoading && !stopScroll) {
  7853. checkScrollReach();
  7854. }
  7855. ruleParser.changeVisibility();
  7856. let curScroll = getBody(document).scrollTop || document.documentElement.scrollTop;
  7857. if (ruleParser.curSiteRule.lockScroll) {
  7858. if (isLoading && Math.abs(lastScroll - curScroll) > 350) {
  7859. getBody(document).scrollTop = lastScroll;
  7860. document.documentElement.scrollTop = lastScroll;
  7861. } else {
  7862. lastScroll = curScroll;
  7863. }
  7864. }
  7865. if (targetY >= 0) {
  7866. if (Math.abs(targetY - curScroll) < 100) {
  7867. targetY = -1;
  7868. }
  7869. }
  7870. if (curScroll <= 20 && curScroll > 0) {
  7871. if (sideController.inited) {
  7872. sideController.pagenum.innerHTML = createHTML("1");
  7873. }
  7874. }
  7875. };
  7876. dblclickHandler = e => {
  7877. if (forceState == 1 || compareNodeName(e.target, ["input", "textarea", "select", "a", "button", "svg", "use", "img", "path"])) return;
  7878. if (!rulesData.dbClick2StopKey) {
  7879. if ((rulesData.dbClick2StopCtrl && !e.ctrlKey) ||
  7880. (rulesData.dbClick2StopAlt && !e.altKey) ||
  7881. (rulesData.dbClick2StopShift && !e.shiftKey) ||
  7882. (rulesData.dbClick2StopMeta && !e.metaKey)) {
  7883. return;
  7884. }
  7885. }
  7886. if (!compareNodeName(e.target, ["body"]) && !e.target.classList.contains('pagetual_pageBar')) {
  7887. try {
  7888. let selection = window.getSelection();
  7889. let selStr = selection.toString().trim();
  7890. if (!selStr) {
  7891. selection = selection.getRangeAt(0);
  7892. selStr = selection && selection.cloneContents().children[0];
  7893. if (selStr && !compareNodeName(selStr, ["img"])) selStr = false;
  7894. }
  7895. if (selStr) {
  7896. return;
  7897. }
  7898. } catch (e) {}
  7899. }
  7900. if (rulesData.dbClick2Stop && (ruleParser.nextLinkHref || loadmoreBtn)) {
  7901. setTimeout(() => {
  7902. if (rulesData.hideBarButNoStop || rulesData.hideBar) {
  7903. changeHideBar(!isHideBar);
  7904. }
  7905. if (!rulesData.hideBarButNoStop) {
  7906. changeStop(!isPause);
  7907. showTips(i18n(isPause ? "disable" : "enable"));
  7908. }
  7909. if (!isPause) {
  7910. checkScrollReach();
  7911. }
  7912. }, 10);
  7913. }
  7914. };
  7915. document.addEventListener('dblclick', dblclickHandler);
  7916. clickToResetHandler = e => {
  7917. if (!ruleParser.nextLinkHref) isLoading = false;
  7918. };
  7919. document.addEventListener('click', clickToResetHandler);
  7920. if (rulesData.dbClick2StopKey) {
  7921. keydownHandler = e => {
  7922. if ((rulesData.dbClick2StopCtrl && !e.ctrlKey) ||
  7923. (rulesData.dbClick2StopAlt && !e.altKey) ||
  7924. (rulesData.dbClick2StopShift && !e.shiftKey) ||
  7925. (rulesData.dbClick2StopMeta && !e.metaKey)) {
  7926. return;
  7927. }
  7928. if (document.activeElement &&
  7929. (compareNodeName(document.activeElement, ["input", "textarea"]) ||
  7930. document.activeElement.contentEditable == 'true')) {
  7931. return;
  7932. }
  7933. var key = e.key.toLowerCase();
  7934. if (rulesData.dbClick2StopKey.toLowerCase() == key) {
  7935. if (forceState == 1) {
  7936. forceState = 0;
  7937. showTips(i18n("enableSiteTips"));
  7938. changeStop(false, true);
  7939. } else {
  7940. forceState = 1;
  7941. showTips(i18n("disableSiteTips"));
  7942. changeStop(true, true);
  7943. sideController.remove();
  7944. }
  7945. if (!ruleParser.curSiteRule.url) {
  7946. setListData("forceState", location.host, forceState);
  7947. setTimeout(() => {
  7948. location.reload();
  7949. }, 500);
  7950. }
  7951. }
  7952. };
  7953. document.addEventListener('keydown', keydownHandler);
  7954. }
  7955. if (ruleParser.curSiteRule.listenHashChange) {
  7956. hashchangeHandler = () => {
  7957. isPause = true;
  7958. ruleParser.urlChanged();
  7959. if (!ruleParser.nextLinkHref) isLoading = false;
  7960. };
  7961. window.addEventListener('hashchange', hashchangeHandler, false);
  7962. }
  7963. let manualMode = typeof ruleParser.curSiteRule.manualMode == 'undefined' ? rulesData.manualMode : ruleParser.curSiteRule.manualMode;
  7964. if (manualMode) {
  7965. manualModeKeyHandler = e => {
  7966. if (document.activeElement &&
  7967. (compareNodeName(document.activeElement, ["input", "textarea"]) ||
  7968. document.activeElement.contentEditable == 'true')) {
  7969. return;
  7970. }
  7971. if (e.keyCode == 39) {
  7972. clickNext();
  7973. } else if (e.keyCode == 37) {
  7974. history.back();
  7975. }
  7976. };
  7977. document.addEventListener('keydown', manualModeKeyHandler);
  7978. pagetualNextHandler = () => {
  7979. clickNext();
  7980. };
  7981. document.addEventListener('pagetual.next', pagetualNextHandler, false);
  7982. return;
  7983. }
  7984. if (rulesData.arrowToScroll) {
  7985. keyupHandler = e => {
  7986. if (document.activeElement &&
  7987. (compareNodeName(document.activeElement, ["input", "textarea"]) ||
  7988. document.activeElement.contentEditable == 'true')) {
  7989. return;
  7990. }
  7991. if (e.keyCode == 39) {
  7992. let nextPageBar=getPageBar().nextBar;
  7993. if (nextPageBar) {
  7994. scrollToPageBar(nextPageBar);
  7995. } else {
  7996. let scrollTop = getBody(document).scrollTop || document.documentElement.scrollTop;
  7997. window.scrollTo({ top: scrollTop + (window.innerHeight || document.documentElement.clientHeight), behavior: 'instant'});
  7998. }
  7999. } else if (e.keyCode == 37) {
  8000. let prePageBar = getPageBar().preBar;
  8001. if (prePageBar) {
  8002. scrollToPageBar(prePageBar);
  8003. } else {
  8004. let scrollTop = getBody(document).scrollTop || document.documentElement.scrollTop;
  8005. window.scrollTo({ top: scrollTop - (window.innerHeight || document.documentElement.clientHeight), behavior: 'instant'});
  8006. }
  8007. }
  8008. };
  8009. document.addEventListener('keyup', keyupHandler);
  8010. }
  8011. if (!ruleParser.curSiteRule.wheel) {
  8012. document.addEventListener('scroll', scrollHandler, true);
  8013. }
  8014. document.addEventListener('wheel', scrollHandler, true);
  8015. }
  8016.  
  8017. let hideTipsTimeout;
  8018. function showTips(content, href, time, wordColor, backColor) {
  8019. initView();
  8020. document.documentElement.appendChild(tipsWords);
  8021. tipsWords.style.color = wordColor || 0xFFFFFF;
  8022. tipsWords.style.backgroundColor = backColor || 0x000;
  8023. let _time = 1500;
  8024. if (href) {
  8025. _time = 3500;
  8026. tipsWords.innerHTML = createHTML(`<a href='${href}' target='_blank'>${content}</a>`);
  8027. tipsWords.style.pointerEvents = 'all';
  8028. } else {
  8029. tipsWords.innerHTML = createHTML(content);
  8030. }
  8031. tipsWords.style.marginLeft = -tipsWords.offsetWidth / 2 + "px";
  8032. setTimeout(() => {
  8033. tipsWords.style.marginLeft = -tipsWords.offsetWidth / 2 + "px";
  8034. }, 0);
  8035. setTimeout(() => {
  8036. tipsWords.style.opacity = 0.8;
  8037. clearTimeout(hideTipsTimeout);
  8038. hideTipsTimeout = setTimeout(() => {
  8039. tipsWords.style.opacity = 0;
  8040. tipsWords.style.pointerEvents = '';
  8041. }, time || _time);
  8042. }, 1);
  8043. }
  8044.  
  8045. const loadmoreReg = /^\s*((点击)?加载更多|(點擊)?加載更多|load\s*more( comments)?|もっと読み込む)[\.…▼\s]*$/i;
  8046. 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";
  8047. function getLoadMore(doc, loadmoreBtn) {
  8048. if (!loadmoreBtn || !getBody(doc).contains(loadmoreBtn) || /less/.test(loadmoreBtn.innerText)) loadmoreBtn = null;
  8049. if (!ruleParser.curSiteRule.smart && !ruleParser.curSiteRule.loadMore) return null;
  8050. if (loadmoreBtn) return loadmoreBtn;
  8051. let btnSel = ruleParser.curSiteRule.loadMore || defaultLoadmoreSel;
  8052. if (btnSel) {
  8053. loadmoreBtn = getElement(btnSel, doc, null, true);
  8054. }
  8055. if (!loadmoreBtn) {
  8056. let buttons = getBody(doc).querySelectorAll("input,button,a,div[onclick]");
  8057. for (let i = 0; i < buttons.length; i++) {
  8058. let button = buttons[i];
  8059. if (!button.innerText || button.innerText.length > 20) continue;
  8060. if (button && loadmoreReg.test(button.innerText)) {
  8061. loadmoreBtn = button;
  8062. break;
  8063. }
  8064. }
  8065. }
  8066. if (loadmoreBtn && !ruleParser.curSiteRule.loadMore && loadmoreBtn.dataset.ajax !== "true") {
  8067. let href = loadmoreBtn.getAttribute("href");
  8068. if (href && href != "/" && !ruleParser.hrefIsJs(href)) {
  8069. loadmoreBtn = null;
  8070. }
  8071. }
  8072. if (loadmoreBtn && /less/.test(loadmoreBtn.innerText)) loadmoreBtn = null;
  8073. if (loadmoreBtn) debug(loadmoreBtn, 'Load more button');
  8074. return loadmoreBtn;
  8075. }
  8076.  
  8077. var targetY = -1;
  8078. function scrollToPageBar(bar) {
  8079. if (window.pageYOffset == 0) {
  8080. bar.scrollIntoView({ behavior: "smooth", block: "start", inline: "nearest" });
  8081. } else {
  8082. let yOffset = -20;
  8083. if (typeof ruleParser.curSiteRule.pageBarTop !== 'undefined') {
  8084. yOffset = -ruleParser.curSiteRule.pageBarTop;
  8085. }
  8086. targetY = bar.getBoundingClientRect().top + window.pageYOffset + yOffset;
  8087. window.scrollTo({ top: targetY, behavior: 'smooth'});
  8088. }
  8089. }
  8090.  
  8091. const pageNumReg=/[&\/\?](p=|page[=\/_-]?)\d+|[_-]\d+\./;
  8092. function createPageBar(url) {
  8093. curPage++;
  8094. sideController.setup();
  8095. let posEle = null;
  8096. let scrollH = Math.max(document.documentElement.scrollHeight, getBody(document).scrollHeight);
  8097. let insert = ruleParser.getInsert();
  8098. if (!insert || !insert.parentNode) return;
  8099. if (forceState == 2) {
  8100. posEle = getBody(document);
  8101. posEle = posEle.children[posEle.children.length - 1];
  8102. } else {
  8103. posEle = insert;
  8104. }
  8105. while (posEle && !posEle.offsetParent) {
  8106. posEle = posEle.previousElementSibling || posEle.parentNode;
  8107. }
  8108. if (posEle) {
  8109. let actualBottom = getElementBottom(posEle);
  8110. bottomGap = scrollH - actualBottom + (window.innerHeight || document.documentElement.clientHeight) * rate;
  8111. if (bottomGap < 100) bottomGap = 100;
  8112. } else {
  8113. bottomGap = 1000;
  8114. }
  8115. if (hidePageBar) return null;
  8116. url = url.replace(/#p{.*/, "");
  8117. let example = (ruleParser.curSiteRule.insertPos == 2 || ruleParser.curSiteRule.insertPos == "in") ? insert.children[0] : (insert.parentNode.children[0] || insert);
  8118. while (example && (compareNodeName(example, ["script", "style"]) || example.className == "pagetual_pageBar")) {
  8119. example = example.nextElementSibling;
  8120. }
  8121. if (!example || !example.parentNode) example = insert;
  8122. if (example.nodeType != 1) {
  8123. example = example.previousElementSibling || example.parentNode;
  8124. if (!example || example.nodeType != 1) return;
  8125. }
  8126. let exampleStyle = _unsafeWindow.getComputedStyle(example);
  8127. let inTable, inLi;
  8128. if (forceState == 2) {
  8129. inTable = inLi = false;
  8130. } else {
  8131. inTable = compareNodeName(example.parentNode, ["table", "tbody"]) ||
  8132. compareNodeName(example, ["tr", "tbody"]) ||
  8133. exampleStyle.display == "table-row" ||
  8134. (example.nextElementSibling && compareNodeName(example.nextElementSibling, ["tr", "tbody"]));
  8135. inLi = compareNodeName(example, ["li"]) || (example.nextElementSibling && compareNodeName(example.nextElementSibling, ["li"]));
  8136. }
  8137. let pageBar = document.createElement(inTable ? "tr" : (inLi ? "li" : "div"));
  8138. let upSpan = document.createElement("span");
  8139. let downSpan = document.createElement("span");
  8140. let pageText = document.createElement("a");
  8141. let pageNum;
  8142. pageBar.className = isHideBar ? "pagetual_pageBar hide" : "pagetual_pageBar";
  8143. pageBar.id = "pagetual_pageBar" + curPage;
  8144. pageBar.setAttribute("translate", "no");
  8145. if (isPause) {
  8146. pageBar.classList.add("stop");
  8147. }
  8148. pageBar.style.cssText = pageBarStyle;
  8149. pageBar.title = i18n(isPause ? "enable" : "disable");
  8150. upSpan.innerHTML = createHTML(upSvg);
  8151. upSpan.children[0].style.cssText = upSvgCSS;
  8152. upSpan.title = i18n("toTop");
  8153. downSpan.innerHTML = createHTML(downSvg);
  8154. downSpan.children[0].style.cssText = downSvgCSS;
  8155. downSpan.title = i18n("toBottom");
  8156. upSpan.style.cssText = initStyle;
  8157. downSpan.style.cssText = initStyle;
  8158. pageText.href = url;
  8159. pageText.style.cssText = pageTextStyle;
  8160. pageText.title = i18n("current");
  8161. if (openInNewTab == 1) pageText.target = "_blank";
  8162. pageBar.appendChild(upSpan);
  8163. pageBar.appendChild(pageText);
  8164. let touched = false;
  8165. let touchBodyHandler = e => {
  8166. touched = false;
  8167. getBody(document).removeEventListener('touchstart', touchBodyHandler, { passive: false, capture: false });
  8168. };
  8169. pageText.addEventListener("touchstart", e => {
  8170. if (touched) return;
  8171. touched = true;
  8172. pageText.style.pointerEvents = 'none';
  8173. setTimeout(() => {
  8174. pageText.style.pointerEvents = 'all';
  8175. }, 250);
  8176. getBody(document).addEventListener("touchstart", touchBodyHandler, { passive: false, capture: false });
  8177. }, { passive: false, capture: false });
  8178. if (ruleParser.nextTitle) {
  8179. pageText.innerHTML = createHTML(ruleParser.nextTitle + " ");
  8180. pageText.title = ruleParser.nextTitle;
  8181. }
  8182. if (ruleParser.curSiteRule.pageNum || pageNumReg.test(url)) {
  8183. pageText.innerHTML = createHTML(pageText.innerHTML + i18n("page"));
  8184. pageNum = document.createElement("span");
  8185. let num = ruleParser.getPageNumFromUrl(url, curPage);
  8186. pageNum.innerHTML = createHTML(num + "<i style='font-size: 0;'>&nbsp;</i>");
  8187. pageNum.className = "pagetual_pageNum";
  8188. pageNum.title = i18n("inputPageNum");
  8189. pageNum.style.cssText = pageTextStyle;
  8190. pageNum.style.cursor = "pointer";
  8191. pageNum.style.color = "";
  8192. pageNum.style.marginLeft = "5px";
  8193. pageNum.addEventListener("click", e => {
  8194. let pageInput = prompt(i18n("inputPageNum"), num || "1");
  8195. if (pageInput) {
  8196. let localPageBar = document.querySelector("#pagetual_pageBar" + pageInput);
  8197. if (localPageBar) {
  8198. scrollToPageBar(localPageBar);
  8199. } else {
  8200. let pageLink = ruleParser.getLinkByPage(url, pageInput);
  8201. if (pageLink) {
  8202. _GM_openInTab(pageLink, {active:true});
  8203. }
  8204. }
  8205. }
  8206. e.preventDefault();
  8207. e.stopPropagation();
  8208. });
  8209. pageBar.appendChild(pageNum);
  8210. } else {
  8211. pageText.innerHTML = createHTML(pageText.innerHTML + i18n("page") + curPage + "<i style='font-size: 0;'>&nbsp;</i>");
  8212. }
  8213. let preBtn = document.createElement("span");
  8214. preBtn.innerHTML = createHTML("∧");
  8215. preBtn.title = i18n("prevPage");
  8216. preBtn.className = "prevScreen";
  8217. 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; ";
  8218. let nextBtn = document.createElement("span");
  8219. nextBtn.innerHTML = createHTML("∨");
  8220. nextBtn.title = i18n("nextPage");
  8221. nextBtn.className = "nextScreen";
  8222. 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; ";
  8223. let localPage = curPage;
  8224. preBtn.addEventListener("click", e => {
  8225. e.stopPropagation();
  8226. e.preventDefault();
  8227. let prePageBar = document.querySelector("#pagetual_pageBar" + (localPage - 1));
  8228. if (prePageBar) {
  8229. scrollToPageBar(prePageBar);
  8230. } else {
  8231. let scrollTop = getBody(document).scrollTop || document.documentElement.scrollTop;
  8232. targetY = scrollTop - (window.innerHeight || document.documentElement.clientHeight);
  8233. window.scrollTo({ top: targetY, behavior: 'smooth'});
  8234. }
  8235. });
  8236. nextBtn.addEventListener("click", e => {
  8237. e.stopPropagation();
  8238. e.preventDefault();
  8239. let nextPageBar = document.querySelector("#pagetual_pageBar" + (localPage + 1));
  8240. if (nextPageBar) {
  8241. scrollToPageBar(nextPageBar);
  8242. } else {
  8243. scrollH = Math.max(document.documentElement.scrollHeight, getBody(document).scrollHeight);
  8244. targetY = scrollH || 9999999;
  8245. window.scrollTo({ top: targetY, behavior: 'smooth'});
  8246. }
  8247. });
  8248. if (!rulesData.hideBarArrow) {
  8249. pageText.insertBefore(preBtn, pageText.firstChild);
  8250. pageText.insertBefore(nextBtn, pageText.firstChild);
  8251. }
  8252. if (curForceIframe) {
  8253. let bgRing = document.createElement("span");
  8254. bgRing.className = "refreshRing";
  8255. bgRing.style.display = "none";
  8256. bgRing.innerHTML = createHTML(upSvg);
  8257. pageText.title = "Refresh";
  8258. pageText.appendChild(bgRing);
  8259. pageText.addEventListener("click", e => {
  8260. e.stopPropagation();
  8261. if (e.ctrlKey || e.altKey || e.shiftKey || e.metaKey) return;
  8262. e.preventDefault();
  8263. let nextEle = pageBar && pageBar.nextElementSibling;
  8264. if (nextEle && nextEle.name == 'pagetual-iframe') {
  8265. if (curForceIframe == nextEle) {
  8266. nextEle.setAttribute("loaded", "refresh");
  8267. }
  8268. nextEle.src = nextEle.src;
  8269. }
  8270. });
  8271. } else if (rulesData.pageBarMenu) {
  8272. pageText.addEventListener("click", e => {
  8273. e.stopPropagation();
  8274. if (e.ctrlKey || e.altKey || e.shiftKey || e.metaKey) return;
  8275. e.preventDefault();
  8276. picker.start();
  8277. });
  8278. }
  8279. pageBar.appendChild(downSpan);
  8280. if (forceState == 2) {
  8281. pageBar.style.width = "99%";
  8282. } else {
  8283. let parentStyle = _unsafeWindow.getComputedStyle(example.parentNode);
  8284. let parentWidth = example.parentNode.offsetWidth || parseInt(parentStyle.width);
  8285. pageBar.style.width = parentWidth - parseInt(parentStyle.paddingLeft) - parseInt(parentStyle.paddingRight) - 10 + "px";
  8286. pageBar.style.margin = '10px 5px';
  8287. if (parentStyle.display == "grid" || parentStyle.display == "inline-grid") {
  8288. pageBar.style.gridColumn = "1/-1";
  8289. }
  8290. if (inTable) {
  8291. example = compareNodeName(example, ["tr", "tbody"]) ? example : example.nextElementSibling || example;
  8292. if (compareNodeName(example, ["tbody"])) example = example.querySelector("tr");
  8293. let nextTr = example;
  8294. while (nextTr && nextTr.children.length == 0) nextTr = nextTr.nextElementSibling;
  8295. if (nextTr) example = nextTr;
  8296. let tdNum = 0;
  8297. if (exampleStyle.display == "table-row") {
  8298. [].forEach.call(example.children, el => {
  8299. tdNum += el.colSpan || 1;
  8300. });
  8301. } else {
  8302. [].forEach.call(example.children, el => {
  8303. if (compareNodeName(el, ["td", "th"])) {
  8304. tdNum += el.colSpan || 1;
  8305. }
  8306. });
  8307. }
  8308. pageBar.style.cssText = "";
  8309. pageBar.style.display = "table-row";
  8310. pageBar.style.backgroundColor = "unset";
  8311. pageBar.style.lineHeight = "20px";
  8312. pageBar.style.boxShadow = "";
  8313. let td = document.createElement("td");
  8314. td.colSpan = tdNum || 1;
  8315. let inTd = document.createElement("div");
  8316. inTd.style.cssText = pageBarStyle;
  8317. inTd.style.display = "";
  8318. inTd.className = pageBar.className;
  8319. pageBar.className = "";
  8320. inTd.appendChild(upSpan);
  8321. inTd.appendChild(pageText);
  8322. if (pageNum) inTd.appendChild(pageNum);
  8323. inTd.appendChild(downSpan);
  8324. td.appendChild(inTd);
  8325. pageBar.appendChild(td);
  8326. } else if (inLi) {
  8327. example = compareNodeName(example, ["li"]) ? example : example.nextElementSibling || example;
  8328. pageBar.style.opacity = 1;
  8329. pageBar.style.display = getComputedStyle(example).display;
  8330. pageBar.style.backgroundColor = "unset";
  8331. pageBar.style.lineHeight = "20px";
  8332. pageBar.style.boxShadow = "";
  8333. pageBar.style.border = "";
  8334. pageBar.style.width = "";
  8335. pageBar.style.maxWidth = "unset";
  8336. pageBar.style.flex = "auto";
  8337. let inTd = document.createElement("div");
  8338. inTd.style.cssText = pageBarStyle;
  8339. inTd.style.display = "";
  8340. inTd.style.margin = "0"
  8341. inTd.style.padding = "0 0";
  8342. inTd.style.textAlign = "center";
  8343. inTd.style.minWidth = "150px";
  8344. inTd.style.width = 'calc(100% - 20px)';
  8345. inTd.className = pageBar.className;
  8346. pageBar.className = "";
  8347. inTd.appendChild(upSpan);
  8348. inTd.appendChild(pageText);
  8349. if (pageNum) inTd.appendChild(pageNum);
  8350. inTd.appendChild(downSpan);
  8351. if (pageBar.style.display === 'table-row') {
  8352. let td = document.createElement("td");
  8353. td.colSpan = example.children.length;
  8354. td.style.width = '100%';
  8355. td.appendChild(inTd);
  8356. pageBar.appendChild(td);
  8357. } else {
  8358. inTd.style.width = '100%';
  8359. pageBar.appendChild(inTd);
  8360. }
  8361. }
  8362. }
  8363.  
  8364. upSpan.addEventListener("click", e => {
  8365. getBody(document).scrollTop = 0;
  8366. document.documentElement.scrollTop = 0;
  8367. e.preventDefault();
  8368. e.stopPropagation();
  8369. });
  8370. downSpan.addEventListener("click", e => {
  8371. if (!e.altKey && !e.ctrlKey && !e.shiftKey && !e.metaKey) {
  8372. changeStop(true);
  8373. }
  8374. pageBar.title = i18n(isPause ? "enable" : "disable");
  8375. scrollH = Math.max(document.documentElement.scrollHeight, getBody(document).scrollHeight);
  8376. getBody(document).scrollTop = scrollH || 9999999;
  8377. document.documentElement.scrollTop = scrollH || 9999999;
  8378. e.preventDefault();
  8379. e.stopPropagation();
  8380. });
  8381. pageBar.addEventListener("click", e => {
  8382. changeStop(!isPause, true);
  8383. pageBar.title = i18n(isPause ? "enable" : "disable");
  8384. });
  8385. ruleParser.insertElement(pageBar);
  8386. ruleParser.runPageBar(pageBar);
  8387.  
  8388. if (sideController.inited) {
  8389. try {
  8390. let observer = new IntersectionObserver(entries => {
  8391. if (entries[0].intersectionRatio > 0) {
  8392. sideController.pagenum.innerHTML = createHTML(localPage);
  8393. }
  8394. });
  8395. observer.observe(pageBar);
  8396. } catch(e) {}
  8397. }
  8398. return pageBar;
  8399. }
  8400.  
  8401. async function waitForElement(sel, doc, maxTime) {
  8402. if (!sel) return null;
  8403. return new Promise((resolve) => {
  8404. let passedTime = 0;
  8405. let checkInv = setInterval(() => {
  8406. let result = getElement(sel, doc, null, true);
  8407. if (result) {
  8408. clearInterval(checkInv);
  8409. resolve(result);
  8410. } else if (maxTime) {
  8411. passedTime += 100;
  8412. if (passedTime >= maxTime) {
  8413. clearInterval(checkInv);
  8414. resolve(result);
  8415. }
  8416. }
  8417. }, 100);
  8418. });
  8419. }
  8420.  
  8421. async function clickAction(sel, doc) {
  8422. let btn = await waitForElement(sel, doc);
  8423. emuClick(btn, doc);
  8424. }
  8425.  
  8426. async function enterAction(sel, doc) {
  8427. let btn = await waitForElement(sel, doc);
  8428. let eventParam = { key: "Enter", keyCode: 13, bubbles: true };
  8429. let event = new KeyboardEvent('keydown', eventParam);
  8430. btn.dispatchEvent(event);
  8431. event = new KeyboardEvent('keyup', eventParam);
  8432. btn.dispatchEvent(event);
  8433. event = new KeyboardEvent('keypress', eventParam);
  8434. btn.dispatchEvent(event);
  8435. }
  8436.  
  8437. async function inputAction(sel, v, doc) {
  8438. let input = await waitForElement(sel, doc);
  8439. let event = new Event('focus', { bubbles: true });
  8440. input.dispatchEvent(event);
  8441. let lastValue = input.value;
  8442. if (input.nodeName.toUpperCase() == "INPUT") {
  8443. var nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value").set;
  8444. nativeInputValueSetter.call(input, v);
  8445. } else if (input.nodeName.toUpperCase() == "TEXTAREA") {
  8446. var nativeTextareaValueSetter = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, "value").set;
  8447. nativeTextareaValueSetter.call(input, v);
  8448. } else {
  8449. input.innerHTML = createHTML(v);
  8450. }
  8451. event = new Event('input', { bubbles: true });
  8452. let tracker = input._valueTracker;
  8453. if (tracker) {
  8454. tracker.setValue(lastValue);
  8455. }
  8456. input.dispatchEvent(event);
  8457. event = new Event('change', { bubbles: true });
  8458. input.dispatchEvent(event);
  8459. debug(input, `input ${sel}`);
  8460. }
  8461.  
  8462. function emuClick(btn, doc) {
  8463. if (!doc) doc = document;
  8464. let curScroll = getBody(doc).scrollTop || doc.documentElement.scrollTop;
  8465. let orgHref = btn.getAttribute('href');
  8466. if (orgHref && orgHref.replace(location.origin + location.pathname, "").indexOf("#") === 0) {
  8467. let hashAction = e => {
  8468. e.preventDefault();
  8469. getBody(doc).scrollTop = curScroll;
  8470. doc.documentElement.scrollTop = curScroll;
  8471. btn.removeEventListener('click', hashAction, false);
  8472. };
  8473. btn.addEventListener('click', hashAction, false);
  8474. }
  8475. if (!PointerEvent) return btn.click();
  8476. let eventParam = {
  8477. isTrusted: true,
  8478. altKey: false,
  8479. azimuthAngle: 0,
  8480. bubbles: true,
  8481. button: 0,
  8482. buttons: 0,
  8483. clientX: 1,
  8484. clientY: 1,
  8485. cancelBubble: false,
  8486. cancelable: true,
  8487. composed: true,
  8488. ctrlKey: false,
  8489. defaultPrevented: false,
  8490. detail: 1,
  8491. eventPhase: 2,
  8492. fromElement: null,
  8493. height: 1,
  8494. isPrimary: false,
  8495. metaKey: false,
  8496. pointerId: 1,
  8497. pointerType: "mouse",
  8498. pressure: 0,
  8499. relatedTarget: null,
  8500. returnValue: true,
  8501. shiftKey: false,
  8502. toElement: null,
  8503. twist: 0,
  8504. which: 1
  8505. };
  8506. let mouseEvent = new PointerEvent("mousedown", eventParam);
  8507. btn.dispatchEvent(mouseEvent);
  8508. mouseEvent = new PointerEvent("mouseup", eventParam);
  8509. btn.dispatchEvent(mouseEvent);
  8510. let dispatchTouchEvent = (ele, type) => {
  8511. let touchEvent;
  8512. try {
  8513. touchEvent = document.createEvent('TouchEvent')
  8514. touchEvent.initTouchEvent(type, true, true)
  8515. } catch (err) {
  8516. try {
  8517. touchEvent = document.createEvent('UIEvent')
  8518. touchEvent.initUIEvent(type, true, true)
  8519. } catch (err) {
  8520. touchEvent = document.createEvent('Event')
  8521. touchEvent.initEvent(type, true, true)
  8522. }
  8523. }
  8524. if (touchEvent) {
  8525. try {
  8526. touchEvent.targetTouches = [{
  8527. pageX: 1,
  8528. pageY: 1,
  8529. clientX: 1,
  8530. clientY: 1,
  8531. target: btn
  8532. }];
  8533. touchEvent.touches = [{
  8534. pageX: 1,
  8535. pageY: 1,
  8536. clientX: 1,
  8537. clientY: 1,
  8538. target: btn
  8539. }];
  8540. touchEvent.changedTouches = [{
  8541. pageX: 1,
  8542. pageY: 1,
  8543. clientX: 1,
  8544. clientY: 1,
  8545. target: btn
  8546. }];
  8547. } catch (err) {}
  8548. ele.dispatchEvent(touchEvent);
  8549. }
  8550. }
  8551. dispatchTouchEvent(btn, "touchstart");
  8552. dispatchTouchEvent(btn, "touchend");
  8553.  
  8554. btn.click();
  8555. }
  8556.  
  8557. function emuInput(input, v) {
  8558. let result = false;
  8559. if (!input) return true;
  8560. let event = new Event('focus', { bubbles: true });
  8561. input.dispatchEvent(event);
  8562. let lastValue = input.value;
  8563. if (input.type == 'file') {
  8564. let file = v;
  8565. let blob = new Blob([file], {
  8566. type: 'text/plain'
  8567. });
  8568. file = new File([blob], 'noname.txt', { type: blob.type });
  8569. let dataTransfer = new DataTransfer();
  8570. dataTransfer.items.add(file);
  8571. input.files = dataTransfer.files;
  8572. v = "c:/fakepath/fakefile";
  8573. } else if (/INPUT/i.test(input.nodeName)) {
  8574. var nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value").set;
  8575. nativeInputValueSetter.call(input, v);
  8576. } else if (/SELECT/i.test(input.nodeName)) {
  8577. var nativeSelectValueSetter = Object.getOwnPropertyDescriptor(window.HTMLSelectElement.prototype, "value").set;
  8578. nativeSelectValueSetter.call(input, v);
  8579. } else if (input.nodeName.toUpperCase() == "TEXTAREA") {
  8580. var nativeTextareaValueSetter = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, "value").set;
  8581. nativeTextareaValueSetter.call(input, v);
  8582. } else {
  8583. input.innerHTML = createHTML(v);
  8584. }
  8585. event = new Event('input', { bubbles: true });
  8586. let tracker = input._valueTracker;
  8587. if (tracker) {
  8588. tracker.setValue(lastValue);
  8589. }
  8590. input.dispatchEvent(event);
  8591. event = new Event('change', { bubbles: true });
  8592. input.dispatchEvent(event);
  8593. return result;
  8594. }
  8595.  
  8596. var failFromIframe = 0;
  8597. var inCors = false;
  8598. var checkRemoveIntv;
  8599. function requestFromIframe(url, callback){
  8600. if (location.protocol === 'https:' && !/^https:/.test(url)) {
  8601. ruleParser.noValidContent(url);
  8602. }
  8603. url = url.indexOf('=') == -1 ? url.replace(/#[^#]*/,"") : url;
  8604. let iframe = document.createElement('iframe');
  8605. iframe.name = 'pagetual-iframe';
  8606. iframe.width = '100%';
  8607. iframe.height = '1000';
  8608. iframe.frameBorder = '0';
  8609. if (ruleParser.curSiteRule.sandbox != false) {
  8610. iframe.sandbox = "allow-same-origin allow-scripts allow-popups allow-forms";
  8611. }
  8612. 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;';
  8613. let waitTime = 100, checkEval;
  8614. ruleParser.runWait((_checkEval, _waitTime) => {
  8615. if (_checkEval) {
  8616. checkEval = _checkEval;
  8617. }
  8618. if (_waitTime) {
  8619. waitTime = _waitTime;
  8620. }
  8621. });
  8622. if (checkRemoveIntv) clearInterval(checkRemoveIntv);
  8623. checkRemoveIntv = setInterval(() => {
  8624. if (!iframe || !getBody(document).contains(iframe)) {
  8625. clearInterval(checkRemoveIntv);
  8626. loadPageOver();
  8627. }
  8628. }, 500);
  8629. let loadedHandler = async e => {
  8630. if (e.data != 'pagetual-iframe:DOMLoaded' && e.type != 'load') return;
  8631. clearInterval(checkRemoveIntv);
  8632. window.removeEventListener('message', loadedHandler, false);
  8633. iframe.removeEventListener('load', loadedHandler, false);
  8634. let pageEleTryTimes = 0;
  8635. async function checkIframe() {
  8636. if (urlChanged || isPause) {
  8637. return callback(false, false);
  8638. }
  8639. try {
  8640. let doc = iframe.contentDocument || iframe.contentWindow.document;
  8641. if (checkEval && !await checkEval(doc)) {
  8642. setTimeout(() => {
  8643. checkIframe();
  8644. }, waitTime);
  8645. return;
  8646. } else {
  8647. let preCode = ruleParser.curSiteRule.pagePre, eles = null;
  8648. if (preCode) {
  8649. try {
  8650. let preResult;
  8651. if (typeof preCode == 'function') {
  8652. preResult = await preCode(doc.documentElement.innerHTML, doc);
  8653. } else if (preCode.length == 2) {
  8654. preResult = doc.documentElement.innerHTML.replace(new RegExp(preCode[0], "gi"), preCode[1]);
  8655. } else {
  8656. preResult = await new AsyncFunction("response", "doc", '"use strict";' + preCode)(doc.documentElement.innerHTML, doc);
  8657. }
  8658. if (typeof preResult !== "undefined") {
  8659. if (typeof preResult === "string") {
  8660. doc.documentElement.innerHTML = preResult;
  8661. } else eles = preResult;
  8662. }
  8663. } catch(e) {
  8664. debug(e);
  8665. }
  8666. }
  8667. let base = doc.querySelector("base");
  8668. ruleParser.basePath = (base && base.href) || url;
  8669. if (eles === null) eles = ruleParser.getPageElement(doc, iframe.contentWindow, pageEleTryTimes < 25);
  8670. if (eles && eles.length > 0) {
  8671. await ruleParser.hookUrl(doc);
  8672. await callback(doc, eles);
  8673. } else if (pageEleTryTimes++ < 100) {
  8674. getBody(doc).scrollTop = 9999999;
  8675. if (doc.documentElement) {
  8676. doc.documentElement.scrollTop = 9999999;
  8677. }
  8678. setTimeout(() => {
  8679. checkIframe();
  8680. }, waitTime);
  8681. return;
  8682. } else {
  8683. if (failFromIframe++ > 2) {
  8684. failFromIframe = 0;
  8685. debug("Stop as failFromIframe");
  8686. changeStop(true);
  8687. callback(false, false);
  8688. } else {
  8689. ruleParser.noValidContent(url);
  8690. callback(false, false);
  8691. }
  8692. }
  8693. }
  8694. } catch(e) {
  8695. inCors = true;
  8696. if (forceState === 3) {
  8697. debug("Stop as cors");
  8698. isPause = true;
  8699. }
  8700. if (!ruleParser.curSiteRule.pageElement) {
  8701. ruleParser.curSiteRule.pageElement = allOfBody;
  8702. ruleParser.getInsert(true);
  8703. }
  8704. ruleParser.curSiteRule.action = 0;
  8705. ruleParser.nextLinkHref = url;
  8706. callback(false, false);
  8707. nextPage();
  8708. }
  8709. if (iframe && iframe.parentNode) iframe.parentNode.removeChild(iframe);
  8710. }
  8711. setTimeout(() => {
  8712. checkIframe();
  8713. }, waitTime);
  8714. };
  8715. let code = ruleParser.curSiteRule.iframeInit;
  8716. if (code) {
  8717. let checkReady = setInterval(() => {
  8718. let doc;
  8719. try {
  8720. doc = iframe.contentDocument || (iframe.contentWindow && iframe.contentWindow.document);
  8721. } catch(e) {
  8722. clearInterval(checkReady);
  8723. return;
  8724. }
  8725. if (doc) {
  8726. clearInterval(checkReady);
  8727. try {
  8728. Function('win', 'iframe', '"use strict";' + code)(iframe.contentWindow, iframe);
  8729. } catch(e) {
  8730. debug(e);
  8731. }
  8732. }
  8733. }, 50);
  8734. }
  8735. window.addEventListener('message', loadedHandler, false);
  8736. iframe.addEventListener('load', loadedHandler, false);
  8737. iframe.src = url;
  8738. try {
  8739. getBody(document).appendChild(iframe);
  8740. } catch (e) {
  8741. return callback(false, false);
  8742. }
  8743. }
  8744.  
  8745. var emuIframe, lastActiveUrl, orgContent, meetCors = false;
  8746. function emuPage(callback) {
  8747. let orgPage = null, preContent = null, iframeDoc, checkTimes = 0, loadmoreBtn, pageEle, nextLink, loadmoreEnd = false, waitTimes = 80, changed = false, checkNext = 0;
  8748. let activeClass = "active";
  8749. if (typeof ruleParser.curSiteRule.activeClass !== 'undefined') {
  8750. activeClass = ruleParser.curSiteRule.activeClass;
  8751. }
  8752. function returnFalse(log) {
  8753. if (curPage > 1) {
  8754. ruleParser.reachedLastPage();
  8755. } else {
  8756. sideController.remove();
  8757. }
  8758. debug(log);
  8759. isPause = true;
  8760. callback(false, false);
  8761. if (emuIframe && emuIframe.parentNode) {
  8762. emuIframe.parentNode.removeChild(emuIframe);
  8763. emuIframe = null;
  8764. }
  8765. }
  8766. async function cloneStatus() {
  8767. if (!iframeDoc || ruleParser.curSiteRule.cloneStatus === false) return;
  8768. let inputs = document.querySelectorAll("input:not([type=button],[type=image],[type=reset],[type=submit])");
  8769. let selectOptions = document.querySelectorAll("select>option");
  8770. [...inputs].forEach(input => {
  8771. let sel = geneSelector(input, true, true);
  8772. let mirrorEle = iframeDoc.querySelector(sel);
  8773. if (!mirrorEle) return;
  8774. if (mirrorEle.type === "checkbox" || mirrorEle.type === "radio") {
  8775. mirrorEle.checked = !!input.checked;
  8776. } else {
  8777. emuInput(mirrorEle, input.value);
  8778. }
  8779. });
  8780. [...selectOptions].forEach(option => {
  8781. let sel = geneSelector(option, true, true);
  8782. let mirrorEle = iframeDoc.querySelector(sel);
  8783. if (!mirrorEle) return;
  8784. let selected = option.selected;
  8785. mirrorEle.selected = !!selected;
  8786. if (selected) {
  8787. mirrorEle.parentNode.dispatchEvent(new Event('change'));
  8788. }
  8789. });
  8790. if (activeClass) {
  8791. let actives = document.querySelectorAll("." + activeClass);
  8792. for (let active of actives) {
  8793. let sel = geneSelector(active, true, true).replace("." + activeClass, "");
  8794. let mirrorEle = await waitForElement(sel, iframeDoc, 5000);
  8795. if (!mirrorEle || mirrorEle.classList.contains(activeClass)) {
  8796. continue;
  8797. }
  8798. emuClick(mirrorEle);
  8799. await sleep(300);
  8800. }
  8801. }
  8802. }
  8803. async function checkPage() {
  8804. if (isPause) return loadPageOver();
  8805. try {
  8806. iframeDoc = emuIframe.contentDocument || emuIframe.contentWindow.document;
  8807. } catch(e) {
  8808. returnFalse("Stop as cors");
  8809. return;
  8810. }
  8811. getBody(iframeDoc).scrollTop = 9999999;
  8812. if (iframeDoc.documentElement) {
  8813. iframeDoc.documentElement.scrollTop = 9999999;
  8814. }
  8815.  
  8816. let waitTime = 200, checkEval;
  8817. ruleParser.runWait((_checkEval, _waitTime) => {
  8818. if (_checkEval) {
  8819. checkEval = _checkEval;
  8820. }
  8821. if (_waitTime) {
  8822. waitTime = _waitTime;
  8823. }
  8824. });
  8825.  
  8826. if (!orgPage) {
  8827. if (!loadmoreEnd) {
  8828. loadmoreBtn = getLoadMore(iframeDoc);
  8829. if (loadmoreBtn && isVisible(loadmoreBtn, emuIframe.contentWindow)) {
  8830. emuClick(loadmoreBtn, iframeDoc);
  8831. let intv = setInterval(() => {
  8832. loadmoreBtn = getLoadMore(iframeDoc);
  8833. if (!loadmoreBtn || !getBody(document).contains(loadmoreBtn) || !isVisible(loadmoreBtn, emuIframe.contentWindow)) {
  8834. clearInterval(intv);
  8835. loadmoreEnd = true;
  8836. setTimeout(() => {
  8837. checkPage();
  8838. }, 500);
  8839. } else if (isInViewPort(loadmoreBtn)) {
  8840. emuClick(loadmoreBtn, iframeDoc);
  8841. }
  8842. }, 200);
  8843. return;
  8844. } else {
  8845. loadmoreEnd = true;
  8846. }
  8847. }
  8848. if (checkEval && !await checkEval(iframeDoc)) {
  8849. waitTimes = 50;
  8850. setTimeout(() => {
  8851. checkPage();
  8852. }, waitTime);
  8853. return;
  8854. } else {
  8855. if (!nextLink || !nextLink.offsetParent) nextLink = await ruleParser.getNextLink(iframeDoc, true);
  8856. if (nextLink) pageEle = ruleParser.getPageElement(iframeDoc, emuIframe.contentWindow, true);
  8857. if (!pageEle || pageEle.length == 0 || !nextLink) {
  8858. getBody(iframeDoc).scrollTop = 9999999;
  8859. if (iframeDoc.documentElement) {
  8860. iframeDoc.documentElement.scrollTop = 9999999;
  8861. }
  8862. if (waitTimes-- > 0) {
  8863. setTimeout(() => {
  8864. checkPage();
  8865. }, waitTime);
  8866. return;
  8867. }
  8868. }
  8869. }
  8870. if (!pageEle || pageEle.length == 0) {
  8871. returnFalse("Stop as no page when emu");
  8872. return;
  8873. }
  8874. pageEle = [].filter.call(pageEle, ele => {return ele && !compareNodeName(ele, ["style", "script", "meta"])});
  8875. if (compareNodeName(pageEle[0], ["ul"]) || pageEle.length == 1) pageEle = pageEle[0];
  8876. else if (pageEle[0].parentNode == pageEle[1].parentNode) {
  8877. pageEle = pageEle[0].parentNode;
  8878. } else {
  8879. pageEle = pageEle[0];
  8880. }
  8881. if (ruleParser.curSiteRule.smart && orgContent != pageEle.innerHTML) {
  8882. orgContent = pageEle.innerHTML;
  8883. if (waitTimes-- > 0) {
  8884. setTimeout(() => {
  8885. checkPage();
  8886. }, 500);
  8887. return;
  8888. }
  8889. }
  8890. orgPage = pageEle;
  8891. if (nextLink) {
  8892. if (compareNodeName(orgPage, ["img"])) {
  8893. if (!ruleParser.curSiteRule.lazyImgSrc) ruleParser.curSiteRule.lazyImgSrc = "0";
  8894. if (orgPage.src) {
  8895. orgContent = orgPage.src;
  8896. } else {
  8897. setTimeout(() => {
  8898. checkPage();
  8899. }, 500);
  8900. return;
  8901. }
  8902. } else {
  8903. orgContent = orgPage.innerHTML;
  8904. }
  8905. preContent = orgContent;
  8906. if (!isVisible(nextLink, emuIframe.contentWindow)) {
  8907. returnFalse("Stop as next hide when emu");
  8908. } else {
  8909. emuClick(nextLink, iframeDoc);
  8910. setTimeout(() => {
  8911. checkPage();
  8912. }, 500);
  8913. }
  8914. } else {
  8915. returnFalse("Stop as no next when emu");
  8916. }
  8917. return;
  8918. }
  8919. if (!ruleParser.checkStopSign(nextLink, iframeDoc)) {
  8920. return returnFalse("Stop as stopSign");
  8921. }
  8922. if (checkTimes++ > 200) {
  8923. returnFalse("Stop as timeout when emu");
  8924. return;
  8925. }
  8926. if (checkEval && !await checkEval(iframeDoc)) {
  8927. checkTimes = 0;
  8928. setTimeout(() => {
  8929. checkPage();
  8930. }, waitTime);
  8931. return;
  8932. }
  8933. let eles = ruleParser.getPageElement(iframeDoc, emuIframe.contentWindow, true), checkItem;
  8934. if (eles && eles.length > 0) {
  8935. eles = [].filter.call(eles, ele => {return ele && !compareNodeName(ele, ["style", "script", "meta"])});
  8936. if (compareNodeName(eles[0], ["ul"]) || eles.length == 1) checkItem = eles[0];
  8937. else if (eles[0].parentNode == eles[1].parentNode) {
  8938. checkItem = eles[0].parentNode;
  8939. } else {
  8940. checkItem = eles[0];
  8941. }
  8942. }
  8943. if (!checkItem) {
  8944. setTimeout(() => {
  8945. checkPage();
  8946. }, waitTime);
  8947. } else {
  8948. let checkInner;
  8949. if (compareNodeName(checkItem, ["img"])) {
  8950. if (checkItem.src) {
  8951. checkInner = checkItem.src;
  8952. } else {
  8953. setTimeout(() => {
  8954. checkPage();
  8955. }, waitTime);
  8956. return;
  8957. }
  8958. } else {
  8959. checkInner = checkItem.innerHTML;
  8960. }
  8961. if (orgPage != checkItem || checkInner != preContent) {
  8962. changed = true;
  8963. checkNext = 0;
  8964. orgPage = checkItem;
  8965. preContent = checkInner;
  8966. setTimeout(() => {
  8967. checkPage();
  8968. }, 500);
  8969. } else if (changed) {
  8970. checkTimes = 0;
  8971. if (orgContent == preContent && (ruleParser.curSiteRule.smart || ruleParser.curSiteRule.stopSame)) {
  8972. returnFalse("Stop as same content");
  8973. } else {
  8974. orgContent = preContent;
  8975. await ruleParser.hookUrl(iframeDoc);
  8976. if (!nextLink || !nextLink.offsetParent) {
  8977. nextLink = await ruleParser.getNextLink(iframeDoc, true);
  8978. }
  8979. if (!nextLink && ++checkNext < 5) {
  8980. setTimeout(() => {
  8981. checkPage();
  8982. }, waitTime);
  8983. }
  8984. callback(iframeDoc, eles);
  8985. }
  8986. } else {
  8987. if (checkTimes % 10 === 5) {
  8988. if (!nextLink || !nextLink.offsetParent) {
  8989. nextLink = await ruleParser.getNextLink(iframeDoc, true);
  8990. }
  8991. if (nextLink) {
  8992. emuClick(nextLink, iframeDoc);
  8993. }
  8994. }
  8995. setTimeout(() => {
  8996. checkPage();
  8997. }, waitTime);
  8998. }
  8999. }
  9000. }
  9001. if (!emuIframe) {
  9002. let loaded = false;
  9003. emuIframe = document.createElement('iframe');
  9004. emuIframe.name = 'pagetual-iframe';
  9005. let notSetSandbox = typeof ruleParser.curSiteRule.sandbox == 'undefined';
  9006. if (notSetSandbox || ruleParser.curSiteRule.sandbox == true) {
  9007. emuIframe.sandbox = "allow-same-origin allow-scripts allow-popups allow-forms";
  9008. } else if (ruleParser.curSiteRule.sandbox) {
  9009. emuIframe.sandbox = ruleParser.curSiteRule.sandbox;
  9010. }
  9011. emuIframe.width = '100%';
  9012. emuIframe.height = '100%';
  9013. emuIframe.frameBorder = '0';
  9014. 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;';
  9015. emuIframe.addEventListener("load", e => {
  9016. try {
  9017. iframeDoc = emuIframe.contentDocument || emuIframe.contentWindow.document;
  9018. } catch(e) {
  9019. if (e.message && e.message.indexOf("cross-origin") != -1 && notSetSandbox && emuIframe.hasAttribute("sandbox")) {
  9020. emuIframe.removeAttribute("sandbox");
  9021. meetCors = true;
  9022. callback(false, false);
  9023. if (ruleParser.curSiteRule.smart) {
  9024. ruleParser.findNoNext();
  9025. }
  9026. } else {
  9027. returnFalse("Stop as cors");
  9028. }
  9029. return;
  9030. }
  9031. setTimeout(async () => {
  9032. if (meetCors && ruleParser.curSiteRule.smart) {
  9033. ruleParser.smartRules = ruleParser.smartRules.filter(item => {return item && item.url !== ruleParser.curSiteRule.url;});
  9034. storage.setItem("smartRules", ruleParser.smartRules);
  9035. }
  9036. meetCors = false;
  9037. let code = ruleParser.curSiteRule.init;
  9038. if (code) {
  9039. try {
  9040. 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)});
  9041. } catch(e) {
  9042. debug(e);
  9043. }
  9044. } else {
  9045. let refreshByClickSel = ruleParser.curSiteRule.refreshByClick;
  9046. if (iframeDoc && refreshByClickSel) {
  9047. let clickBtn = await waitForElement(refreshByClickSel, iframeDoc);
  9048. await sleep(500);
  9049. await cloneStatus();
  9050. emuClick(clickBtn, iframeDoc);
  9051. await sleep(500);
  9052. } else {
  9053. await cloneStatus();
  9054. await sleep(500);
  9055. }
  9056. }
  9057. if (loaded) return;
  9058. loaded = true;
  9059. checkPage();
  9060. }, 500);
  9061. });
  9062. let code = ruleParser.curSiteRule.iframeInit;
  9063. if (code) {
  9064. let checkReady = setInterval(() => {
  9065. try {
  9066. iframeDoc = emuIframe.contentDocument || (emuIframe.contentWindow && emuIframe.contentWindow.document);
  9067. } catch(e) {
  9068. clearInterval(checkReady);
  9069. return;
  9070. }
  9071. if (iframeDoc) {
  9072. clearInterval(checkReady);
  9073. try {
  9074. Function('win', 'iframe', '"use strict";' + code)(emuIframe.contentWindow, emuIframe);
  9075. } catch(e) {
  9076. debug(e);
  9077. }
  9078. }
  9079. }, 50);
  9080. }
  9081. if (!lastActiveUrl) lastActiveUrl = location.href;
  9082. emuIframe.src = lastActiveUrl;
  9083. getBody(document).appendChild(emuIframe);
  9084. } else {
  9085. if (emuIframe.src != lastActiveUrl || meetCors) {
  9086. emuIframe.src = lastActiveUrl;
  9087. return;
  9088. }
  9089. checkPage();
  9090. }
  9091. }
  9092.  
  9093. var scrollToResizeInited = false;
  9094. var resizePool = [];
  9095. var scrollingToResize = false;
  9096.  
  9097. function isTouchViewPort(element) {
  9098. const viewWidth = window.innerWidth || document.documentElement.clientWidth;
  9099. const viewHeight = window.innerHeight || document.documentElement.clientHeight;
  9100. const {
  9101. top,
  9102. right,
  9103. bottom,
  9104. left,
  9105. } = element.getBoundingClientRect();
  9106.  
  9107. return (
  9108. top < viewHeight &&
  9109. left < viewWidth &&
  9110. right > 0 &&
  9111. bottom > 0
  9112. );
  9113. }
  9114.  
  9115. function resizeIframe(iframe, frameDoc, pageEle) {
  9116. if (targetY >= 0) {
  9117. window.scrollTo({ top: targetY, behavior: 'instant'});
  9118. targetY = -1;
  9119. }
  9120. let curScroll = getBody(document).scrollTop || document.documentElement.scrollTop;
  9121. if (ruleParser.curSiteRule.smart || forceState === 2) {
  9122. let height = (getBody(frameDoc).scrollHeight || getBody(frameDoc).offsetHeight || 500);
  9123. if (!iframe.style.height || parseInt(iframe.style.height) === 0 || height - parseInt(iframe.style.height) > window.innerHeight) {
  9124. iframe.style.height = height + "px";
  9125. iframe.style.minHeight = iframe.style.height;
  9126. }
  9127. iframe.style.width = "100%";
  9128. frameDoc.documentElement.scrollTop = 0;
  9129. frameDoc.documentElement.scrollLeft = 0;
  9130. } else {
  9131. if (pageEle) {
  9132. if (document.body.scrollWidth) frameDoc.documentElement.style.width = document.body.scrollWidth + "px";
  9133. let fitWidth = ruleParser.curSiteRule.fitWidth !== false;
  9134. let targetElement = pageEle[0];
  9135. if (!targetElement) return;
  9136. if (pageEle.length > 1) {
  9137. targetElement = targetElement.parentNode;
  9138. }
  9139. let scrollHeight = targetElement.scrollHeight || targetElement.offsetHeight || 500;
  9140. iframe.style.height = scrollHeight + "px";
  9141. let scrollTop = 0, scrollLeft = 0;
  9142. getBody(frameDoc).scrollTop = 0;
  9143. getBody(frameDoc).scrollLeft = 0;
  9144. while (targetElement && targetElement.offsetParent) {
  9145. targetElement.offsetParent.scrollTop = targetElement.offsetTop;
  9146. if (targetElement.offsetParent.scrollTop == 0) {
  9147. scrollTop += targetElement.offsetTop;
  9148. }
  9149. if (fitWidth) {
  9150. targetElement.offsetParent.scrollLeft = targetElement.offsetLeft;
  9151. if (targetElement.offsetParent.scrollLeft == 0) {
  9152. scrollLeft += targetElement.offsetLeft;
  9153. }
  9154. }
  9155. targetElement = targetElement.offsetParent;
  9156. }
  9157. frameDoc.documentElement.scrollTop = scrollTop;
  9158. frameDoc.documentElement.scrollLeft = scrollLeft;
  9159. if (frameDoc.documentElement.scrollTop == 0 && frameDoc.documentElement.scrollLeft == 0) {
  9160. getBody(frameDoc).scrollTop += scrollTop;
  9161. getBody(frameDoc).scrollLeft += scrollLeft;
  9162. }
  9163. if (!fitWidth && iframe.style.marginLeft == '0px') {
  9164. iframe.style.width = "100vw";
  9165. iframe.style.maxWidth = "100vw";
  9166. iframe.style.minWidth = "100vw";
  9167. var cWidth = document.body.clientWidth || document.documentElement.clientWidth;
  9168. var iWidth = window.innerWidth;
  9169. iframe.style.marginLeft = -iframe.getBoundingClientRect().left - (iWidth - cWidth) / 2 + "px";
  9170. }
  9171. }
  9172. }
  9173. let newScroll = getBody(document).scrollTop || document.documentElement.scrollTop;
  9174. if (newScroll != curScroll) {
  9175. getBody(document).scrollTop = curScroll;
  9176. document.documentElement.scrollTop = curScroll;
  9177. }
  9178. }
  9179.  
  9180. function scrollToResize(e) {
  9181. if (scrollingToResize) return;
  9182. else {
  9183. scrollingToResize = true;
  9184. let resizeHandler = () => {
  9185. let touched = 0;
  9186. for (let i = 0; i < resizePool.length; i++) {
  9187. let resizeArr = resizePool[i];
  9188. let iframe = resizeArr[1]();
  9189. if (isTouchViewPort(iframe)) {
  9190. touched++;
  9191. let pageEle = resizeArr[0]();
  9192. let frameDoc = resizeArr[2]();
  9193. resizeIframe(iframe, frameDoc, pageEle);
  9194. } else if (touched) {
  9195. if (touched == 1) {
  9196. let pageEle = resizeArr[0]();
  9197. let frameDoc = resizeArr[2]();
  9198. resizeIframe(iframe, frameDoc, pageEle);
  9199. }
  9200. break;
  9201. } else if (!iframe.parentNode) {
  9202. resizePool.splice(i, 1);
  9203. break;
  9204. }
  9205. }
  9206. };
  9207. setTimeout(() => {
  9208. scrollingToResize = false;
  9209. }, 300);
  9210. resizeHandler();
  9211. }
  9212. }
  9213.  
  9214. var curForceIframe;
  9215. function forceIframe(url, callback) {
  9216. url = url.indexOf('=') == -1 ? url.replace(/#[^#]*/,"") : url;
  9217. let curIframe = document.createElement('iframe'), iframeDoc, pageElement = null, inAction = true;
  9218. let loadedHandler = () => {
  9219. let getPageEle = () => {
  9220. if (ruleParser.curSiteRule.smart) {
  9221. return null;
  9222. } else {
  9223. if (!pageElement || pageElement.length === 0 || !pageElement[0].offsetParent) {
  9224. pageElement = ruleParser.getPageElement(iframeDoc, curIframe.contentWindow);
  9225. }
  9226. return pageElement;
  9227. }
  9228. };
  9229. resizeIframe(curIframe, iframeDoc, getPageEle());
  9230. let loaded = curIframe.getAttribute("loaded");
  9231. if (loaded == "true") {
  9232. return;
  9233. }
  9234. curIframe.setAttribute("loaded", "true");
  9235. let getIframe = () => {
  9236. return curIframe;
  9237. };
  9238. let getFrameDoc = () => {
  9239. return iframeDoc;
  9240. };
  9241. ruleParser.insertPage(iframeDoc, [], url, ele => {
  9242. callback(curIframe, loaded == "refresh");
  9243. inAction = false;
  9244. }, true);
  9245. if (!loaded) {
  9246. resizePool.push([getPageEle, getIframe, getFrameDoc]);
  9247. }
  9248. };
  9249. let checkIframeTimer = setInterval(() => {
  9250. if (!curIframe.parentNode) {
  9251. clearInterval(checkIframeTimer);
  9252. return curIframe.getAttribute("loaded") == "true" || callback(false);
  9253. }
  9254. }, 500);
  9255. let code = ruleParser.curSiteRule.iframeInit;
  9256. if (code) {
  9257. let checkReady = setInterval(() => {
  9258. try {
  9259. iframeDoc = curIframe.contentDocument || (curIframe.contentWindow && curIframe.contentWindow.document);
  9260. } catch(e) {
  9261. clearInterval(checkReady);
  9262. return;
  9263. }
  9264. if (iframeDoc) {
  9265. clearInterval(checkReady);
  9266. try {
  9267. Function('win', 'iframe', '"use strict";' + code)(curIframe.contentWindow, curIframe);
  9268. } catch(e) {
  9269. debug(e);
  9270. }
  9271. }
  9272. }, 50);
  9273. }
  9274. let waitTime = 300, checkEval;
  9275. ruleParser.runWait((_checkEval, _waitTime) => {
  9276. if (_checkEval) {
  9277. checkEval = _checkEval;
  9278. }
  9279. if (_waitTime) {
  9280. waitTime = _waitTime;
  9281. }
  9282. });
  9283. async function checkIframe() {
  9284. if (checkEval && !await checkEval(iframeDoc)) {
  9285. setTimeout(() => {
  9286. checkIframe();
  9287. }, waitTime);
  9288. return;
  9289. }
  9290. loadedHandler();
  9291. }
  9292. curIframe.name = 'pagetual-iframe';
  9293. curIframe.sandbox = "allow-same-origin allow-scripts allow-popups allow-forms";
  9294. curIframe.frameBorder = '0';
  9295. curIframe.scrolling = "no";
  9296. 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;';
  9297. curIframe.addEventListener("load", async e => {
  9298. clearInterval(checkIframeTimer);
  9299. if (isPause) return callback(false);
  9300. try {
  9301. iframeDoc = curIframe.contentDocument || curIframe.contentWindow.document;
  9302. } catch(e) {
  9303. debug("Stop as cors");
  9304. isPause = true;
  9305. callback(false);
  9306. return;
  9307. }
  9308. let css;
  9309. if (rulesData.customCss && ruleParser.curSiteRule.css) {
  9310. let globalCssArr = rulesData.customCss.split("inIframe:");
  9311. let ruleCssArr = ruleParser.curSiteRule.css.split("inIframe:");
  9312. let mainCss = globalCssArr[0] + ruleCssArr[0], inCss = (globalCssArr[1] || "") + (ruleCssArr[1] || "");
  9313. css = mainCss + (inCss ? ("inIframe:" + inCss) : "");
  9314. } else {
  9315. css = ruleParser.curSiteRule.css || rulesData.customCss;
  9316. }
  9317. if (css) {
  9318. let cssArr = css.split("inIframe:");
  9319. if (cssArr && cssArr.length > 1) {
  9320. let styleEle = iframeDoc.createElement("style");
  9321. styleEle.innerHTML = cssArr[1];
  9322. iframeDoc.head.appendChild(styleEle);
  9323. }
  9324. }
  9325. curIframe.style.height = "";
  9326. checkIframe();
  9327. iframeDoc.addEventListener('wheel', e => {
  9328. document.dispatchEvent(new Event('wheel'));
  9329. }, true);
  9330. });
  9331. let checkTimes = 0, findPageEle = false;
  9332. let forceRefresh = e => {
  9333. if (inAction || !iframeDoc) return;
  9334. inAction = true;
  9335. let foundNext = () => {
  9336. document.removeEventListener("scroll", forceRefresh);
  9337. }
  9338. setTimeout(async () => {
  9339. inAction = false;
  9340. if (!ruleParser.nextLinkHref && !isPause) {
  9341. checkTimes++;
  9342. await ruleParser.getNextLink(iframeDoc, true);
  9343. if (ruleParser.nextLinkHref) {
  9344. foundNext();
  9345. if (isLoading) isLoading = false;
  9346. } else if (checkTimes >= 10) {
  9347. foundNext();
  9348. } else if (checkTimes >= 3 && !findPageEle) {
  9349. if (!pageElement) pageElement = ruleParser.getPageElement(iframeDoc, curIframe.contentWindow);
  9350. if (!pageElement) {
  9351. inAction = true;
  9352. curIframe.contentWindow.location.reload();
  9353. } else {
  9354. findPageEle = true;
  9355. }
  9356. }
  9357. } else {
  9358. foundNext();
  9359. }
  9360. }, 100);
  9361. };
  9362. document.addEventListener("scroll", forceRefresh);
  9363. curIframe.src = url;
  9364. curForceIframe = curIframe;
  9365. let insert = ruleParser.getInsert();
  9366. let body = getBody(document);
  9367. let curScroll = body.scrollTop || document.documentElement.scrollTop;
  9368. if (forceState == 2) {
  9369. document.documentElement.appendChild(loadingDiv);
  9370. body.appendChild(curIframe);
  9371. let bodyStyle = getComputedStyle(body);
  9372. if (bodyStyle.display == "flex" || bodyStyle.display == "inline-flex") {
  9373. body.style.flexDirection = "column";
  9374. }
  9375. } else {
  9376. ruleParser.insertElement(curIframe);
  9377. }
  9378. body.scrollTop = curScroll;
  9379. document.documentElement.scrollTop = curScroll;
  9380.  
  9381. if (!scrollToResizeInited) {
  9382. scrollToResizeInited = true;
  9383. document.addEventListener("scroll", scrollToResize);
  9384. }
  9385. return curIframe;
  9386. }
  9387.  
  9388. function loadPageOver() {
  9389. isLoading = false;
  9390. stopScroll = true;
  9391. setTimeout(() => {stopScroll = false;}, 300);
  9392. if (loadingDiv.parentNode) {
  9393. loadingDiv.parentNode.removeChild(loadingDiv);
  9394. }
  9395. if (rate !== 1 && !clickMode) {
  9396. setTimeout(() => {
  9397. if (distToBottom() < bottomGap) {
  9398. nextPage();
  9399. }
  9400. }, 1);
  9401. }
  9402. if (sideController.inited) {
  9403. sideController.frame.classList.remove("loading");
  9404. }
  9405. }
  9406.  
  9407. function checkAutoLoadNum() {
  9408. if (autoLoadNum >= 0) {
  9409. if (autoLoadNum !== 0 && --autoLoadNum === 0) {
  9410. autoLoadNum = -1;
  9411. } else {
  9412. setTimeout(() => nextPage(), 1);
  9413. }
  9414. }
  9415. }
  9416.  
  9417. async function nextPage() {
  9418. if (isPause || isLoading || forceState === 1) return;
  9419. if (ruleParser.curSiteRule.delay) {
  9420. try {
  9421. let checkDelay = ((typeof ruleParser.curSiteRule.delay === 'function') ? ruleParser.curSiteRule.delay : Function('"use strict";' + ruleParser.curSiteRule.delay))();
  9422. if (!checkDelay) return;
  9423. } catch(e) {
  9424. debug(e);
  9425. }
  9426. }
  9427. let nextLink = ruleParser.nextLinkHref;
  9428. if (!nextLink) {
  9429. isLoading = true;
  9430. if (curPage === 1) {
  9431. await ruleParser.getNextLink(document, true);
  9432. nextLink = ruleParser.nextLinkHref;
  9433. }
  9434. if (!nextLink) {
  9435. if (curPage === 1) {
  9436. if (ruleParser.curSiteRule.pinUrl) {
  9437. setTimeout(() => {isLoading = false;}, 500);
  9438. } else if (tryTimes++ < 5) {
  9439. setTimeout(() => {isLoading = false;}, 1000);
  9440. } else {
  9441. ruleParser.findNoNext();
  9442. }
  9443. } else if (!showedLastPageTips) {
  9444. ruleParser.reachedLastPage();
  9445. showedLastPageTips = true;
  9446. }
  9447. return;
  9448. }
  9449. isLoading = false;
  9450. }
  9451. showedLastPageTips = false;
  9452. let pvGallery = document.querySelector("span.pv-gallery-container");
  9453. if (pvGallery && pvGallery.style.display !== "none") return;
  9454. let insert = ruleParser.getInsert();
  9455. if (insert) {
  9456. if (curPage === 1) {
  9457. initView();
  9458. }
  9459. /*if (curPage == 1) {
  9460. window.postMessage({
  9461. command: 'pagetual.insert'
  9462. }, '*');
  9463. }*/
  9464. let isJs = ruleParser.curSiteRule.action == 3 || ruleParser.hrefIsJs(nextLink);
  9465. if (!isJs) {
  9466. emuIframe = null;
  9467. lastActiveUrl = nextLink;
  9468. if (location.protocol === "https:" && /^http:/.test(nextLink)) {
  9469. nextLink = nextLink.replace(/^http/, "https");
  9470. }
  9471. }
  9472. isLoading = true;
  9473. if (curPage !== 1 || !isJs || !ruleParser.curSiteRule.smart) {
  9474. ruleParser.beginLoading(loadingDiv);
  9475. } else {
  9476. if (sideController.inited) {
  9477. sideController.frame.classList.add("loading");
  9478. }
  9479. }
  9480. let sleep = ruleParser.curSiteRule.sleep || 0;
  9481. setTimeout(() => {
  9482. if (ruleParser.curSiteRule.pageElementByJs) {
  9483. var over = eles => {
  9484. if (urlChanged || isPause) {
  9485. loadPageOver();
  9486. return;
  9487. }
  9488. if (eles) {
  9489. ruleParser.insertPage(document, eles, nextLink, () => {
  9490. createPageBar(nextLink);
  9491. checkAutoLoadNum();
  9492. }, true);
  9493. } else {
  9494. debug("Stop as no page when get by js");
  9495. isPause = true;
  9496. loadPageOver();
  9497. }
  9498. };
  9499. try {
  9500. ((typeof ruleParser.curSiteRule.pageElementByJs === 'function') ? ruleParser.curSiteRule.pageElementByJs : Function("over", "pageNum",'"use strict";' + ruleParser.curSiteRule.pageElementByJs))(over, curPage);
  9501. } catch(e) {
  9502. debug(e);
  9503. }
  9504. } else if ((forceState === 2 || ruleParser.curSiteRule.action == 2) && !isJs) {
  9505. forceIframe(nextLink, (iframe, refresh) => {
  9506. if (urlChanged || isPause) {
  9507. loadPageOver();
  9508. return;
  9509. }
  9510. if (!refresh) {
  9511. let pageBar = createPageBar(nextLink);
  9512. if (pageBar && iframe && iframe.parentNode) iframe.parentNode.insertBefore(pageBar, iframe);
  9513. }
  9514. loadPageOver();
  9515. checkAutoLoadNum();
  9516. });
  9517. } else if ((forceState === 3 || ruleParser.curSiteRule.action == 1) && !isJs) {
  9518. requestFromIframe(nextLink, async (doc, eles) => {
  9519. if (urlChanged || isPause) {
  9520. loadPageOver();
  9521. return;
  9522. }
  9523. if (eles) {
  9524. await ruleParser.insertPage(doc, eles, nextLink, () => {
  9525. createPageBar(nextLink);
  9526. checkAutoLoadNum();
  9527. }, true);
  9528. } else {
  9529. loadPageOver();
  9530. if (autoLoadNum >= 0) {
  9531. setTimeout(() => nextPage(), 2000);
  9532. }
  9533. }
  9534. });
  9535. } else {
  9536. if (!isJs) {
  9537. requestDoc(nextLink, (eles) => {
  9538. if (urlChanged || isPause) {
  9539. loadPageOver();
  9540. return;
  9541. }
  9542. if (eles) {
  9543. createPageBar(nextLink);
  9544. checkAutoLoadNum();
  9545. } else {
  9546. loadPageOver();
  9547. if (autoLoadNum >= 0) {
  9548. setTimeout(() => nextPage(), 2000);
  9549. }
  9550. }
  9551. });
  9552. } else {
  9553. emuPage((doc, eles) => {
  9554. if (urlChanged || isPause) {
  9555. loadPageOver();
  9556. return;
  9557. }
  9558. if (eles) {
  9559. ruleParser.insertPage(doc, eles, "", () => {
  9560. createPageBar(nextLink);
  9561. checkAutoLoadNum();
  9562. }, true);
  9563. } else {
  9564. loadPageOver();
  9565. if (autoLoadNum >= 0) {
  9566. setTimeout(() => nextPage(), 2000);
  9567. }
  9568. }
  9569. });
  9570. }
  9571. }
  9572. }, sleep);
  9573. }
  9574. }
  9575.  
  9576. function init() {
  9577. if (document.readyState === 'loading' || document.readyState === 'uninitialized') {
  9578. let domReady = e => {
  9579. initRules(() => {
  9580. initPage();
  9581. });
  9582. document.removeEventListener("DOMContentLoaded", domReady, false);
  9583. };
  9584. document.addEventListener("DOMContentLoaded", domReady, false);
  9585. } else {
  9586. initRules(() => {
  9587. initPage();
  9588. });
  9589. }
  9590. }
  9591.  
  9592. function visibilitychangeHandler() {
  9593. document.removeEventListener('visibilitychange', visibilitychangeHandler);
  9594. init();
  9595. }
  9596.  
  9597. setTimeout(() => {
  9598. if (document.hidden) {
  9599. document.addEventListener('visibilitychange', visibilitychangeHandler);
  9600. } else {
  9601. init();
  9602. }
  9603. }, 300);
  9604. })();