东方永页机

自动翻页脚本 - 自动加载并拼接下一分页内容,无需规则驱动支持任意网页

目前为 2022-07-02 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Pagetual
  3. // @name:zh-CN 东方永页机
  4. // @name:zh-TW 東方永頁機
  5. // @name:ja 東方永頁機
  6. // @name:ru Пейджетуал
  7. // @name:de Pagetual
  8. // @name:es Pagetual
  9. // @name:fr Pagetual
  10. // @name:it Pagetual
  11. // @name:ko 東方永頁機
  12. // @namespace hoothin
  13. // @version 1.9.26.15
  14. // @description Perpetual pages - Most powerful Auto Pager script. Auto loading next paginated web pages and inserting into current page.
  15. // @description:zh-CN 自动翻页脚本 - 自动加载并拼接下一分页内容,无需规则驱动支持任意网页
  16. // @description:zh-TW 自動翻頁脚本 - 自動加載並拼接下一分頁內容,無需規則驅動支持任意網頁
  17. // @description:ja Webページを自動で読み込み継ぎ足し表示を行うブラウザ拡張です
  18. // @description:ru Просто автоматически загрузите следующую страницу
  19. // @description:de Laden Sie einfach automatisch die nächste Seite
  20. // @description:es Carga automática de páginas web paginadas
  21. // @description:fr Chargement automatique des pages Web paginées
  22. // @description:it Caricamento automatico di pagine Web impaginate
  23. // @description:ko 다음 페이지를 자동으로 로드하세요
  24. // @author hoothin
  25. // @match *://*/*
  26. // @license MIT
  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.xmlHttpRequest
  38. // @grant GM.registerMenuCommand
  39. // @grant GM.notification
  40. // @grant GM.getValue
  41. // @grant GM.setValue
  42. // @grant GM.addStyle
  43. // @grant GM.openInTab
  44. // @grant GM.deleteValue
  45. // @grant GM.info
  46. // @supportURL https://github.com/hoothin/UserScripts/issues
  47. // @connect wedata.net
  48. // @connect githubusercontent.com
  49. // @run-at document-idle
  50. // @exclude http://www.toodledo.com/tasks/*
  51. // @exclude http*://maps.google.com*/*
  52. // @exclude *://www.google.*/_/chrome/newtab*
  53. // @exclude *://mega.*/*
  54. // @exclude *://*.mega.*/*
  55. // @exclude *://*.youku.com/v_*
  56. // @exclude *://*pan.baidu.com
  57. // @exclude *://*.iqiyi.com/v_*
  58. // @exclude *://*.iqiyi.com/w_*
  59. // @exclude *://*.iqiyi.com/a_*
  60. // @exclude *://*.le.com/ptv/vplay/*
  61. // @exclude *://v.qq.com/x/cover/*
  62. // @exclude *://v.qq.com/x/page/*
  63. // @exclude *://v.qq.com/tv/*
  64. // @exclude *://*.tudou.com/listplay/*
  65. // @exclude *://*.tudou.com/albumplay/*
  66. // @exclude *://*.tudou.com/programs/view/*
  67. // @exclude *://*.mgtv.com/b/*
  68. // @exclude *://film.sohu.com/album/*
  69. // @exclude *://tv.sohu.com/v/*
  70. // @exclude *://*.bilibili.com/video/*
  71. // @exclude *://*.bilibili.com/bangumi/play/*
  72. // @exclude *://*.baofeng.com/play/*
  73. // @exclude *://vip.pptv.com/show/*
  74. // @exclude *://v.pptv.com/show/*
  75. // @exclude *://www.le.com/ptv/vplay/*
  76. // @exclude *://www.wasu.cn/Play/show/*
  77. // @exclude *://m.v.qq.com/*
  78. // @exclude *://m.iqiyi.com/*
  79. // @exclude *://m.youku.com/alipay_video/*
  80. // @exclude *://m.mgtv.com/b/*
  81. // @exclude *://m.tv.sohu.com/v/*
  82. // @exclude *://m.film.sohu.com/album/*
  83. // @exclude *://m.le.com/ptv/vplay/*
  84. // @exclude *://m.pptv.com/show/*
  85. // @exclude *://m.acfun.cn/v/*
  86. // @exclude *://m.bilibili.com/video/*
  87. // @exclude *://m.bilibili.com/anime/*
  88. // @exclude *://m.bilibili.com/bangumi/play/*
  89. // @exclude *://m.wasu.cn/Play/show/*
  90. // @exclude *://www.youtube.com
  91. // @exclude *://www.youtube.com/
  92. // @exclude *://www.youtube.com/watch*
  93. // @exclude *://baike.baidu.com/*
  94. // @exclude *://*.instagram.com/*
  95. // @exclude *://order.jd.com/*
  96. // @exclude *://pagetual.hoothin.com/*
  97. // @exclude *://hoothin.github.io/PagetualGuide/*
  98. // @exclude *://wenku.baidu.com/view/*
  99. // @connect *
  100. // ==/UserScript==
  101.  
  102. (function() {
  103. 'use strict';
  104.  
  105. if (window.name === 'pagetual-iframe' || (window.frameElement && window.frameElement.name === 'pagetual-iframe')) {
  106. var domloaded = function (){
  107. window.scroll(window.scrollX, 999999);
  108. window.parent.postMessage('pagetual-iframe:DOMLoaded', '*');
  109. };
  110. if(window.opera){
  111. document.addEventListener('DOMContentLoaded', domloaded, false);
  112. } else {
  113. domloaded();
  114. }
  115. return;
  116. }
  117.  
  118. if(window.top != window.self){
  119. try{
  120. if (top.location.hostname != window.location.hostname || window.top != window.parent) {
  121. return;
  122. }
  123. }catch(e){
  124. return;
  125. }
  126. }
  127.  
  128. const lang = navigator.appName=="Netscape"?navigator.language:navigator.userLanguage;
  129. let config={};
  130. switch (lang){
  131. case "zh-CN":
  132. case "zh-SG":
  133. config={
  134. enableDebug:"调试模式,输出信息至控制台",
  135. disable:"暂时禁用",
  136. disableSite:"切换禁用状态",
  137. disableSiteTips:"已在此站禁用",
  138. enableSiteTips:"已在此站启用",
  139. enable:"启用翻页",
  140. toTop:"回到顶部",
  141. toBottom:"前往页尾",
  142. current:"当前页",
  143. forceIframe:"强制拼接",
  144. cancelForceIframe:"取消强制拼接",
  145. configure:"打开配置页",
  146. firstUpdate:"点击此处初始化规则",
  147. update:"更新规则",
  148. click2update:"点击立即更新规则",
  149. loadNow:"立即翻页",
  150. loadConfirm:"要翻几页?(0为不间断)",
  151. noNext:"没有找到下一页,请新建规则",
  152. passSec:"更新于 #t# 秒前",
  153. passMin:"更新于 #t# 分钟前",
  154. passHour:"更新于 #t# 小时前",
  155. passDay:"更新于 #t# 天前",
  156. cantDel:"无法删除内置规则",
  157. confirmDel:"是否确认要删除此规则?",
  158. updateSucc:"更新成功",
  159. beginUpdate:"正在更新,请耐心等待,不要关闭页面",
  160. customUrls:"导入规则url,一行一条,AutoPagerize 格式规则需要以\"0|\"开头",
  161. customRules:"输入【东方永页机】格式的自定义规则",
  162. save:"保存设置",
  163. loadingText:"少女祈祷中...",
  164. opacity:"不透明值",
  165. hideBar:"隐藏分页隔条",
  166. dbClick2Stop:"空白处双击暂停翻页",
  167. sortTitle:"排序在下次更新规则后生效",
  168. autoRun:"自动启用,否则为白名单模式",
  169. inputPageNum:"输入页码跳转",
  170. enableHistory:"翻页后写入历史记录",
  171. initRun:"打开页面后立即尝试翻页,否则滚动至页尾再翻页",
  172. preload:"翻页前预读下一页,加速浏览",
  173. click2ImportRule:"点击下方添加特殊规则库,并静待更新成功:",
  174. forceAllBody:"是否拼接整个页面?",
  175. openInNewTab:"使拼接页面的内容在新页面打开",
  176. importSucc:"导入成功",
  177. editCurrent:"自定义此站规则",
  178. editBlacklist:"编辑黑名单网址,一行一条,支持? *通配符",
  179. upBtnImg:"回到页首图标",
  180. downBtnImg:"前往页尾图标",
  181. dbClick2StopCtrl:"Ctrl 键",
  182. dbClick2StopAlt:"Alt 键",
  183. dbClick2StopShift:"Shift 键",
  184. dbClick2StopMeta:"Meta 键",
  185. dbClick2StopKey:"快捷键"
  186. };
  187. break;
  188. case "zh-TW":
  189. case "zh-HK":
  190. config={
  191. enableDebug:"調試模式,輸出信息至控制台",
  192. disable:"暫時禁用",
  193. disableSite:"切換禁用狀態",
  194. disableSiteTips:"已在此站禁用",
  195. enableSiteTips:"已在此站啟用",
  196. enable:"啟用翻頁",
  197. toTop:"回到頂部",
  198. toBottom:"前往頁尾",
  199. current:"當前頁",
  200. forceIframe:"強制拼接",
  201. cancelForceIframe:"取消强制拼接",
  202. configure:"打開配置頁",
  203. firstUpdate:"點擊此處初始化規則",
  204. update:"更新規則",
  205. click2update:"點擊立即更新規則",
  206. loadNow:"立即翻頁",
  207. loadConfirm:"要翻几頁?(0為不間斷)",
  208. noNext:"沒有找到下一頁,請新建規則",
  209. passSec:"更新于 #t# 秒前",
  210. passMin:"更新于 #t# 分鐘前",
  211. passHour:"更新于 #t# 小時前",
  212. passDay:"更新于 #t# 天前",
  213. cantDel:"無法刪除内置規則",
  214. confirmDel:"是否確認要刪除此規則?",
  215. updateSucc:"更新成功",
  216. beginUpdate:"正在更新,請稍候",
  217. customUrls:"導入規則url,一行一條,AutoPagerize 格式規則需要以\"0|\"開頭",
  218. customRules:"輸入【東方永頁機】格式的自定義規則",
  219. save:"存儲設置",
  220. loadingText:"少女祈禱中...",
  221. opacity:"不透明值",
  222. hideBar:"隱藏分頁隔條",
  223. dbClick2Stop:"空白處雙擊暫停翻頁",
  224. sortTitle:"排序在下次更新規則後生效",
  225. autoRun:"自動啓用,否則為白名單模式",
  226. inputPageNum:"輸入頁碼跳轉",
  227. enableHistory:"翻頁后寫入歷史記錄",
  228. initRun:"打開頁面后立即嘗試翻頁,否則滾動至頁尾再翻頁",
  229. preload:"翻頁前預讀下一頁,加速瀏覽",
  230. click2ImportRule:"點擊下方添加特殊規則庫,并靜待更新成功:",
  231. forceAllBody:"是否拼接整個頁面?",
  232. openInNewTab:"使拼接頁面的内容在新頁面打開",
  233. importSucc:"導入成功",
  234. editCurrent:"自定義此站規則",
  235. editBlacklist:"編輯黑名單網址,一行一條,支持? *通配符",
  236. upBtnImg:"回到頁首圖標",
  237. downBtnImg:"前往頁尾圖標",
  238. dbClick2StopCtrl:"Ctrl 鍵",
  239. dbClick2StopAlt:"Alt 鍵",
  240. dbClick2StopShift:"Shift 鍵",
  241. dbClick2StopMeta:"Meta 鍵",
  242. dbClick2StopKey:"快捷鍵"
  243. };
  244. break;
  245. case "ja":
  246. config = {
  247. enableDebug:"デバッグモード",
  248. disable: "一時的に無効にする",
  249. disableSite:"無効状態の切り替え",
  250. disableSiteTips:"このサイトで既に無効になっています",
  251. enableSiteTips:"このサイトで既に有効になっています",
  252. enable: "ページめくりを有効にする",
  253. toTop: "トップに戻る",
  254. toBottom: "ページの下部に移動",
  255. current: "現在のページ",
  256. forceIframe: "強制ステッチ",
  257. cancelForceIframe: "強制ステッチをキャンセル",
  258. configure: "設定ページを開く",
  259. firstUpdate:"ここをクリックしてルールを初期化します",
  260. update: "更新ルール",
  261. click2update:"今すぐルールを更新してください",
  262. loadNow:"今すぐページをめくる",
  263. loadConfirm:"数ページめくりたいですか?(0は途切れない)",
  264. noNext:"次のページが見つかりません、新しいルールを作成してください",
  265. passSec: "#t#秒前に更新",
  266. passMin: "#t#分前に更新",
  267. passHour: "#t#時間前に更新",
  268. passDay: "#t#日前に更新",
  269. cantDel: "組み込みルールを削除できません",
  270. confirmDel: "このルールを削除してもよろしいですか?",
  271. updateSucc: "更新に成功しました",
  272. beginUpdate: "更新中、お待ちください",
  273. customUrls: "インポートルールのURL、1行に1つ、AutoPagerizeフォーマットルールは\"0|\"で始まる必要があります",
  274. customRules: "【東方永頁機】の形式でカスタムルールを入力してください",
  275. save: "設定を保存",
  276. loadingText: "少女祈祷中...",
  277. opacity:"不透明値",
  278. hideBar:"ページ区切り文字を非表示にします",
  279. dbClick2Stop:"空白部分をダブルクリックしてページめくりを一時停止します",
  280. sortTitle:"並べ替えは、次のルールの更新後に有効になります",
  281. autoRun:"自動的に有効",
  282. inputPageNum:"ジャンプするページ番号を入力",
  283. enableHistory:"ページめくり後の履歴を書く",
  284. initRun:"Webページを開いた直後にページをめくる",
  285. preload:"事前に次のページを読む",
  286. click2ImportRule:"以下をクリックして、ルールベースを追加します:",
  287. forceAllBody:"フルページ埋め込み?",
  288. openInNewTab:"スプライスされたページのコンテンツを新しいページで開きます",
  289. importSucc:"インポート完了",
  290. editCurrent:"現在のルールの編集",
  291. editBlacklist:"ブラックリストのURLを編集し、1行ずつ、サポート? *ワイルドカード",
  292. upBtnImg:"トップアイコンに戻る",
  293. downBtnImg:"フッターアイコンに移動",
  294. dbClick2StopCtrl:"Ctrlキー",
  295. dbClick2StopAlt:"Altキー",
  296. dbClick2StopShift:"Shiftキー",
  297. dbClick2StopMeta:"Metaキー",
  298. dbClick2StopKey:"Shortcutキー"
  299. };
  300. break;
  301. default:
  302. config={
  303. enableDebug:"Enable debug output",
  304. disable:"Disable",
  305. disableSite:"Toggle disabled state",
  306. disableSiteTips:"Disabled on this site",
  307. enableSiteTips:"Enabled on this site",
  308. enable:"Enable",
  309. toTop:"To Top",
  310. toBottom:"To Bottom",
  311. current:"Current Page",
  312. forceIframe:"Force to join",
  313. cancelForceIframe:"Cancel Force join",
  314. configure:"Configure",
  315. firstUpdate:"Click here to initialize the rules",
  316. update:"Update rules",
  317. click2update:"Click to update rules from url now",
  318. loadNow:"Load next now",
  319. loadConfirm:"How much pages do you want to load? (0 means infinite)",
  320. noNext:"No next link found, please create a new rule",
  321. passSec:"Updated #t# seconds ago",
  322. passMin:"Updated #t# minutes ago",
  323. passHour:"Updated #t# hours ago",
  324. passDay:"Updated #t# days ago",
  325. cantDel:"Can't delete buildin rules",
  326. confirmDel:"Are you sure you want to delete this rule?",
  327. updateSucc:"Update succeeded",
  328. beginUpdate:"Begin update, wait a minute please",
  329. customUrls:"Import rule url, One url per line, rules on AutoPagerize format need to start with \"0|\"",
  330. customRules:"Input custom rules with [Pagetual] format",
  331. save:"Save",
  332. loadingText:"Shojo Now Loading...",
  333. opacity:"Opacity",
  334. hideBar:"hide the paging spacer",
  335. dbClick2Stop:"Double-click on the blank space to pause",
  336. sortTitle:"Sorting takes effect after the next rule update",
  337. autoRun:"Auto run (black list mode)",
  338. inputPageNum:"Enter page number to jump",
  339. enableHistory:"Write history after page turning",
  340. initRun:"Turn pages immediately after opening",
  341. preload:"Preload next page for speeding up",
  342. click2ImportRule:"Click to import base rules link, then wait until the update is complete:",
  343. forceAllBody:"Join full body of page?",
  344. openInNewTab:"Open urls of additions in new tab",
  345. importSucc:"Import completed",
  346. editCurrent:"Edit rule for current",
  347. editBlacklist:"Edit the blacklist urls, line by line, Support ? * for wildcard",
  348. upBtnImg:"Icon of back to top",
  349. downBtnImg:"Icon of go to footer",
  350. dbClick2StopCtrl:"Ctrl key",
  351. dbClick2StopAlt:"Alt key",
  352. dbClick2StopShift:"Shift key",
  353. dbClick2StopMeta:"Meta key",
  354. dbClick2StopKey:"Shortcut key"
  355. };
  356. break;
  357. }
  358. var i18n=(name, param)=>{
  359. return config[name]?config[name].replace("#t#",param):name;
  360. };
  361.  
  362. var noRuleTest=false;
  363. var enableDebug=true;
  364. var debug=str=>{
  365. if(enableDebug){
  366. console.log(
  367. `%cPagetual v.${_GM_info.script.version}】 debug`,
  368. 'color: yellow;font-size: x-large;font-weight: bold;'
  369. );
  370. console.debug(str);
  371. }
  372. };
  373.  
  374. var _GM_xmlhttpRequest,_GM_registerMenuCommand,_GM_notification,_GM_addStyle,_GM_openInTab,_GM_info;
  375. if(typeof GM_xmlhttpRequest!='undefined'){
  376. _GM_xmlhttpRequest=GM_xmlhttpRequest;
  377. }else if(typeof GM!='undefined' && typeof GM.xmlHttpRequest!='undefined'){
  378. _GM_xmlhttpRequest=GM.xmlHttpRequest;
  379. }else{
  380. _GM_xmlhttpRequest=(f)=>{fetch(f.url).then(response=>response.text()).then(data=>{let res={response:data};f.onload(res)}).catch(f.onerror())};
  381. }
  382. if(typeof GM_registerMenuCommand!='undefined'){
  383. _GM_registerMenuCommand=GM_registerMenuCommand;
  384. }else if(typeof GM!='undefined' && typeof GM.registerMenuCommand!='undefined'){
  385. _GM_registerMenuCommand=GM.registerMenuCommand;
  386. }else{
  387. _GM_registerMenuCommand=(s,f)=>{};
  388. }
  389. if(typeof GM_info!='undefined'){
  390. _GM_info=GM_info;
  391. }else if(typeof GM!='undefined' && typeof GM.info!='undefined'){
  392. _GM_info=GM.info;
  393. }else{
  394. _GM_info={script:1};
  395. }
  396. if(typeof GM_notification!='undefined'){
  397. _GM_notification=GM_notification;
  398. }else if(typeof GM!='undefined' && typeof GM.notification!='undefined'){
  399. _GM_notification=GM.notification;
  400. }else{
  401. _GM_notification=(s)=>{showTips(s)};
  402. }
  403. if(typeof GM_openInTab!='undefined'){
  404. _GM_openInTab=GM_openInTab;
  405. }else if(typeof GM!='undefined' && typeof GM.openInTab!='undefined'){
  406. _GM_openInTab=GM.openInTab;
  407. }else{
  408. _GM_openInTab=(s,t)=>{window.open(s)};
  409. }
  410. if(typeof GM_addStyle!='undefined'){
  411. _GM_addStyle=GM_addStyle;
  412. }else if(typeof GM!='undefined' && typeof GM.addStyle!='undefined'){
  413. _GM_addStyle=GM.addStyle;
  414. }else{
  415. _GM_addStyle=cssStr=>{
  416. let styleEle=document.createElement("style");
  417. styleEle.innerHTML=cssStr;
  418. document.head.appendChild(styleEle);
  419. };
  420. }
  421. var _unsafeWindow=(typeof unsafeWindow=='undefined')?window:unsafeWindow;//兼容 ios userscripts 的寫法
  422. var storage={
  423. supportGM: typeof GM_getValue=='function' && typeof GM_getValue('a','b')!='undefined',
  424. supportGMPromise: typeof GM!='undefined' && typeof GM.getValue=='function' && typeof GM.getValue('a','b')!='undefined',
  425. mxAppStorage:(function(){
  426. try{
  427. return window.external.mxGetRuntime().storage;
  428. }catch(e){
  429. }
  430. })(),
  431. operaUJSStorage:(function(){
  432. try{
  433. return window.opera.scriptStorage;
  434. }catch(e){
  435. }
  436. })(),
  437. setItem:function(key,value){
  438. if(this.operaUJSStorage){
  439. this.operaUJSStorage.setItem(key,value);
  440. }else if(this.mxAppStorage){
  441. this.mxAppStorage.setConfig(key,value);
  442. }else if(this.supportGM){
  443. GM_setValue(key,value);
  444. if(value==="" && typeof GM_deleteValue!='undefined'){
  445. GM_deleteValue(key);
  446. }
  447. }else if(this.supportGMPromise){
  448. GM.setValue(key,value);
  449. if(value==="" && typeof GM!='undefined' && typeof GM.deleteValue!='undefined'){
  450. GM.deleteValue(key);
  451. }
  452. }else if(window.localStorage){
  453. window.localStorage.setItem(key,value);
  454. }
  455. },
  456. getItem:function(key,cb){
  457. var value;
  458. if(this.operaUJSStorage){
  459. value=this.operaUJSStorage.getItem(key);
  460. }else if(this.mxAppStorage){
  461. value=this.mxAppStorage.getConfig(key);
  462. }else if(this.supportGM){
  463. value=GM_getValue(key);
  464. }else if(this.supportGMPromise){
  465. value=GM.getValue(key).then(v=>{cb(v)});
  466. return;
  467. }else if(window.localStorage){
  468. value=window.localStorage.getItem(key);
  469. };
  470. cb(value);
  471. }
  472. };
  473. var rulesData={},ruleUrls,updateDate,configPage="https://github.com/hoothin/UserScripts/tree/master/Pagetual";
  474. var ruleImportUrlReg=/greasyfork\.org\/.*scripts\/438684[^\/]*(\/discussions|\/?$)|github\.com\/hoothin\/UserScripts\/(tree\/master\/Pagetual|issues)/i;
  475. var allOfBody="body>*";
  476. _GM_registerMenuCommand(i18n("configure"), ()=>{
  477. _GM_openInTab(configPage,{active:true});
  478. });
  479. _GM_registerMenuCommand(i18n("editCurrent"), ()=>{
  480. let editTemp;
  481. if(ruleParser.curSiteRule.url && !ruleParser.curSiteRule.singleUrl){
  482. editTemp=ruleParser.curSiteRule;
  483. }else{
  484. editTemp={
  485. name: document.title,
  486. url: "^"+location.origin.replace(/\./g,"\\."),
  487. pageElement: ruleParser.curSiteRule.pageElement||""
  488. };
  489. }
  490. rulesData.editTemp=editTemp;
  491. storage.setItem("rulesData", rulesData);
  492. _GM_openInTab(configPage,{active:true});
  493. });
  494.  
  495. function getElementByXpath(xpath, contextNode, doc){
  496. doc = doc || document;
  497. contextNode = contextNode || doc;
  498. try {
  499. var result = doc.evaluate(xpath, contextNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
  500. return result.singleNodeValue && result.singleNodeValue.nodeType === 1 && result.singleNodeValue;
  501. } catch (err) {
  502. throw new Error(`Invalid xpath: ${xpath}`);
  503. }
  504. }
  505.  
  506. function getAllElementsByXpath(xpath, contextNode, doc){
  507. doc = doc || document;
  508. contextNode = contextNode || doc;
  509. var result = [];
  510. try {
  511. var query = doc.evaluate(xpath, contextNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  512. for (var i = 0; i < query.snapshotLength; i++) {
  513. var node = query.snapshotItem(i);
  514. if (node.nodeType === 1) result.push(node);
  515. }
  516. } catch (err) {
  517. throw new Error(`Invalid xpath: ${xpath}`);
  518. }
  519. return result;
  520. }
  521.  
  522. class RuleParser {
  523. constructor() {
  524. this.hpRules=[];
  525. this.customRules=[];
  526. this.rules=[];
  527. this.pageDoc=document;
  528. this.nextLinkHref=null;
  529. this.nextTitle="";
  530. this.oldUrl="";
  531. this.curUrl=location.href;
  532. this.curSiteRule={};
  533. }
  534.  
  535. initSavedRules(callback){
  536. var self=this;
  537. storage.getItem("hpRules", hpRules=>{
  538. if(hpRules)self.hpRules=hpRules;
  539. storage.getItem("customRules", customRules=>{
  540. if(customRules)self.customRules=customRules;
  541. storage.getItem("rules", rules=>{
  542. if(rules)self.rules=rules;
  543. callback();
  544. });
  545. });
  546. });
  547. }
  548.  
  549. saveCurSiteRule(){
  550. if(!this.curSiteRule || !this.curSiteRule.url || this.curSiteRule.singleUrl || this.curSiteRule.url.length<13)return;
  551. this.hpRules=this.hpRules.filter(item=>{return item&&item.url!=this.curSiteRule.url});
  552. this.hpRules.unshift(this.curSiteRule);
  553. if(this.hpRules.length>30){
  554. this.hpRules.pop();
  555. }
  556. storage.setItem("hpRules", this.hpRules);
  557. }
  558.  
  559. requestJSON(url, callback){
  560. _GM_xmlhttpRequest({
  561. url: url,
  562. method: 'GET',
  563. timeout: 20000,
  564. onload: function(res) {
  565. let json=null;
  566. try{
  567. json=JSON.parse(res.response||res.responseText);
  568. }catch(e){
  569. debug(e);
  570. }
  571. callback(json);
  572. },
  573. onerror: function(e) {
  574. callback(null, e);
  575. },
  576. ontimeout: function(e) {
  577. callback(null, e);
  578. }
  579. });
  580. }
  581.  
  582. formatRule(item, type, from){
  583. switch(type){
  584. case 0:
  585. return {
  586. from:from,
  587. type:type,
  588. name:item.name,
  589. action:item.data.forceIframe=="true"?1:0,
  590. url:item.data.url,
  591. pageElement:item.data.pageElement,
  592. nextLink:item.data.nextLink,
  593. insert:item.data.insertBefore,
  594. insertPos:1,
  595. updatedAt:item.data.updated_at,
  596. css:item.data.Stylus+item.data.CSS,
  597. pageAction:item.data.bookmarklet
  598. };
  599. break;
  600. case 1:
  601. default:
  602. item.from=from;
  603. if(typeof(item.type) == "undefined")item.type=type;
  604. return item;
  605. break;
  606. }
  607. return null;
  608. }
  609.  
  610. addRuleByUrl(url, type, from, callback) {
  611. if(url.indexOf("?")==-1){
  612. url=url+"?"+Date.now();
  613. }else{
  614. url=url+"&"+Date.now();
  615. }
  616. this.requestJSON(url, (json,err)=>{
  617. if(!json){
  618. debug("Update "+url+" rules fail!");
  619. debug(err);
  620. }
  621. this.addRules(json, type, from);
  622. callback(json, err);
  623. });
  624. }
  625.  
  626. addRules(rules, type, from) {
  627. if(rules && rules.length>0){
  628. this.rules=this.rules.filter(item=>{return item.from!=from});
  629. rules.forEach(item=>{
  630. let rule=this.formatRule(item, type, from);
  631. if(rule){
  632. this.rules.unshift(rule);
  633. }
  634. });
  635. }
  636. }
  637.  
  638. ruleMatch(r) {
  639. let pageElement,nextLink,insert;
  640. if(r.nextLink && r.nextLink!="0" && r.nextLink!=0){
  641. nextLink=r.type==0?getElementByXpath(r.nextLink):document.querySelector(r.nextLink);
  642. if(!nextLink)return false;
  643. }
  644. if(r.pageElement){
  645. pageElement=r.type==0?getElementByXpath(r.pageElement):document.querySelector(r.pageElement);
  646. if(!pageElement)return false;
  647. }
  648. if(r.insert){
  649. insert=r.type==0?getElementByXpath(r.insert):document.querySelector(r.insert);
  650. if(!insert)return false;
  651. }
  652. return true;
  653. }
  654.  
  655. getRule(callback) {
  656. if(noRuleTest){
  657. this.curSiteRule={};
  658. this.curSiteRule.url=location.origin+location.pathname;
  659. this.curSiteRule.singleUrl=true;
  660. callback();
  661. return;
  662. }
  663. if(this.curSiteRule && this.curSiteRule.url){
  664. return this.curSiteRule;
  665. }
  666. var self=this;
  667.  
  668. function setRule(r) {
  669. self.curSiteRule=r;
  670. debug(r);
  671. callback();
  672. }
  673.  
  674. function checkRule(r) {
  675. let urlReg=new RegExp(r.url, "i");
  676. if(urlReg.test(location.href)){
  677. if(r.include){
  678. let include=r.type==0?getElementByXpath(r.include):document.querySelector(r.include);
  679. if(!include)return false;
  680. }
  681. if(r.exclude){
  682. let exclude=r.type==0?getElementByXpath(r.exclude):document.querySelector(r.exclude);
  683. if(exclude)return false;
  684. }
  685. if(r.wait){
  686. let waitTime=500,checkEval;
  687. if(isNaN(r.wait)){
  688. try{
  689. checkEval=(typeof _unsafeWindow.pagetualWait=='undefined') ? Function("doc",'"use strict";' + r.wait) : _unsafeWindow.pagetualWait;
  690. }catch(e){
  691. debug(e);
  692. }
  693. }else{
  694. waitTime=r.wait;
  695. }
  696. let checkReady=()=>{
  697. setTimeout(()=>{
  698. if(!self.ruleMatch(r) || (checkEval && !checkEval(document))){
  699. checkReady();
  700. }else{
  701. setRule(r);
  702. }
  703. },parseInt(waitTime));
  704. };
  705. checkReady();
  706. return true;
  707. }
  708. if(r.pinUrl){
  709. setRule(r);
  710. return true;
  711. }
  712. if(!self.ruleMatch(r)){
  713. return false;
  714. }
  715. setRule(r);
  716. return true;
  717. }
  718. return false;
  719. }
  720.  
  721. for(let i in this.hpRules){
  722. let rule=this.hpRules[i];
  723. if(!rule || !rule.url)continue;
  724. if(rule.singleUrl){
  725. if(location.origin+location.pathname==rule.url){
  726. setRule(rule);
  727. return;
  728. }
  729. continue;
  730. }
  731. if(checkRule(rule))return;
  732. }
  733. for(let i in this.customRules){
  734. let rule=this.customRules[i];
  735. if(!rule || !rule.url)continue;
  736. if(checkRule(rule))return;
  737. }
  738. let r=0;
  739. function searchByTime(){
  740. setTimeout(()=>{
  741. let end=r+10;
  742. end=end>self.rules.length?self.rules.length:end;
  743. for(;r<end;r++){
  744. let rule=self.rules[r];
  745. if(checkRule(rule))return;
  746. }
  747. if(end>=self.rules.length){
  748. self.curSiteRule={};
  749. self.curSiteRule.url=location.origin+location.pathname;
  750. self.curSiteRule.singleUrl=true;
  751. callback();
  752. return;
  753. }else{
  754. searchByTime();
  755. }
  756. },1);
  757. }
  758. searchByTime();
  759. }
  760.  
  761. geneSelector(ele){
  762. let selector=ele.tagName;
  763. //Google id class都是隨機。百度更過分,style script順序都是隨機的
  764. //if(ele.id) selector += '#' + ele.id;
  765. //if(ele.classList) selector += [].map.call(ele.classList,d=>'.'+d).join('');
  766. if(ele.tagName!="HTML" && ele.tagName!="BODY"){
  767. if(ele.className) selector += [].map.call(ele.classList,d=>'.'+d).join('');
  768. let parent = ele.parentElement;
  769. if(parent){
  770. selector = this.geneSelector(parent) + ' > ' + selector;
  771. if(!ele.className){
  772. let i,j=0;
  773. for(i=0;i<parent.children.length;i++){
  774. if(parent.children[i].tagName==ele.tagName){
  775. j++;
  776. if(parent.children[i]==ele){
  777. break;
  778. }
  779. }
  780. }
  781. selector += (parent.tagName=="HTML"?"":`:nth-of-type(${j})`);
  782. }
  783. }
  784. }
  785. return selector;
  786. }
  787.  
  788. getPageElement(doc, curWin, dontFind) {
  789. let pageElement=null;
  790. let self=this;
  791. let body=doc.body;
  792. if(this.curSiteRule.pageElement){
  793. pageElement=this.curSiteRule.type==0?getAllElementsByXpath(this.curSiteRule.pageElement,doc,doc):doc.querySelectorAll(this.curSiteRule.pageElement);
  794. }else if(!this.curSiteRule.singleUrl && this.curSiteRule.type==0){
  795. pageElement=[body];
  796. }
  797. if(this.curSiteRule.singleUrl && pageElement && pageElement.length>0 && pageElement[0].tagName=="TR"){
  798. let mainTr=this.insert.parentNode.querySelector('tr'),mainTdNum=0,newTdNum=0;
  799. [].forEach.call(mainTr.children, el=>{
  800. if(el.tagName=="TD" || el.tagName=="TH"){
  801. mainTdNum+=el.colSpan||1;
  802. }
  803. });
  804. [].forEach.call(pageElement[0].children, el=>{
  805. if(el.tagName=="TD" || el.tagName=="TH"){
  806. newTdNum+=el.colSpan||1;
  807. }
  808. });
  809. if(mainTdNum!=newTdNum){
  810. this.curSiteRule.pageElement=allOfBody;
  811. pageElement=[body];
  812. this.getInsert(true);
  813. }
  814. }
  815. if((this.curSiteRule.singleUrl || !this.curSiteRule.pageElement) && (!pageElement || pageElement.length==0) && curWin && !dontFind){
  816. if(!body)return null;
  817. let bodyHeight=parseInt(body.offsetHeight || body.scrollHeight);
  818. let curHeight=bodyHeight;
  819. let windowHeight=window.innerHeight || document.documentElement.clientHeight;
  820. let needCheckNext=(doc==document && this.initNext);
  821. function checkElement(ele){
  822. if(ele.childNodes && ele.childNodes.length==1)ele=ele.childNodes[0];
  823. if(ele.tagName=="PICTURE"){
  824. self.curSiteRule.pageElement=self.geneSelector(ele.parentNode)+">"+ele.tagName;
  825. debug(self.curSiteRule.pageElement);
  826. return [ele];
  827. }
  828. if(curHeight/bodyHeight<=0.25){
  829. self.curSiteRule.pageElement=allOfBody;
  830. debug(self.curSiteRule.pageElement);
  831. return [body];
  832. }
  833. if(ele.tagName=="FORM"){
  834. self.curSiteRule.pageElement=self.geneSelector(ele)+">*";
  835. debug(self.curSiteRule.pageElement);
  836. return ele.children;
  837. }
  838. if(ele.children.length==0 && !self.curSiteRule.pageElement){
  839. if(ele.parentNode.tagName=="P")ele=ele.parentNode;
  840. self.curSiteRule.pageElement=self.geneSelector(ele.parentNode)+">"+ele.tagName;
  841. debug(self.curSiteRule.pageElement);
  842. return [ele];
  843. }
  844. let i,maxHeight=curHeight*0.55,curMaxEle=null,curMaxArea=0,maxWidth=0;
  845. let isHori=true;
  846. let offsetTop=ele.children[0].offsetTop;
  847. for(i=1;i<ele.children.length;i++){
  848. if(ele.children[i].offsetTop!=offsetTop){
  849. isHori=false;
  850. break;
  851. }
  852. }
  853. for(i=0;i<ele.children.length;i++){
  854. let curNode=ele.children[i];
  855. if(curNode.tagName=="CANVAS")continue;
  856. if(curNode.tagName!="IMG" && /^\s*$/.test(curNode.innerText))continue;
  857. if(needCheckNext && !curNode.contains(self.initNext) && getElementTop(curNode)>windowHeight){
  858. continue;
  859. }
  860. let comStyle=curWin.getComputedStyle(curNode);
  861. let h=parseInt(curNode.offsetHeight || curNode.scrollHeight);
  862. let w=parseInt(curNode.scrollWidth);
  863. if(isNaN(h) || isNaN(w))continue;
  864. if(isHori && h<=50)continue;
  865. let a=h*w+h,moreChild=curNode.children[0];
  866. while(moreChild){
  867. comStyle=curWin.getComputedStyle(moreChild);
  868. let ch=parseInt(moreChild.offsetHeight || moreChild.scrollHeight);
  869. let cw=parseInt(moreChild.scrollWidth);
  870. if(h<ch)h=ch;
  871. if(moreChild.innerText!="" && !isNaN(ch) && !isNaN(cw)){
  872. a+=ch*cw;
  873. }
  874. moreChild=moreChild.nextElementSibling;
  875. }
  876. let isMax=false;
  877. if(isHori){
  878. if(maxWidth<w){
  879. isMax=true;
  880. }else if(maxWidth==w && curMaxArea<a){
  881. isMax=true;
  882. }
  883. }else{
  884. isMax=curMaxArea<a;
  885. }
  886. if(curMaxEle==null || isMax){
  887. if(h>0 || !isHori)curHeight=h;
  888. curMaxArea=a;
  889. maxWidth=w;
  890. curMaxEle=curNode;
  891. }
  892. }
  893. if(curMaxEle && (isHori || curHeight>maxHeight || (needCheckNext && curHeight>windowHeight && ele.contains(self.initNext)))){
  894. return checkElement(curMaxEle);
  895. }
  896. if(ele.tagName=="P" || ele.tagName=="BR")ele=ele.parentNode;
  897. if(ele.tagName=="TBODY"){
  898. self.curSiteRule.pageElement=self.geneSelector(ele)+">*";
  899. if(ele.children.length>0 && ele.children[0].querySelector("th")){
  900. self.curSiteRule.pageElement+=":not(:first-child)";
  901. }
  902. debug(self.curSiteRule.pageElement);
  903. return ele.children;
  904. }
  905. self.curSiteRule.pageElement=self.geneSelector(ele);
  906. if(ele.children.length>1){
  907. let hasText=false;
  908. for(let i in ele.childNodes){
  909. let child=ele.childNodes[i];
  910. if(child.nodeType==3 && child.nodeValue.trim()!=''){
  911. hasText=true;
  912. ele=[ele];
  913. break;
  914. }
  915. }
  916. if(!hasText){
  917. let middleChild=ele.children[parseInt(ele.children.length/2)];
  918. if((middleChild.style && middleChild.style.position=="absolute" && middleChild.style.left && middleChild.style.top) || ele.tagName=="UL" || curHeight==0){
  919. ele=[ele];
  920. }else{
  921. self.curSiteRule.pageElement+=">*";
  922. ele=ele.children;
  923. }
  924. }
  925. }else{
  926. ele=[ele];
  927. }
  928. debug(self.curSiteRule.pageElement);
  929. return ele;
  930. }
  931. pageElement=checkElement(body);
  932. //if(pageElement)this.saveCurSiteRule();
  933. }
  934. return pageElement;
  935. }
  936.  
  937. getPage(doc){
  938. if(typeof _unsafeWindow.Discourse!='undefined')return {};
  939. let canSave=false;//發現頁碼選擇器在其他頁對不上,還是別保存了
  940. let url=this.curUrl.replace("#!","").replace("index.php?","?");
  941. let _url=url.replace(/\.s?html?$/i,"");
  942. let pageNum=1,preStr="",afterStr="";
  943. let pageMatch1=url.match(/(.*[a-z\/\-_](?:p|page)?\/?)(\d+)(\.s?html?$|\/?$)/i);
  944. let pageMatch2=url.match(/(.*[\?&]p(?:age)?=)(\d+)($|[#&].*)/i);
  945. if(pageMatch1){
  946. preStr=pageMatch1[1];
  947. pageNum=parseInt(pageMatch1[2]);
  948. afterStr=pageMatch1[3];
  949. }else if(pageMatch2){
  950. preStr=pageMatch2[1];
  951. pageNum=parseInt(pageMatch2[2]);
  952. afterStr=pageMatch2[3];
  953. }
  954. let curPage=doc,i,cur,jsNext;
  955. let next1,next2,next3,next4,nextJs1,nextJs2,nextJs3;
  956. let next=curPage.querySelector(".page-next>a")||
  957. curPage.querySelector("a.next_page")||
  958. curPage.querySelector("#next_page")||
  959. curPage.querySelector(".nextPage")||
  960. curPage.querySelector("a[data-pagination=next]")||
  961. curPage.querySelector("ul.pagination>li.active+li>a")||
  962. curPage.querySelector(".pagination a[rel=next]")||
  963. curPage.querySelector(".pagination-nav__item--next>a")||
  964. curPage.querySelector("a[title='Next page']")||
  965. curPage.querySelector("a.pageright")||
  966. curPage.querySelector("a#rightFix")||
  967. curPage.querySelector("a#next")||
  968. curPage.querySelector(".next>a")||
  969. curPage.querySelector(".next>button")||
  970. curPage.querySelector("a[alt=next]")||
  971. curPage.querySelector("button.next")||
  972. curPage.querySelector("[title=next]")||
  973. curPage.querySelector("a#btnPreGn")||
  974. getElementByXpath("//a[contains(@class, 'page__next')]",curPage,curPage);
  975. if(!next){
  976. let nexts=curPage.querySelectorAll("a.next");
  977. for(i=0;i<nexts.length;i++){
  978. if(!/^([上前首尾][一1]?[页頁张張]|previous(\s*page)?\s*›?$|前のページ)/i.test(nexts[i].innerText.trim()) &&
  979. nexts[i].style.display!=="none" &&
  980. nexts[i].parentNode.style.display!=="none"){
  981. next=nexts[i];
  982. break;
  983. }
  984. }
  985. }
  986. if(next && (!next.href || /^javascript:/.test(next.href) || next.getAttribute("href")=="#")){
  987. jsNext=next;
  988. next=null;
  989. }
  990. if(!next){
  991. next=curPage.querySelectorAll("[aria-label='Next page']");
  992. if(next && next.length==1){
  993. next=next[0];
  994. if(!next.href || /^javascript:/.test(next.href) || next.getAttribute("href")=="#"){
  995. if(!jsNext)jsNext=next;
  996. next=null;
  997. }
  998. }else{
  999. next=null;
  1000. }
  1001. }
  1002. if(!next){
  1003. next=curPage.querySelectorAll("[aria-label='Next']");
  1004. if(next && next.length==1){
  1005. next=next[0];
  1006. if(!next.href || /^javascript:/.test(next.href) || next.getAttribute("href")=="#"){
  1007. if(!jsNext)jsNext=next;
  1008. next=null;
  1009. }
  1010. }else{
  1011. next=null;
  1012. }
  1013. }
  1014. if(next && /^[下后後][一1]?[章话話篇]/i.test(next.innerText.trim())){
  1015. next2=next;
  1016. next=null;
  1017. }
  1018. if(!next){
  1019. next=curPage.querySelector("a.curr");
  1020. if(next){
  1021. next=next.nextSibling;
  1022. }
  1023. }
  1024. if(!next){
  1025. next=curPage.querySelector("div.wp-pagenavi>span.current+a,div.page-nav>span.current+a,div.article-paging>span+a");
  1026. }
  1027. if(!next){
  1028. let pageDiv=curPage.querySelector("div.pages>ul");
  1029. if(pageDiv){
  1030. cur=pageDiv.querySelector("li>b");
  1031. if(cur)next=cur.parentNode.nextElementSibling;
  1032. if(next)next=next.querySelector("a");
  1033. }
  1034. }
  1035. if(!next){
  1036. cur=curPage.querySelector(".number>ul>li.active");
  1037. if(cur)next=cur.nextElementSibling;
  1038. if(next)next=next.querySelector("a");
  1039. }
  1040. if(!next){
  1041. let aTags=curPage.querySelectorAll("a,button");
  1042. for(i=aTags.length-1;i>=0;i--){
  1043. if(next1 && next2 && next3 && next4)break;
  1044. let aTag=aTags[i];
  1045. if(aTag.innerText=="§")continue;
  1046. if(aTag.innerText.length>50)continue;
  1047. if(aTag.style.display=="none")continue;
  1048. if(aTag.href && /next$/i.test(aTag.href))continue;
  1049. if(aTag.className && /slick|slide/i.test(aTag.className))continue;
  1050. if(aTag.innerText.length<=18){
  1051. if(!next1){
  1052. if(/^[下后後][一1]?[页頁张張]|^next([ _-]?page)?\s*[›>→»]?$|次のページ|^次へ?$/i.test(aTag.innerText.trim())){
  1053. if(!aTag.href || /^javascript:/.test(aTag.href) || aTag.getAttribute("href")=="#"){
  1054. if(!nextJs1)nextJs1=aTag;
  1055. }else{
  1056. next1=aTag;
  1057. }
  1058. }
  1059. }
  1060. if(!next2){
  1061. if(/^[下后後][一1]?[章话話篇]/i.test(aTag.innerText.trim()) || /nextpage/i.test(aTag.className)){
  1062. if(!aTag.href || /^javascript:/.test(aTag.href) || aTag.getAttribute("href")=="#"){
  1063. if(!nextJs2)nextJs2=aTag;
  1064. }else{
  1065. next2=aTag;
  1066. }
  1067. }
  1068. }
  1069. if(!next3){
  1070. if(aTag.innerText=="&gt;" || aTag.innerText=="▶" || aTag.innerText==">" || aTag.innerText=="›" || aTag.innerText=="→" || aTag.innerText=="»"){
  1071. if(!aTag.href || /^javascript:/.test(aTag.href) || aTag.getAttribute("href")=="#"){
  1072. if(!nextJs3)nextJs3=aTag;
  1073. }else{
  1074. next3=aTag;
  1075. }
  1076. }
  1077. }
  1078. }
  1079. if(!aTag.href || /^javascript:/.test(aTag.href) || aTag.getAttribute("href")=="#")continue;
  1080. if(!next4 && aTag.href.length<250){
  1081. let _aHref=aTag.href.replace("?&","?").replace("#!","").replace("index.php?","?");
  1082. let _aHrefTrim=_aHref;
  1083. if(preStr)_aHrefTrim=_aHrefTrim.replace(preStr,"");
  1084. if(afterStr)_aHrefTrim=_aHrefTrim.replace(afterStr,"");
  1085. if(pageNum<999 && _aHrefTrim==pageNum+1){
  1086. next4=aTag;
  1087. }else if(this.curUrl!=aTag.href){
  1088. _aHref=_aHref.replace(/\.s?html?$/i,"");
  1089. if(_aHref.indexOf(_url)!=-1 && /^[\/\?&]?[_-]?(p|page)?=?\/?2(\/|\?|&|$)/i.test(_aHref.replace(_url,""))){
  1090. let curHref=aTag.getAttribute("href");
  1091. let pageOne=curHref.replace(/\/2(\/|\?|&|$)/,"/1$1");
  1092. if(pageOne==curHref)pageOne=null;
  1093. else pageOne=curPage.querySelector(`a[href='${pageOne}']`);
  1094. if(!pageOne || pageOne.className!=curHref.className)next4=aTag;
  1095. }
  1096. }
  1097. }
  1098. }
  1099. if(next3){
  1100. let eles=getAllElementsByXpath(`//a[text()='${next3.innerText}']`,curPage,curPage);
  1101. if(eles.length>2)next3=null;
  1102. }
  1103. }
  1104. if(!next)next=next1||next4||next3||next2||jsNext||nextJs1||nextJs3||nextJs2;
  1105. if(next && next.classList.contains("results-more"))next=null;
  1106. return {next:next,canSave:canSave};
  1107. }
  1108.  
  1109. canonicalUri(src) {
  1110. if(src.charAt(0)=="#")return location.href+src;
  1111. var root_page = /^[^?#]*\//.exec(location.href)[0],
  1112. base_path = location.pathname.replace(/\/[^\/]+\.[^\/]+$/, "/"),
  1113. root_domain = /^\w+\:\/\/\/?[^\/]+/.exec(root_page)[0],
  1114. absolute_regex = /^\w+\:\/\//;
  1115. src=src.replace(/\.\//,"");
  1116. if (/^\/\/\/?/.test(src)){
  1117. src = location.protocol + src;
  1118. }
  1119. else if (!absolute_regex.test(src) && src.charAt(0) != "/"){
  1120. src = (base_path || "") + src;
  1121. }
  1122. return (absolute_regex.test(src) ? src : ((src.charAt(0) == "/" ? root_domain : root_page) + src));
  1123. }
  1124.  
  1125. getLinkByPage(url, pageNum) {
  1126. if(!url)return;
  1127. if(this.curSiteRule.pageNum){
  1128. let result=this.curSiteRule.pageNum;
  1129. let strMatch=result.match(/\{.*?}/);
  1130. if(!strMatch)return null;
  1131. let urlReg=new RegExp("("+result.replace(strMatch[0], ")\\d+(")+")","i");
  1132. let code=strMatch[0].replace(/^{/,"").replace(/}$/,"").replace(/\$p/g,pageNum);
  1133. if(code==pageNum){
  1134. result=url.replace(urlReg,"$1"+code+"$2");
  1135. }else{
  1136. try{
  1137. code=Function('"use strict";return ' + code)();
  1138. result=url.replace(urlReg,"$1"+code+"$2");
  1139. }catch(e){
  1140. debug(e);
  1141. }
  1142. }
  1143. if(result!=url){
  1144. return result;
  1145. }
  1146. }
  1147. return url.replace(/([&\/\?](p=|page[=\/_-]?))\d+/i, "$1"+pageNum).replace(/([_-])\d+\./i, "$1"+pageNum+".");
  1148. }
  1149.  
  1150. getPageNumFromUrl(url) {
  1151. if(!url)return curPage;
  1152. if(this.curSiteRule.pageNum){
  1153. let result=this.curSiteRule.pageNum;
  1154. let strMatch=result.match(/\{.*?}/);
  1155. if(!strMatch)return null;
  1156. let urlReg=new RegExp(".*"+result.replace(strMatch[0], "(\\d+)")+".*","i");
  1157. let curShowNum=url.replace(urlReg,"$1");
  1158. if (curShowNum!=url){
  1159. let code=strMatch[0].replace(/^{/,"").replace(/}$/,"");
  1160. if(code=="$p"){
  1161. return curShowNum;
  1162. }else{
  1163. try{
  1164. let page1=Function('"use strict";return ' + code.replace("$p", "0"))();
  1165. let page2=Function('"use strict";return ' + code.replace("$p", "1"))();
  1166. let numGap=page2-page1;
  1167. return (curShowNum - page1) / numGap;
  1168. }catch(e){
  1169. debug(e);
  1170. }
  1171. }
  1172. }
  1173. }
  1174. let pageNum=url.replace(/.*[&\/\?](p=|page[=\/_-]?)(\d+).*/i, "$2");
  1175. return pageNum==url?curPage:pageNum;
  1176. }
  1177.  
  1178. getNextLink(doc) {
  1179. let nextLink=null,page,href;
  1180. let getNextLinkByForm=(form,n)=>{
  1181. let params=[];
  1182. [].forEach.call(form.querySelectorAll("input"), input=>{
  1183. if(n && /^(p|page)$/i.test(input.name)){
  1184. params.push('p='+n);
  1185. }else{
  1186. params.push(input.name+'='+input.value);
  1187. }
  1188. });
  1189. return form.action+'?'+params.join('&');
  1190. };
  1191. if(this.curSiteRule.pageElementByJs){
  1192. this.nextLinkHref="#";
  1193. return true;
  1194. }else if(this.curSiteRule.nextLinkByJs){
  1195. try{
  1196. let targetUrl=((typeof _unsafeWindow.pagetualNextLinkByJs=='undefined') ? Function("doc",'"use strict";' + this.curSiteRule.nextLinkByJs) : _unsafeWindow.pagetualNextLinkByJs)(doc);
  1197. if(targetUrl)nextLink={href:targetUrl};
  1198. }catch(e){
  1199. debug(e);
  1200. }
  1201. }else if(this.curSiteRule.nextLinkByUrl){
  1202. let targetUrl=this.curUrl.replace(new RegExp(this.curSiteRule.nextLinkByUrl[0],"i"), this.curSiteRule.nextLinkByUrl[1]);
  1203. if(targetUrl != this.curUrl){
  1204. let reps=targetUrl.match(/{.*?}/g);
  1205. if(reps){
  1206. reps.forEach(rep=>{
  1207. let code=rep.replace("{","").replace("}","");
  1208. let result=code.match(/^(\d*)\+1$/);
  1209. if(result){
  1210. result=parseInt(result[1]||1)+1;
  1211. }else{
  1212. try{
  1213. result=Function('"use strict";return ' + code)();
  1214. }catch(e){
  1215. debug(e);
  1216. }
  1217. }
  1218. targetUrl=targetUrl.replace(rep, result);
  1219. });
  1220. }
  1221. }
  1222. nextLink={href:targetUrl};
  1223. }else if(this.curSiteRule.nextLink){
  1224. if(this.curSiteRule.nextLink!="0" && this.curSiteRule.nextLink!=0){
  1225. nextLink=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.nextLink,doc,doc):doc.querySelector(this.curSiteRule.nextLink);
  1226. }
  1227. }else{
  1228. page=this.getPage(doc);
  1229. nextLink=page.next;
  1230. if(nextLink){
  1231. if(nextLink.tagName=="INPUT" && nextLink.parentNode.tagName=="FORM"){
  1232. let form=nextLink.parentNode;
  1233. nextLink.href=getNextLinkByForm(form);
  1234. }
  1235. if(nextLink.parentNode.style.display=="none" || nextLink.style.display=="none" || nextLink.classList.contains("noClick") || nextLink.hasAttribute("disabled")){
  1236. this.nextLinkHref=false;
  1237. return null;
  1238. }else if(doc==document){
  1239. if((!nextLink.href || /^javascript:/.test(nextLink.href)) && !isVisible(nextLink, _unsafeWindow)){
  1240. this.nextLinkHref=false;
  1241. return null;
  1242. }else{
  1243. let nextLinkCs=_unsafeWindow.getComputedStyle(nextLink);
  1244. if(nextLinkCs.cursor=="not-allowed"){
  1245. this.nextLinkHref=false;
  1246. return null;
  1247. }
  1248. this.initNext=nextLink;
  1249. }
  1250. }
  1251. let form=doc.querySelector('#search-form');
  1252. if(!nextLink.href && nextLink.hasAttribute("onclick") && form){
  1253. if(form && /^\d+$/.test(nextLink.innerText)){
  1254. href=getNextLinkByForm(form, nextLink.innerText);
  1255. }
  1256. }
  1257. }
  1258. }
  1259. if(nextLink){
  1260. let needUrl=(this.curSiteRule.action==0 || this.curSiteRule.action==1);
  1261. if(!href)href=nextLink.href;
  1262. if(href && nextLink.getAttribute){
  1263. let _href=nextLink.getAttribute("href");
  1264. if(!_href || _href.charAt(0)=="#" || _href=="?"){
  1265. href="#";
  1266. }
  1267. }
  1268.  
  1269. if((href===""||href===null) && needUrl){
  1270. this.nextLinkHref=false;
  1271. }else if(/^(javascript:void\(0\)|#)/.test(href) && needUrl){
  1272. this.nextLinkHref=false;
  1273. }else{
  1274. this.nextLinkHref=(href && !/^(javascript:|#)/.test(href))?this.canonicalUri(href):"#";
  1275. if(this.nextLinkHref!="#" && (this.nextLinkHref==this.curUrl || this.nextLinkHref==this.curUrl+"#" || this.nextLinkHref==this.oldUrl || this.nextLinkHref==this.oldUrl+"#")){
  1276. this.nextLinkHref=false;
  1277. }else if(doc==document)debug(nextLink);
  1278. }
  1279. }else{
  1280. this.nextLinkHref=false;
  1281. }
  1282. this.preload();
  1283. return nextLink;
  1284. }
  1285.  
  1286. preload(){
  1287. if(!rulesData.preload)return;
  1288. if(!this.nextLinkHref || this.nextLinkHref=="#")return;
  1289. let self=this;
  1290. if(this.curSiteRule && this.curSiteRule.action==1){
  1291. if(!this.preloadIframe){
  1292. this.preloadIframe = document.createElement('iframe');
  1293. let iframe = this.preloadIframe;
  1294. iframe.name = 'pagetual-iframe';
  1295. iframe.width = '100%';
  1296. iframe.height = '0';
  1297. iframe.frameBorder = '0';
  1298. if(ruleParser.curSiteRule.sandbox!=false){
  1299. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1300. }
  1301. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1302. iframe.addEventListener('load', function (e) {
  1303. try{
  1304. let doc=iframe.contentDocument || iframe.contentWindow.document;
  1305. var body = doc.body;
  1306. if (body && body.firstChild) {
  1307. self.lazyImgAction(body.children);
  1308. }
  1309. }catch(e){
  1310. return;
  1311. }
  1312. }, false);
  1313. document.body.appendChild(iframe);
  1314. }
  1315. this.preloadIframe.src = this.nextLinkHref;
  1316. }else{
  1317. _GM_xmlhttpRequest({
  1318. url: this.nextLinkHref,
  1319. method: 'GET',
  1320. overrideMimeType: 'text/html;charset='+document.charset,
  1321. headers: {
  1322. 'Referer': location.href
  1323. },
  1324. timeout: 5000,
  1325. onload: function(res) {
  1326. var doc=null;
  1327. try {
  1328. doc=document.implementation.createHTMLDocument('');
  1329. doc.documentElement.innerHTML=res.response;
  1330. var body = doc.body;
  1331. if (body && body.firstChild) {
  1332. self.lazyImgAction(body.children);
  1333. }
  1334. if(!self.preloadDiv){
  1335. self.preloadDiv = document.createElement('div');
  1336. self.preloadDiv.id = "pagetual-preload";
  1337. self.preloadDiv.style.cssText = 'display:none!important;';
  1338. document.body.appendChild(self.preloadDiv);
  1339. self.checkedImgs={};
  1340. }
  1341. [].forEach.call(doc.images, i=>{
  1342. let iSrc=i.src;
  1343. if(iSrc && !self.checkedImgs[iSrc]){
  1344. self.checkedImgs[iSrc] = true;
  1345. let img = document.createElement('img');
  1346. img.src = iSrc;
  1347. self.preloadDiv.appendChild(img);
  1348. }
  1349. });
  1350. }
  1351. catch (e) {
  1352. return;
  1353. }
  1354. }
  1355. });
  1356. }
  1357. }
  1358.  
  1359. getInsert(refresh) {
  1360. if(refresh){
  1361. this.insert=null;
  1362. }
  1363. if(this.insert && !refresh){
  1364. let parent=this.insert;
  1365. while(parent && parent.nodeName!="BODY"){
  1366. parent=parent.parentNode;
  1367. }
  1368. if(parent && parent.nodeName=="BODY"){
  1369. return this.insert;
  1370. }
  1371. }
  1372. if(this.curSiteRule.insert){
  1373. this.insert=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.insert,document):document.querySelector(this.curSiteRule.insert);
  1374. }else{
  1375. let pageElement=this.getPageElement(document, _unsafeWindow);
  1376. if(pageElement && pageElement.length>0){
  1377. var pELast = pageElement[pageElement.length - 1];
  1378. this.insert = pELast.nextSibling ? pELast.nextSibling : pELast.parentNode.appendChild(document.createTextNode(' '));
  1379. }
  1380. }
  1381. return this.insert;
  1382. }
  1383.  
  1384. pageInit(doc,eles){
  1385. let code=this.curSiteRule.pageInit;
  1386. if(code){
  1387. try{
  1388. ((typeof _unsafeWindow.pagetualPageInit=='undefined') ? Function("doc", "eles", '"use strict";' + code) : _unsafeWindow.pagetualPageInit)(doc, eles);
  1389. }catch(e){
  1390. debug(e);
  1391. }
  1392. }
  1393. }
  1394.  
  1395. pageAction(doc,eles){
  1396. let code=this.curSiteRule.pageAction;
  1397. if(code){
  1398. try{
  1399. ((typeof _unsafeWindow.pagetualPageAction=='undefined') ? Function("doc", "eles", '"use strict";' + code) : _unsafeWindow.pagetualPageAction)(doc, eles);
  1400. }catch(e){
  1401. debug(e);
  1402. }
  1403. }
  1404. this.lazyImgAction(eles);
  1405. this.openInNewTab(eles);
  1406. }
  1407.  
  1408. openInNewTab(eles){
  1409. if(rulesData.openInNewTab){
  1410. [].forEach.call(eles, ele=>{
  1411. if(ele.tagName=="A" && ele.href && !/^(mailto:|javascript:|#)/.test(ele.href)){
  1412. ele.setAttribute('target', '_blank');
  1413. }else{
  1414. [].forEach.call(ele.querySelectorAll('a[href]:not([href^="mailto:"]):not([href^="javascript:"]):not([href^="#"])'), a=>{
  1415. a.setAttribute('target', '_blank');
  1416. if (a.getAttribute('onclick') == 'atarget(this)') {
  1417. a.removeAttribute('onclick');
  1418. }
  1419. });
  1420. }
  1421. });
  1422. }
  1423. }
  1424.  
  1425. lazyImgAction(eles){
  1426. let setLazyImg=img=>{
  1427. let realSrc;
  1428. if(img.getAttribute("_src") && !img.src){
  1429. realSrc=img.getAttribute("_src");
  1430. }else if(img.dataset && img.dataset.original){
  1431. realSrc=img.dataset.original;
  1432. }else if(img.dataset && img.dataset.src){
  1433. realSrc=img.dataset.src;
  1434. }else if(img._lazyrias && img._lazyrias.srcset){
  1435. realSrc=img._lazyrias.srcset[img._lazyrias.srcset.length-1];
  1436. }else if(img.dataset && img.dataset.origFile){
  1437. realSrc=img.dataset.origFile;
  1438. }else if(img.srcset){
  1439. var srcs=img.srcset.split(/[xw],/),largeSize=0;
  1440. srcs.forEach(srci=>{
  1441. let srcInfo=srci.trim().split(" "),curSize=parseInt(srcInfo[1]);
  1442. if(srcInfo[1] && curSize>largeSize){
  1443. largeSize=curSize;
  1444. realSrc=srcInfo[0];
  1445. }
  1446. });
  1447. }
  1448. if(realSrc){
  1449. img.src=realSrc;
  1450. img.style.display="block";
  1451. }
  1452. };
  1453. [].forEach.call(eles, ele=>{
  1454. if(ele.tagName=="IMG"){
  1455. setLazyImg(ele);
  1456. }else{
  1457. [].forEach.call(ele.querySelectorAll("img"), img=>{
  1458. setLazyImg(img);
  1459. });
  1460. [].forEach.call(ele.querySelectorAll("div[data-src][data-thumb]"), div=>{
  1461. div.style.setProperty("background-image", "url("+div.dataset.src+")", "important");
  1462. });
  1463. }
  1464. if(ele.tagName=="A" && ele.classList.contains("lazyload")){
  1465. if(ele.dataset.original){
  1466. ele.style.backgroundImage='url("'+ele.dataset.original+'")';
  1467. }
  1468. }else{
  1469. [].forEach.call(ele.querySelectorAll("a.lazyload"), a=>{
  1470. if(a.dataset.original){
  1471. a.style.backgroundImage='url("'+a.dataset.original+'")';
  1472. }
  1473. });
  1474. }
  1475. });
  1476. let lazyImgSrc=this.curSiteRule.lazyImgSrc;
  1477. if(lazyImgSrc){
  1478. [].forEach.call(eles, ele=>{
  1479. [].forEach.call(ele.querySelectorAll("img"), img=>{
  1480. if(img.getAttribute(lazyImgSrc)){
  1481. img.src=img.getAttribute(lazyImgSrc);
  1482. }
  1483. });
  1484. });
  1485. }
  1486. }
  1487.  
  1488. initPage(callback){
  1489. let self=this;
  1490. curPage=1;
  1491. //if(this.curSiteRule.url && !this.curSiteRule.singleUrl)return;
  1492. this.curSiteRule={};
  1493. this.pageDoc=document;
  1494. this.nextLinkHref=null;
  1495. this.curUrl=location.href;
  1496. this.getRule(()=>{
  1497. if(self.curSiteRule.enable==0){
  1498. debug("Stop as rule disable");
  1499. isPause=true;
  1500. return;
  1501. }
  1502. //若是再亂匹配就不緩存wedata,或者只在找完本地規則之後再考慮wedata的緩存
  1503. if(self.curSiteRule && !self.curSiteRule.singleUrl && self.curSiteRule.url.length>13){
  1504. self.hpRules=self.hpRules.filter(item=>{return item&&item.url!=self.curSiteRule.url});
  1505. self.hpRules.unshift(self.curSiteRule);
  1506. if(self.hpRules.length>30){
  1507. self.hpRules.pop();
  1508. }
  1509. storage.setItem("hpRules", self.hpRules);
  1510. }
  1511. let css=self.curSiteRule.css;
  1512. if(css){
  1513. _GM_addStyle(css);
  1514. }
  1515. let autoClick=self.curSiteRule.autoClick;
  1516. if(autoClick){
  1517. let autoClickBtn;
  1518. try{
  1519. autoClickBtn=document.querySelector(autoClick);
  1520. }catch(e){
  1521. autoClickBtn=getElementByXpath(autoClick);
  1522. }
  1523. if(autoClickBtn){
  1524. emuClick(autoClickBtn);
  1525. }
  1526. }
  1527. let code=self.curSiteRule.init;
  1528. if(code){
  1529. try{
  1530. ((typeof _unsafeWindow.pagetualInit=='undefined') ? Function('doc','win','iframe','"use strict";' + code) : _unsafeWindow.pagetualInit)(null,null,null);
  1531. }catch(e){
  1532. debug(e);
  1533. }
  1534. }
  1535. self.getNextLink(document);
  1536. callback();
  1537. });
  1538. }
  1539.  
  1540. insertElement(ele) {
  1541. if(this.curSiteRule.insertPos==2){
  1542. this.insert.appendChild(ele);
  1543. }else{
  1544. this.insert.parentNode.insertBefore(ele, this.insert);
  1545. }
  1546. }
  1547.  
  1548. insertPage(doc, eles, url, callback, tried){
  1549. this.oldUrl=this.curUrl;
  1550. let oldTitle=this.pageDoc.title;
  1551. this.pageDoc=doc;
  1552. this.curUrl=url;
  1553. let nextLink=this.getNextLink(doc);
  1554. this.nextTitle="";
  1555. if(this.curSiteRule.pageBarText){
  1556. if(this.curSiteRule.pageBarText==1){
  1557. this.nextTitle=doc.title;
  1558. }else{
  1559. try{
  1560. this.nextTitle=((typeof _unsafeWindow.pagetualPageBarText=='undefined') ? Function("doc",'"use strict";' + this.curSiteRule.pageBarText) : _unsafeWindow.pagetualPageBarText)(doc);
  1561. }catch(e){
  1562. debug(e);
  1563. }
  1564. }
  1565. }
  1566. if(curPage==1 && !tried && !nextLink && this.curSiteRule.singleUrl && this.curSiteRule.pageElement && this.curSiteRule.action!=0){
  1567. this.curSiteRule.action=1;
  1568. this.curUrl=location.href;
  1569. return false;
  1570. }
  1571. if(callback)callback(eles);
  1572. this.getInsert();
  1573. var self=this,newEles=[];
  1574. if(!eles || eles.length==0 || !self.insert || !self.insert.parentNode){
  1575. }else{
  1576. this.pageInit(doc, eles);
  1577. [].forEach.call(eles, ele=>{
  1578. let newEle=ele.cloneNode(true);
  1579. let oldCanvass=ele.querySelectorAll("canvas");
  1580. let newCanvass=newEle.querySelectorAll("canvas");
  1581. for(let i=0;i<oldCanvass.length;i++){
  1582. let oldCanvas=oldCanvass[i];
  1583. let newCanvas=newCanvass[i];
  1584. newCanvas.getContext('2d').drawImage(oldCanvas, 0, 0);
  1585. }
  1586. self.insertElement(newEle);
  1587. newEles.push(newEle);
  1588. });
  1589. }
  1590. this.pageAction(doc, newEles);
  1591. if(this.oldUrl!=location.href){
  1592. let isJs=/^(javascript|#)/.test(this.oldUrl.replace(location.href,""));
  1593. let enableHistory = this.curSiteRule.history;
  1594. if (enableHistory == 1) {
  1595. enableHistory = true;
  1596. } else if (enableHistory == 0) {
  1597. enableHistory = false;
  1598. } else {
  1599. enableHistory = rulesData.enableHistory;
  1600. }
  1601. if(enableHistory && !isJs){
  1602. _unsafeWindow.history.replaceState(undefined, oldTitle, this.oldUrl);
  1603. document.title=oldTitle;
  1604. }
  1605. }
  1606. return true;
  1607. }
  1608. }
  1609. var ruleParser = new RuleParser();
  1610.  
  1611. function initConfig(){
  1612. initView();
  1613. _GM_registerMenuCommand(i18n(forceState==1?"enable":"disableSite"), ()=>{
  1614. forceState=(forceState==1?0:1);
  1615. storage.setItem("forceState_"+location.host, forceState);
  1616. showTips(i18n(forceState==1?"disableSiteTips":"enableSiteTips"));
  1617. if(!ruleParser.curSiteRule.url) location.reload();
  1618. });
  1619. _GM_registerMenuCommand(i18n("update"), ()=>{
  1620. updateRules(()=>{
  1621. showTips(i18n("updateSucc"));
  1622. location.reload();
  1623. },(rule,err)=>{
  1624. showTips("Update "+rule.url+" rules fail!");
  1625. });
  1626. showTips(i18n("beginUpdate"));
  1627. });
  1628.  
  1629. var configCon,insertPos;
  1630. if(ruleImportUrlReg.test(location.href)){
  1631. document.addEventListener("click", e=>{
  1632. if(e.target.tagName=="PRE"){
  1633. let nameAttr=e.target.getAttribute("name");
  1634. if(nameAttr=="pagetual" || nameAttr=="user-content-pagetual" || location.href.indexOf("gf.qytechs.cn") != -1){
  1635. let rules=e.target.innerText.trim();
  1636. let isContent=/['"]name['"]/i.test(rules);
  1637. if(!window.confirm("Import?")) return;
  1638. if(isContent){
  1639. let ruleList=JSON.parse(`[${rules}]`);
  1640. for(let i in ruleList){
  1641. let hasRule = false;
  1642. let r = ruleList[i];
  1643. for(let j in ruleParser.customRules){
  1644. if(ruleParser.customRules[j].name == r.name){
  1645. ruleParser.customRules[j] = r;
  1646. hasRule = true;
  1647. break;
  1648. }
  1649. }
  1650. if(!hasRule)ruleParser.customRules.push(r);
  1651. }
  1652. storage.setItem("customRules", ruleParser.customRules);
  1653. showTips(i18n("importSucc"));
  1654. }else{
  1655. rules=rules.split("\n");
  1656. let diff=false;
  1657. for(let c=0;c<rules.length;c++){
  1658. let urlArr=rules[c].split("|"),url,type=1;
  1659. if(urlArr.length==1){
  1660. url=urlArr[0].trim();
  1661. if(!/^http/.test(url)){
  1662. showTips("Wrong url, check again!");
  1663. return;
  1664. }
  1665. }else if(urlArr.length==2){
  1666. type=urlArr[0].trim();
  1667. url=urlArr[1].trim();
  1668. if(!/^http/.test(url)){
  1669. showTips("Wrong url, check again!");
  1670. return;
  1671. }
  1672. }else{
  1673. break;
  1674. }
  1675. let maxId=0,hasUrl=false;
  1676. if(!rulesData.urls){
  1677. rulesData.urls=[];
  1678. maxId=1;
  1679. }else{
  1680. rulesData.urls.forEach(u=>{
  1681. if(maxId<u.id){
  1682. maxId=u.id;
  1683. }
  1684. if(u.url==url){
  1685. hasUrl=true;
  1686. }
  1687. });
  1688. if(hasUrl)break;
  1689. }
  1690. diff=true;
  1691. if(!rulesData.sort)rulesData.sort=[1];
  1692. rulesData.urls.push({id:maxId+1,url:url,type:type});
  1693. rulesData.sort.unshift(maxId+1);
  1694. }
  1695. if(!diff)return;
  1696. storage.setItem("rulesData", rulesData);
  1697.  
  1698. if(rulesData.urls)ruleUrls=ruleUrls.concat(rulesData.urls);
  1699. if(rulesData.sort){
  1700. let urls=[];
  1701. rulesData.sort.forEach(id=>{
  1702. for(let s=0;s<ruleUrls.length;s++){
  1703. if(id==ruleUrls[s].id){
  1704. urls.push(ruleUrls[s]);
  1705. break;
  1706. }
  1707. }
  1708. });
  1709. ruleUrls=urls;
  1710. }
  1711. updateRules(()=>{
  1712. showTips(i18n("updateSucc"));
  1713. location.reload();
  1714. },(rule,err)=>{
  1715. showTips("Update "+rule.url+" rules fail!");
  1716. });
  1717. showTips(i18n("beginUpdate"));
  1718. }
  1719. }
  1720. }
  1721. });
  1722. }
  1723. if(location.href==configPage){
  1724. _GM_addStyle(`
  1725. p>span:nth-child(1),p>span:nth-child(2),p>span:nth-child(3){
  1726. cursor: pointer;
  1727. user-select: none;
  1728. }
  1729. p>span:nth-child(1):hover,p>span:nth-child(2):hover,p>span:nth-child(3):hover{
  1730. color:red;
  1731. }
  1732. .updateDate{
  1733. cursor: pointer;
  1734. user-select: none;
  1735. }
  1736. .updateDate:hover{
  1737. color:red;
  1738. }
  1739. `);
  1740. document.querySelector("[name='user-content-click2import']").innerText=i18n("click2ImportRule")
  1741. configCon=document.querySelector(".markdown-body");
  1742. insertPos=configCon.querySelector("hr");
  1743.  
  1744. if(rulesData.urls && rulesData.urls.length>0){
  1745. document.querySelector("pre[name='user-content-pagetual']").style.display="none";
  1746. document.querySelector("p[name='user-content-click2import']").style.display="none";
  1747. }
  1748. }else return false;
  1749. class Rulebar {
  1750. init(ruleUrl){
  1751. this.ruleUrl=ruleUrl;
  1752. this.item=document.createElement("p");
  1753. this.item.title=ruleUrl.type==0?"AutoPagerize Rules":"Pagetual Rules";
  1754. this.item.dataset.id=this.ruleUrl.id;
  1755. let url=document.createElement("span");
  1756. url.innerHTML=ruleUrl.url;
  1757. let up=document.createElement("span");
  1758. up.innerHTML="↑ ";
  1759. up.title=i18n("sortTitle");
  1760. let down=document.createElement("span");
  1761. down.innerHTML="↓ ";
  1762. down.title=i18n("sortTitle");
  1763. let del=document.createElement("span");
  1764. del.innerHTML="× ";
  1765. up.onclick=e=>{
  1766. this.moveUp();
  1767. };
  1768. down.onclick=e=>{
  1769. this.moveDown();
  1770. };
  1771. del.onclick=e=>{
  1772. this.del();
  1773. };
  1774. this.item.appendChild(up);
  1775. this.item.appendChild(down);
  1776. this.item.appendChild(del);
  1777. this.item.appendChild(url);
  1778. configCon.insertBefore(this.item, insertPos);
  1779. }
  1780. saveSort(){
  1781. let sort=[];
  1782. [].forEach.call(this.item.parentNode.querySelectorAll("p[data-id]"), i=>{
  1783. sort.push(i.dataset.id);
  1784. });
  1785. rulesData.sort=sort;
  1786. storage.setItem("rulesData", rulesData);
  1787. }
  1788. moveUp(){
  1789. let preE=this.item.previousElementSibling;
  1790. if(preE.tagName=="P" && preE.children.length>1){
  1791. this.item.parentNode.insertBefore(this.item,preE);
  1792. this.saveSort();
  1793. }
  1794. }
  1795. moveDown(){
  1796. let nextE=this.item.nextElementSibling;
  1797. if(nextE.tagName=="P" && nextE.children.length>1){
  1798. this.item.parentNode.insertBefore(nextE,this.item);
  1799. this.saveSort();
  1800. }
  1801. }
  1802. del(){
  1803. if(this.ruleUrl.id<2){
  1804. showTips(i18n("cantDel"));
  1805. }else if(window.confirm(i18n("confirmDel"))){
  1806. for(let u=0;u<rulesData.urls.length;u++){
  1807. if(this.ruleUrl.id==rulesData.urls[u].id){
  1808. rulesData.urls.splice(u,1);
  1809. break;
  1810. }
  1811. }
  1812. for(let u=0;u<rulesData.sort.length;u++){
  1813. if(this.ruleUrl.id==rulesData.sort[u]){
  1814. rulesData.sort.splice(u,1);
  1815. break;
  1816. }
  1817. }
  1818. storage.setItem("rulesData", rulesData);
  1819. ruleParser.rules=ruleParser.rules.filter(item=>{return item.from!=this.ruleUrl.id});
  1820. storage.setItem("rules", ruleParser.rules);
  1821. this.item.parentNode.removeChild(this.item);
  1822. //location.reload();
  1823. }
  1824. }
  1825. }
  1826. let updateP=document.createElement("p"),i=0;
  1827. let now=new Date().getTime(),inUpdate=false;
  1828.  
  1829.  
  1830. let pastDate=(new Date(updateDate)).toString(),passStr;
  1831. let passTime=(now-updateDate)/1000;
  1832. if(isNaN(passTime)){
  1833. passStr=i18n("firstUpdate");
  1834. }else if(passTime<60){
  1835. passStr=i18n("passSec", parseInt(passTime))+" 👆 "+i18n("click2update");
  1836. }else if(passTime<60*60){
  1837. passStr=i18n("passMin", parseInt(passTime/60))+" 👆 "+i18n("click2update");
  1838. }else if(passTime<60*60*24){
  1839. passStr=i18n("passHour", parseInt(passTime/3600))+" 👆 "+i18n("click2update");
  1840. }else{
  1841. passStr=i18n("passDay", parseInt(passTime/86400))+" 👆 "+i18n("click2update");
  1842. }
  1843.  
  1844.  
  1845. updateP.className="updateDate";
  1846. updateP.innerHTML=passStr;
  1847. updateP.title=i18n("update")+" - "+pastDate;
  1848. updateP.onclick=e=>{
  1849. updateRules(()=>{
  1850. showTips(i18n("updateSucc"));
  1851. updateP.innerHTML=i18n("passSec", 0);
  1852. updateP.title=i18n("update");
  1853. },(rule,err)=>{
  1854. showTips("Update "+rule.url+" rules fail!");
  1855. });
  1856. showTips(i18n("beginUpdate"));
  1857. };
  1858. configCon.insertBefore(updateP, insertPos);
  1859. if(ruleUrls){
  1860. ruleUrls.forEach(ruleUrl=>{
  1861. var rulebar=new Rulebar();
  1862. rulebar.init(ruleUrl);
  1863. });
  1864. }
  1865. let customUrlsTitle=document.createElement("h2");
  1866. customUrlsTitle.innerHTML=i18n("customUrls");
  1867. configCon.insertBefore(customUrlsTitle, insertPos);
  1868. let customUrlsInput=document.createElement("textarea");
  1869. customUrlsInput.style.width="100%";
  1870. customUrlsInput.placeholder="0 | http://wedata.net/databases/AutoPagerize/items_all.json";
  1871. configCon.insertBefore(customUrlsInput, insertPos);
  1872.  
  1873. let upBtnImg=document.createElement("div");
  1874. upBtnImg.style.width="45%";
  1875. upBtnImg.style.float="left";
  1876. let upBtnImgTitle=document.createElement("h2");
  1877. upBtnImgTitle.style.whiteSpace="nowrap";
  1878. upBtnImgTitle.style.overflow="hidden";
  1879. upBtnImgTitle.innerHTML=i18n("upBtnImg");
  1880. upBtnImg.appendChild(upBtnImgTitle);
  1881. let upBtnImgInput=document.createElement("input");
  1882. upBtnImgInput.style.width="100%";
  1883. upBtnImgInput.placeholder="data:image/png;base64,UpBtn";
  1884. upBtnImgInput.value=rulesData.upBtnImg||'';
  1885. upBtnImg.appendChild(upBtnImgInput);
  1886. configCon.insertBefore(upBtnImg, insertPos);
  1887.  
  1888. let downBtnImg=document.createElement("div");
  1889. downBtnImg.style.width="45%";
  1890. downBtnImg.style.float="left";
  1891. let downBtnImgTitle=document.createElement("h2");
  1892. downBtnImgTitle.style.whiteSpace="nowrap";
  1893. downBtnImgTitle.style.overflow="hidden";
  1894. downBtnImgTitle.innerHTML=i18n("downBtnImg");
  1895. downBtnImg.appendChild(downBtnImgTitle);
  1896. let downBtnImgInput=document.createElement("input");
  1897. downBtnImgInput.style.width="100%";
  1898. downBtnImgInput.placeholder="data:image/png;base64,DownBtn";
  1899. downBtnImgInput.value=rulesData.downBtnImg||'';
  1900. downBtnImg.appendChild(downBtnImgInput);
  1901. configCon.insertBefore(downBtnImg, insertPos);
  1902.  
  1903. let opacity=document.createElement("div");
  1904. opacity.style.width="10%";
  1905. opacity.style.float="left";
  1906. opacity.style.marginBottom="50px";
  1907. let opacityTitle=document.createElement("h2");
  1908. opacityTitle.style.whiteSpace="nowrap";
  1909. opacityTitle.style.overflow="hidden";
  1910. opacityTitle.innerHTML=i18n("opacity");
  1911. opacity.appendChild(opacityTitle);
  1912. let opacityInput=document.createElement("input");
  1913. opacityInput.value=rulesData.opacity*100;
  1914. opacityInput.type="number";
  1915. opacityInput.style.width="95px";
  1916. opacityInput.style.margin="0";
  1917. opacity.appendChild(opacityInput);
  1918. configCon.insertBefore(opacity, insertPos);
  1919.  
  1920. let configTable=document.createElement("table");
  1921. configTable.style.width="100%";
  1922. let configTbody=document.createElement("tbody");
  1923. configTbody.style.width="100%";
  1924. configTbody.style.display="inline-table";
  1925. configTable.appendChild(configTbody);
  1926. configCon.insertBefore(configTable, insertPos);
  1927. function createCheckbox(innerText, val, tag, parentCheck, otherType){
  1928. if (typeof val == 'undefined') val = "";
  1929. let title=document.createElement(tag||"h3");
  1930. title.innerHTML=innerText;
  1931. let input=document.createElement("input");
  1932. input.type=otherType||"checkbox";
  1933. input.style.width="50px";
  1934. input.style.height="20px";
  1935. input.value=val;
  1936. input.checked=val;
  1937. let td=document.createElement("td");
  1938. td.appendChild(input);
  1939. if(parentCheck){
  1940. td.appendChild(title);
  1941. let parent=parentCheck.parentNode.nextElementSibling;
  1942. let tr=parent.querySelector("tr");
  1943. if(!tr){
  1944. tr=document.createElement("tr");
  1945. parent.appendChild(tr);
  1946. }
  1947. tr.appendChild(td);
  1948. if(!parentCheck.checked){
  1949. td.style.display="none";
  1950. }
  1951. parentCheck.addEventListener("click", e=>{
  1952. td.style.display=parentCheck.checked?"":"none";
  1953. });
  1954. }else{
  1955. let tr=document.createElement("tr");
  1956. tr.appendChild(td);
  1957. td=document.createElement("td");
  1958. td.appendChild(title);
  1959. tr.appendChild(td);
  1960. configTable.children[0].appendChild(tr);
  1961. }
  1962. return input;
  1963. }
  1964.  
  1965. let enableWhiteListInput=createCheckbox(i18n("autoRun"), rulesData.enableWhiteList!=true);
  1966. let enableDebugInput=createCheckbox(i18n("enableDebug"), rulesData.enableDebug!=false);
  1967. let enableHistoryInput=createCheckbox(i18n("enableHistory"), rulesData.enableHistory===true);
  1968. let openInNewTabInput=createCheckbox(i18n("openInNewTab"), rulesData.openInNewTab!=false);
  1969. let initRunInput=createCheckbox(i18n("initRun"), rulesData.initRun!=false);
  1970. let preloadInput=createCheckbox(i18n("preload"), rulesData.preload!=false);
  1971. let dbClick2StopInput=createCheckbox(i18n("dbClick2Stop"), rulesData.dbClick2Stop);
  1972. let hideBarInput=createCheckbox(i18n("hideBar"), rulesData.hideBar, "h4", dbClick2StopInput);
  1973. let dbClick2StopCtrlInput=createCheckbox(i18n("dbClick2StopCtrl"), rulesData.dbClick2StopCtrl, "h4", dbClick2StopInput);
  1974. let dbClick2StopAltInput=createCheckbox(i18n("dbClick2StopAlt"), rulesData.dbClick2StopAlt, "h4", dbClick2StopInput);
  1975. let dbClick2StopShiftInput=createCheckbox(i18n("dbClick2StopShift"), rulesData.dbClick2StopShift, "h4", dbClick2StopInput);
  1976. let dbClick2StopMetaInput=createCheckbox(i18n("dbClick2StopMeta"), rulesData.dbClick2StopMeta, "h4", dbClick2StopInput);
  1977. let dbClick2StopKeyInput=createCheckbox(i18n("dbClick2StopKey"), rulesData.dbClick2StopKey, "h4", dbClick2StopInput, "text");
  1978. dbClick2StopKeyInput.setAttribute("maxlength", "1");
  1979.  
  1980. let customRulesTitle=document.createElement("h2");
  1981. customRulesTitle.innerHTML=i18n("customRules");
  1982. configCon.insertBefore(customRulesTitle, insertPos);
  1983. let customRulesInput=document.createElement("textarea");
  1984. configCon.insertBefore(customRulesInput, insertPos);
  1985. if(rulesData.editTemp){
  1986. if(!ruleParser.customRules){
  1987. ruleParser.customRules=[];
  1988. }
  1989. for(let i in ruleParser.customRules){
  1990. if(ruleParser.customRules[i].url==rulesData.editTemp.url){
  1991. ruleParser.customRules.splice(i, 1);
  1992. break;
  1993. }
  1994. }
  1995. ruleParser.customRules.unshift(rulesData.editTemp);
  1996. rulesData.editTemp=null;
  1997. storage.setItem("rulesData", rulesData);
  1998. customRulesInput.previousElementSibling.scrollIntoView();
  1999. }
  2000. customRulesInput.style.width="100%";
  2001. customRulesInput.style.height="800px";
  2002. 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]`;
  2003. customRulesInput.value=getFormatJSON(ruleParser.customRules);
  2004. let blacklistInput=document.createElement("textarea");
  2005. blacklistInput.style.width="100%";
  2006. blacklistInput.style.height="500px";
  2007. blacklistInput.style.display="none";
  2008. blacklistInput.placeholder="http://*.xxx.com/*/y";
  2009. blacklistInput.value=rulesData.blacklist?rulesData.blacklist.join("\n"):"";
  2010. let blacklistBtn=document.createElement("button");
  2011. blacklistBtn.innerText=i18n("editBlacklist");
  2012. blacklistBtn.style.width="100%";
  2013. blacklistBtn.onclick=e=>{
  2014. blacklistInput.style.display=blacklistInput.style.display=="none"?"":"none";
  2015. };
  2016. configCon.insertBefore(blacklistBtn, insertPos);
  2017. configCon.insertBefore(blacklistInput, insertPos);
  2018. let saveBtn=document.createElement("button");
  2019. saveBtn.innerHTML=i18n("save");
  2020. saveBtn.style.width="100%";
  2021. configCon.insertBefore(saveBtn, insertPos);
  2022. saveBtn.onclick=e=>{
  2023. try{
  2024. storage.setItem("hpRules", []);
  2025. if(customRulesInput.value==""){
  2026. storage.setItem("customRules", "");
  2027. }else{
  2028. let customRules=JSON.parse(customRulesInput.value);
  2029. if(Array && Array.isArray && !Array.isArray(customRules)){
  2030. showTips("Rules must be a Array!");
  2031. return;
  2032. }
  2033. debug(customRules);
  2034. storage.setItem("customRules", customRules);
  2035. }
  2036. }catch(e){
  2037. debug(e);
  2038. showTips("JSON error, check again!");
  2039. return;
  2040. }
  2041. rulesData.opacity=opacityInput.value/100;
  2042. rulesData.blacklist=blacklistInput.value?blacklistInput.value.split("\n"):"";
  2043. rulesData.hideBar=hideBarInput.checked;
  2044. rulesData.dbClick2Stop=dbClick2StopInput.checked;
  2045. rulesData.enableWhiteList=!enableWhiteListInput.checked;
  2046. rulesData.enableDebug=enableDebugInput.checked;
  2047. rulesData.enableHistory=enableHistoryInput.checked;
  2048. rulesData.openInNewTab=openInNewTabInput.checked;
  2049. rulesData.initRun=initRunInput.checked;
  2050. rulesData.preload=preloadInput.checked;
  2051. rulesData.upBtnImg=upBtnImgInput.value;
  2052. rulesData.downBtnImg=downBtnImgInput.value;
  2053. rulesData.dbClick2StopCtrl=dbClick2StopCtrlInput.checked;
  2054. rulesData.dbClick2StopAlt=dbClick2StopAltInput.checked;
  2055. rulesData.dbClick2StopShift=dbClick2StopShiftInput.checked;
  2056. rulesData.dbClick2StopMeta=dbClick2StopMetaInput.checked;
  2057. rulesData.dbClick2StopKey=dbClick2StopKeyInput.value;
  2058. storage.setItem("rulesData", rulesData);
  2059. let customUrls=customUrlsInput.value.trim();
  2060. if(customUrls){
  2061. customUrls=customUrls.split(/\n/);
  2062. for(let c=0;c<customUrls.length;c++){
  2063. let urlArr=customUrls[c].split("|"),url,type=1;
  2064. if(urlArr.length==1){
  2065. url=urlArr[0].trim();
  2066. if(!/^http/.test(url)){
  2067. showTips("Wrong url, check again!");
  2068. return;
  2069. }
  2070. }else if(urlArr.length==2){
  2071. type=urlArr[0].trim();
  2072. url=urlArr[1].trim();
  2073. if(!/^http/.test(url)){
  2074. showTips("Wrong url, check again!");
  2075. return;
  2076. }
  2077. }else{
  2078. break;
  2079. }
  2080. let maxId=0,hasUrl=false;
  2081. if(!rulesData.urls){
  2082. rulesData.urls=[];
  2083. maxId=1;
  2084. }else{
  2085. rulesData.urls.forEach(u=>{
  2086. if(maxId<u.id){
  2087. maxId=u.id;
  2088. }
  2089. if(u.url==url){
  2090. hasUrl=true;
  2091. }
  2092. });
  2093. if(hasUrl)break;
  2094. }
  2095. if(!rulesData.sort)rulesData.sort=[1];
  2096. rulesData.urls.push({id:maxId+1,url:url,type:type});
  2097. rulesData.sort.push(maxId+1);
  2098. storage.setItem("rulesData", rulesData);
  2099. }
  2100. }
  2101. showTips("The settings are saved");
  2102. location.reload();
  2103. };
  2104. return true;
  2105. }
  2106.  
  2107. var inUpdate=false;
  2108. function updateRules(success,fail){
  2109. if(inUpdate)return;
  2110. inUpdate=true;
  2111. let ruleIndex=ruleUrls.length-1;
  2112. storage.setItem("hpRules", []);
  2113. function addNextRule(){
  2114. if(ruleIndex<0){
  2115. let now=new Date().getTime();
  2116. storage.setItem("ruleLastUpdate", now);
  2117. storage.setItem("rules", ruleParser.rules);
  2118. inUpdate=false;
  2119. success();
  2120. }else{
  2121. let rule=ruleUrls[ruleIndex--];
  2122. ruleParser.addRuleByUrl(rule.url, rule.type, rule.id, (json,err)=>{
  2123. if(!json){
  2124. fail(rule,err);
  2125. }
  2126. addNextRule();
  2127. })
  2128. }
  2129. }
  2130. addNextRule();
  2131. }
  2132.  
  2133. function objIsArr(obj) {
  2134. return obj &&
  2135. typeof obj === 'object' &&
  2136. typeof obj.length === 'number' &&
  2137. !(obj.propertyIsEnumerable('length'));
  2138. }
  2139.  
  2140. function isVisible(el, win) {
  2141. if(!el.offsetParent)return false;
  2142. var loopable = true,
  2143. visible = el.tagName && win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  2144. while(loopable && visible) {
  2145. el = el.parentNode;
  2146.  
  2147. if(el && el.tagName && el.tagName!="BODY") {
  2148. visible = win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  2149. }else {
  2150. loopable = false;
  2151. }
  2152. }
  2153. return visible;
  2154. }
  2155.  
  2156. function getElementTop(ele) {
  2157. var actualTop = ele.offsetTop;
  2158. var current = ele.offsetParent;
  2159. while (current) {
  2160. actualTop += current.offsetTop;
  2161. current = current.offsetParent;
  2162. }
  2163. return actualTop;
  2164. }
  2165.  
  2166. function getFormatJSON(obj){
  2167. if(!objIsArr(obj) || obj.length === 0)return "";
  2168. return JSON.stringify(obj, null, 4);
  2169. let ret="[\n";
  2170. let len=obj.length,i=0,isLast;
  2171. obj.forEach(item=>{
  2172. ret+=" {\n";
  2173. let iLen=Object.keys(item).length,j=0;
  2174. for(let key in item){
  2175. isLast=(++j)==iLen;
  2176. let value=item[key];
  2177. if(objIsArr(value)){
  2178. let vstr="[",v=0,vIsLast=false;
  2179. value.forEach(vi=>{
  2180. vIsLast=(++v)==value.length;
  2181. vstr+="\""+vi.replace(/\\/g,"\\\\")+"\""+(vIsLast?"":",");
  2182. });
  2183. vstr+="]";
  2184. ret+=" \""+key+"\":"+vstr+""+(isLast?"":",")+"\n";
  2185. }else{
  2186. if(typeof value=="string"){
  2187. value=value.replace(/\\/g,"\\\\").replace(/"/g,"\\\"");
  2188. value="\""+value+"\"";
  2189. }
  2190. ret+=" \""+key+"\":"+value+""+(isLast?"":",")+"\n";
  2191. }
  2192. }
  2193. isLast=(++i)==len;
  2194. ret+=" }"+(isLast?"":",")+"\n";
  2195. });
  2196. ret+="]";
  2197. return ret;
  2198. }
  2199.  
  2200. function globMatch(first, second) {
  2201. if (first.length == 0 && second.length == 0){
  2202. return true;
  2203. }
  2204.  
  2205. if (first.length > 1 && first[0] == '*' &&
  2206. second.length == 0){
  2207. return false;
  2208. }
  2209.  
  2210. if ((first.length > 1 && first[0] == '?') ||
  2211. (first.length != 0 && second.length != 0 &&
  2212. first[0] == second[0])){
  2213. return globMatch(first.substring(1),
  2214. second.substring(1));
  2215. }
  2216.  
  2217. if (first.length > 0 && first[0] == '*'){
  2218. return globMatch(first.substring(1), second) ||
  2219. globMatch(first, second.substring(1));
  2220. }
  2221.  
  2222. return false;
  2223. }
  2224.  
  2225. function initRules(callback) {
  2226. /*0 wedata格式,1 pagetual格式*/
  2227. ruleUrls=[
  2228. {
  2229. id:1,
  2230. url:'http://wedata.net/databases/AutoPagerize/items_all.json',
  2231. type:0,
  2232. }
  2233. ];var i=0,j=0;
  2234.  
  2235. ruleParser.initSavedRules(()=>{
  2236. storage.getItem("rulesData", data=>{
  2237. if(data){
  2238. rulesData=data;
  2239. if(data.urls)ruleUrls=ruleUrls.concat(data.urls);
  2240. if(data.sort){
  2241. let urls=[];
  2242. data.sort.forEach(id=>{
  2243. for(let s=0;s<ruleUrls.length;s++){
  2244. if(id==ruleUrls[s].id){
  2245. urls.push(ruleUrls[s]);
  2246. break;
  2247. }
  2248. }
  2249. });
  2250. ruleUrls=urls;
  2251. }
  2252. }
  2253. let upBtnImg=rulesData.upBtnImg,downBtnImg=rulesData.downBtnImg;
  2254. if(upBtnImg && downBtnImg){
  2255. downSvgCSS=downSvgCSS.replace("transform: rotate(180deg);","");
  2256. }else if(upBtnImg && !downBtnImg){
  2257. downBtnImg=upBtnImg;
  2258. }else if(downBtnImg && !upBtnImg){
  2259. upBtnImg=downBtnImg;
  2260. }
  2261. if(upBtnImg){
  2262. upSvg=`<img src="${upBtnImg}"/>`;
  2263. }
  2264. if(downBtnImg){
  2265. downSvg=`<img src="${downBtnImg}"/>`;
  2266. }
  2267. if(typeof(rulesData.opacity)=="undefined"){
  2268. rulesData.opacity=0.3;
  2269. }
  2270. if(typeof(rulesData.hideBar)=="undefined"){
  2271. rulesData.hideBar=false;
  2272. }
  2273. if(typeof(rulesData.dbClick2Stop)=="undefined"){
  2274. rulesData.dbClick2Stop=true;
  2275. }
  2276. if(typeof(rulesData.enableWhiteList)=="undefined"){
  2277. rulesData.enableWhiteList=false;
  2278. }
  2279. if(typeof(rulesData.enableHistory)=="undefined"){
  2280. rulesData.enableHistory=false;
  2281. }
  2282. if(typeof(rulesData.openInNewTab)=="undefined"){
  2283. rulesData.openInNewTab=true;
  2284. }
  2285. if(typeof(rulesData.enableDebug)=="undefined"){
  2286. rulesData.enableDebug=true;
  2287. }
  2288. if(typeof(rulesData.initRun)=="undefined"){
  2289. rulesData.initRun=true;
  2290. }
  2291. if(typeof(rulesData.preload)=="undefined"){
  2292. rulesData.preload=true;
  2293. }
  2294. if(rulesData.blacklist && rulesData.blacklist.length>0){
  2295. for(let b in rulesData.blacklist){
  2296. let curGlob=rulesData.blacklist[b];
  2297. if(globMatch(curGlob, location.href)){
  2298. return;
  2299. }
  2300. }
  2301. }
  2302. enableDebug=rulesData.enableDebug;
  2303. storage.getItem("forceState_"+location.host, v=>{
  2304. storage.getItem("ruleLastUpdate", date=>{
  2305. if(typeof(v)=="undefined"){
  2306. v=(rulesData.enableWhiteList?1:0);
  2307. }
  2308. forceState=v;
  2309. updateDate=date;
  2310. if(initConfig())return;
  2311. if(forceState==1)return;
  2312. let now=new Date().getTime();
  2313. if(!date || now-date>2*24*60*60*1000){
  2314. updateRules(()=>{
  2315. },(rule,err)=>{});
  2316. storage.setItem("ruleLastUpdate", now);
  2317. }
  2318. callback();
  2319. });
  2320. });
  2321. });
  2322. });
  2323. }
  2324.  
  2325. function requestDoc(url, callback){
  2326. _GM_xmlhttpRequest({
  2327. url: url,
  2328. method: 'GET',
  2329. overrideMimeType: 'text/html;charset='+document.charset,
  2330. headers: {
  2331. 'Referer': location.href,
  2332. "Content-Type": "text/html;charset="+document.charset,
  2333. },
  2334. timeout: 5000,
  2335. onload: function(res) {
  2336. var doc=null,response=res.response;
  2337. let preCode=ruleParser.curSiteRule.pageElementPre || ruleParser.curSiteRule.pagePre;
  2338. if(preCode){
  2339. try{
  2340. if (typeof _unsafeWindow.pagetualPagePre!='undefined') {
  2341. response = _unsafeWindow.pagetualPagePre(response);
  2342. } else if (preCode.length == 2) {
  2343. response = response.replace(new RegExp(preCode[0], "gi"), preCode[1]);
  2344. } else {
  2345. response = Function("response",'"use strict";' + preCode)(response);
  2346. }
  2347. }catch(e){
  2348. debug(e);
  2349. }
  2350. }
  2351. try {
  2352. doc=document.implementation.createHTMLDocument('');
  2353. doc.documentElement.innerHTML=response;
  2354. }
  2355. catch (e) {
  2356. debug('parse error'+e.toString());
  2357. }
  2358. let pageElement=ruleParser.getPageElement(doc);
  2359. if(inCors && (!pageElement || pageElement.length==0)){
  2360. ruleParser.curSiteRule.pageElement=allOfBody;
  2361. pageElement=ruleParser.getPageElement(doc);
  2362. ruleParser.getInsert(true);
  2363. }
  2364. //只有1的話怕不是圖片哦
  2365. if(pageElement && (pageElement.length>1 || (pageElement.length==1 && pageElement[0].tagName!="IMG") )){
  2366. let result=ruleParser.insertPage(doc, pageElement, url, callback, false);
  2367. ruleParser.curSiteRule.action=0;
  2368. if(!result){
  2369. ruleParser.curSiteRule.action=1;
  2370. requestFromIframe(url, (doc, eles)=>{
  2371. loadPageOver();
  2372. if(eles){
  2373. ruleParser.insertPage(doc, eles, url, callback, true);
  2374. }
  2375. });
  2376. }
  2377. }else if(ruleParser.curSiteRule.singleUrl || curPage==1){
  2378. ruleParser.curSiteRule.action=1;
  2379. requestFromIframe(url, (doc, eles)=>{
  2380. loadPageOver();
  2381. if(eles){
  2382. ruleParser.insertPage(doc, eles, url, callback, true);
  2383. }
  2384. });
  2385. }else{
  2386. isPause=true;
  2387. callback(false);
  2388. }
  2389. },
  2390. onerror: function(e){
  2391. debug(e);
  2392. callback(false);
  2393. },
  2394. ontimeout: function(e){
  2395. debug(e);
  2396. callback(false);
  2397. }
  2398. });
  2399. }
  2400.  
  2401. function initPage(){
  2402. ruleParser.initPage(()=>{
  2403. if(ruleParser.nextLinkHref){
  2404. let isJs=/^(javascript|#)/.test(ruleParser.nextLinkHref.replace(location.href,""));
  2405. if(!isJs){
  2406. let inForce=(forceState == 2 || forceState == 3);
  2407. _GM_registerMenuCommand(i18n(inForce?"cancelForceIframe":"forceIframe"), ()=>{
  2408. if(inForce){
  2409. storage.setItem("forceState_"+location.host, "");
  2410. }else{
  2411. let _state=ruleParser.curSiteRule.action>0 || confirm(i18n("forceAllBody"))?2:3;
  2412. storage.setItem("forceState_"+location.host, _state);
  2413. }
  2414. location.reload();
  2415. });
  2416. }
  2417. _GM_registerMenuCommand(i18n("loadNow"), ()=>{
  2418. let loadNum=window.prompt(i18n("loadConfirm"), "1");
  2419. if(loadNum==="" || loadNum===null)return;
  2420. autoLoadNum=Math.abs(parseInt(loadNum));
  2421. nextPage();
  2422. });
  2423. }
  2424. initListener();
  2425. if(rulesData.initRun && ruleParser.curSiteRule.initRun!=0)nextPage();
  2426. });
  2427. }
  2428.  
  2429. var pageBarStyle;
  2430. function initView(){
  2431. _GM_addStyle(`
  2432. .pagetual_pageBar{
  2433. -moz-transition:opacity 0.3s ease-in-out 0s;
  2434. -webkit-transition:opacity 0.3s ease-in-out 0s;
  2435. transition:opacity 0.3s ease-in-out 0s;
  2436. }
  2437. .pagetual_pageBar.stop {
  2438. -webkit-filter: invert(100%);
  2439. filter: invert(100%);
  2440. opacity: 1!important;
  2441. }
  2442. .pagetual_pageBar.hide {
  2443. display: none!important;
  2444. }
  2445. .pagetual_pageBar:hover {
  2446. opacity: 1!important;
  2447. }
  2448. .pagetual_pageBar span {
  2449. vertical-align: super;
  2450. }
  2451. .pagetual_pageBar a>span {
  2452. margin-top: 0!important;
  2453. opacity: 0;
  2454. -moz-transition:all 0.3s ease-in-out 0s;
  2455. -webkit-transition:all 0.3s ease-in-out 0s;
  2456. transition:all 0.3s ease-in-out 0s;
  2457. }
  2458. .pagetual_pageBar a>span:hover {
  2459. color: red;
  2460. }
  2461. .pagetual_pageBar a:hover>span {
  2462. opacity: 1;
  2463. }
  2464. .pagetual_pageBar a:hover>span.prev {
  2465. margin-top: -30px!important;
  2466. }
  2467. .pagetual_pageBar a:hover>span.next {
  2468. margin-top: 30px!important;
  2469. }
  2470.  
  2471. .pagetual_pageBar span>svg:hover {
  2472. animation: touhouAni 1s infinite;
  2473. }
  2474. .pagetual_pageBar .pagetual_pageNum{
  2475. color: #55555f;
  2476. }
  2477. .pagetual_pageBar .pagetual_pageNum:hover{
  2478. color: #ff6464;
  2479. }
  2480. .pagetual_tipsWords{
  2481. font-size: 50px;
  2482. font-weight: bold;
  2483. font-family: "黑体", -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto",
  2484. "Oxygen", "Ubuntu", "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji",
  2485. "Segoe UI Emoji", "Segoe UI Symbol";
  2486. color: #ffffff;
  2487. height: 70px;
  2488. line-height: 70px;
  2489. position: fixed;
  2490. left: 50%;
  2491. top: 10%;
  2492. margin-left: -150px;
  2493. padding: 0 10px;
  2494. z-index: 999999999;
  2495. background-color: #000;
  2496. border: 1px solid black;
  2497. border-radius: 10px;
  2498. opacity: 0;
  2499. filter: alpha(opacity=65);
  2500. box-shadow: 5px 5px 20px 0px #000;
  2501. -moz-transition:opacity 0.3s ease-in-out 0s;
  2502. -webkit-transition:opacity 0.3s ease-in-out 0s;
  2503. transition:opacity 0.3s ease-in-out 0s;
  2504. pointer-events: none;
  2505. }
  2506.  
  2507. @keyframes touhouAni{
  2508. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  2509. to {transform: rotate(360deg);}
  2510. }
  2511. @-webkit-keyframes touhouAni{
  2512. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  2513. to {transform: rotate(360deg);}
  2514. }
  2515. .pagetual_loading {
  2516. width: 50px;
  2517. height: 50px;
  2518. margin: 10px auto;
  2519. border-radius: 100%;
  2520. -webkit-animation: pagetual_loading_scaleout 1.0s infinite ease-in-out;
  2521. animation: pagetual_loading_scaleout 1.0s infinite ease-in-out;
  2522. }
  2523. @-webkit-keyframes pagetual_loading_scaleout {
  2524. 0% { -webkit-transform: scale(0.0) }
  2525. 100% {
  2526. -webkit-transform: scale(1.0);
  2527. opacity: 0;
  2528. }
  2529. }
  2530. @keyframes pagetual_loading_scaleout {
  2531. 0% {
  2532. transform: scale(0.0);
  2533. -webkit-transform: scale(0.0);
  2534. } 100% {
  2535. transform: scale(1.0);
  2536. -webkit-transform: scale(1.0);
  2537. opacity: 0;
  2538. }
  2539. }
  2540. .pagetual_loading_text {
  2541. -webkit-animation: pagetual_loading_opacity 2.6s infinite ease-in-out;
  2542. animation: pagetual_loading_opacity 2.6s infinite ease-in-out;
  2543. }
  2544. @-webkit-keyframes pagetual_loading_opacity {
  2545. 0% { opacity: 1 }
  2546. 50% { opacity: 0.2 }
  2547. 100% { opacity: 1 }
  2548. }
  2549. @keyframes pagetual_loading_opacity {
  2550. 0% { opacity: 1 }
  2551. 50% { opacity: 0.2 }
  2552. 100% { opacity: 1 }
  2553. }
  2554. `);
  2555. pageBarStyle=`line-height:1;opacity:${rulesData.opacity};display:${rulesData.opacity==0?"none":"block"};padding:0;box-shadow: 0px 0px 10px 0px #000000aa;border-radius: 20px;background-color: rgb(240 240 240 / 80%);font-size: 30px;visibility: visible; position: initial; width: auto; height: 30px; float: none; clear: both; margin: 5px auto; text-align: center;`;
  2556. }
  2557. var loadingDiv=document.createElement("div");
  2558. loadingDiv.style.cssText="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;";
  2559. loadingDiv.innerHTML=`<p class="pagetual_loading_text" style="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;">${i18n("loadingText")}</p><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" p-id="6364"><path d="M296 440c-44.1 0-80 35.9-80 80s35.9 80 80 80 80-35.9 80-80-35.9-80-80-80z" fill="#6e6e6e" p-id="6365"></path><path d="M960 512c0-247-201-448-448-448S64 265 64 512c0 1.8 0.1 3.5 0.1 5.3 0 0.9-0.1 1.8-0.1 2.7h0.2C68.5 763.3 267.7 960 512 960c236.2 0 430.1-183.7 446.7-415.7 0.1-0.8 0.1-1.6 0.2-2.3 0.4-4.6 0.5-9.3 0.7-13.9 0.1-2.7 0.4-5.3 0.4-8h-0.2c0-2.8 0.2-5.4 0.2-8.1z m-152 8c0 44.1-35.9 80-80 80s-80-35.9-80-80 35.9-80 80-80 80 35.9 80 80zM512 928C284.4 928 99 744.3 96.1 517.3 97.6 408.3 186.6 320 296 320c110.3 0 200 89.7 200 200 0 127.9 104.1 232 232 232 62.9 0 119.9-25.2 161.7-66-66 142.7-210.4 242-377.7 242z" fill="#6e6e6e" p-id="6366"></path></svg></div>`;
  2560. var loadingCSS=`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;`;
  2561.  
  2562. var upSvg=`<svg width="30" height="30" style="display:initial;position:absolute;cursor: pointer;margin: 0 -45px;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" p-id="6364"><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" p-id="6365"></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" p-id="6366"></path></svg>`;
  2563. var upSvgCSS=`display:initial;position:absolute;cursor: pointer;margin: 0 -45px;width: 30px;height: 30px;vertical-align: middle;fill: currentColor;overflow: hidden;`;
  2564. var downSvg=`<svg width="30" height="30" style="display:initial;position:absolute;cursor: pointer;margin: 0 15px;width: 30px;height: 30px;vertical-align: middle;fill: currentColor;overflow: hidden;transform: rotate(180deg);" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="6364"><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" p-id="6365"></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" p-id="6366"></path></svg>`;
  2565. var downSvgCSS=`display:initial;position:absolute;cursor: pointer;margin: 0 15px;width: 30px;height: 30px;vertical-align: middle;fill: currentColor;overflow: hidden;transform: rotate(180deg);`;
  2566.  
  2567. var initStyle=`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 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;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;`;
  2568. var pageTextStyle=`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 auto;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;`;
  2569.  
  2570. var tipsWords=document.createElement("div");
  2571. tipsWords.className="pagetual_tipsWords";
  2572.  
  2573. var isPause=false,isLoading=false,curPage=1,forceState=0,bottomGap=1000,autoLoadNum=-1;
  2574.  
  2575. function changeStop(stop, hide){
  2576. isPause=stop;
  2577. [].forEach.call(document.querySelectorAll(".pagetual_pageBar"), bar=>{
  2578. if(isPause){
  2579. bar.classList.add("stop");
  2580. if(hide)bar.classList.add("hide");
  2581. }else{
  2582. bar.classList.remove("stop");
  2583. if(hide)bar.classList.remove("hide");
  2584. }
  2585. });
  2586. }
  2587.  
  2588. function isInViewPort(element) {
  2589. if(!element.parentNode)return false;
  2590. if(_unsafeWindow.getComputedStyle(element).display=="none")return false;
  2591. const viewWidth = window.innerWidth || document.documentElement.clientWidth;
  2592. const viewHeight = window.innerHeight || document.documentElement.clientHeight;
  2593. const {
  2594. top,
  2595. right,
  2596. bottom,
  2597. left,
  2598. } = element.getBoundingClientRect();
  2599.  
  2600. return (
  2601. top >= 0 &&
  2602. left >= 0 &&
  2603. right <= viewWidth + 1 &&
  2604. bottom <= viewHeight * 2
  2605. );
  2606. }
  2607.  
  2608. var urlChanged=false;
  2609. var _wr = function(type) {
  2610. var orig = history[type];
  2611. return function() {
  2612. var rv = orig.apply(this, arguments);
  2613. var e = new Event(type);
  2614. e.arguments = arguments;
  2615. window.dispatchEvent(e);
  2616. return rv;
  2617. };
  2618. };
  2619. history.pushState = _wr('pushState');
  2620. window.addEventListener('pushState', function(e) {
  2621. urlChanged=true;
  2622. isPause=true;
  2623. setTimeout(()=>{
  2624. if(location.href==configPage){
  2625. location.reload();
  2626. }else if(!ruleParser.ruleMatch(ruleParser.curSiteRule)){
  2627. initPage();
  2628. }
  2629. },1);
  2630. });
  2631.  
  2632. function initListener(){
  2633. let loadmoreBtn,loading=true,lastScroll=0,checkLoadMoreTimes=0;
  2634. let checkLoadMore=setInterval(()=>{
  2635. loadmoreBtn=getLoadMore(document);
  2636. if(loadmoreBtn && isVisible(loadmoreBtn, _unsafeWindow)){
  2637. loading=false;
  2638. clearInterval(checkLoadMore);
  2639. }else if(checkLoadMoreTimes>10){
  2640. clearInterval(checkLoadMore);
  2641. }
  2642. },300);
  2643. let checkScrollReach=()=>{
  2644. let scrolly=window.scrollY;
  2645. let windowHeight=window.innerHeight || document.documentElement.clientHeight;
  2646. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  2647. if(scrollH-scrolly-windowHeight<bottomGap){
  2648. nextPage();
  2649. }
  2650. };
  2651. let scrollHandler = e=>{
  2652. if(urlChanged){
  2653. ruleParser.initPage(()=>{
  2654. if(ruleParser.nextLinkHref)initView();
  2655. });
  2656. urlChanged=false;
  2657. isPause=false;
  2658. }
  2659. if(isPause)return;
  2660. if(!loading){
  2661. if(!loadmoreBtn || !loadmoreBtn.parentNode){
  2662. loadmoreBtn=getLoadMore(document);
  2663. }
  2664. if(loadmoreBtn){
  2665. if(isInViewPort(loadmoreBtn)){
  2666. emuClick(loadmoreBtn);
  2667. loading=true;
  2668. setTimeout(()=>{loading=false},200);
  2669. }
  2670. }else{
  2671. loading=true;
  2672. setTimeout(()=>{loading=false},200);
  2673. }
  2674. }
  2675. if(!isLoading){
  2676. checkScrollReach();
  2677. }
  2678. if(ruleParser.curSiteRule.lockScroll){
  2679. let curScroll=document.body.scrollTop||document.documentElement.scrollTop;
  2680. if(isLoading && Math.abs(lastScroll-curScroll)>200){
  2681. document.body.scrollTop=lastScroll;
  2682. document.documentElement.scrollTop=lastScroll;
  2683. }else{
  2684. lastScroll=curScroll;
  2685. }
  2686. }
  2687. };
  2688. if(!ruleParser.curSiteRule.wheel){
  2689. document.addEventListener('scroll', scrollHandler, true);
  2690. }
  2691. document.addEventListener('wheel', scrollHandler, true);
  2692. document.addEventListener('dblclick', e=>{
  2693. if(forceState==1 || e.target.tagName=='INPUT' || e.target.tagName=='TEXTAREA') return;
  2694. if(!rulesData.dbClick2StopKey){
  2695. if((rulesData.dbClick2StopCtrl && !e.ctrlKey) ||
  2696. (rulesData.dbClick2StopAlt && !e.altKey) ||
  2697. (rulesData.dbClick2StopShift && !e.shiftKey) ||
  2698. (rulesData.dbClick2StopMeta && !e.metaKey)){
  2699. return;
  2700. }
  2701. }
  2702. if(e.target.tagName!="BODY"){
  2703. let selStr=document.getSelection().toString();
  2704. if(selStr && selStr.trim()){
  2705. return;
  2706. }
  2707. }
  2708. if(rulesData.dbClick2Stop && (ruleParser.nextLinkHref || loadmoreBtn)){
  2709. setTimeout(()=>{
  2710. changeStop(!isPause, rulesData.hideBar);
  2711. if(!isPause){
  2712. checkScrollReach();
  2713. }
  2714. showTips(i18n(isPause?"disable":"enable"));
  2715. },10);
  2716. }
  2717. });
  2718. if(rulesData.dbClick2StopKey){
  2719. document.addEventListener('keydown', e=>{
  2720. if((rulesData.dbClick2StopCtrl && !e.ctrlKey) ||
  2721. (rulesData.dbClick2StopAlt && !e.altKey) ||
  2722. (rulesData.dbClick2StopShift && !e.shiftKey) ||
  2723. (rulesData.dbClick2StopMeta && !e.metaKey)){
  2724. return;
  2725. }
  2726. if (document.activeElement &&
  2727. (document.activeElement.tagName == 'INPUT' ||
  2728. document.activeElement.tagName == 'TEXTAREA')) {
  2729. return;
  2730. }
  2731. var key = String.fromCharCode(e.keyCode).toLowerCase();
  2732. if(rulesData.dbClick2StopKey.toLowerCase()==key){
  2733. forceState=(forceState==1?0:1);
  2734. showTips(i18n(forceState==1?"disableSiteTips":"enableSiteTips"));
  2735. if(!ruleParser.curSiteRule.url) {
  2736. storage.setItem("forceState_"+location.host, forceState);
  2737. location.reload();
  2738. }
  2739. }
  2740. });
  2741. }
  2742. }
  2743.  
  2744. function showTips(content, wordColor, backColor){
  2745. document.body.appendChild(tipsWords);
  2746. tipsWords.style.opacity=0.8;
  2747. tipsWords.innerText=content;
  2748. tipsWords.style.marginLeft=-tipsWords.offsetWidth/2+"px";
  2749. tipsWords.style.color=wordColor||0xFFFFFF;
  2750. tipsWords.style.backgroundColor=backColor||0x000;
  2751. setTimeout(()=>{tipsWords.style.opacity=0},1000);
  2752. }
  2753.  
  2754. function getLoadMore(doc){
  2755. if(ruleParser.curSiteRule.loadMore==="")return null;
  2756. let btnSel=ruleParser.curSiteRule.loadMore||".LoadMore,.load-more,.button-show-more,button[data-testid='more-results-button']",loadmoreBtn;
  2757. if(btnSel){
  2758. try{
  2759. loadmoreBtn=doc.querySelector(btnSel);
  2760. }catch(e){
  2761. loadmoreBtn=getElementByXpath(btnSel,doc,doc);
  2762. }
  2763. }
  2764. if(!loadmoreBtn){
  2765. let buttons=doc.querySelectorAll("input,button,a,div[onclick]"),loadmoreReg=/^\s*(加载更多|加載更多|load\s*more|もっと読み込む)\s*$/i;
  2766. for(let i=0;i<buttons.length;i++){
  2767. let button=buttons[i];
  2768. if(button && loadmoreReg.test(button.innerText)){
  2769. loadmoreBtn=button;
  2770. break;
  2771. }
  2772. }
  2773. }
  2774. if(loadmoreBtn && !ruleParser.curSiteRule.loadMore && loadmoreBtn.href && !/^(javascript|#)/.test(loadmoreBtn.href))loadmoreBtn=null;
  2775. return loadmoreBtn;
  2776. }
  2777.  
  2778. var hasPageNum=true;
  2779. function createPageBar(url){
  2780. let insert=ruleParser.getInsert();
  2781. if(!insert || !insert.parentNode)return;
  2782. curPage++;
  2783. let example=ruleParser.curSiteRule.insertPos==2?insert.children[0]:(insert.parentNode.children[parseInt(insert.parentNode.children.length/2)]||insert);
  2784. if (example.className=="pagetual_pageBar") {
  2785. example=example.previousElementSibling;
  2786. }
  2787. if(!example || !example.parentNode)example=insert;
  2788. let exampleStyle = _unsafeWindow.getComputedStyle(example);
  2789. let inTable=example.parentNode.tagName=="TABLE" ||
  2790. example.tagName=="TR" ||
  2791. example.tagName=="TBODY" ||
  2792. exampleStyle.display=="table-row" ||
  2793. (example.previousElementSibling && example.previousElementSibling.tagName=="TR") ||
  2794. (example.previousElementSibling && example.previousElementSibling.tagName=="TBODY");
  2795. let inLi=example.tagName=="LI" || (example.previousElementSibling && example.previousElementSibling.tagName=="LI");
  2796. if(forceState==2){
  2797. inTable=inLi=false;
  2798. }
  2799. let pageBar=document.createElement(inTable?"tr":(inLi?"li":"div"));
  2800. let upSpan=document.createElement("span");
  2801. let downSpan=document.createElement("span");
  2802. let pageText=document.createElement("a");
  2803. let pageNum;
  2804. pageBar.className="pagetual_pageBar";
  2805. pageBar.id="pagetual_pageBar"+curPage;
  2806. if(isPause){
  2807. pageBar.classList.add("stop");
  2808. }
  2809. pageBar.style.cssText=pageBarStyle;
  2810. pageBar.title=i18n(isPause?"enable":"disable");
  2811. upSpan.innerHTML=upSvg;
  2812. upSpan.children[0].style.cssText=upSvgCSS;
  2813. upSpan.title=i18n("toTop");
  2814. downSpan.innerHTML=downSvg;
  2815. downSpan.children[0].style.cssText=downSvgCSS;
  2816. downSpan.title=i18n("toBottom");
  2817. upSpan.style.cssText=initStyle;
  2818. downSpan.style.cssText=initStyle;
  2819. pageText.href=url;
  2820. pageText.style.cssText=pageTextStyle;
  2821. pageText.title=i18n("current");
  2822. pageBar.appendChild(upSpan);
  2823. pageBar.appendChild(pageText);
  2824. if(ruleParser.nextTitle){
  2825. pageText.innerHTML=ruleParser.nextTitle+" ";
  2826. pageText.title=ruleParser.nextTitle;
  2827. }
  2828. if(ruleParser.curSiteRule.pageNum || (hasPageNum && /[&\/\?](p=|page[=\/_-]?)\d+|[_-]\d+\./.test(url))){
  2829. pageText.innerHTML+="Page ";
  2830. pageNum=document.createElement("span");
  2831. pageNum.innerText=ruleParser.getPageNumFromUrl(url);
  2832. pageNum.className="pagetual_pageNum";
  2833. pageNum.title=i18n("inputPageNum");
  2834. pageNum.style.cssText=pageTextStyle;
  2835. pageNum.style.cursor="pointer";
  2836. pageNum.style.color="";
  2837. pageNum.style.marginLeft="5px";
  2838. pageNum.addEventListener("click", e=>{
  2839. let pageInput=prompt(i18n("inputPageNum"), "1");
  2840. if(pageInput){
  2841. let pageLink=ruleParser.getLinkByPage(url, pageInput);
  2842. if(pageLink){
  2843. _GM_openInTab(pageLink,{active:true});
  2844. }
  2845. }
  2846. e.preventDefault();
  2847. e.stopPropagation();
  2848. });
  2849. pageBar.appendChild(pageNum);
  2850. }else{
  2851. pageText.innerHTML+="Page "+curPage;
  2852. hasPageNum=false;
  2853. }
  2854. let preBtn=document.createElement("span");
  2855. preBtn.innerText="∧";
  2856. preBtn.title="Prev page";
  2857. preBtn.className="prev";
  2858. preBtn.style.cssText="float: left; margin-top: -30px; width: 40px; background: rgba(240, 240, 240, 0.8); position: absolute; border-radius: 20px 20px 0 0; box-shadow: rgb(0 0 0 / 50%) 0px -5px 5px;z-index:9999999";
  2859. let nextBtn=document.createElement("span");
  2860. nextBtn.innerText="∨";
  2861. nextBtn.title="Next page";
  2862. nextBtn.className="next";
  2863. nextBtn.style.cssText="float: left; margin-top: 30px; width: 40px; background: rgba(240, 240, 240, 0.8); position: absolute; border-radius: 0 0 20px 20px; box-shadow: rgb(0 0 0 / 50%) 0px 5px 5px;z-index:9999999";
  2864. let localPage=curPage;
  2865. let scrollToPageBar = bar => {
  2866. bar.scrollIntoView();
  2867. if (typeof ruleParser.curSiteRule.pageBarTop !== 'undefined') {
  2868. document.documentElement.scrollBy(0, -ruleParser.curSiteRule.pageBarTop);
  2869. }
  2870. };
  2871. preBtn.addEventListener("click", e=>{
  2872. e.stopPropagation();
  2873. e.preventDefault();
  2874. let prePageBar = document.querySelector("#pagetual_pageBar"+(localPage-1));
  2875. if (prePageBar) {
  2876. scrollToPageBar(prePageBar);
  2877. } else {
  2878. document.body.scrollTop=0;
  2879. document.documentElement.scrollTop=0;
  2880. }
  2881. });
  2882. nextBtn.addEventListener("click", e=>{
  2883. e.stopPropagation();
  2884. e.preventDefault();
  2885. let prePageBar=document.querySelector("#pagetual_pageBar"+(localPage+1));
  2886. if (prePageBar) {
  2887. scrollToPageBar(prePageBar);
  2888. } else {
  2889. document.body.scrollTop=9999999;
  2890. document.documentElement.scrollTop=9999999;
  2891. }
  2892. });
  2893. pageText.insertBefore(preBtn, pageText.firstChild);
  2894. pageText.insertBefore(nextBtn, pageText.firstChild);
  2895. pageBar.appendChild(downSpan);
  2896. let parentStyle=_unsafeWindow.getComputedStyle(example.parentNode);
  2897. let parentWidth=example.parentNode.scrollWidth||parseInt(parentStyle.width);
  2898. pageBar.style.width=parentWidth-parseInt(parentStyle.paddingLeft)-parseInt(parentStyle.paddingRight)-10+"px";
  2899. if(parentStyle.display=="grid" || parentStyle.display=="inline-grid"){
  2900. pageBar.style.gridColumnStart=1;
  2901. pageBar.style.gridColumnEnd=1+parseInt(example.parentNode.offsetWidth/example.offsetWidth);
  2902. }
  2903. if(inTable){
  2904. example=(example.tagName=="TR" || example.tagName=="TBODY")?example:example.previousElementSibling;
  2905. if(example.tagName=="TBODY")example=example.querySelector("tr");
  2906. let preTr=example;
  2907. while(preTr && preTr.children.length==0)preTr=preTr.previousElementSibling;
  2908. if(preTr)example=preTr;
  2909. let tdNum=0;
  2910. if (exampleStyle.display=="table-row") {
  2911. tdNum = example.children.length;
  2912. } else {
  2913. [].forEach.call(example.children, el=>{
  2914. if(el.tagName=="TD" || el.tagName=="TH"){
  2915. tdNum+=el.colSpan||1;
  2916. }
  2917. });
  2918. }
  2919. pageBar.style.display="table-row";
  2920. pageBar.style.backgroundColor="unset";
  2921. pageBar.style.lineHeight="20px";
  2922. pageBar.style.boxShadow="";
  2923. let td=document.createElement("td");
  2924. td.colSpan=tdNum||1;
  2925. let inTd=document.createElement("div");
  2926. inTd.style.backgroundColor="rgb(240 240 240 / 80%)";
  2927. inTd.style.borderRadius="20px";
  2928. inTd.style.padding="0 0";
  2929. inTd.style.margin="10px";
  2930. inTd.style.lineHeight="20px";
  2931. inTd.style.textAlign="center";
  2932. inTd.style.boxShadow="rgb(0 0 0 / 67%) 0px 0px 10px 0px";
  2933. inTd.appendChild(upSpan);
  2934. inTd.appendChild(pageText);
  2935. if(pageNum)inTd.appendChild(pageNum);
  2936. inTd.appendChild(downSpan);
  2937. td.appendChild(inTd);
  2938. pageBar.appendChild(td);
  2939. }else if(inLi){
  2940. example=example.tagName=="LI"?example:example.previousElementSibling;
  2941. pageBar.style.display="table-row";
  2942. pageBar.style.backgroundColor="unset";
  2943. pageBar.style.lineHeight="20px";
  2944. pageBar.style.boxShadow="";
  2945. let td=document.createElement("td");
  2946. td.colSpan=example.children.length;
  2947. let inTd=document.createElement("div");
  2948. inTd.style.backgroundColor="rgb(240 240 240 / 80%)";
  2949. inTd.style.borderRadius="20px";
  2950. inTd.style.margin="10px"
  2951. inTd.style.padding="0 0";
  2952. inTd.style.textAlign="center";
  2953. inTd.style.minWidth="150px";
  2954. inTd.appendChild(upSpan);
  2955. inTd.appendChild(pageText);
  2956. inTd.style.width=parseInt(pageBar.style.width)-20+"px";
  2957. inTd.style.boxShadow="rgb(0 0 0 / 67%) 0px 0px 10px 0px";
  2958. if(pageNum)inTd.appendChild(pageNum);
  2959. inTd.appendChild(downSpan);
  2960. td.appendChild(inTd);
  2961. pageBar.appendChild(td);
  2962. }
  2963.  
  2964. upSpan.addEventListener("click", e=>{
  2965. document.body.scrollTop=0;
  2966. document.documentElement.scrollTop=0;
  2967. e.preventDefault();
  2968. e.stopPropagation();
  2969. });
  2970. downSpan.addEventListener("click", e=>{
  2971. changeStop(true);
  2972. pageBar.title=i18n(isPause?"enable":"disable");
  2973. document.body.scrollTop=9999999;
  2974. document.documentElement.scrollTop=9999999;
  2975. e.preventDefault();
  2976. e.stopPropagation();
  2977. });
  2978. pageBar.addEventListener("click", e=>{
  2979. changeStop(!isPause);
  2980. pageBar.title=i18n(isPause?"enable":"disable");
  2981. });
  2982. pageText.addEventListener("click", e=>{
  2983. e.stopPropagation();
  2984. if (e.ctrlKey || e.altKey || e.shiftKey || e.metaKey) return;
  2985. if (e.which == 1) {
  2986. e.preventDefault();
  2987. scrollToPageBar(pageBar);
  2988. }
  2989. });
  2990. ruleParser.insertElement(pageBar);
  2991. if(ruleParser.curSiteRule.pageBar){
  2992. try{
  2993. ((typeof _unsafeWindow.pagetualPageBar=='undefined') ? Function("pageBar",'"use strict";' + ruleParser.curSiteRule.pageBar) : _unsafeWindow.pagetualPageBar)(pageBar);
  2994. }catch(e){
  2995. debug(e);
  2996. }
  2997. }
  2998.  
  2999. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  3000. let posEle=pageBar.nextElementSibling||pageBar;
  3001. while(posEle && !posEle.offsetParent){
  3002. posEle=posEle.previousElementSibling||posEle.parentNode;
  3003. }
  3004. if(posEle){
  3005. let actualTop = getElementTop(posEle);
  3006. bottomGap=scrollH-actualTop+(window.innerHeight||document.documentElement.clientHeight)*(ruleParser.curSiteRule.rate||1);
  3007. if(bottomGap<100)bottomGap=100;
  3008. }else{
  3009. bottomGap=1000;
  3010. }
  3011. if(rulesData.opacity==0)pageBar.style.display="none";
  3012. return pageBar;
  3013. }
  3014.  
  3015. function emuClick(btn){
  3016. if(!PointerEvent)return btn.click();
  3017. let eventParam={
  3018. isTrusted: true,
  3019. altKey: false,
  3020. azimuthAngle: 0,
  3021. bubbles: true,
  3022. button: 0,
  3023. buttons: 0,
  3024. clientX: 1,
  3025. clientY: 1,
  3026. cancelBubble: false,
  3027. cancelable: true,
  3028. composed: true,
  3029. ctrlKey: false,
  3030. defaultPrevented: false,
  3031. detail: 1,
  3032. eventPhase: 2,
  3033. fromElement: null,
  3034. height: 1,
  3035. isPrimary: false,
  3036. metaKey: false,
  3037. pointerId: 1,
  3038. pointerType: "mouse",
  3039. pressure: 0,
  3040. relatedTarget: null,
  3041. returnValue: true,
  3042. shiftKey: false,
  3043. toElement: null,
  3044. twist: 0,
  3045. which: 1
  3046. };
  3047. var mouseEvent = new PointerEvent("mousedown",eventParam);
  3048. btn.dispatchEvent(mouseEvent);
  3049. mouseEvent = new PointerEvent("mouseup",eventParam);
  3050. btn.dispatchEvent(mouseEvent);
  3051. btn.click();
  3052. }
  3053.  
  3054. var failFromIframe=0;
  3055. var inCors=false;
  3056. function requestFromIframe(url, callback){
  3057. url=url.replace(/#[^#]*/,"");
  3058. let orgPage,curPage;
  3059. let iframe = document.createElement('iframe');
  3060. iframe.name = 'pagetual-iframe';
  3061. iframe.width = '100%';
  3062. iframe.height = '0';
  3063. iframe.frameBorder = '0';
  3064. if(ruleParser.curSiteRule.sandbox!=false){
  3065. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  3066. }
  3067. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  3068. let waitTime=100,checkEval;
  3069. if(ruleParser.curSiteRule.wait){
  3070. if(isNaN(ruleParser.curSiteRule.wait)){
  3071. try{
  3072. checkEval=(typeof _unsafeWindow.pagetualWait=='undefined') ? Function("doc",'"use strict";' + ruleParser.curSiteRule.wait) : _unsafeWindow.pagetualWait;
  3073. }catch(e){
  3074. debug(e);
  3075. }
  3076. }else{
  3077. waitTime=ruleParser.curSiteRule.wait;
  3078. }
  3079. }
  3080. let loadedHandler=e=>{
  3081. if(e.data != 'pagetual-iframe:DOMLoaded' && e.type != 'load')return;
  3082. window.removeEventListener('message', loadedHandler, false);
  3083. iframe.removeEventListener('load', loadedHandler, false);
  3084. let tryTimes=0;
  3085. function checkIframe(){
  3086. try{
  3087. let doc=iframe.contentDocument || iframe.contentWindow.document;
  3088. let eles=ruleParser.getPageElement(doc, iframe.contentWindow);
  3089. if(checkEval && !checkEval(doc)){
  3090. setTimeout(()=>{
  3091. checkIframe();
  3092. },waitTime);
  3093. return;
  3094. }else if(eles && eles.length>0){
  3095. callback(doc, eles);
  3096. }else if(tryTimes++ < 10){
  3097. setTimeout(()=>{
  3098. checkIframe();
  3099. },waitTime);
  3100. return;
  3101. }else{
  3102. if(failFromIframe++ > 2){
  3103. failFromIframe=0;
  3104. debug("Stop as failFromIframe");
  3105. isPause=true;
  3106. callback(false, false);
  3107. }else{
  3108. callback(false, false);
  3109. }
  3110. }
  3111. }catch(e){
  3112. debug("Stop as cors");
  3113. inCors=true;
  3114. //isPause=true;
  3115. if(!ruleParser.curSiteRule.pageElement){
  3116. ruleParser.curSiteRule.pageElement=allOfBody;
  3117. ruleParser.getInsert(true);
  3118. }
  3119. ruleParser.curSiteRule.action=0;
  3120. ruleParser.nextLinkHref=url;
  3121. callback(false, false);
  3122. nextPage();
  3123. }
  3124. document.body.removeChild(iframe);
  3125. }
  3126. setTimeout(()=>{
  3127. checkIframe();
  3128. },waitTime);
  3129. };
  3130. window.addEventListener('message', loadedHandler, false);
  3131. iframe.addEventListener('load', loadedHandler, false);
  3132. iframe.src=url;
  3133. document.body.appendChild(iframe);
  3134. }
  3135.  
  3136. var emuIframe,lastActiveUrl=location.href;
  3137. function emuPage(callback){
  3138. let orgPage=null,orgContent=null,preContent=null,curPage,iframeDoc,times=0,loadmoreBtn,loadmoreEnd=false,waitTimes=10,changed=false;
  3139. function checkPage(){
  3140. if(isPause)return;
  3141. try{
  3142. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  3143. }catch(e){
  3144. debug("Stop as cors");
  3145. isPause=true;
  3146. callback(false, false);
  3147. return;
  3148. }
  3149.  
  3150. let nextLink=ruleParser.getNextLink(iframeDoc);
  3151. let waitTime=200,checkEval;
  3152. if(ruleParser.curSiteRule.wait){
  3153. if(isNaN(ruleParser.curSiteRule.wait)){
  3154. try{
  3155. checkEval=(typeof _unsafeWindow.pagetualWait=='undefined') ? Function("doc",'"use strict";' + ruleParser.curSiteRule.wait) : _unsafeWindow.pagetualWait;
  3156. }catch(e){
  3157. debug(e);
  3158. }
  3159. }else{
  3160. waitTime=ruleParser.curSiteRule.wait;
  3161. }
  3162. }
  3163.  
  3164. if(!orgPage){
  3165. if(!loadmoreEnd){
  3166. loadmoreBtn=getLoadMore(iframeDoc);
  3167. if(loadmoreBtn && isVisible(loadmoreBtn, iframeDoc.defaultView)){
  3168. emuClick(loadmoreBtn);
  3169. let intv=setInterval(()=>{
  3170. loadmoreBtn=getLoadMore(iframeDoc);
  3171. if(!loadmoreBtn || !loadmoreBtn.parentNode || !isVisible(loadmoreBtn, iframeDoc.defaultView)){
  3172. clearInterval(intv);
  3173. loadmoreEnd=true;
  3174. setTimeout(()=>{
  3175. checkPage();
  3176. },500);
  3177. }else{
  3178. emuClick(loadmoreBtn);
  3179. }
  3180. },200);
  3181. return;
  3182. }else{
  3183. loadmoreEnd=true;
  3184. }
  3185. }
  3186. let pageEle=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true);
  3187. if(checkEval && !checkEval(iframeDoc)){
  3188. setTimeout(()=>{
  3189. checkPage();
  3190. },waitTime);
  3191. return;
  3192. }else if(!nextLink || !pageEle || pageEle.length==0){
  3193. if(waitTimes-->0){
  3194. setTimeout(()=>{
  3195. checkPage();
  3196. },waitTime);
  3197. return;
  3198. }
  3199. }
  3200. orgPage=pageEle;
  3201. if(!orgPage || orgPage.length==0){
  3202. debug("Stop as no page when emu");
  3203. isPause=true;
  3204. callback(false, false);
  3205. return;
  3206. }
  3207. if(orgPage && orgPage[0].tagName=="UL")orgPage=orgPage[0].children;
  3208. if(orgPage && nextLink){
  3209. orgPage=orgPage[parseInt(orgPage.length/2)];
  3210. orgContent=orgPage.innerText;
  3211. preContent=orgContent;
  3212. if(!isVisible(nextLink, iframeDoc.defaultView)){
  3213. debug("Stop as next hide when emu");
  3214. isPause=true;
  3215. callback(false, false);
  3216. }else{
  3217. emuClick(nextLink);
  3218. setTimeout(()=>{
  3219. checkPage();
  3220. },500);
  3221. }
  3222. }else{
  3223. debug("Stop as no next when emu");
  3224. isPause=true;
  3225. callback(false, false);
  3226. }
  3227. return;
  3228. }
  3229. if(times++ > 20){
  3230. debug("Stop as timeout when emu");
  3231. isPause=true;
  3232. callback(false, false);
  3233. return;
  3234. }
  3235. let eles=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true),checkItem;
  3236. if(eles && eles.length>0){
  3237. checkItem=eles;
  3238. if(eles[0].tagName=="UL"){
  3239. checkItem=eles[0].children;
  3240. }
  3241. checkItem=checkItem[parseInt(checkItem.length/2)];
  3242. }
  3243. if(!checkItem || (checkEval && !checkEval(iframeDoc))){
  3244. setTimeout(()=>{
  3245. checkPage();
  3246. },waitTime);
  3247. }else{
  3248. if(orgPage!=checkItem || checkItem.innerText!=preContent){
  3249. changed=true;
  3250. orgPage=checkItem;
  3251. preContent=checkItem.innerText;
  3252. setTimeout(()=>{
  3253. checkPage();
  3254. },waitTime);
  3255. }else if(changed){
  3256. if (orgContent == preContent) {
  3257. debug("Stop as same content");
  3258. isPause=true;
  3259. callback(false, false);
  3260. } else {
  3261. callback(iframeDoc, eles);
  3262. }
  3263. }else{
  3264. setTimeout(()=>{
  3265. checkPage();
  3266. },waitTime);
  3267. }
  3268. }
  3269. }
  3270. if(!emuIframe){
  3271. let loaded=false;
  3272. emuIframe = document.createElement('iframe');
  3273. emuIframe.name = 'pagetual-iframe';
  3274. if(ruleParser.curSiteRule.sandbox!=false){
  3275. emuIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  3276. }
  3277. emuIframe.width = '100%';
  3278. emuIframe.height = '0';
  3279. emuIframe.frameBorder = '0';
  3280. emuIframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  3281. emuIframe.addEventListener("load", e=>{
  3282. setTimeout(()=>{
  3283. try{
  3284. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  3285. }catch(e){
  3286. debug("Stop as cors");
  3287. isPause=true;
  3288. callback(false, false);
  3289. return;
  3290. }
  3291. let code=ruleParser.curSiteRule.init;
  3292. if(code){
  3293. try{
  3294. Function('doc','win','iframe','"use strict";' + code)(iframeDoc, iframeDoc.defaultView, emuIframe);
  3295. }catch(e){
  3296. debug(e);
  3297. }
  3298. }
  3299. if(loaded)return;
  3300. loaded=true;
  3301. checkPage();
  3302. },500);
  3303. });
  3304. emuIframe.src=lastActiveUrl.replace(/#[^#]*/,"");
  3305. document.body.appendChild(emuIframe);
  3306. }else{
  3307. checkPage();
  3308. }
  3309. }
  3310.  
  3311. var scrollToResizeInited = false;
  3312. var resizePool = [];
  3313. function scrollToResize() {
  3314. if (scrollToResizeInited) return;
  3315. scrollToResizeInited = true;
  3316. var scrollingToResize = false;
  3317. document.addEventListener("scroll", e => {
  3318. if (scrollingToResize) return;
  3319. else {
  3320. scrollingToResize = true;
  3321. setTimeout(() => {scrollingToResize = false}, 500);
  3322. }
  3323. resizePool.forEach(resizeArr => {
  3324. let iframe = resizeArr[1]();
  3325. let frameDoc = resizeArr[2]();
  3326. if(ruleParser.curSiteRule.singleUrl){
  3327. iframe.style.height=frameDoc.body.scrollHeight+"px";
  3328. iframe.style.width=frameDoc.body.scrollWidth+"px";
  3329. }else{
  3330. let pageEle = resizeArr[0]();
  3331. if(pageEle){
  3332. let targetElement = pageEle[0];
  3333. if(pageEle.length > 1){
  3334. targetElement = targetElement.parentNode;
  3335. }
  3336. if(parseInt(iframe.style.height)==targetElement.scrollHeight) return;
  3337. iframe.style.height=targetElement.scrollHeight+"px";
  3338. frameDoc.documentElement.scrollTop = 0;
  3339. frameDoc.documentElement.scrollLeft = 0;
  3340. while(targetElement && targetElement.offsetParent){
  3341. targetElement.offsetParent.scrollTop = targetElement.offsetTop;
  3342. if(targetElement.offsetParent.scrollTop == 0){
  3343. frameDoc.documentElement.scrollTop += targetElement.offsetTop;
  3344. }
  3345. targetElement.offsetParent.scrollLeft = targetElement.offsetLeft;
  3346. if(targetElement.offsetParent.scrollLeft == 0){
  3347. frameDoc.documentElement.scrollLeft += targetElement.offsetLeft;
  3348. }
  3349. targetElement = targetElement.offsetParent;
  3350. }
  3351. }
  3352. }
  3353. });
  3354. });
  3355. }
  3356.  
  3357. function forceIframe(url, callback){
  3358. url=url.replace(/#[^#]*/,"");
  3359. let curIframe = document.createElement('iframe'),iframeDoc,isloaded=false,inAction=true;
  3360. let loadedHandler = ()=>{
  3361. inAction=false;
  3362. if(isloaded)return;
  3363. isloaded=true;
  3364. ruleParser.insertPage(iframeDoc, [], url, null, true);
  3365. callback(curIframe, true);
  3366. let getIframe = () => {
  3367. return curIframe;
  3368. };
  3369. let getFrameDoc = () => {
  3370. return iframeDoc;
  3371. };
  3372. if(ruleParser.curSiteRule.singleUrl){
  3373. resizePool.push([() => {}, getIframe, getFrameDoc]);
  3374. }else{
  3375. let pageElement = ruleParser.getPageElement(iframeDoc,iframeDoc.defaultView);
  3376. let getPageEle = () => {
  3377. if (!pageElement || pageElement.length===0) {
  3378. pageElement = ruleParser.getPageElement(iframeDoc,iframeDoc.defaultView);
  3379. }
  3380. return pageElement;
  3381. };
  3382. resizePool.push([getPageEle, getIframe, getFrameDoc]);
  3383. }
  3384. };
  3385. curIframe.name = 'pagetual-iframe';
  3386. curIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  3387. curIframe.frameBorder = '0';
  3388. curIframe.scrolling="no";
  3389. curIframe.style.cssText = 'display: block; visibility: visible; float: none; clear: both; width: 100%;height:0;background: initial; border: 0px; border-radius: 0px; margin: 0px 0px 2rem; padding: 0px; z-index: 2147483647;';
  3390. curIframe.addEventListener("load", e=>{
  3391. try{
  3392. iframeDoc=curIframe.contentDocument || curIframe.contentWindow.document;
  3393. }catch(e){
  3394. debug("Stop as cors");
  3395. isPause=true;
  3396. callback(false, false);
  3397. return;
  3398. }
  3399. let css=ruleParser.curSiteRule.css;
  3400. if(css){
  3401. let styleEle=iframeDoc.createElement("style");
  3402. styleEle.innerHTML=css;
  3403. iframeDoc.head.appendChild(styleEle);
  3404. }
  3405. loadedHandler();
  3406. let code=ruleParser.curSiteRule.init;
  3407. if(code){
  3408. try{
  3409. Function('doc','win','iframe','"use strict";' + code)(iframeDoc,iframeDoc.defaultView,curIframe);
  3410. }catch(e){
  3411. debug(e);
  3412. }
  3413. }
  3414. });
  3415. let checkTimes=0,findPageEle=false;
  3416. let forceRefresh=e=>{
  3417. if(inAction || !iframeDoc)return;
  3418. inAction=true;
  3419. let foundNext=()=>{
  3420. document.removeEventListener("scroll", forceRefresh);
  3421. }
  3422. setTimeout(()=>{
  3423. inAction=false;
  3424. if(!ruleParser.nextLinkHref){
  3425. checkTimes++;
  3426. ruleParser.getNextLink(iframeDoc);
  3427. if(ruleParser.nextLinkHref){
  3428. foundNext();
  3429. }else if(checkTimes>=10){
  3430. foundNext();
  3431. }else if(checkTimes>=3 && !findPageEle){
  3432. let pageElement = ruleParser.getPageElement(iframeDoc,iframeDoc.defaultView);
  3433. if(!pageElement){
  3434. inAction=true;
  3435. curIframe.contentWindow.location.reload();
  3436. }else{
  3437. findPageEle=true;
  3438. }
  3439. }
  3440. }else{
  3441. foundNext();
  3442. }
  3443. },50);
  3444. };
  3445. document.addEventListener("scroll", forceRefresh);
  3446. curIframe.src=url;
  3447. let insert=ruleParser.getInsert();
  3448. if(ruleParser.curSiteRule.singleUrl || forceState==2){
  3449. document.body.appendChild(loadingDiv);
  3450. document.body.appendChild(curIframe);
  3451. }else{
  3452. ruleParser.insertElement(curIframe);
  3453. }
  3454. scrollToResize();
  3455. return curIframe;
  3456. }
  3457.  
  3458. function loadPageOver(){
  3459. isLoading=false;
  3460. if(loadingDiv.parentNode){
  3461. loadingDiv.parentNode.removeChild(loadingDiv);
  3462. }
  3463. /*setTimeout(()=>{
  3464. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  3465. if(scrollH <= (window.innerHeight || document.documentElement.clientHeight)){
  3466. nextPage();
  3467. }
  3468. },1);*/
  3469. }
  3470.  
  3471. var tryTimes = 0;
  3472.  
  3473. function nextPage(){
  3474. if(isPause || isLoading || forceState==1)return;
  3475. if(ruleParser.curSiteRule.delay){
  3476. try{
  3477. let checkDelay=((typeof _unsafeWindow.pagetualDelay=='undefined') ? Function('"use strict";' + ruleParser.curSiteRule.delay) : _unsafeWindow.pagetualDelay)();
  3478. if(!checkDelay)return;
  3479. }catch(e){
  3480. debug(e);
  3481. }
  3482. }
  3483. let nextLink=ruleParser.nextLinkHref;
  3484. if(!nextLink){
  3485. if(curPage==1){
  3486. ruleParser.getNextLink(document);
  3487. nextLink=ruleParser.nextLinkHref;
  3488. }
  3489. if(!nextLink){
  3490. isLoading=true;
  3491. if(curPage==1 && (ruleParser.curSiteRule.pinUrl || tryTimes++ <= 10)){
  3492. setTimeout(()=>{isLoading=false},500);
  3493. }
  3494. return;
  3495. }
  3496. }
  3497. let pvGallery=document.querySelector("span.pv-gallery-container");
  3498. if(pvGallery && pvGallery.style.display!="none")return;
  3499. let insert=ruleParser.getInsert();
  3500. if(insert){
  3501. let isJs=/^(javascript|#)/.test(nextLink.replace(location.href,""));
  3502. if(!isJs){
  3503. emuIframe=null;
  3504. lastActiveUrl=nextLink;
  3505. }
  3506. if(location.protocol=="https:" && /^http:/.test(nextLink)){
  3507. nextLink=nextLink.replace(/^http/,"https");
  3508. }
  3509. isLoading=true;
  3510. ruleParser.insertElement(loadingDiv);
  3511. loadingDiv.style.cssText=loadingCSS;
  3512. let sleep=ruleParser.curSiteRule.sleep||0;
  3513. setTimeout(()=>{
  3514. if(ruleParser.curSiteRule.pageElementByJs){
  3515. var over=ele=>{
  3516. loadPageOver();
  3517. if(ele){
  3518. createPageBar(nextLink);
  3519. ruleParser.insertPage(null, ele, nextLink, null, true);
  3520. if(autoLoadNum>=0){
  3521. if(autoLoadNum!=0 && --autoLoadNum==0){
  3522. autoLoadNum=-1;
  3523. }else{
  3524. nextPage();
  3525. }
  3526. }
  3527. }else{
  3528. debug("Stop as no page when get by js");
  3529. isPause=true;
  3530. }
  3531. };
  3532. try{
  3533. ((typeof _unsafeWindow.pagetualPageElementByJs=='undefined') ? Function("over",'"use strict";' + ruleParser.curSiteRule.pageElementByJs) : _unsafeWindow.pagetualPageElementByJs)(over);
  3534. }catch(e){
  3535. debug(e);
  3536. }
  3537. }else if((forceState==3||ruleParser.curSiteRule.action==1) && !isJs){
  3538. requestFromIframe(nextLink, (doc, eles)=>{
  3539. loadPageOver();
  3540. if(eles){
  3541. ruleParser.insertPage(doc, eles, nextLink, ()=>{
  3542. createPageBar(nextLink);
  3543. }, true);
  3544. if(autoLoadNum>=0){
  3545. if(autoLoadNum!=0 && --autoLoadNum==0){
  3546. autoLoadNum=-1;
  3547. }else{
  3548. nextPage();
  3549. }
  3550. }
  3551. }
  3552. });
  3553. }else if((forceState==2||ruleParser.curSiteRule.action==2) && !isJs){
  3554. forceIframe(nextLink, (iframe, eles)=>{
  3555. loadPageOver();
  3556. let pageBar=createPageBar(nextLink);
  3557. if(pageBar)iframe.parentNode.insertBefore(pageBar, iframe);
  3558. if(autoLoadNum>=0){
  3559. if(autoLoadNum!=0 && --autoLoadNum==0){
  3560. autoLoadNum=-1;
  3561. }else{
  3562. nextPage();
  3563. }
  3564. }
  3565. });
  3566. }else{
  3567. if(!isJs){
  3568. requestDoc(nextLink, (eles)=>{
  3569. loadPageOver();
  3570. if(eles){
  3571. createPageBar(nextLink);
  3572. if(autoLoadNum>=0){
  3573. if(autoLoadNum!=0 && --autoLoadNum==0){
  3574. autoLoadNum=-1;
  3575. }else{
  3576. nextPage();
  3577. }
  3578. }
  3579. }
  3580. });
  3581. }else{
  3582. emuPage((doc, eles)=>{
  3583. loadPageOver();
  3584. if(eles){
  3585. ruleParser.insertPage(doc, eles, "", ()=>{
  3586. createPageBar(nextLink);
  3587. }, true);
  3588. if(autoLoadNum>=0){
  3589. if(autoLoadNum!=0 && --autoLoadNum==0){
  3590. autoLoadNum=-1;
  3591. }else{
  3592. nextPage();
  3593. }
  3594. }
  3595. }
  3596. });
  3597. }
  3598. }
  3599. },sleep);
  3600. }
  3601. }
  3602.  
  3603. function init(){
  3604. initRules(()=>{
  3605. initPage();
  3606. });
  3607. }
  3608.  
  3609. function visibilitychangeHandler(){
  3610. document.removeEventListener('visibilitychange', visibilitychangeHandler);
  3611. init();
  3612. }
  3613.  
  3614. setTimeout(()=>{
  3615. if (document.hidden) {
  3616. document.addEventListener('visibilitychange', visibilitychangeHandler);
  3617. } else {
  3618. init();
  3619. }
  3620. },100);
  3621. })();

QingJ © 2025

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