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

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

当前为 2022-03-18 提交的版本,查看 最新版本

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

QingJ © 2025

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