东方永页机

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

当前为 2022-05-11 提交的版本,查看 最新版本

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

QingJ © 2025

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