东方永页机

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

目前为 2022-06-08 提交的版本。查看 最新版本

  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.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:"Pagination spacer 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 click to update rules:",
  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)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. getRule(callback) {
  639. if(noRuleTest){
  640. this.curSiteRule={};
  641. this.curSiteRule.url=location.origin+location.pathname;
  642. this.curSiteRule.singleUrl=true;
  643. callback();
  644. return;
  645. }
  646. if(this.curSiteRule && this.curSiteRule.url){
  647. return this.curSiteRule;
  648. }
  649. var self=this;
  650.  
  651. function setRule(r){
  652. self.curSiteRule=r;
  653. debug(r);
  654. callback();
  655. }
  656.  
  657. function ruleMatch(r){
  658. let pageElement,nextLink,insert;
  659. if(r.nextLink && r.nextLink!="0" && r.nextLink!=0){
  660. nextLink=r.type==0?getElementByXpath(r.nextLink):document.querySelector(r.nextLink);
  661. if(!nextLink)return false;
  662. }
  663. if(r.pageElement){
  664. pageElement=r.type==0?getElementByXpath(r.pageElement):document.querySelector(r.pageElement);
  665. if(!pageElement)return false;
  666. }
  667. if(r.insert){
  668. insert=r.type==0?getElementByXpath(r.insert):document.querySelector(r.insert);
  669. if(!insert)return false;
  670. }
  671. return true;
  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.wait){
  682. let waitTime=500,checkEval;
  683. if(isNaN(r.wait)){
  684. try{
  685. checkEval=Function("doc",'"use strict";' + r.wait);
  686. }catch(e){
  687. debug(e);
  688. }
  689. }else{
  690. waitTime=r.wait;
  691. }
  692. let checkReady=()=>{
  693. setTimeout(()=>{
  694. if(!ruleMatch(r) || (checkEval && !checkEval(document))){
  695. checkReady();
  696. }else{
  697. setRule(r);
  698. }
  699. },parseInt(waitTime));
  700. };
  701. checkReady();
  702. return true;
  703. }
  704. if(r.pinUrl){
  705. setRule(r);
  706. return true;
  707. }
  708. if(!ruleMatch(r)){
  709. return false;
  710. }
  711. setRule(r);
  712. return true;
  713. }
  714. return false;
  715. }
  716.  
  717. for(let i in this.hpRules){
  718. let rule=this.hpRules[i];
  719. if(!rule || !rule.url)continue;
  720. if(rule.singleUrl){
  721. if(location.origin+location.pathname==rule.url){
  722. setRule(rule);
  723. return;
  724. }
  725. continue;
  726. }
  727. if(checkRule(rule))return;
  728. }
  729. for(let i in this.customRules){
  730. let rule=this.customRules[i];
  731. if(!rule || !rule.url)continue;
  732. if(checkRule(rule))return;
  733. }
  734. let r=0;
  735. function searchByTime(){
  736. setTimeout(()=>{
  737. let end=r+50;
  738. end=end>self.rules.length?self.rules.length:end;
  739. for(;r<end;r++){
  740. let rule=self.rules[r];
  741. if(checkRule(rule))return;
  742. }
  743. if(end>=self.rules.length){
  744. self.curSiteRule={};
  745. self.curSiteRule.url=location.origin+location.pathname;
  746. self.curSiteRule.singleUrl=true;
  747. callback();
  748. return;
  749. }else{
  750. searchByTime();
  751. }
  752. },10);
  753. }
  754. searchByTime();
  755. }
  756.  
  757. geneSelector(ele){
  758. let selector=ele.tagName;
  759. //Google id class都是隨機。百度更過分,style script順序都是隨機的
  760. //if(ele.id) selector += '#' + ele.id;
  761. //if(ele.classList) selector += [].map.call(ele.classList,d=>'.'+d).join('');
  762. if(ele.tagName!="HTML" && ele.tagName!="BODY"){
  763. if(ele.className) selector += [].map.call(ele.classList,d=>'.'+d).join('');
  764. let parent = ele.parentElement;
  765. if(parent){
  766. selector = this.geneSelector(parent) + ' > ' + selector;
  767. if(!ele.className){
  768. let i,j=0;
  769. for(i=0;i<parent.children.length;i++){
  770. if(parent.children[i].tagName==ele.tagName){
  771. j++;
  772. if(parent.children[i]==ele){
  773. break;
  774. }
  775. }
  776. }
  777. selector += (parent.tagName=="HTML"?"":`:nth-of-type(${j})`);
  778. }
  779. }
  780. }
  781. return selector;
  782. }
  783.  
  784. getPageElement(doc, curWin, dontFind) {
  785. let pageElement=null;
  786. let self=this;
  787. let body=doc.body;
  788. if(this.curSiteRule.pageElement){
  789. pageElement=this.curSiteRule.type==0?getAllElementsByXpath(this.curSiteRule.pageElement,doc,doc):doc.querySelectorAll(this.curSiteRule.pageElement);
  790. }else if(!this.curSiteRule.singleUrl && this.curSiteRule.type==0){
  791. pageElement=[body];
  792. }
  793. if(this.curSiteRule.singleUrl && pageElement && pageElement.length>0 && pageElement[0].tagName=="TR"){
  794. let mainTr=this.insert.previousElementSibling,mainTdNum=0,newTdNum=0;
  795. [].forEach.call(mainTr.children, el=>{
  796. if(el.tagName=="TD" || el.tagName=="TH"){
  797. mainTdNum+=el.colSpan||1;
  798. }
  799. });
  800. [].forEach.call(pageElement[0].children, el=>{
  801. if(el.tagName=="TD" || el.tagName=="TH"){
  802. newTdNum+=el.colSpan||1;
  803. }
  804. });
  805. if(mainTdNum!=newTdNum){
  806. this.curSiteRule.pageElement=allOfBody;
  807. pageElement=[body];
  808. this.getInsert(true);
  809. }
  810. }
  811. if((this.curSiteRule.singleUrl || !this.curSiteRule.pageElement) && (!pageElement || pageElement.length==0) && curWin && !dontFind){
  812. if(!body)return null;
  813. let bodyHeight=parseInt(body.offsetHeight || body.scrollHeight);
  814. let curHeight=bodyHeight;
  815. let windowHeight=window.innerHeight || document.documentElement.clientHeight;
  816. let needCheckNext=(doc==document && this.initNext);
  817. function checkElement(ele){
  818. if(ele.childNodes && ele.childNodes.length==1)ele=ele.childNodes[0];
  819. if(ele.tagName=="PICTURE"){
  820. self.curSiteRule.pageElement=self.geneSelector(ele.parentNode)+">"+ele.tagName;
  821. debug(self.curSiteRule.pageElement);
  822. return [ele];
  823. }
  824. if(curHeight/bodyHeight<=0.25){
  825. self.curSiteRule.pageElement=allOfBody;
  826. debug(self.curSiteRule.pageElement);
  827. return [body];
  828. }
  829. if(ele.tagName=="FORM"){
  830. self.curSiteRule.pageElement=self.geneSelector(ele)+">*";
  831. debug(self.curSiteRule.pageElement);
  832. return ele.children;
  833. }
  834. if(ele.children.length==0 && !self.curSiteRule.pageElement){
  835. if(ele.parentNode.tagName=="P")ele=ele.parentNode;
  836. self.curSiteRule.pageElement=self.geneSelector(ele.parentNode)+">"+ele.tagName;
  837. debug(self.curSiteRule.pageElement);
  838. return [ele];
  839. }
  840. let i,maxHeight=curHeight*0.55,curMaxEle=null,curMaxArea=0,maxWidth=0;
  841. let isHori=true;
  842. let offsetTop=ele.children[0].offsetTop;
  843. for(i=1;i<ele.children.length;i++){
  844. if(ele.children[i].offsetTop!=offsetTop){
  845. isHori=false;
  846. break;
  847. }
  848. }
  849. for(i=0;i<ele.children.length;i++){
  850. let curNode=ele.children[i];
  851. if(curNode.tagName=="CANVAS")continue;
  852. if(curNode.tagName!="IMG" && /^\s*$/.test(curNode.innerText))continue;
  853. if(needCheckNext && !curNode.contains(self.initNext) && getElementTop(curNode)>windowHeight){
  854. continue;
  855. }
  856. let comStyle=curWin.getComputedStyle(curNode);
  857. let h=parseInt(curNode.offsetHeight || curNode.scrollHeight);
  858. let w=parseInt(curNode.scrollWidth);
  859. if(isNaN(h) || isNaN(w))continue;
  860. if(isHori && h<=50)continue;
  861. let a=h*w+h,moreChild=curNode.children[0];
  862. while(moreChild){
  863. comStyle=curWin.getComputedStyle(moreChild);
  864. let ch=parseInt(moreChild.offsetHeight || moreChild.scrollHeight);
  865. let cw=parseInt(moreChild.scrollWidth);
  866. if(h<ch)h=ch;
  867. if(moreChild.innerText!="" && !isNaN(ch) && !isNaN(cw)){
  868. a+=ch*cw;
  869. }
  870. moreChild=moreChild.nextElementSibling;
  871. }
  872. let isMax=false;
  873. if(isHori){
  874. if(maxWidth<w){
  875. isMax=true;
  876. }else if(maxWidth==w && curMaxArea<a){
  877. isMax=true;
  878. }
  879. }else{
  880. isMax=curMaxArea<a;
  881. }
  882. if(curMaxEle==null || isMax){
  883. if(h>0 || !isHori)curHeight=h;
  884. curMaxArea=a;
  885. maxWidth=w;
  886. curMaxEle=curNode;
  887. }
  888. }
  889. if(curMaxEle && (isHori || curHeight>maxHeight || (needCheckNext && curHeight>windowHeight && ele.contains(self.initNext)))){
  890. return checkElement(curMaxEle);
  891. }
  892. if(ele.tagName=="P" || ele.tagName=="BR")ele=ele.parentNode;
  893. if(ele.tagName=="TBODY"){
  894. self.curSiteRule.pageElement=self.geneSelector(ele)+">*";
  895. if(ele.children.length>0 && ele.children[0].querySelector("th")){
  896. self.curSiteRule.pageElement+=":not(:first-child)";
  897. }
  898. debug(self.curSiteRule.pageElement);
  899. return ele.children;
  900. }
  901. self.curSiteRule.pageElement=self.geneSelector(ele);
  902. if(ele.children.length>1){
  903. let hasText=false;
  904. for(let i in ele.childNodes){
  905. let child=ele.childNodes[i];
  906. if(child.nodeType==3 && child.nodeValue.trim()!=''){
  907. hasText=true;
  908. ele=[ele];
  909. break;
  910. }
  911. }
  912. if(!hasText){
  913. let middleChild=ele.children[parseInt(ele.children.length/2)];
  914. if((middleChild.style && middleChild.style.position=="absolute" && middleChild.style.left && middleChild.style.top) || ele.tagName=="UL" || curHeight==0){
  915. ele=[ele];
  916. }else{
  917. self.curSiteRule.pageElement+=">*";
  918. ele=ele.children;
  919. }
  920. }
  921. }else{
  922. ele=[ele];
  923. }
  924. debug(self.curSiteRule.pageElement);
  925. return ele;
  926. }
  927. pageElement=checkElement(body);
  928. //if(pageElement)this.saveCurSiteRule();
  929. }
  930. return pageElement;
  931. }
  932.  
  933. getPage(doc){
  934. if(_unsafeWindow.Discourse)return {};
  935. let canSave=false;//發現頁碼選擇器在其他頁對不上,還是別保存了
  936. let url=this.curUrl.replace("#!","").replace("index.php?","?");
  937. let _url=url.replace(/\.s?html?$/i,"");
  938. let pageNum=1,preStr="",afterStr="";
  939. let pageMatch1=url.match(/(.*[a-z\/\-_](?:p|page)?\/?)(\d+)(\.s?html?$|\/?$)/i);
  940. let pageMatch2=url.match(/(.*[\?&]p(?:age)?=)(\d+)($|[#&].*)/i);
  941. if(pageMatch1){
  942. preStr=pageMatch1[1];
  943. pageNum=parseInt(pageMatch1[2]);
  944. afterStr=pageMatch1[3];
  945. }else if(pageMatch2){
  946. preStr=pageMatch2[1];
  947. pageNum=parseInt(pageMatch2[2]);
  948. afterStr=pageMatch2[3];
  949. }
  950. let curPage=doc,i,cur,jsNext;
  951. let next1,next2,next3,next4,nextJs1,nextJs2,nextJs3;
  952. let next=curPage.querySelector(".page-next>a")||
  953. curPage.querySelector("a.next_page")||
  954. curPage.querySelector("#next_page")||
  955. curPage.querySelector(".nextPage")||
  956. curPage.querySelector("a[data-pagination=next]")||
  957. curPage.querySelector("ul.pagination>li.active+li>a")||
  958. curPage.querySelector(".pagination a[rel=next]")||
  959. curPage.querySelector(".pagination-nav__item--next>a")||
  960. curPage.querySelector("a[title='Next page']")||
  961. curPage.querySelector("a.pageright")||
  962. curPage.querySelector("a#rightFix")||
  963. curPage.querySelector("a#next")||
  964. curPage.querySelector(".next>a")||
  965. curPage.querySelector(".next>button")||
  966. curPage.querySelector("a[alt=next]")||
  967. curPage.querySelector("button.next")||
  968. curPage.querySelector("[title=next]")||
  969. curPage.querySelector("a#btnPreGn")||
  970. getElementByXpath("//a[contains(@class, 'page__next')]",curPage,curPage);
  971. if(!next){
  972. let nexts=curPage.querySelectorAll("a.next");
  973. for(i=0;i<nexts.length;i++){
  974. if(!/^([上前首尾][一1]?[页頁张張]|previous(\s*page)?\s*›?$|前のページ)/i.test(nexts[i].innerText.trim()) &&
  975. nexts[i].style.display!=="none" &&
  976. nexts[i].parentNode.style.display!=="none"){
  977. next=nexts[i];
  978. break;
  979. }
  980. }
  981. }
  982. if(next && (!next.href || /^javascript:/.test(next.href) || next.getAttribute("href")=="#")){
  983. jsNext=next;
  984. next=null;
  985. }
  986. if(!next){
  987. next=curPage.querySelectorAll("[aria-label='Next page']");
  988. if(next && next.length==1){
  989. next=next[0];
  990. if(!next.href || /^javascript:/.test(next.href) || next.getAttribute("href")=="#"){
  991. if(!jsNext)jsNext=next;
  992. next=null;
  993. }
  994. }else{
  995. next=null;
  996. }
  997. }
  998. if(!next){
  999. next=curPage.querySelectorAll("[aria-label='Next']");
  1000. if(next && next.length==1){
  1001. next=next[0];
  1002. if(!next.href || /^javascript:/.test(next.href) || next.getAttribute("href")=="#"){
  1003. if(!jsNext)jsNext=next;
  1004. next=null;
  1005. }
  1006. }else{
  1007. next=null;
  1008. }
  1009. }
  1010. if(next && /^[下后後][一1]?[章话話篇]/i.test(next.innerText.trim())){
  1011. next2=next;
  1012. next=null;
  1013. }
  1014. if(!next){
  1015. next=curPage.querySelector("a.curr");
  1016. if(next){
  1017. next=next.nextSibling;
  1018. }
  1019. }
  1020. if(!next){
  1021. next=curPage.querySelector("div.wp-pagenavi>span.current+a,div.page-nav>span.current+a,div.article-paging>span+a");
  1022. }
  1023. if(!next){
  1024. let pageDiv=curPage.querySelector("div.pages>ul");
  1025. if(pageDiv){
  1026. cur=pageDiv.querySelector("li>b");
  1027. if(cur)next=cur.parentNode.nextElementSibling;
  1028. if(next)next=next.querySelector("a");
  1029. }
  1030. }
  1031. if(!next){
  1032. cur=curPage.querySelector(".number>ul>li.active");
  1033. if(cur)next=cur.nextElementSibling;
  1034. if(next)next=next.querySelector("a");
  1035. }
  1036. if(!next){
  1037. let aTags=curPage.querySelectorAll("a,button");
  1038. for(i=aTags.length-1;i>=0;i--){
  1039. if(next1 && next2 && next3 && next4)break;
  1040. let aTag=aTags[i];
  1041. if(aTag.innerText=="§")continue;
  1042. if(aTag.innerText.length>50)continue;
  1043. if(aTag.style.display=="none")continue;
  1044. if(aTag.href && /next$/i.test(aTag.href))continue;
  1045. if(aTag.className && /slick|slide/i.test(aTag.className))continue;
  1046. if(aTag.innerText.length<=18){
  1047. if(!next1){
  1048. if(/^[下后後][一1]?[页頁张張]|^next([ _-]?page)?\s*[›>→»]?$|次のページ|^次へ?$/i.test(aTag.innerText.trim())){
  1049. if(!aTag.href || /^javascript:/.test(aTag.href) || aTag.getAttribute("href")=="#"){
  1050. if(!nextJs1)nextJs1=aTag;
  1051. }else{
  1052. next1=aTag;
  1053. }
  1054. }
  1055. }
  1056. if(!next2){
  1057. if(/^[下后後][一1]?[章话話篇]/i.test(aTag.innerText.trim()) || /nextpage/i.test(aTag.className)){
  1058. if(!aTag.href || /^javascript:/.test(aTag.href) || aTag.getAttribute("href")=="#"){
  1059. if(!nextJs2)nextJs2=aTag;
  1060. }else{
  1061. next2=aTag;
  1062. }
  1063. }
  1064. }
  1065. if(!next3){
  1066. if(aTag.innerText=="&gt;" || aTag.innerText=="▶" || aTag.innerText==">" || aTag.innerText=="›" || aTag.innerText=="→" || aTag.innerText=="»"){
  1067. if(!aTag.href || /^javascript:/.test(aTag.href) || aTag.getAttribute("href")=="#"){
  1068. if(!nextJs3)nextJs3=aTag;
  1069. }else{
  1070. next3=aTag;
  1071. }
  1072. }
  1073. }
  1074. }
  1075. if(!aTag.href || /^javascript:/.test(aTag.href) || aTag.getAttribute("href")=="#")continue;
  1076. if(!next4 && aTag.href.length<250){
  1077. let _aHref=aTag.href.replace("?&","?").replace("#!","").replace("index.php?","?");
  1078. let _aHrefTrim=_aHref;
  1079. if(preStr)_aHrefTrim=_aHrefTrim.replace(preStr,"");
  1080. if(afterStr)_aHrefTrim=_aHrefTrim.replace(afterStr,"");
  1081. if(pageNum<999 && _aHrefTrim==pageNum+1){
  1082. next4=aTag;
  1083. }else if(this.curUrl!=aTag.href){
  1084. _aHref=_aHref.replace(/\.s?html?$/i,"");
  1085. if(_aHref.indexOf(_url)!=-1 && /^[\/\?&]?[_-]?(p|page)?=?\/?2(\/|\?|&|$)/i.test(_aHref.replace(_url,""))){
  1086. let curHref=aTag.getAttribute("href");
  1087. let pageOne=curHref.replace(/\/2(\/|\?|&|$)/,"/1$1");
  1088. if(pageOne==curHref)pageOne=null;
  1089. else pageOne=curPage.querySelector(`a[href='${pageOne}']`);
  1090. if(!pageOne || pageOne.className!=curHref.className)next4=aTag;
  1091. }
  1092. }
  1093. }
  1094. }
  1095. if(next3){
  1096. let eles=getAllElementsByXpath(`//a[text()='${next3.innerText}']`,curPage,curPage);
  1097. if(eles.length>1)next3=null;
  1098. }
  1099. }
  1100. if(!next)next=next1||next4||next3||next2||jsNext||nextJs1||nextJs3||nextJs2;
  1101. if(next && next.classList.contains("results-more"))next=null;
  1102. return {next:next,canSave:canSave};
  1103. }
  1104.  
  1105. canonicalUri(src) {
  1106. if(src.charAt(0)=="#")return location.href+src;
  1107. var root_page = /^[^?#]*\//.exec(location.href)[0],
  1108. base_path = location.pathname.replace(/\/[^\/]+\.[^\/]+$/, "/"),
  1109. root_domain = /^\w+\:\/\/\/?[^\/]+/.exec(root_page)[0],
  1110. absolute_regex = /^\w+\:\/\//;
  1111. src=src.replace(/\.\//,"");
  1112. if (/^\/\/\/?/.test(src)){
  1113. src = location.protocol + src;
  1114. }
  1115. else if (!absolute_regex.test(src) && src.charAt(0) != "/"){
  1116. src = (base_path || "") + src;
  1117. }
  1118. return (absolute_regex.test(src) ? src : ((src.charAt(0) == "/" ? root_domain : root_page) + src));
  1119. }
  1120.  
  1121. getLinkByPage(url, pageNum) {
  1122. if(!url)return;
  1123. if(this.curSiteRule.pageNum){
  1124. let result=this.curSiteRule.pageNum;
  1125. let strMatch=result.match(/\{.*?}/);
  1126. if(!strMatch)return null;
  1127. let urlReg=new RegExp("("+result.replace(strMatch[0], ")\\d+(")+")","i");
  1128. let code=strMatch[0].replace(/^{/,"").replace(/}$/,"").replace(/\$p/g,pageNum);
  1129. if(code==pageNum){
  1130. result=url.replace(urlReg,"$1"+code+"$2");
  1131. }else{
  1132. try{
  1133. code=Function('"use strict";return ' + code)();
  1134. result=url.replace(urlReg,"$1"+code+"$2");
  1135. }catch(e){
  1136. debug(e);
  1137. }
  1138. }
  1139. return result==url?url.replace(/([&\/\?](p=|page[=\/_-]?))\d+/i, "$1"+pageNum).replace(/([_-])\d+\./i, "$1"+pageNum+"."):result;
  1140. }else{
  1141. return url.replace(/([&\/\?](p=|page[=\/_-]?))\d+/i, "$1"+pageNum).replace(/([_-])\d+\./i, "$1"+pageNum+".");
  1142. }
  1143. }
  1144.  
  1145. getNextLink(doc) {
  1146. let nextLink=null,page,href;
  1147. let getNextLinkByForm=(form,n)=>{
  1148. let params=[];
  1149. [].forEach.call(form.querySelectorAll("input"), input=>{
  1150. if(n && /^(p|page)$/i.test(input.name)){
  1151. params.push('p='+n);
  1152. }else{
  1153. params.push(input.name+'='+input.value);
  1154. }
  1155. });
  1156. return form.action+'?'+params.join('&');
  1157. };
  1158. if(this.curSiteRule.pageElementByJs){
  1159. this.nextLinkHref="#";
  1160. return true;
  1161. }else if(this.curSiteRule.nextLinkByJs){
  1162. try{
  1163. let targetUrl=Function("doc",'"use strict";' + this.curSiteRule.nextLinkByJs)(doc);
  1164. if(targetUrl)nextLink={href:targetUrl};
  1165. }catch(e){
  1166. debug(e);
  1167. }
  1168. }else if(this.curSiteRule.nextLinkByUrl){
  1169. let targetUrl=this.curUrl.replace(new RegExp(this.curSiteRule.nextLinkByUrl[0],"i"), this.curSiteRule.nextLinkByUrl[1]);
  1170. if(targetUrl != this.curUrl){
  1171. let reps=targetUrl.match(/{.*?}/g);
  1172. if(reps){
  1173. reps.forEach(rep=>{
  1174. let code=rep.replace("{","").replace("}","");
  1175. let result=code.match(/^(\d+)\+1$/);
  1176. if(result){
  1177. result=parseInt(result[1])+1;
  1178. }else{
  1179. try{
  1180. result=Function('"use strict";return ' + code)();
  1181. }catch(e){
  1182. debug(e);
  1183. }
  1184. }
  1185. targetUrl=targetUrl.replace(rep, result);
  1186. });
  1187. }
  1188. }
  1189. nextLink={href:targetUrl};
  1190. }else if(this.curSiteRule.nextLink){
  1191. if(this.curSiteRule.nextLink!="0" && this.curSiteRule.nextLink!=0){
  1192. nextLink=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.nextLink,doc,doc):doc.querySelector(this.curSiteRule.nextLink);
  1193. }
  1194. }else{
  1195. page=this.getPage(doc);
  1196. nextLink=page.next;
  1197. if(nextLink){
  1198. if(nextLink.tagName=="INPUT" && nextLink.parentNode.tagName=="FORM"){
  1199. let form=nextLink.parentNode;
  1200. nextLink.href=getNextLinkByForm(form);
  1201. }
  1202. if(nextLink.parentNode.style.display=="none" || nextLink.style.display=="none" || nextLink.classList.contains("noClick") || nextLink.hasAttribute("disabled")){
  1203. this.nextLinkHref=false;
  1204. return null;
  1205. }else if(doc==document){
  1206. if((!nextLink.href || /^javascript:/.test(nextLink.href)) && !isVisible(nextLink, _unsafeWindow)){
  1207. this.nextLinkHref=false;
  1208. return null;
  1209. }else{
  1210. let nextLinkCs=_unsafeWindow.getComputedStyle(nextLink);
  1211. if(nextLinkCs.cursor=="not-allowed"){
  1212. this.nextLinkHref=false;
  1213. return null;
  1214. }
  1215. this.initNext=nextLink;
  1216. }
  1217. }
  1218. let form=doc.querySelector('#search-form');
  1219. if(!nextLink.href && nextLink.hasAttribute("onclick") && form){
  1220. if(form && /^\d+$/.test(nextLink.innerText)){
  1221. href=getNextLinkByForm(form, nextLink.innerText);
  1222. }
  1223. }
  1224. }
  1225. }
  1226. if(nextLink){
  1227. let needUrl=(this.curSiteRule.action==0 || this.curSiteRule.action==1);
  1228. if(!href)href=nextLink.href;
  1229. if(href && nextLink.getAttribute){
  1230. let _href=nextLink.getAttribute("href");
  1231. if(!_href || _href.charAt(0)=="#" || _href=="?"){
  1232. href="#";
  1233. }
  1234. }
  1235.  
  1236. if((href===""||href===null) && needUrl){
  1237. this.nextLinkHref=false;
  1238. }else if(/^(javascript:void\(0\)|#)/.test(href) && needUrl){
  1239. this.nextLinkHref=false;
  1240. }else{
  1241. this.nextLinkHref=(href && !/^(javascript:|#)/.test(href))?this.canonicalUri(href):"#";
  1242. if(this.nextLinkHref!="#" && (this.nextLinkHref==this.curUrl || this.nextLinkHref==this.curUrl+"#" || this.nextLinkHref==this.oldUrl || this.nextLinkHref==this.oldUrl+"#")){
  1243. this.nextLinkHref=false;
  1244. }else if(doc==document)debug(nextLink);
  1245. }
  1246. }else{
  1247. this.nextLinkHref=false;
  1248. }
  1249. this.preload();
  1250. return nextLink;
  1251. }
  1252.  
  1253. preload(){
  1254. if(!rulesData.preload)return;
  1255. if(!this.nextLinkHref || this.nextLinkHref=="#")return;
  1256. let self=this;
  1257. if(this.curSiteRule && this.curSiteRule.action==1){
  1258. if(!this.preloadIframe){
  1259. this.preloadIframe = document.createElement('iframe');
  1260. let iframe = this.preloadIframe;
  1261. iframe.name = 'pagetual-iframe';
  1262. iframe.width = '100%';
  1263. iframe.height = '0';
  1264. iframe.frameBorder = '0';
  1265. if(ruleParser.curSiteRule.sandbox!=false){
  1266. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1267. }
  1268. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1269. iframe.addEventListener('load', function (e) {
  1270. try{
  1271. let doc=iframe.contentDocument || iframe.contentWindow.document;
  1272. var body = doc.body;
  1273. if (body && body.firstChild) {
  1274. self.lazyImgAction(body.children);
  1275. }
  1276. }catch(e){
  1277. return;
  1278. }
  1279. }, false);
  1280. document.body.appendChild(iframe);
  1281. }
  1282. this.preloadIframe.src = this.nextLinkHref;
  1283. }else{
  1284. _GM_xmlhttpRequest({
  1285. url: this.nextLinkHref,
  1286. method: 'GET',
  1287. overrideMimeType: 'text/html;charset='+document.charset,
  1288. headers: {
  1289. 'Referer': location.href
  1290. },
  1291. timeout: 5000,
  1292. onload: function(res) {
  1293. var doc=null;
  1294. try {
  1295. doc=document.implementation.createHTMLDocument('');
  1296. doc.documentElement.innerHTML=res.response;
  1297. var body = doc.body;
  1298. if (body && body.firstChild) {
  1299. self.lazyImgAction(body.children);
  1300. }
  1301. if(!self.preloadDiv){
  1302. self.preloadDiv = document.createElement('div');
  1303. self.preloadDiv.id = "pagetual-preload";
  1304. self.preloadDiv.style.cssText = 'display:none!important;';
  1305. document.body.appendChild(self.preloadDiv);
  1306. self.checkedImgs={};
  1307. }
  1308. [].forEach.call(doc.images, i=>{
  1309. let iSrc=i.src;
  1310. if(iSrc && !self.checkedImgs[iSrc]){
  1311. self.checkedImgs[iSrc] = true;
  1312. let img = document.createElement('img');
  1313. img.src = iSrc;
  1314. self.preloadDiv.appendChild(img);
  1315. }
  1316. });
  1317. }
  1318. catch (e) {
  1319. return;
  1320. }
  1321. }
  1322. });
  1323. }
  1324. }
  1325.  
  1326. getInsert(refresh) {
  1327. if(refresh){
  1328. this.insert=null;
  1329. }
  1330. if(this.insert && !refresh){
  1331. let parent=this.insert;
  1332. while(parent && parent.nodeName!="BODY"){
  1333. parent=parent.parentNode;
  1334. }
  1335. if(parent && parent.nodeName=="BODY"){
  1336. return this.insert;
  1337. }
  1338. }
  1339. if(this.curSiteRule.insert){
  1340. this.insert=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.insert,document):document.querySelector(this.curSiteRule.insert);
  1341. }else{
  1342. let pageElement=this.getPageElement(document, _unsafeWindow);
  1343. if(pageElement && pageElement.length>0){
  1344. var pELast = pageElement[pageElement.length - 1];
  1345. this.insert = pELast.nextSibling ? pELast.nextSibling : pELast.parentNode.appendChild(document.createTextNode(' '));
  1346. }
  1347. }
  1348. return this.insert;
  1349. }
  1350.  
  1351. pageInit(doc,eles){
  1352. let code=this.curSiteRule.pageInit;
  1353. if(code){
  1354. try{
  1355. Function("doc","eles",'"use strict";' + code)(doc,eles);
  1356. }catch(e){
  1357. debug(e);
  1358. }
  1359. }
  1360. }
  1361.  
  1362. pageAction(doc,eles){
  1363. let code=this.curSiteRule.pageAction;
  1364. if(code){
  1365. try{
  1366. Function("doc","eles",'"use strict";' + code)(doc,eles);
  1367. }catch(e){
  1368. debug(e);
  1369. }
  1370. }
  1371. this.lazyImgAction(eles);
  1372. this.openInNewTab(eles);
  1373. }
  1374.  
  1375. openInNewTab(eles){
  1376. if(rulesData.openInNewTab){
  1377. [].forEach.call(eles, ele=>{
  1378. if(ele.tagName=="A" && ele.href && !/^(mailto:|javascript:|#)/.test(ele.href)){
  1379. ele.setAttribute('target', '_blank');
  1380. }else{
  1381. [].forEach.call(ele.querySelectorAll('a[href]:not([href^="mailto:"]):not([href^="javascript:"]):not([href^="#"])'), a=>{
  1382. a.setAttribute('target', '_blank');
  1383. if (a.getAttribute('onclick') == 'atarget(this)') {
  1384. a.removeAttribute('onclick');
  1385. }
  1386. });
  1387. }
  1388. });
  1389. }
  1390. }
  1391.  
  1392. lazyImgAction(eles){
  1393. let setLazyImg=img=>{
  1394. let realSrc;
  1395. if(img.getAttribute("_src") && !img.src){
  1396. realSrc=img.getAttribute("_src");
  1397. }else if(img.dataset && img.dataset.original){
  1398. realSrc=img.dataset.original;
  1399. }else if(img.dataset && img.dataset.src){
  1400. realSrc=img.dataset.src;
  1401. }else if(img._lazyrias && img._lazyrias.srcset){
  1402. realSrc=img._lazyrias.srcset[img._lazyrias.srcset.length-1];
  1403. }else if(img.dataset && img.dataset.origFile){
  1404. realSrc=img.dataset.origFile;
  1405. }else if(img.srcset){
  1406. var srcs=img.srcset.split(/[xw],/),largeSize=0;
  1407. srcs.forEach(srci=>{
  1408. let srcInfo=srci.trim().split(" "),curSize=parseInt(srcInfo[1]);
  1409. if(srcInfo[1] && curSize>largeSize){
  1410. largeSize=curSize;
  1411. realSrc=srcInfo[0];
  1412. }
  1413. });
  1414. }
  1415. if(realSrc){
  1416. img.src=realSrc;
  1417. img.style.display="block";
  1418. }
  1419. };
  1420. [].forEach.call(eles, ele=>{
  1421. if(ele.tagName=="IMG"){
  1422. setLazyImg(ele);
  1423. }else{
  1424. [].forEach.call(ele.querySelectorAll("img"), img=>{
  1425. setLazyImg(img);
  1426. });
  1427. }
  1428. if(ele.tagName=="A" && ele.classList.contains("lazyload")){
  1429. if(ele.dataset.original){
  1430. ele.style.backgroundImage='url("'+ele.dataset.original+'")';
  1431. }
  1432. }else{
  1433. [].forEach.call(ele.querySelectorAll("a.lazyload"), a=>{
  1434. if(a.dataset.original){
  1435. a.style.backgroundImage='url("'+a.dataset.original+'")';
  1436. }
  1437. });
  1438. }
  1439. });
  1440. let lazyImgSrc=this.curSiteRule.lazyImgSrc;
  1441. if(lazyImgSrc){
  1442. [].forEach.call(eles, ele=>{
  1443. [].forEach.call(ele.querySelectorAll("img"), img=>{
  1444. if(img.getAttribute(lazyImgSrc)){
  1445. img.src=img.getAttribute(lazyImgSrc);
  1446. }
  1447. });
  1448. });
  1449. }
  1450. }
  1451.  
  1452. initPage(callback){
  1453. let self=this;
  1454. curPage=1;
  1455. //if(this.curSiteRule.url && !this.curSiteRule.singleUrl)return;
  1456. this.curSiteRule={};
  1457. this.pageDoc=document;
  1458. this.nextLinkHref=null;
  1459. this.curUrl=location.href;
  1460. this.getRule(()=>{
  1461. if(self.curSiteRule.enable==0){
  1462. debug("Stop as rule disable");
  1463. isPause=true;
  1464. return;
  1465. }
  1466. if(self.curSiteRule && !self.curSiteRule.singleUrl){
  1467. self.hpRules=self.hpRules.filter(item=>{return item&&item.url!=self.curSiteRule.url});
  1468. self.hpRules.unshift(self.curSiteRule);
  1469. if(self.hpRules.length>30){
  1470. self.hpRules.pop();
  1471. }
  1472. storage.setItem("hpRules", self.hpRules);
  1473. }
  1474. let css=self.curSiteRule.css;
  1475. if(css){
  1476. _GM_addStyle(css);
  1477. }
  1478. let autoClick=self.curSiteRule.autoClick;
  1479. if(autoClick){
  1480. let autoClickBtn;
  1481. try{
  1482. autoClickBtn=document.querySelector(autoClick);
  1483. }catch(e){
  1484. autoClickBtn=getElementByXpath(autoClick);
  1485. }
  1486. if(autoClickBtn){
  1487. emuClick(autoClickBtn);
  1488. }
  1489. }
  1490. let code=self.curSiteRule.init;
  1491. if(code){
  1492. try{
  1493. Function('doc','win','iframe','"use strict";' + code)(null,null,null);
  1494. }catch(e){
  1495. debug(e);
  1496. }
  1497. }
  1498. self.getNextLink(document);
  1499. callback();
  1500. });
  1501. }
  1502.  
  1503. insertElement(ele) {
  1504. if(this.curSiteRule.insertPos==2){
  1505. this.insert.appendChild(ele);
  1506. }else{
  1507. this.insert.parentNode.insertBefore(ele, this.insert);
  1508. }
  1509. }
  1510.  
  1511. insertPage(doc, eles, url, callback, tried){
  1512. this.oldUrl=this.curUrl;
  1513. let oldTitle=this.pageDoc.title;
  1514. this.pageDoc=doc;
  1515. this.curUrl=url;
  1516. let nextLink=this.getNextLink(doc);
  1517. this.nextTitle="";
  1518. if(this.curSiteRule.pageBarText){
  1519. if(this.curSiteRule.pageBarText==1){
  1520. this.nextTitle=doc.title;
  1521. }else{
  1522. try{
  1523. this.nextTitle=Function("doc",'"use strict";' + this.curSiteRule.pageBarText)(doc);
  1524. }catch(e){
  1525. debug(e);
  1526. }
  1527. }
  1528. }
  1529. if(curPage==1 && !tried && !nextLink && this.curSiteRule.singleUrl && this.curSiteRule.pageElement && this.curSiteRule.action!=0){
  1530. this.curSiteRule.action=1;
  1531. this.curUrl=location.href;
  1532. return false;
  1533. }
  1534. if(callback)callback(eles);
  1535. this.getInsert();
  1536. var self=this,newEles=[];
  1537. if(!eles || eles.length==0 || !self.insert || !self.insert.parentNode){
  1538. }else{
  1539. this.pageInit(doc, eles);
  1540. [].forEach.call(eles, ele=>{
  1541. let newEle=ele.cloneNode(true);
  1542. let oldCanvass=ele.querySelectorAll("canvas");
  1543. let newCanvass=newEle.querySelectorAll("canvas");
  1544. for(let i=0;i<oldCanvass.length;i++){
  1545. let oldCanvas=oldCanvass[i];
  1546. let newCanvas=newCanvass[i];
  1547. newCanvas.getContext('2d').drawImage(oldCanvas, 0, 0);
  1548. }
  1549. self.insertElement(newEle);
  1550. newEles.push(newEle);
  1551. });
  1552. }
  1553. this.pageAction(doc, newEles);
  1554. if(this.oldUrl!=location.href){
  1555. let isJs=/^(javascript|#)/.test(this.oldUrl.replace(location.href,""));
  1556. if(rulesData.enableHistory && !isJs){
  1557. _unsafeWindow.history.replaceState(undefined, oldTitle, this.oldUrl);
  1558. document.title=oldTitle;
  1559. }
  1560. }
  1561. return true;
  1562. }
  1563. }
  1564. var ruleParser = new RuleParser();
  1565.  
  1566. function initConfig(){
  1567. initView();
  1568. _GM_registerMenuCommand(i18n(forceState==1?"enable":"disableSite"), ()=>{
  1569. forceState=(forceState==1?0:1);
  1570. storage.setItem("forceState_"+location.host, forceState);
  1571. showTips(i18n(forceState==1?"disableSiteTips":"enableSiteTips"));
  1572. if(!ruleParser.curSiteRule.url) location.reload();
  1573. });
  1574. _GM_registerMenuCommand(i18n("update"), ()=>{
  1575. updateRules(()=>{
  1576. showTips(i18n("updateSucc"));
  1577. location.reload();
  1578. },(rule,err)=>{
  1579. showTips("Update "+rule.url+" rules fail!");
  1580. });
  1581. showTips(i18n("beginUpdate"));
  1582. });
  1583.  
  1584. var configCon,insertPos;
  1585. if(ruleImportUrlReg.test(location.href)){
  1586. document.addEventListener("click", e=>{
  1587. if(e.target.tagName=="PRE"){
  1588. let nameAttr=e.target.getAttribute("name");
  1589. if(nameAttr=="pagetual" || nameAttr=="user-content-pagetual" || location.href.indexOf("greasyfork.org") != -1){
  1590. let rules=e.target.innerText.trim();
  1591. let isContent=/['"]name['"]/i.test(rules);
  1592. if(!window.confirm("Import?")) return;
  1593. if(isContent){
  1594. let ruleList=JSON.parse(`[${rules}]`);
  1595. for(let i in ruleList){
  1596. let hasRule = false;
  1597. let r = ruleList[i];
  1598. for(let j in ruleParser.customRules){
  1599. if(ruleParser.customRules[j].name == r.name){
  1600. ruleParser.customRules[j] = r;
  1601. hasRule = true;
  1602. break;
  1603. }
  1604. }
  1605. if(!hasRule)ruleParser.customRules.push(r);
  1606. }
  1607. storage.setItem("customRules", ruleParser.customRules);
  1608. showTips(i18n("importSucc"));
  1609. }else{
  1610. rules=rules.split("\n");
  1611. let diff=false;
  1612. for(let c=0;c<rules.length;c++){
  1613. let urlArr=rules[c].split("|"),url,type=1;
  1614. if(urlArr.length==1){
  1615. url=urlArr[0].trim();
  1616. if(!/^http/.test(url)){
  1617. showTips("Wrong url, check again!");
  1618. return;
  1619. }
  1620. }else if(urlArr.length==2){
  1621. type=urlArr[0].trim();
  1622. url=urlArr[1].trim();
  1623. if(!/^http/.test(url)){
  1624. showTips("Wrong url, check again!");
  1625. return;
  1626. }
  1627. }else{
  1628. break;
  1629. }
  1630. let maxId=0,hasUrl=false;
  1631. if(!rulesData.urls){
  1632. rulesData.urls=[];
  1633. maxId=1;
  1634. }else{
  1635. rulesData.urls.forEach(u=>{
  1636. if(maxId<u.id){
  1637. maxId=u.id;
  1638. }
  1639. if(u.url==url){
  1640. hasUrl=true;
  1641. }
  1642. });
  1643. if(hasUrl)break;
  1644. }
  1645. diff=true;
  1646. if(!rulesData.sort)rulesData.sort=[1];
  1647. rulesData.urls.push({id:maxId+1,url:url,type:type});
  1648. rulesData.sort.unshift(maxId+1);
  1649. }
  1650. if(!diff)return;
  1651. storage.setItem("rulesData", rulesData);
  1652.  
  1653. if(rulesData.urls)ruleUrls=ruleUrls.concat(rulesData.urls);
  1654. if(rulesData.sort){
  1655. let urls=[];
  1656. rulesData.sort.forEach(id=>{
  1657. for(let s=0;s<ruleUrls.length;s++){
  1658. if(id==ruleUrls[s].id){
  1659. urls.push(ruleUrls[s]);
  1660. break;
  1661. }
  1662. }
  1663. });
  1664. ruleUrls=urls;
  1665. }
  1666. updateRules(()=>{
  1667. showTips(i18n("updateSucc"));
  1668. },(rule,err)=>{
  1669. showTips("Update "+rule.url+" rules fail!");
  1670. });
  1671. showTips(i18n("beginUpdate"));
  1672. }
  1673. }
  1674. }
  1675. });
  1676. }
  1677. if(location.href==configPage){
  1678. _GM_addStyle(`
  1679. p>span:nth-child(1),p>span:nth-child(2),p>span:nth-child(3){
  1680. cursor: pointer;
  1681. user-select: none;
  1682. }
  1683. p>span:nth-child(1):hover,p>span:nth-child(2):hover,p>span:nth-child(3):hover{
  1684. color:red;
  1685. }
  1686. .updateDate{
  1687. cursor: pointer;
  1688. user-select: none;
  1689. }
  1690. .updateDate:hover{
  1691. color:red;
  1692. }
  1693. `);
  1694. document.querySelector("[name='user-content-click2import']").innerText=i18n("click2ImportRule")
  1695. configCon=document.querySelector(".markdown-body");
  1696. insertPos=configCon.querySelector("hr");
  1697.  
  1698. if(rulesData.urls && rulesData.urls.length>0){
  1699. document.querySelector("pre[name='user-content-pagetual']").style.display="none";
  1700. document.querySelector("p[name='user-content-click2import']").style.display="none";
  1701. }
  1702. }else return false;
  1703. class Rulebar {
  1704. init(ruleUrl){
  1705. this.ruleUrl=ruleUrl;
  1706. this.item=document.createElement("p");
  1707. this.item.title=ruleUrl.type==0?"AutoPagerize Rules":"Pagetual Rules";
  1708. this.item.dataset.id=this.ruleUrl.id;
  1709. let url=document.createElement("span");
  1710. url.innerHTML=ruleUrl.url;
  1711. let up=document.createElement("span");
  1712. up.innerHTML="↑ ";
  1713. up.title=i18n("sortTitle");
  1714. let down=document.createElement("span");
  1715. down.innerHTML="↓ ";
  1716. down.title=i18n("sortTitle");
  1717. let del=document.createElement("span");
  1718. del.innerHTML="× ";
  1719. up.onclick=e=>{
  1720. this.moveUp();
  1721. };
  1722. down.onclick=e=>{
  1723. this.moveDown();
  1724. };
  1725. del.onclick=e=>{
  1726. this.del();
  1727. };
  1728. this.item.appendChild(up);
  1729. this.item.appendChild(down);
  1730. this.item.appendChild(del);
  1731. this.item.appendChild(url);
  1732. configCon.insertBefore(this.item, insertPos);
  1733. }
  1734. saveSort(){
  1735. let sort=[];
  1736. [].forEach.call(this.item.parentNode.querySelectorAll("p[data-id]"), i=>{
  1737. sort.push(i.dataset.id);
  1738. });
  1739. rulesData.sort=sort;
  1740. storage.setItem("rulesData", rulesData);
  1741. }
  1742. moveUp(){
  1743. let preE=this.item.previousElementSibling;
  1744. if(preE.tagName=="P" && preE.children.length>1){
  1745. this.item.parentNode.insertBefore(this.item,preE);
  1746. this.saveSort();
  1747. }
  1748. }
  1749. moveDown(){
  1750. let nextE=this.item.nextElementSibling;
  1751. if(nextE.tagName=="P" && nextE.children.length>1){
  1752. this.item.parentNode.insertBefore(nextE,this.item);
  1753. this.saveSort();
  1754. }
  1755. }
  1756. del(){
  1757. if(this.ruleUrl.id<2){
  1758. showTips(i18n("cantDel"));
  1759. }else if(window.confirm(i18n("confirmDel"))){
  1760. for(let u=0;u<rulesData.urls.length;u++){
  1761. if(this.ruleUrl.id==rulesData.urls[u].id){
  1762. rulesData.urls.splice(u,1);
  1763. break;
  1764. }
  1765. }
  1766. for(let u=0;u<rulesData.sort.length;u++){
  1767. if(this.ruleUrl.id==rulesData.sort[u]){
  1768. rulesData.sort.splice(u,1);
  1769. break;
  1770. }
  1771. }
  1772. storage.setItem("rulesData", rulesData);
  1773. ruleParser.rules=ruleParser.rules.filter(item=>{return item.from!=this.ruleUrl.id});
  1774. storage.setItem("rules", ruleParser.rules);
  1775. this.item.parentNode.removeChild(this.item);
  1776. //location.reload();
  1777. }
  1778. }
  1779. }
  1780. let updateP=document.createElement("p"),i=0;
  1781. let now=new Date().getTime(),inUpdate=false;
  1782.  
  1783.  
  1784. let pastDate=(new Date(updateDate)).toString(),passStr;
  1785. let passTime=(now-updateDate)/1000;
  1786. if(isNaN(passTime)){
  1787. passStr=i18n("firstUpdate");
  1788. }else if(passTime<60){
  1789. passStr=i18n("passSec", parseInt(passTime))+" ← "+i18n("click2update");
  1790. }else if(passTime<60*60){
  1791. passStr=i18n("passMin", parseInt(passTime/60))+" ← "+i18n("click2update");
  1792. }else if(passTime<60*60*24){
  1793. passStr=i18n("passHour", parseInt(passTime/3600))+" ← "+i18n("click2update");
  1794. }else{
  1795. passStr=i18n("passDay", parseInt(passTime/86400))+" ← "+i18n("click2update");
  1796. }
  1797.  
  1798.  
  1799. updateP.className="updateDate";
  1800. updateP.innerHTML=passStr;
  1801. updateP.title=i18n("update")+" - "+pastDate;
  1802. updateP.onclick=e=>{
  1803. updateRules(()=>{
  1804. showTips(i18n("updateSucc"));
  1805. updateP.innerHTML=i18n("passSec", 0);
  1806. updateP.title=i18n("update");
  1807. },(rule,err)=>{
  1808. showTips("Update "+rule.url+" rules fail!");
  1809. });
  1810. showTips(i18n("beginUpdate"));
  1811. };
  1812. configCon.insertBefore(updateP, insertPos);
  1813. if(ruleUrls){
  1814. ruleUrls.forEach(ruleUrl=>{
  1815. var rulebar=new Rulebar();
  1816. rulebar.init(ruleUrl);
  1817. });
  1818. }
  1819. let customUrlsTitle=document.createElement("h2");
  1820. customUrlsTitle.innerHTML=i18n("customUrls");
  1821. configCon.insertBefore(customUrlsTitle, insertPos);
  1822. let customUrlsInput=document.createElement("textarea");
  1823. customUrlsInput.style.width="100%";
  1824. customUrlsInput.placeholder="0 | http://wedata.net/databases/AutoPagerize/items_all.json";
  1825. configCon.insertBefore(customUrlsInput, insertPos);
  1826.  
  1827. let upBtnImgTitle=document.createElement("h2");
  1828. upBtnImgTitle.innerHTML=i18n("upBtnImg");
  1829. upBtnImgTitle.style.width="50%";
  1830. upBtnImgTitle.style.float="left";
  1831. let upBtnImgInput=document.createElement("input");
  1832. upBtnImgInput.style.width="100%";
  1833. upBtnImgInput.placeholder="data:image/png;base64,UpBtn";
  1834. upBtnImgInput.value=rulesData.upBtnImg||'';
  1835. upBtnImgTitle.appendChild(upBtnImgInput);
  1836. configCon.insertBefore(upBtnImgTitle, insertPos);
  1837.  
  1838. let downBtnImgTitle=document.createElement("h2");
  1839. downBtnImgTitle.innerHTML=i18n("downBtnImg");
  1840. downBtnImgTitle.style.width="50%";
  1841. downBtnImgTitle.style.float="left";
  1842. let downBtnImgInput=document.createElement("input");
  1843. downBtnImgInput.style.width="100%";
  1844. downBtnImgInput.placeholder="data:image/png;base64,DownBtn";
  1845. downBtnImgInput.value=rulesData.downBtnImg||'';
  1846. downBtnImgTitle.appendChild(downBtnImgInput);
  1847. configCon.insertBefore(downBtnImgTitle, insertPos);
  1848.  
  1849. let opacityTitle=document.createElement("h2");
  1850. opacityTitle.innerHTML=i18n("opacity");
  1851. let opacityInput=document.createElement("input");
  1852. opacityInput.value=rulesData.opacity*100;
  1853. opacityInput.type="number";
  1854. opacityInput.style.width="50px";
  1855. opacityInput.style.margin="0 0 0 10px";
  1856. opacityTitle.appendChild(opacityInput);
  1857. configCon.insertBefore(opacityTitle, insertPos);
  1858.  
  1859. let configTable=document.createElement("table");
  1860. configTable.appendChild(document.createElement("tbody"));
  1861. configCon.insertBefore(configTable, insertPos);
  1862. function createCheckbox(innerText, val, tag, parentCheck, otherType){
  1863. let title=document.createElement(tag||"h3");
  1864. title.innerHTML=innerText;
  1865. let input=document.createElement("input");
  1866. input.type=otherType||"checkbox";
  1867. input.style.width="50px";
  1868. input.style.height="20px";
  1869. input.value=val;
  1870. input.checked=val;
  1871. let td=document.createElement("td");
  1872. td.appendChild(input);
  1873. if(parentCheck){
  1874. td.appendChild(title);
  1875. let parent=parentCheck.parentNode.nextElementSibling;
  1876. let tr=parent.querySelector("tr");
  1877. if(!tr){
  1878. tr=document.createElement("tr");
  1879. parent.appendChild(tr);
  1880. }
  1881. tr.appendChild(td);
  1882. if(!parentCheck.checked){
  1883. td.style.display="none";
  1884. }
  1885. parentCheck.addEventListener("click", e=>{
  1886. td.style.display=parentCheck.checked?"":"none";
  1887. });
  1888. }else{
  1889. let tr=document.createElement("tr");
  1890. tr.appendChild(td);
  1891. td=document.createElement("td");
  1892. td.appendChild(title);
  1893. tr.appendChild(td);
  1894. configTable.children[0].appendChild(tr);
  1895. }
  1896. return input;
  1897. }
  1898.  
  1899. let enableWhiteListInput=createCheckbox(i18n("autoRun"), rulesData.enableWhiteList!=true);
  1900. let enableDebugInput=createCheckbox(i18n("enableDebug"), rulesData.enableDebug!=false);
  1901. let enableHistoryInput=createCheckbox(i18n("enableHistory"), rulesData.enableHistory===true);
  1902. let openInNewTabInput=createCheckbox(i18n("openInNewTab"), rulesData.openInNewTab!=false);
  1903. let initRunInput=createCheckbox(i18n("initRun"), rulesData.initRun!=false);
  1904. let preloadInput=createCheckbox(i18n("preload"), rulesData.preload!=false);
  1905. let dbClick2StopInput=createCheckbox(i18n("dbClick2Stop"), rulesData.dbClick2Stop);
  1906. let hideBarInput=createCheckbox(i18n("hideBar"), rulesData.hideBar, "h4", dbClick2StopInput);
  1907. let dbClick2StopCtrlInput=createCheckbox(i18n("dbClick2StopCtrl"), rulesData.dbClick2StopCtrl, "h4", dbClick2StopInput);
  1908. let dbClick2StopAltInput=createCheckbox(i18n("dbClick2StopAlt"), rulesData.dbClick2StopAlt, "h4", dbClick2StopInput);
  1909. let dbClick2StopShiftInput=createCheckbox(i18n("dbClick2StopShift"), rulesData.dbClick2StopShift, "h4", dbClick2StopInput);
  1910. let dbClick2StopMetaInput=createCheckbox(i18n("dbClick2StopMeta"), rulesData.dbClick2StopMeta, "h4", dbClick2StopInput);
  1911. let dbClick2StopKeyInput=createCheckbox(i18n("dbClick2StopKey"), rulesData.dbClick2StopKey, "h4", dbClick2StopInput, "text");
  1912. dbClick2StopKeyInput.setAttribute("maxlength", "1");
  1913.  
  1914. let customRulesTitle=document.createElement("h2");
  1915. customRulesTitle.innerHTML=i18n("customRules");
  1916. configCon.insertBefore(customRulesTitle, insertPos);
  1917. let customRulesInput=document.createElement("textarea");
  1918. configCon.insertBefore(customRulesInput, insertPos);
  1919. if(rulesData.editTemp){
  1920. if(!ruleParser.customRules){
  1921. ruleParser.customRules=[];
  1922. }
  1923. for(let i in ruleParser.customRules){
  1924. if(ruleParser.customRules[i].url==rulesData.editTemp.url){
  1925. ruleParser.customRules.splice(i, 1);
  1926. break;
  1927. }
  1928. }
  1929. ruleParser.customRules.unshift(rulesData.editTemp);
  1930. rulesData.editTemp=null;
  1931. storage.setItem("rulesData", rulesData);
  1932. customRulesInput.previousElementSibling.scrollIntoView();
  1933. }
  1934. customRulesInput.style.width="100%";
  1935. customRulesInput.style.height="500px";
  1936. 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]`;
  1937. customRulesInput.value=getFormatJSON(ruleParser.customRules);
  1938. let blacklistInput=document.createElement("textarea");
  1939. blacklistInput.style.width="100%";
  1940. blacklistInput.style.height="500px";
  1941. blacklistInput.style.display="none";
  1942. blacklistInput.placeholder="http://*.xxx.com/*/y";
  1943. blacklistInput.value=rulesData.blacklist?rulesData.blacklist.join("\n"):"";
  1944. let blacklistBtn=document.createElement("button");
  1945. blacklistBtn.innerText=i18n("editBlacklist");
  1946. blacklistBtn.style.width="100%";
  1947. blacklistBtn.onclick=e=>{
  1948. blacklistInput.style.display=blacklistInput.style.display=="none"?"":"none";
  1949. };
  1950. configCon.insertBefore(blacklistBtn, insertPos);
  1951. configCon.insertBefore(blacklistInput, insertPos);
  1952. let saveBtn=document.createElement("button");
  1953. saveBtn.innerHTML=i18n("save");
  1954. saveBtn.style.width="100%";
  1955. configCon.insertBefore(saveBtn, insertPos);
  1956. saveBtn.onclick=e=>{
  1957. try{
  1958. storage.setItem("hpRules", []);
  1959. if(customRulesInput.value==""){
  1960. storage.setItem("customRules", "");
  1961. }else{
  1962. let customRules=JSON.parse(customRulesInput.value);
  1963. if(Array && Array.isArray && !Array.isArray(customRules)){
  1964. showTips("Rules must be a Array!");
  1965. return;
  1966. }
  1967. debug(customRules);
  1968. storage.setItem("customRules", customRules);
  1969. }
  1970. }catch(e){
  1971. debug(e);
  1972. showTips("JSON error, check again!");
  1973. return;
  1974. }
  1975. rulesData.opacity=opacityInput.value/100;
  1976. rulesData.blacklist=blacklistInput.value?blacklistInput.value.split("\n"):"";
  1977. rulesData.hideBar=hideBarInput.checked;
  1978. rulesData.dbClick2Stop=dbClick2StopInput.checked;
  1979. rulesData.enableWhiteList=!enableWhiteListInput.checked;
  1980. rulesData.enableDebug=enableDebugInput.checked;
  1981. rulesData.enableHistory=enableHistoryInput.checked;
  1982. rulesData.openInNewTab=openInNewTabInput.checked;
  1983. rulesData.initRun=initRunInput.checked;
  1984. rulesData.preload=preloadInput.checked;
  1985. rulesData.upBtnImg=upBtnImgInput.value;
  1986. rulesData.downBtnImg=downBtnImgInput.value;
  1987. rulesData.dbClick2StopCtrl=dbClick2StopCtrlInput.checked;
  1988. rulesData.dbClick2StopAlt=dbClick2StopAltInput.checked;
  1989. rulesData.dbClick2StopShift=dbClick2StopShiftInput.checked;
  1990. rulesData.dbClick2StopMeta=dbClick2StopMetaInput.checked;
  1991. rulesData.dbClick2StopKey=dbClick2StopKeyInput.value;
  1992. storage.setItem("rulesData", rulesData);
  1993. let customUrls=customUrlsInput.value.trim();
  1994. if(customUrls){
  1995. customUrls=customUrls.split(/\n/);
  1996. for(let c=0;c<customUrls.length;c++){
  1997. let urlArr=customUrls[c].split("|"),url,type=1;
  1998. if(urlArr.length==1){
  1999. url=urlArr[0].trim();
  2000. if(!/^http/.test(url)){
  2001. showTips("Wrong url, check again!");
  2002. return;
  2003. }
  2004. }else if(urlArr.length==2){
  2005. type=urlArr[0].trim();
  2006. url=urlArr[1].trim();
  2007. if(!/^http/.test(url)){
  2008. showTips("Wrong url, check again!");
  2009. return;
  2010. }
  2011. }else{
  2012. break;
  2013. }
  2014. let maxId=0,hasUrl=false;
  2015. if(!rulesData.urls){
  2016. rulesData.urls=[];
  2017. maxId=1;
  2018. }else{
  2019. rulesData.urls.forEach(u=>{
  2020. if(maxId<u.id){
  2021. maxId=u.id;
  2022. }
  2023. if(u.url==url){
  2024. hasUrl=true;
  2025. }
  2026. });
  2027. if(hasUrl)break;
  2028. }
  2029. if(!rulesData.sort)rulesData.sort=[1];
  2030. rulesData.urls.push({id:maxId+1,url:url,type:type});
  2031. rulesData.sort.push(maxId+1);
  2032. storage.setItem("rulesData", rulesData);
  2033. }
  2034. }
  2035. showTips("The settings are saved");
  2036. location.reload();
  2037. };
  2038. return true;
  2039. }
  2040.  
  2041. var inUpdate=false;
  2042. function updateRules(success,fail){
  2043. if(inUpdate)return;
  2044. inUpdate=true;
  2045. let ruleIndex=ruleUrls.length-1;
  2046. storage.setItem("hpRules", []);
  2047. function addNextRule(){
  2048. if(ruleIndex<0){
  2049. let now=new Date().getTime();
  2050. storage.setItem("ruleLastUpdate", now);
  2051. storage.setItem("rules", ruleParser.rules);
  2052. inUpdate=false;
  2053. success();
  2054. }else{
  2055. let rule=ruleUrls[ruleIndex--];
  2056. ruleParser.addRuleByUrl(rule.url, rule.type, rule.id, (json,err)=>{
  2057. if(!json){
  2058. fail(rule,err);
  2059. }
  2060. addNextRule();
  2061. })
  2062. }
  2063. }
  2064. addNextRule();
  2065. }
  2066.  
  2067. function objIsArr(obj) {
  2068. return obj &&
  2069. typeof obj === 'object' &&
  2070. typeof obj.length === 'number' &&
  2071. !(obj.propertyIsEnumerable('length'));
  2072. }
  2073.  
  2074. function isVisible(el, win) {
  2075. if(!el.offsetParent)return false;
  2076. var loopable = true,
  2077. visible = el.tagName && win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  2078. while(loopable && visible) {
  2079. el = el.parentNode;
  2080.  
  2081. if(el && el.tagName && el.tagName!="BODY") {
  2082. visible = win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  2083. }else {
  2084. loopable = false;
  2085. }
  2086. }
  2087. return visible;
  2088. }
  2089.  
  2090. function getElementTop(ele) {
  2091. var actualTop = ele.offsetTop;
  2092. var current = ele.offsetParent;
  2093. while (current) {
  2094. actualTop += current.offsetTop;
  2095. current = current.offsetParent;
  2096. }
  2097. return actualTop;
  2098. }
  2099.  
  2100. function getFormatJSON(obj){
  2101. if(!objIsArr(obj))return "";
  2102. let ret="[\n";
  2103. let len=obj.length,i=0,isLast;
  2104. obj.forEach(item=>{
  2105. ret+=" {\n";
  2106. let iLen=Object.keys(item).length,j=0;
  2107. for(let key in item){
  2108. isLast=(++j)==iLen;
  2109. let value=item[key];
  2110. if(objIsArr(value)){
  2111. let vstr="[",v=0,vIsLast=false;
  2112. value.forEach(vi=>{
  2113. vIsLast=(++v)==value.length;
  2114. vstr+="\""+vi.replace(/\\/g,"\\\\")+"\""+(vIsLast?"":",");
  2115. });
  2116. vstr+="]";
  2117. ret+=" \""+key+"\":"+vstr+""+(isLast?"":",")+"\n";
  2118. }else{
  2119. if(typeof value=="string"){
  2120. value=value.replace(/\\/g,"\\\\").replace(/"/g,"\\\"");
  2121. value="\""+value+"\"";
  2122. }
  2123. ret+=" \""+key+"\":"+value+""+(isLast?"":",")+"\n";
  2124. }
  2125. }
  2126. isLast=(++i)==len;
  2127. ret+=" }"+(isLast?"":",")+"\n";
  2128. });
  2129. ret+="]";
  2130. return ret;
  2131. }
  2132.  
  2133. function globMatch(first, second) {
  2134. if (first.length == 0 && second.length == 0){
  2135. return true;
  2136. }
  2137.  
  2138. if (first.length > 1 && first[0] == '*' &&
  2139. second.length == 0){
  2140. return false;
  2141. }
  2142.  
  2143. if ((first.length > 1 && first[0] == '?') ||
  2144. (first.length != 0 && second.length != 0 &&
  2145. first[0] == second[0])){
  2146. return globMatch(first.substring(1),
  2147. second.substring(1));
  2148. }
  2149.  
  2150. if (first.length > 0 && first[0] == '*'){
  2151. return globMatch(first.substring(1), second) ||
  2152. globMatch(first, second.substring(1));
  2153. }
  2154.  
  2155. return false;
  2156. }
  2157.  
  2158. function initRules(callback) {
  2159. /*0 wedata格式,1 pagetual格式*/
  2160. ruleUrls=[
  2161. {
  2162. id:1,
  2163. url:'http://wedata.net/databases/AutoPagerize/items_all.json',
  2164. type:0,
  2165. }
  2166. ];var i=0,j=0;
  2167.  
  2168. ruleParser.initSavedRules(()=>{
  2169. storage.getItem("rulesData", data=>{
  2170. if(data){
  2171. rulesData=data;
  2172. if(data.urls)ruleUrls=ruleUrls.concat(data.urls);
  2173. if(data.sort){
  2174. let urls=[];
  2175. data.sort.forEach(id=>{
  2176. for(let s=0;s<ruleUrls.length;s++){
  2177. if(id==ruleUrls[s].id){
  2178. urls.push(ruleUrls[s]);
  2179. break;
  2180. }
  2181. }
  2182. });
  2183. ruleUrls=urls;
  2184. }
  2185. }
  2186. let upBtnImg=rulesData.upBtnImg,downBtnImg=rulesData.downBtnImg;
  2187. if(upBtnImg && downBtnImg){
  2188. downSvgCSS=downSvgCSS.replace("transform: rotate(180deg);","");
  2189. }else if(upBtnImg && !downBtnImg){
  2190. downBtnImg=upBtnImg;
  2191. }else if(downBtnImg && !upBtnImg){
  2192. upBtnImg=downBtnImg;
  2193. }
  2194. if(upBtnImg){
  2195. upSvg=`<img src="${upBtnImg}"/>`;
  2196. }
  2197. if(downBtnImg){
  2198. downSvg=`<img src="${downBtnImg}"/>`;
  2199. }
  2200. if(typeof(rulesData.opacity)=="undefined"){
  2201. rulesData.opacity=0.3;
  2202. }
  2203. if(typeof(rulesData.hideBar)=="undefined"){
  2204. rulesData.hideBar=false;
  2205. }
  2206. if(typeof(rulesData.dbClick2Stop)=="undefined"){
  2207. rulesData.dbClick2Stop=true;
  2208. }
  2209. if(typeof(rulesData.enableWhiteList)=="undefined"){
  2210. rulesData.enableWhiteList=false;
  2211. }
  2212. if(typeof(rulesData.enableHistory)=="undefined"){
  2213. rulesData.enableHistory=false;
  2214. }
  2215. if(typeof(rulesData.openInNewTab)=="undefined"){
  2216. rulesData.openInNewTab=true;
  2217. }
  2218. if(typeof(rulesData.enableDebug)=="undefined"){
  2219. rulesData.enableDebug=true;
  2220. }
  2221. if(typeof(rulesData.initRun)=="undefined"){
  2222. rulesData.initRun=true;
  2223. }
  2224. if(typeof(rulesData.preload)=="undefined"){
  2225. rulesData.preload=true;
  2226. }
  2227. if(rulesData.blacklist && rulesData.blacklist.length>0){
  2228. for(let b in rulesData.blacklist){
  2229. let curGlob=rulesData.blacklist[b];
  2230. if(globMatch(curGlob, location.href)){
  2231. return;
  2232. }
  2233. }
  2234. }
  2235. enableDebug=rulesData.enableDebug;
  2236. storage.getItem("forceState_"+location.host, v=>{
  2237. storage.getItem("ruleLastUpdate", date=>{
  2238. if(typeof(v)=="undefined"){
  2239. v=(rulesData.enableWhiteList?1:0);
  2240. }
  2241. forceState=v;
  2242. updateDate=date;
  2243. if(initConfig())return;
  2244. if(forceState==1)return;
  2245. let now=new Date().getTime();
  2246. if(!date || now-date>2*24*60*60*1000){
  2247. updateRules(()=>{
  2248. },(rule,err)=>{});
  2249. }
  2250. callback();
  2251. });
  2252. });
  2253. });
  2254. });
  2255. }
  2256.  
  2257. function requestDoc(url, callback){
  2258. _GM_xmlhttpRequest({
  2259. url: url,
  2260. method: 'GET',
  2261. overrideMimeType: 'text/html;charset='+document.charset,
  2262. headers: {
  2263. 'Referer': location.href,
  2264. "Content-Type": "text/html;charset="+document.charset,
  2265. },
  2266. timeout: 5000,
  2267. onload: function(res) {
  2268. var doc=null,response=res.response;
  2269. let preCode=ruleParser.curSiteRule.pageElementPre || ruleParser.curSiteRule.pagePre;
  2270. if(preCode){
  2271. try{
  2272. response=Function("response",'"use strict";' + preCode)(response);
  2273. }catch(e){
  2274. debug(e);
  2275. }
  2276. }
  2277. try {
  2278. doc=document.implementation.createHTMLDocument('');
  2279. doc.documentElement.innerHTML=response;
  2280. }
  2281. catch (e) {
  2282. debug('parse error'+e.toString());
  2283. }
  2284. let pageElement=ruleParser.getPageElement(doc);
  2285. if(inCors && (!pageElement || pageElement.length==0)){
  2286. ruleParser.curSiteRule.pageElement=allOfBody;
  2287. pageElement=ruleParser.getPageElement(doc);
  2288. ruleParser.getInsert(true);
  2289. }
  2290. //只有1的話怕不是圖片哦
  2291. if(pageElement && (pageElement.length>1 || (pageElement.length==1 && pageElement[0].tagName!="IMG") )){
  2292. let result=ruleParser.insertPage(doc, pageElement, url, callback, false);
  2293. ruleParser.curSiteRule.action=0;
  2294. if(!result){
  2295. ruleParser.curSiteRule.action=1;
  2296. requestFromIframe(url, (doc, eles)=>{
  2297. loadPageOver();
  2298. if(eles){
  2299. ruleParser.insertPage(doc, eles, url, callback, true);
  2300. }
  2301. });
  2302. }
  2303. }else if(ruleParser.curSiteRule.singleUrl || curPage==1){
  2304. ruleParser.curSiteRule.action=1;
  2305. requestFromIframe(url, (doc, eles)=>{
  2306. loadPageOver();
  2307. if(eles){
  2308. ruleParser.insertPage(doc, eles, url, callback, true);
  2309. }
  2310. });
  2311. }else{
  2312. isPause=true;
  2313. callback(false);
  2314. }
  2315. },
  2316. onerror: function(e){
  2317. debug(e);
  2318. callback(false);
  2319. },
  2320. ontimeout: function(e){
  2321. debug(e);
  2322. callback(false);
  2323. }
  2324. });
  2325. }
  2326.  
  2327. var failFromIframe=0;
  2328. var inCors=false;
  2329. function requestFromIframe(url, callback){
  2330. url=url.replace(/#[^#]*/,"");
  2331. let orgPage,curPage;
  2332. let iframe = document.createElement('iframe');
  2333. iframe.name = 'pagetual-iframe';
  2334. iframe.width = '100%';
  2335. iframe.height = '0';
  2336. iframe.frameBorder = '0';
  2337. if(ruleParser.curSiteRule.sandbox!=false){
  2338. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  2339. }
  2340. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  2341. let waitTime=100,checkEval;
  2342. if(ruleParser.curSiteRule.wait){
  2343. if(isNaN(ruleParser.curSiteRule.wait)){
  2344. try{
  2345. checkEval=Function("doc",'"use strict";' + ruleParser.curSiteRule.wait);
  2346. }catch(e){
  2347. debug(e);
  2348. }
  2349. }else{
  2350. waitTime=ruleParser.curSiteRule.wait;
  2351. }
  2352. }
  2353. let loadedHandler=e=>{
  2354. if(e.data != 'pagetual-iframe:DOMLoaded' && e.type != 'load')return;
  2355. window.removeEventListener('message', loadedHandler, false);
  2356. iframe.removeEventListener('load', loadedHandler, false);
  2357. let tryTimes=0;
  2358. function checkIframe(){
  2359. try{
  2360. let doc=iframe.contentDocument || iframe.contentWindow.document;
  2361. let eles=ruleParser.getPageElement(doc, iframe.contentWindow);
  2362. if(checkEval && !checkEval(doc)){
  2363. setTimeout(()=>{
  2364. checkIframe();
  2365. },waitTime);
  2366. return;
  2367. }else if(eles && eles.length>0){
  2368. callback(doc, eles);
  2369. }else if(tryTimes++ < 10){
  2370. setTimeout(()=>{
  2371. checkIframe();
  2372. },waitTime);
  2373. return;
  2374. }else{
  2375. if(failFromIframe++ > 2){
  2376. failFromIframe=0;
  2377. debug("Stop as failFromIframe");
  2378. isPause=true;
  2379. callback(false, false);
  2380. }else{
  2381. callback(false, false);
  2382. }
  2383. }
  2384. }catch(e){
  2385. debug("Stop as cors");
  2386. inCors=true;
  2387. //isPause=true;
  2388. if(!ruleParser.curSiteRule.pageElement){
  2389. ruleParser.curSiteRule.pageElement=allOfBody;
  2390. ruleParser.getInsert(true);
  2391. }
  2392. ruleParser.curSiteRule.action=0;
  2393. ruleParser.nextLinkHref=url;
  2394. callback(false, false);
  2395. nextPage();
  2396. }
  2397. document.body.removeChild(iframe);
  2398. }
  2399. setTimeout(()=>{
  2400. checkIframe();
  2401. },waitTime);
  2402. };
  2403. window.addEventListener('message', loadedHandler, false);
  2404. iframe.addEventListener('load', loadedHandler, false);
  2405. iframe.src=url;
  2406. document.body.appendChild(iframe);
  2407. }
  2408.  
  2409. function initPage(){
  2410. ruleParser.initPage(()=>{
  2411. if(ruleParser.nextLinkHref){
  2412. let isJs=/^(javascript|#)/.test(ruleParser.nextLinkHref.replace(location.href,""));
  2413. if(!isJs){
  2414. let inForce=(forceState == 2 || forceState == 3);
  2415. _GM_registerMenuCommand(i18n(inForce?"cancelForceIframe":"forceIframe"), ()=>{
  2416. if(inForce){
  2417. storage.setItem("forceState_"+location.host, "");
  2418. }else{
  2419. let _state=ruleParser.curSiteRule.action>0 || confirm(i18n("forceAllBody"))?2:3;
  2420. storage.setItem("forceState_"+location.host, _state);
  2421. }
  2422. location.reload();
  2423. });
  2424. }
  2425. _GM_registerMenuCommand(i18n("loadNow"), ()=>{
  2426. let loadNum=window.prompt(i18n("loadConfirm"), "1");
  2427. if(loadNum==="" || loadNum===null)return;
  2428. autoLoadNum=Math.abs(parseInt(loadNum));
  2429. nextPage();
  2430. });
  2431. }
  2432. initListener();
  2433. if(rulesData.initRun && ruleParser.curSiteRule.initRun!=0)nextPage();
  2434. });
  2435. }
  2436.  
  2437. var pageBarStyle;
  2438. function initView(){
  2439. _GM_addStyle(`
  2440. .pagetual_pageBar.stop {
  2441. -webkit-filter: invert(100%);
  2442. filter: invert(100%);
  2443. opacity: 1!important;
  2444. }
  2445. .pagetual_pageBar.hide {
  2446. display: none!important;
  2447. }
  2448. .pagetual_pageBar:hover {
  2449. opacity: 1!important;
  2450. }
  2451. .pagetual_pageBar span {
  2452. vertical-align: super;
  2453. }
  2454.  
  2455. .pagetual_pageBar span>svg:hover {
  2456. animation: touhouAni 1s infinite;
  2457. }
  2458. .pagetual_pageBar .pagetual_pageNum{
  2459. color: #55555f;
  2460. }
  2461. .pagetual_pageBar .pagetual_pageNum:hover{
  2462. color: #ff6464;
  2463. }
  2464. .pagetual_tipsWords{
  2465. font-size: 50px;
  2466. font-weight: bold;
  2467. font-family: "黑体", -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto",
  2468. "Oxygen", "Ubuntu", "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji",
  2469. "Segoe UI Emoji", "Segoe UI Symbol";
  2470. color: #ffffff;
  2471. height: 70px;
  2472. line-height: 70px;
  2473. position: fixed;
  2474. left: 50%;
  2475. top: 10%;
  2476. margin-left: -150px;
  2477. padding: 0 10px;
  2478. z-index: 999999999;
  2479. background-color: #000;
  2480. border: 1px solid black;
  2481. border-radius: 10px;
  2482. opacity: 0;
  2483. filter: alpha(opacity=65);
  2484. box-shadow: 5px 5px 20px 0px #000;
  2485. -moz-transition:opacity 0.3s ease-in-out 0s;
  2486. -webkit-transition:opacity 0.3s ease-in-out 0s;
  2487. transition:opacity 0.3s ease-in-out 0s;
  2488. pointer-events: none;
  2489. }
  2490.  
  2491. @keyframes touhouAni{
  2492. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  2493. to {transform: rotate(360deg);}
  2494. }
  2495. @-webkit-keyframes touhouAni{
  2496. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  2497. to {transform: rotate(360deg);}
  2498. }
  2499. .pagetual_loading {
  2500. width: 50px;
  2501. height: 50px;
  2502. margin: 10px auto;
  2503. border-radius: 100%;
  2504. -webkit-animation: pagetual_loading_scaleout 1.0s infinite ease-in-out;
  2505. animation: pagetual_loading_scaleout 1.0s infinite ease-in-out;
  2506. }
  2507. @-webkit-keyframes pagetual_loading_scaleout {
  2508. 0% { -webkit-transform: scale(0.0) }
  2509. 100% {
  2510. -webkit-transform: scale(1.0);
  2511. opacity: 0;
  2512. }
  2513. }
  2514. @keyframes pagetual_loading_scaleout {
  2515. 0% {
  2516. transform: scale(0.0);
  2517. -webkit-transform: scale(0.0);
  2518. } 100% {
  2519. transform: scale(1.0);
  2520. -webkit-transform: scale(1.0);
  2521. opacity: 0;
  2522. }
  2523. }
  2524. `);
  2525. 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;`;
  2526. }
  2527. var loadingDiv=document.createElement("div");
  2528. 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;";
  2529. loadingDiv.innerHTML=`<p 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>`;
  2530. 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;`;
  2531.  
  2532. 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>`;
  2533. var upSvgCSS=`display:initial;position:absolute;cursor: pointer;margin: 0 -45px;width: 30px;height: 30px;vertical-align: middle;fill: currentColor;overflow: hidden;`;
  2534. 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>`;
  2535. 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);`;
  2536.  
  2537. 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;`;
  2538. 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;`;
  2539.  
  2540. var tipsWords=document.createElement("div");
  2541. tipsWords.className="pagetual_tipsWords";
  2542.  
  2543. var isPause=false,isLoading=false,curPage=1,forceState=0,bottomGap=1000,autoLoadNum=-1;
  2544.  
  2545. function changeStop(stop, hide){
  2546. isPause=stop;
  2547. [].forEach.call(document.querySelectorAll(".pagetual_pageBar"), bar=>{
  2548. if(isPause){
  2549. bar.classList.add("stop");
  2550. if(hide)bar.classList.add("hide");
  2551. }else{
  2552. bar.classList.remove("stop");
  2553. if(hide)bar.classList.remove("hide");
  2554. }
  2555. });
  2556. }
  2557.  
  2558. function isInViewPort(element) {
  2559. if(!element.parentNode)return false;
  2560. if(_unsafeWindow.getComputedStyle(element).display=="none")return false;
  2561. const viewWidth = window.innerWidth || document.documentElement.clientWidth;
  2562. const viewHeight = window.innerHeight || document.documentElement.clientHeight;
  2563. const {
  2564. top,
  2565. right,
  2566. bottom,
  2567. left,
  2568. } = element.getBoundingClientRect();
  2569.  
  2570. return (
  2571. top >= 0 &&
  2572. left >= 0 &&
  2573. right <= viewWidth + 1 &&
  2574. bottom <= viewHeight * 2
  2575. );
  2576. }
  2577.  
  2578. var urlChanged=false;
  2579. var _wr = function(type) {
  2580. var orig = history[type];
  2581. return function() {
  2582. var rv = orig.apply(this, arguments);
  2583. var e = new Event(type);
  2584. e.arguments = arguments;
  2585. window.dispatchEvent(e);
  2586. return rv;
  2587. };
  2588. };
  2589. history.pushState = _wr('pushState');
  2590. window.addEventListener('pushState', function(e) {
  2591. urlChanged=true;
  2592. isPause=true;
  2593. setTimeout(()=>{
  2594. if(location.href==configPage){
  2595. location.reload();
  2596. }
  2597. },1);
  2598. });
  2599.  
  2600. function initListener(){
  2601. let loadmoreBtn,loading=true,lastScroll=0,checkLoadMoreTimes=0;
  2602. let checkLoadMore=setInterval(()=>{
  2603. loadmoreBtn=getLoadMore(document);
  2604. if(loadmoreBtn && isVisible(loadmoreBtn, _unsafeWindow)){
  2605. loading=false;
  2606. clearInterval(checkLoadMore);
  2607. }else if(checkLoadMoreTimes>10){
  2608. clearInterval(checkLoadMore);
  2609. }
  2610. },300);
  2611. let checkScrollReach=()=>{
  2612. let scrolly=window.scrollY;
  2613. let windowHeight=window.innerHeight || document.documentElement.clientHeight;
  2614. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  2615. if(scrollH-scrolly-windowHeight<bottomGap){
  2616. nextPage();
  2617. }
  2618. };
  2619. let scrollHandler = e=>{
  2620. if(urlChanged){
  2621. ruleParser.initPage(()=>{
  2622. if(ruleParser.nextLinkHref)initView();
  2623. });
  2624. urlChanged=false;
  2625. isPause=false;
  2626. }
  2627. if(isPause)return;
  2628. if(!loading){
  2629. if(!loadmoreBtn || !loadmoreBtn.parentNode){
  2630. loadmoreBtn=getLoadMore(document);
  2631. }
  2632. if(loadmoreBtn){
  2633. if(isInViewPort(loadmoreBtn)){
  2634. emuClick(loadmoreBtn);
  2635. loading=true;
  2636. setTimeout(()=>{loading=false},200);
  2637. }
  2638. }else{
  2639. loading=true;
  2640. setTimeout(()=>{loading=false},200);
  2641. }
  2642. }
  2643. if(!isLoading){
  2644. checkScrollReach();
  2645. }
  2646. if(ruleParser.curSiteRule.lockScroll){
  2647. let curScroll=document.body.scrollTop||document.documentElement.scrollTop;
  2648. if(lastScroll!=0 && isLoading && Math.abs(lastScroll-curScroll)>100){
  2649. document.body.scrollTop=lastScroll;
  2650. document.documentElement.scrollTop=lastScroll;
  2651. }else{
  2652. lastScroll=curScroll;
  2653. }
  2654. }
  2655. };
  2656. if(!ruleParser.curSiteRule.wheel){
  2657. document.addEventListener('scroll', scrollHandler, true);
  2658. }
  2659. document.addEventListener('wheel', scrollHandler, true);
  2660. document.addEventListener('dblclick', e=>{
  2661. if(forceState==1 || e.target.tagName=='INPUT' || e.target.tagName=='TEXTAREA') return;
  2662. if(!rulesData.dbClick2StopKey){
  2663. if((rulesData.dbClick2StopCtrl && !e.ctrlKey) ||
  2664. (rulesData.dbClick2StopAlt && !e.altKey) ||
  2665. (rulesData.dbClick2StopShift && !e.shiftKey) ||
  2666. (rulesData.dbClick2StopMeta && !e.metaKey)){
  2667. return;
  2668. }
  2669. }
  2670. if(e.target.tagName!="BODY"){
  2671. let selStr=document.getSelection().toString();
  2672. if(selStr){
  2673. return;
  2674. }
  2675. }
  2676. if(rulesData.dbClick2Stop && (ruleParser.nextLinkHref || loadmoreBtn)){
  2677. setTimeout(()=>{
  2678. changeStop(!isPause, rulesData.hideBar);
  2679. if(!isPause){
  2680. checkScrollReach();
  2681. }
  2682. showTips(i18n(isPause?"disable":"enable"));
  2683. },10);
  2684. }
  2685. });
  2686. if(rulesData.dbClick2StopKey){
  2687. document.addEventListener('keydown', e=>{
  2688. if((rulesData.dbClick2StopCtrl && !e.ctrlKey) ||
  2689. (rulesData.dbClick2StopAlt && !e.altKey) ||
  2690. (rulesData.dbClick2StopShift && !e.shiftKey) ||
  2691. (rulesData.dbClick2StopMeta && !e.metaKey)){
  2692. return;
  2693. }
  2694. var key = String.fromCharCode(e.keyCode).toLowerCase();
  2695. if(rulesData.dbClick2StopKey.toLowerCase()==key){
  2696. forceState=(forceState==1?0:1);
  2697. showTips(i18n(forceState==1?"disableSiteTips":"enableSiteTips"));
  2698. if(!ruleParser.curSiteRule.url) {
  2699. storage.setItem("forceState_"+location.host, forceState);
  2700. location.reload();
  2701. }
  2702. }
  2703. });
  2704. }
  2705. }
  2706.  
  2707. function showTips(content, wordColor, backColor){
  2708. document.body.appendChild(tipsWords);
  2709. tipsWords.style.opacity=0.8;
  2710. tipsWords.innerText=content;
  2711. tipsWords.style.marginLeft=-tipsWords.offsetWidth/2+"px";
  2712. tipsWords.style.color=wordColor||0xFFFFFF;
  2713. tipsWords.style.backgroundColor=backColor||0x000;
  2714. setTimeout(()=>{tipsWords.style.opacity=0},1000);
  2715. }
  2716.  
  2717. function getLoadMore(doc){
  2718. if(ruleParser.curSiteRule.loadMore==="")return null;
  2719. let btnSel=ruleParser.curSiteRule.loadMore||".LoadMore,.load-more,.button-show-more",loadmoreBtn;
  2720. if(btnSel){
  2721. try{
  2722. loadmoreBtn=doc.querySelector(btnSel);
  2723. }catch(e){
  2724. loadmoreBtn=getElementByXpath(btnSel,doc,doc);
  2725. }
  2726. }
  2727. if(!loadmoreBtn){
  2728. let buttons=doc.querySelectorAll("input,button,a,div[onclick]"),loadmoreReg=/^\s*(加载更多|加載更多|load\s*more|もっと読み込む)\s*$/i;
  2729. for(let i=0;i<buttons.length;i++){
  2730. let button=buttons[i];
  2731. if(button && loadmoreReg.test(button.innerText)){
  2732. loadmoreBtn=button;
  2733. break;
  2734. }
  2735. }
  2736. }
  2737. if(loadmoreBtn && !ruleParser.curSiteRule.loadMore && loadmoreBtn.href && !/^(javascript|#)/.test(loadmoreBtn.href))loadmoreBtn=null;
  2738. return loadmoreBtn;
  2739. }
  2740.  
  2741. var hasPageNum=true;
  2742. function createPageBar(url){
  2743. let insert=ruleParser.getInsert();
  2744. if(!insert || !insert.parentNode)return;
  2745. curPage++;
  2746. let example=ruleParser.curSiteRule.insertPos==2?insert.children[0]:(insert.previousElementSibling||insert);
  2747. if(!example || !example.parentNode)example=insert;
  2748. let inTable=example.parentNode.tagName=="TABLE" ||
  2749. example.tagName=="TR" ||
  2750. example.tagName=="TBODY" ||
  2751. (example.previousElementSibling && example.previousElementSibling.tagName=="TR") ||
  2752. (example.previousElementSibling && example.previousElementSibling.tagName=="TBODY");
  2753. let inLi=example.tagName=="LI" || (example.previousElementSibling && example.previousElementSibling.tagName=="LI");
  2754. if(forceState==2){
  2755. inTable=inLi=false;
  2756. }
  2757. let pageBar=document.createElement(inTable?"tr":(inLi?"li":"div"));
  2758. let upSpan=document.createElement("span");
  2759. let downSpan=document.createElement("span");
  2760. let pageText=document.createElement("a");
  2761. let pageNum;
  2762. pageBar.className="pagetual_pageBar";
  2763. pageBar.id="pagetual_pageBar";
  2764. if(isPause){
  2765. pageBar.classList.add("stop");
  2766. }
  2767. pageBar.style.cssText=pageBarStyle;
  2768. pageBar.title=i18n(isPause?"enable":"disable");
  2769. upSpan.innerHTML=upSvg;
  2770. upSpan.children[0].style.cssText=upSvgCSS;
  2771. upSpan.title=i18n("toTop");
  2772. downSpan.innerHTML=downSvg;
  2773. downSpan.children[0].style.cssText=downSvgCSS;
  2774. downSpan.title=i18n("toBottom");
  2775. upSpan.style.cssText=initStyle;
  2776. downSpan.style.cssText=initStyle;
  2777. pageText.href=url;
  2778. pageText.style.cssText=pageTextStyle;
  2779. pageText.title=i18n("current");
  2780. pageBar.appendChild(upSpan);
  2781. pageBar.appendChild(pageText);
  2782. if(ruleParser.nextTitle){
  2783. pageText.innerHTML=ruleParser.nextTitle+" ";
  2784. pageText.title=ruleParser.nextTitle;
  2785. }
  2786. if(ruleParser.curSiteRule.pageNum || (hasPageNum && /[&\/\?](p=|page[=\/_-]?)\d+|[_-]\d+\./.test(url))){
  2787. pageText.innerHTML+="Page ";
  2788. pageNum=document.createElement("span");
  2789. pageNum.innerText=curPage;
  2790. pageNum.className="pagetual_pageNum";
  2791. pageNum.title=i18n("inputPageNum");
  2792. pageNum.style.cssText=pageTextStyle;
  2793. pageNum.style.cursor="pointer";
  2794. pageNum.style.color="";
  2795. pageNum.style.marginLeft="5px";
  2796. pageNum.addEventListener("click", e=>{
  2797. let pageInput=prompt(i18n("inputPageNum"), "1");
  2798. if(pageInput){
  2799. let pageLink=ruleParser.getLinkByPage(url, pageInput);
  2800. if(pageLink){
  2801. _GM_openInTab(pageLink,{active:true});
  2802. }
  2803. }
  2804. e.preventDefault();
  2805. e.stopPropagation();
  2806. });
  2807. pageBar.appendChild(pageNum);
  2808. }else{
  2809. pageText.innerHTML+="Page "+curPage;
  2810. hasPageNum=false;
  2811. }
  2812. pageBar.appendChild(downSpan);
  2813. let parentStyle=_unsafeWindow.getComputedStyle(example.parentNode);
  2814. let parentWidth=example.parentNode.scrollWidth||parseInt(parentStyle.width);
  2815. pageBar.style.width=parentWidth-parseInt(parentStyle.paddingLeft)-parseInt(parentStyle.paddingRight)-10+"px";
  2816. if(parentStyle.display=="grid" || parentStyle.display=="inline-grid"){
  2817. pageBar.style.gridColumnStart=1;
  2818. pageBar.style.gridColumnEnd=1+parseInt(example.parentNode.offsetWidth/example.offsetWidth);
  2819. }
  2820. if(inTable){
  2821. example=(example.tagName=="TR" || example.tagName=="TBODY")?example:example.previousElementSibling;
  2822. if(example.tagName=="TBODY")example=example.querySelector("tr");
  2823. let preTr=example;
  2824. while(preTr && preTr.children.length==0)preTr=preTr.previousElementSibling;
  2825. if(preTr)example=preTr;
  2826. let tdNum=0;
  2827. [].forEach.call(example.children, el=>{
  2828. if(el.tagName=="TD" || el.tagName=="TH"){
  2829. tdNum+=el.colSpan||1;
  2830. }
  2831. });
  2832. pageBar.style.display="table-row";
  2833. pageBar.style.backgroundColor="unset";
  2834. pageBar.style.lineHeight="20px";
  2835. pageBar.style.boxShadow="";
  2836. let td=document.createElement("td");
  2837. td.colSpan=tdNum||1;
  2838. let inTd=document.createElement("div");
  2839. inTd.style.backgroundColor="rgb(240 240 240 / 80%)";
  2840. inTd.style.borderRadius="20px";
  2841. inTd.style.padding="0 0";
  2842. inTd.style.margin="10px";
  2843. inTd.style.lineHeight="20px";
  2844. inTd.style.textAlign="center";
  2845. inTd.style.boxShadow="rgb(0 0 0 / 67%) 0px 0px 10px 0px";
  2846. inTd.appendChild(upSpan);
  2847. inTd.appendChild(pageText);
  2848. if(pageNum)inTd.appendChild(pageNum);
  2849. inTd.appendChild(downSpan);
  2850. td.appendChild(inTd);
  2851. pageBar.appendChild(td);
  2852. }else if(inLi){
  2853. example=example.tagName=="LI"?example:example.previousElementSibling;
  2854. pageBar.style.display="table-row";
  2855. pageBar.style.backgroundColor="unset";
  2856. pageBar.style.lineHeight="20px";
  2857. pageBar.style.boxShadow="";
  2858. let td=document.createElement("td");
  2859. td.colSpan=example.children.length;
  2860. let inTd=document.createElement("div");
  2861. inTd.style.backgroundColor="rgb(240 240 240 / 80%)";
  2862. inTd.style.borderRadius="20px";
  2863. inTd.style.margin="10px"
  2864. inTd.style.padding="0 0";
  2865. inTd.style.textAlign="center";
  2866. inTd.style.minWidth="150px";
  2867. inTd.appendChild(upSpan);
  2868. inTd.appendChild(pageText);
  2869. inTd.style.width=parseInt(pageBar.style.width)-20+"px";
  2870. inTd.style.boxShadow="rgb(0 0 0 / 67%) 0px 0px 10px 0px";
  2871. if(pageNum)inTd.appendChild(pageNum);
  2872. inTd.appendChild(downSpan);
  2873. td.appendChild(inTd);
  2874. pageBar.appendChild(td);
  2875. }
  2876.  
  2877. upSpan.addEventListener("click", e=>{
  2878. document.body.scrollTop=0;
  2879. document.documentElement.scrollTop=0;
  2880. e.preventDefault();
  2881. e.stopPropagation();
  2882. });
  2883. downSpan.addEventListener("click", e=>{
  2884. changeStop(true);
  2885. pageBar.title=i18n(isPause?"enable":"disable");
  2886. document.body.scrollTop=9999999;
  2887. document.documentElement.scrollTop=9999999;
  2888. e.preventDefault();
  2889. e.stopPropagation();
  2890. });
  2891. pageBar.addEventListener("click", e=>{
  2892. changeStop(!isPause);
  2893. pageBar.title=i18n(isPause?"enable":"disable");
  2894. });
  2895. pageText.addEventListener("click", e=>{
  2896. e.stopPropagation();
  2897. });
  2898. ruleParser.insertElement(pageBar);
  2899. if(ruleParser.curSiteRule.pageBar){
  2900. try{
  2901. Function("pageBar",'"use strict";' + ruleParser.curSiteRule.pageBar)(pageBar);
  2902. }catch(e){
  2903. debug(e);
  2904. }
  2905. }
  2906.  
  2907. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  2908. let posEle=pageBar.nextElementSibling||pageBar;
  2909. while(posEle && !posEle.offsetParent){
  2910. posEle=posEle.previousElementSibling||posEle.parentNode;
  2911. }
  2912. if(posEle){
  2913. let actualTop = getElementTop(posEle);
  2914. bottomGap=scrollH-actualTop+(window.innerHeight||document.documentElement.clientHeight)*(ruleParser.curSiteRule.rate||1);
  2915. if(bottomGap<100)bottomGap=100;
  2916. }else{
  2917. bottomGap=1000;
  2918. }
  2919. if(rulesData.opacity==0)pageBar.style.display="none";
  2920. return pageBar;
  2921. }
  2922.  
  2923. function emuClick(btn){
  2924. if(!PointerEvent)return btn.click();
  2925. let eventParam={
  2926. isTrusted: true,
  2927. altKey: false,
  2928. azimuthAngle: 0,
  2929. bubbles: true,
  2930. button: 0,
  2931. buttons: 0,
  2932. clientX: 1,
  2933. clientY: 1,
  2934. cancelBubble: false,
  2935. cancelable: true,
  2936. composed: true,
  2937. ctrlKey: false,
  2938. defaultPrevented: false,
  2939. detail: 1,
  2940. eventPhase: 2,
  2941. fromElement: null,
  2942. height: 1,
  2943. isPrimary: false,
  2944. metaKey: false,
  2945. pointerId: 1,
  2946. pointerType: "mouse",
  2947. pressure: 0,
  2948. relatedTarget: null,
  2949. returnValue: true,
  2950. shiftKey: false,
  2951. toElement: null,
  2952. twist: 0,
  2953. which: 1
  2954. };
  2955. var mouseEvent = new PointerEvent("mousedown",eventParam);
  2956. btn.dispatchEvent(mouseEvent);
  2957. mouseEvent = new PointerEvent("mouseup",eventParam);
  2958. btn.dispatchEvent(mouseEvent);
  2959. btn.click();
  2960. }
  2961.  
  2962. var emuIframe,lastActiveUrl=location.href;
  2963. function emuPage(callback){
  2964. let orgPage=null,orgContent=null,curPage,iframeDoc,times=0,loadmoreBtn,loadmoreEnd=false,waitTimes=10,changed=false;
  2965. function checkPage(){
  2966. if(isPause)return;
  2967. try{
  2968. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  2969. }catch(e){
  2970. debug("Stop as cors");
  2971. isPause=true;
  2972. callback(false, false);
  2973. return;
  2974. }
  2975.  
  2976. let nextLink=ruleParser.getNextLink(iframeDoc);
  2977. let waitTime=200,checkEval;
  2978. if(ruleParser.curSiteRule.wait){
  2979. if(isNaN(ruleParser.curSiteRule.wait)){
  2980. try{
  2981. checkEval=Function("doc",'"use strict";' + ruleParser.curSiteRule.wait);
  2982. }catch(e){
  2983. debug(e);
  2984. }
  2985. }else{
  2986. waitTime=ruleParser.curSiteRule.wait;
  2987. }
  2988. }
  2989.  
  2990. if(!orgPage){
  2991. if(!loadmoreEnd){
  2992. loadmoreBtn=getLoadMore(iframeDoc);
  2993. if(loadmoreBtn && isVisible(loadmoreBtn, iframeDoc.defaultView)){
  2994. emuClick(loadmoreBtn);
  2995. let intv=setInterval(()=>{
  2996. loadmoreBtn=getLoadMore(iframeDoc);
  2997. if(!loadmoreBtn || !loadmoreBtn.parentNode || !isVisible(loadmoreBtn, iframeDoc.defaultView)){
  2998. clearInterval(intv);
  2999. loadmoreEnd=true;
  3000. setTimeout(()=>{
  3001. checkPage();
  3002. },500);
  3003. }else{
  3004. emuClick(loadmoreBtn);
  3005. }
  3006. },200);
  3007. return;
  3008. }else{
  3009. loadmoreEnd=true;
  3010. }
  3011. }
  3012. let pageEle=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true);
  3013. if(!nextLink || !pageEle || pageEle.length==0 || (checkEval && !checkEval(iframeDoc))){
  3014. if(waitTimes-->0){
  3015. setTimeout(()=>{
  3016. checkPage();
  3017. },waitTime);
  3018. return;
  3019. }
  3020. }
  3021. orgPage=pageEle;
  3022. if(!orgPage || orgPage.length==0){
  3023. debug("Stop as no page when emu");
  3024. isPause=true;
  3025. callback(false, false);
  3026. return;
  3027. }
  3028. if(orgPage && orgPage[0].tagName=="UL")orgPage=orgPage[0].children;
  3029. if(orgPage && nextLink){
  3030. orgPage=orgPage[parseInt(orgPage.length/2)];
  3031. orgContent=orgPage.innerText;
  3032. if(!isVisible(nextLink, iframeDoc.defaultView)){
  3033. debug("Stop as next hide when emu");
  3034. isPause=true;
  3035. callback(false, false);
  3036. }else{
  3037. emuClick(nextLink);
  3038. setTimeout(()=>{
  3039. checkPage();
  3040. },500);
  3041. }
  3042. }else{
  3043. debug("Stop as no next when emu");
  3044. isPause=true;
  3045. callback(false, false);
  3046. }
  3047. return;
  3048. }
  3049. if(times++ > 20){
  3050. debug("Stop as timeout when emu");
  3051. isPause=true;
  3052. callback(false, false);
  3053. return;
  3054. }
  3055. let eles=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true),checkItem;
  3056. if(eles && eles.length>0){
  3057. checkItem=eles;
  3058. if(eles[0].tagName=="UL"){
  3059. checkItem=eles[0].children;
  3060. }
  3061. checkItem=checkItem[parseInt(checkItem.length/2)];
  3062. }
  3063. if(!checkItem || (checkEval && !checkEval(iframeDoc))){
  3064. setTimeout(()=>{
  3065. checkPage();
  3066. },waitTime);
  3067. }else{
  3068. if(orgPage!=checkItem || checkItem.innerText!=orgContent){
  3069. changed=true;
  3070. orgPage=checkItem;
  3071. orgContent=checkItem.innerText;
  3072. setTimeout(()=>{
  3073. checkPage();
  3074. },waitTime);
  3075. }else if(changed){
  3076. callback(iframeDoc, eles);
  3077. }else{
  3078. setTimeout(()=>{
  3079. checkPage();
  3080. },waitTime);
  3081. }
  3082. }
  3083. }
  3084. if(!emuIframe){
  3085. let loaded=false;
  3086. emuIframe = document.createElement('iframe');
  3087. emuIframe.name = 'pagetual-iframe';
  3088. if(ruleParser.curSiteRule.sandbox!=false){
  3089. emuIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  3090. }
  3091. emuIframe.width = '100%';
  3092. emuIframe.height = '0';
  3093. emuIframe.frameBorder = '0';
  3094. emuIframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  3095. emuIframe.addEventListener("load", e=>{
  3096. setTimeout(()=>{
  3097. try{
  3098. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  3099. }catch(e){
  3100. debug("Stop as cors");
  3101. isPause=true;
  3102. callback(false, false);
  3103. return;
  3104. }
  3105. let code=ruleParser.curSiteRule.init;
  3106. if(code){
  3107. try{
  3108. Function('doc','win','iframe','"use strict";' + code)(iframeDoc, iframeDoc.defaultView, emuIframe);
  3109. }catch(e){
  3110. debug(e);
  3111. }
  3112. }
  3113. if(loaded)return;
  3114. loaded=true;
  3115. checkPage();
  3116. },500);
  3117. });
  3118. emuIframe.src=lastActiveUrl.replace(/#[^#]*/,"");
  3119. document.body.appendChild(emuIframe);
  3120. }else{
  3121. checkPage();
  3122. }
  3123. }
  3124.  
  3125. var scrollToResizeInited = false;
  3126. var resizePool = [];
  3127. function scrollToResize() {
  3128. if (scrollToResizeInited) return;
  3129. scrollToResizeInited = true;
  3130. var scrollingToResize = false;
  3131. document.addEventListener("scroll", e => {
  3132. if (scrollingToResize) return;
  3133. else {
  3134. scrollingToResize = true;
  3135. setTimeout(() => {scrollingToResize = false}, 500);
  3136. }
  3137. resizePool.forEach(resizeArr => {
  3138. let iframe = resizeArr[1]();
  3139. let frameDoc = resizeArr[2]();
  3140. if(ruleParser.curSiteRule.singleUrl){
  3141. iframe.style.height=frameDoc.body.scrollHeight+"px";
  3142. iframe.style.width=frameDoc.body.scrollWidth+"px";
  3143. }else{
  3144. let pageEle = resizeArr[0]();
  3145. if(pageEle){
  3146. let targetElement = pageEle[0];
  3147. if(pageEle.length > 1){
  3148. targetElement = targetElement.parentNode;
  3149. }
  3150. iframe.style.height=targetElement.scrollHeight+"px";
  3151. frameDoc.documentElement.scrollTop = 0;
  3152. frameDoc.documentElement.scrollLeft = 0;
  3153. while(targetElement && targetElement.offsetParent){
  3154. targetElement.offsetParent.scrollTop = targetElement.offsetTop;
  3155. if(targetElement.offsetParent.scrollTop == 0){
  3156. frameDoc.documentElement.scrollTop += targetElement.offsetTop;
  3157. }
  3158. targetElement.offsetParent.scrollLeft = targetElement.offsetLeft;
  3159. if(targetElement.offsetParent.scrollLeft == 0){
  3160. frameDoc.documentElement.scrollLeft += targetElement.offsetLeft;
  3161. }
  3162. targetElement = targetElement.offsetParent;
  3163. }
  3164. }
  3165. }
  3166. });
  3167. });
  3168. }
  3169.  
  3170. function forceIframe(url, callback){
  3171. url=url.replace(/#[^#]*/,"");
  3172. let curIframe = document.createElement('iframe'),iframeDoc;
  3173. let setPosition = ()=>{
  3174. let getIframe = () => {
  3175. return curIframe;
  3176. };
  3177. let getFrameDoc = () => {
  3178. return iframeDoc;
  3179. };
  3180. if(ruleParser.curSiteRule.singleUrl){
  3181. resizePool.push([() => {}, getIframe, getFrameDoc]);
  3182. }else{
  3183. let pageElement = ruleParser.getPageElement(iframeDoc,iframeDoc.defaultView);
  3184. let getPageEle = () => {
  3185. if (!pageElement) {
  3186. pageElement = ruleParser.getPageElement(iframeDoc,iframeDoc.defaultView);
  3187. }
  3188. return pageElement;
  3189. };
  3190. resizePool.push([getPageEle, getIframe, getFrameDoc]);
  3191. }
  3192. };
  3193. curIframe.name = 'pagetual-iframe';
  3194. curIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  3195. curIframe.frameBorder = '0';
  3196. curIframe.scrolling="no";
  3197. 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;';
  3198. curIframe.addEventListener("load", e=>{
  3199. try{
  3200. iframeDoc=curIframe.contentDocument || curIframe.contentWindow.document;
  3201. }catch(e){
  3202. debug("Stop as cors");
  3203. isPause=true;
  3204. callback(false, false);
  3205. return;
  3206. }
  3207. ruleParser.insertPage(iframeDoc, [], url, null, true);
  3208. callback(curIframe, true);
  3209. let css=ruleParser.curSiteRule.css;
  3210. if(css){
  3211. let styleEle=iframeDoc.createElement("style");
  3212. styleEle.innerHTML=css;
  3213. iframeDoc.head.appendChild(styleEle);
  3214. }
  3215. setPosition();
  3216. let code=ruleParser.curSiteRule.init;
  3217. if(code){
  3218. try{
  3219. Function('doc','win','iframe','"use strict";' + code)(iframeDoc,iframeDoc.defaultView,curIframe);
  3220. }catch(e){
  3221. debug(e);
  3222. }
  3223. }
  3224. });
  3225. let inAction=false,checkTimes=0;
  3226. let forceRefresh=e=>{
  3227. if(inAction || !iframeDoc)return;
  3228. inAction=true;
  3229. let foundNext=()=>{
  3230. document.removeEventListener("scroll", forceRefresh);
  3231. }
  3232. setTimeout(()=>{
  3233. inAction=false;
  3234. if(!ruleParser.nextLinkHref){
  3235. checkTimes++;
  3236. ruleParser.getNextLink(iframeDoc);
  3237. if(ruleParser.nextLinkHref){
  3238. foundNext();
  3239. }else if(checkTimes>=10){
  3240. foundNext();
  3241. }
  3242. }else{
  3243. foundNext();
  3244. }
  3245. },50);
  3246. };
  3247. document.addEventListener("scroll", forceRefresh);
  3248. curIframe.src=url;
  3249. let insert=ruleParser.getInsert();
  3250. if(ruleParser.curSiteRule.singleUrl || forceState==2){
  3251. document.body.appendChild(loadingDiv);
  3252. document.body.appendChild(curIframe);
  3253. }else{
  3254. ruleParser.insertElement(curIframe);
  3255. }
  3256. scrollToResize();
  3257. return curIframe;
  3258. }
  3259.  
  3260. function loadPageOver(){
  3261. isLoading=false;
  3262. if(loadingDiv.parentNode){
  3263. loadingDiv.parentNode.removeChild(loadingDiv);
  3264. }
  3265. /*setTimeout(()=>{
  3266. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  3267. if(scrollH <= (window.innerHeight || document.documentElement.clientHeight)){
  3268. nextPage();
  3269. }
  3270. },1);*/
  3271. }
  3272.  
  3273. var tryTimes = 0;
  3274.  
  3275. function nextPage(){
  3276. if(isPause || isLoading || forceState==1)return;
  3277. if(ruleParser.curSiteRule.delay){
  3278. try{
  3279. let checkDelay=Function('"use strict";' + ruleParser.curSiteRule.delay)();
  3280. if(!checkDelay)return;
  3281. }catch(e){
  3282. debug(e);
  3283. }
  3284. }
  3285. let nextLink=ruleParser.nextLinkHref;
  3286. if(!nextLink){
  3287. if(curPage==1){
  3288. ruleParser.getNextLink(document);
  3289. nextLink=ruleParser.nextLinkHref;
  3290. }
  3291. if(!nextLink){
  3292. isPause=true;
  3293. if(curPage==1 && (ruleParser.curSiteRule.pinUrl || tryTimes++ <= 10)){
  3294. setTimeout(()=>{isPause=false},500);
  3295. }
  3296. return;
  3297. }
  3298. }
  3299. let pvGallery=document.querySelector("span.pv-gallery-container");
  3300. if(pvGallery && pvGallery.style.display!="none")return;
  3301. let insert=ruleParser.getInsert();
  3302. if(insert){
  3303. let isJs=/^(javascript|#)/.test(nextLink.replace(location.href,""));
  3304. if(!isJs){
  3305. emuIframe=null;
  3306. lastActiveUrl=nextLink;
  3307. }
  3308. if(location.protocol=="https:" && /^http:/.test(nextLink)){
  3309. nextLink=nextLink.replace(/^http/,"https");
  3310. }
  3311. isLoading=true;
  3312. ruleParser.insertElement(loadingDiv);
  3313. loadingDiv.style.cssText=loadingCSS;
  3314. let sleep=ruleParser.curSiteRule.sleep||0;
  3315. setTimeout(()=>{
  3316. if(ruleParser.curSiteRule.pageElementByJs){
  3317. var over=ele=>{
  3318. loadPageOver();
  3319. if(ele){
  3320. createPageBar(nextLink);
  3321. ruleParser.insertPage(null, ele, nextLink, null, true);
  3322. if(autoLoadNum>=0){
  3323. if(autoLoadNum!=0 && --autoLoadNum==0){
  3324. autoLoadNum=-1;
  3325. }else{
  3326. nextPage();
  3327. }
  3328. }
  3329. }else{
  3330. debug("Stop as no page when get by js");
  3331. isPause=true;
  3332. }
  3333. };
  3334. try{
  3335. Function("over",'"use strict";' + ruleParser.curSiteRule.pageElementByJs)(over);
  3336. }catch(e){
  3337. debug(e);
  3338. }
  3339. }else if((forceState==3||ruleParser.curSiteRule.action==1) && !isJs){
  3340. requestFromIframe(nextLink, (doc, eles)=>{
  3341. loadPageOver();
  3342. if(eles){
  3343. ruleParser.insertPage(doc, eles, nextLink, ()=>{
  3344. createPageBar(nextLink);
  3345. }, true);
  3346. if(autoLoadNum>=0){
  3347. if(autoLoadNum!=0 && --autoLoadNum==0){
  3348. autoLoadNum=-1;
  3349. }else{
  3350. nextPage();
  3351. }
  3352. }
  3353. }
  3354. });
  3355. }else if((forceState==2||ruleParser.curSiteRule.action==2) && !isJs){
  3356. forceIframe(nextLink, (iframe, eles)=>{
  3357. loadPageOver();
  3358. let pageBar=createPageBar(nextLink);
  3359. if(pageBar)iframe.parentNode.insertBefore(pageBar, iframe);
  3360. if(autoLoadNum>=0){
  3361. if(autoLoadNum!=0 && --autoLoadNum==0){
  3362. autoLoadNum=-1;
  3363. }else{
  3364. nextPage();
  3365. }
  3366. }
  3367. });
  3368. }else{
  3369. if(!isJs){
  3370. requestDoc(nextLink, (eles)=>{
  3371. loadPageOver();
  3372. if(eles){
  3373. createPageBar(nextLink);
  3374. if(autoLoadNum>=0){
  3375. if(autoLoadNum!=0 && --autoLoadNum==0){
  3376. autoLoadNum=-1;
  3377. }else{
  3378. nextPage();
  3379. }
  3380. }
  3381. }
  3382. });
  3383. }else{
  3384. emuPage((doc, eles)=>{
  3385. loadPageOver();
  3386. if(eles){
  3387. ruleParser.insertPage(doc, eles, "", ()=>{
  3388. createPageBar(nextLink);
  3389. }, true);
  3390. if(autoLoadNum>=0){
  3391. if(autoLoadNum!=0 && --autoLoadNum==0){
  3392. autoLoadNum=-1;
  3393. }else{
  3394. nextPage();
  3395. }
  3396. }
  3397. }
  3398. });
  3399. }
  3400. }
  3401. },sleep);
  3402. }
  3403. }
  3404.  
  3405. function init(){
  3406. initRules(()=>{
  3407. initPage();
  3408. });
  3409. }
  3410. setTimeout(()=>{
  3411. init();
  3412. },100);
  3413. })();