东方永页机

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

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

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