东方永页机 - 自动翻页脚本

自动加载并拼接下一分页内容,无需规则即可支持任何网页

当前为 2022-04-27 提交的版本,查看 最新版本

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

QingJ © 2025

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