东方永页机

自动翻页

当前为 2022-02-14 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Pagetual
  3. // @name:zh-CN 东方永页机
  4. // @name:zh-TW 東方永頁機
  5. // @name:ja 東方永頁機
  6. // @name:ru Пейджетуал
  7. // @name:de Pagetual
  8. // @name:es Pagetual
  9. // @name:fr Pagetual
  10. // @name:it Pagetual
  11. // @name:ko 東方永頁機
  12. // @namespace hoothin
  13. // @version 1.0.29
  14. // @description Simply auto loading paginated web pages
  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,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAAdVBMVEUAAADZHQbYHQXaHQbYHgbZHATYHgbYHgbZHQXYHgXZHgbZHgfYHQXYHQbXHQDYHgbYHgbYHQXZHgbYHgbYHgbYHgXaHQbYHQbYHQbZHgbZHgbZHQbZHgbYHgbYHQbYHQXYHgfaHwDZHQXZHQbYHwTVHQrYHgbCqWmRAAAAJnRSTlMAUL8oyD/el2cy1CCPcg/35euggPG6FajOr4Z617OdXkkIi1g4GcTbfAwAAAJDSURBVFjD7dbXtqpADADQ0NsA0hHQY83/f+K9rqNOCzPwfvaTugimjEH4s86739yX0+3n8dwd7dQh/seiaWbHscUqCnZEP24LvrXjXLyyaVJMp2RbeFajZInhJWCHcurB7idEVfS+89SGsS28qJFwyN59ZcgsnXeRVrwvSNLFNJEA1/jfDqW4Po8Z1+XwsX6HGA1Cft1Y0ndw0OjCrwxDj4hPDqgYXbGlZ35pj0fQ1dr0C4DM5++lZHMt/qLNXq2rAG5qtWPdoaL5/ZwXloHAP1onUKs3SOSOO5YEsFNLkJN2T/IRRt0gj6ZUUpZTyMmzUx/Vw8wVhwgEI9pog2PiHRO0OhTq2hLnytBK3yRdsKeCGjRnoagKLRbQNfwsXdGiAkLMu5ihWUSvr5S/tPWPlIV8kxvn58CKatMu7Ly1+Kzcsgwj0wqXlgnNMT7CrFPwwaTp+OsSKS4Y1UJ5Phl/BSM3F7JBQmKO78UGJWT/zWJpTae7E4CTtJcnVJ2E7dV4RAWlY36uM96gFnHQT0HFe0zOIZYbnGsVRJZHc/DZFS15pu54URfUSgYJvVJ8BgpPWWu3TwfJUxkvPahylAzy573ybXfQHVEUFt/2uC67KgWcybPp602gndMMKF647bfIUg9oQYmCH6B1PF7jHFDQk2n6PJ7gDcil1FekowdGuVBGqw7rGZXNFSweLnJRJo4pD4cENphb/CoH57O6o8q/wzbJtCBXuXVz7sqQBbBDMJ9a6e+SA/tlzjx0Q3TLL0/4Y/QPSYfEIomUUSEAAAAASUVORK5CYII=
  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 *://pagetual.hoothin.com/*
  95. // @exclude *://hoothin.github.io/PagetualGuide/*
  96. // @connect *
  97. // ==/UserScript==
  98.  
  99. (function() {
  100. 'use strict';
  101.  
  102. if (window.name === 'pagetual-iframe') {
  103. var domloaded = function (){
  104. window.scroll(window.scrollX, 999999);
  105. //window.parent.postMessage('pagetual-iframe:DOMLoaded', '*');
  106. };
  107. if(window.opera){
  108. document.addEventListener('DOMContentLoaded', domloaded, false);
  109. } else {
  110. domloaded();
  111. }
  112. return;
  113. }
  114.  
  115. if(window.top != window.self){
  116. return;
  117. }
  118.  
  119. const lang = navigator.appName=="Netscape"?navigator.language:navigator.userLanguage;
  120. var i18n=(name, param)=>{
  121. let config={};
  122. switch (lang){
  123. case "zh-CN":
  124. case "zh-SG":
  125. config={
  126. disable:"暂时禁用",
  127. disableSite:"在此站禁用",
  128. enable:"启用翻页",
  129. toTop:"回到顶部",
  130. toBottom:"前往页尾",
  131. current:"当前页",
  132. forceIframe:"强制拼接",
  133. cancelForceIframe:"取消强制拼接",
  134. configure:"打开配置页",
  135. update:"立即更新规则",
  136. passSec:"更新于 #t# 秒前",
  137. passMin:"更新于 #t# 分钟前",
  138. passHour:"更新于 #t# 小时前",
  139. passDay:"更新于 #t# 天前",
  140. cantDel:"无法删除内置规则",
  141. confirmDel:"是否确认要删除此规则?",
  142. updateSucc:"更新成功",
  143. beginUpdate:"正在更新,请稍候",
  144. customUrls:"导入规则url,一行一条,AutoPagerize 格式规则需要以\"0|\"开头",
  145. customRules:"输入【东方永页机】格式的自定义规则",
  146. save:"保存设置",
  147. loadingText:"少女祈祷中...",
  148. opacity:"分页隔条不透明值",
  149. hideBar:"空白处双击隐藏分页隔条",
  150. dbClick2Stop:"空白处双击暂停翻页",
  151. sortTitle:"排序在下次更新规则后生效",
  152. showPageUpDown:"显示翻屏按钮",
  153. pageUp:"上翻一屏",
  154. pageDown:"下翻一屏",
  155. showRealPage:"显示真实页数",
  156. modifyImage:"修改按钮图标,一行一条,依次为[页首][页尾][上翻][下翻]",
  157. btnCss:"添加按钮CSS",
  158. autoRun:"自动启用"
  159. };
  160. break;
  161. case "zh-TW":
  162. case "zh-HK":
  163. config={
  164. disable:"暫時禁用",
  165. disableSite:"在此站禁用",
  166. enable:"啟用翻頁",
  167. toTop:"回到頂部",
  168. toBottom:"前往頁尾",
  169. current:"當前頁",
  170. forceIframe:"強制拼接",
  171. cancelForceIframe:"取消强制拼接",
  172. configure:"打開配置頁",
  173. update:"立即更新規則",
  174. passSec:"更新于 #t# 秒前",
  175. passMin:"更新于 #t# 分鐘前",
  176. passHour:"更新于 #t# 小時前",
  177. passDay:"更新于 #t# 天前",
  178. cantDel:"無法刪除内置規則",
  179. confirmDel:"是否確認要刪除此規則?",
  180. updateSucc:"更新成功",
  181. beginUpdate:"正在更新,請稍候",
  182. customUrls:"導入規則url,一行一條,AutoPagerize 格式規則需要以\"0|\"開頭",
  183. customRules:"輸入【東方永頁機】格式的自定義規則",
  184. save:"存儲設置",
  185. loadingText:"少女祈禱中...",
  186. opacity:"分頁隔條不透明值",
  187. hideBar:"空白處雙擊隱藏分頁隔條",
  188. dbClick2Stop:"空白處雙擊暫停翻頁",
  189. sortTitle:"排序在下次更新規則後生效",
  190. showPageUpDown:"顯示翻屏按鈕",
  191. pageUp:"上翻一屏",
  192. pageDown:"下翻一屏",
  193. showRealPage:"顯示真實頁數",
  194. modifyImage:"修改按鈕圖標,一行一條,依次為[頁首][頁尾][上翻][下翻]",
  195. btnCss:"添加按鈕CSS",
  196. autoRun:"自動啓用"
  197. };
  198. break;
  199. case "ja":
  200. config = {
  201. disable: "一時的に無効にする",
  202. disableSite:"このサイト無効",
  203. enable: "ページめくりを有効にする",
  204. toTop: "トップに戻る",
  205. toBottom: "ページの下部に移動",
  206. current: "現在のページ",
  207. forceIframe: "強制ステッチ",
  208. cancelForceIframe: "強制ステッチをキャンセル",
  209. configure: "設定ページを開く",
  210. update: "今すぐルールを更新してください",
  211. passSec: "#t#秒前に更新",
  212. passMin: "#t#分前に更新",
  213. passHour: "#t#時間前に更新",
  214. passDay: "#t#日前に更新",
  215. cantDel: "組み込みルールを削除できません",
  216. confirmDel: "このルールを削除してもよろしいですか?",
  217. updateSucc: "更新に成功しました",
  218. beginUpdate: "更新中、お待ちください",
  219. customUrls: "インポートルールのURL、1行に1つ、AutoPagerizeフォーマットルールは\"0|\"で始まる必要があります",
  220. customRules: "【東方永頁機】の形式でカスタムルールを入力してください",
  221. save: "設定を保存",
  222. loadingText: "少女祈祷中...",
  223. opacity:"ページネーションバーの不透明値",
  224. hideBar:"空白部分をダブルクリックして、ページ区切り文字を非表示にします",
  225. dbClick2Stop:"空白部分をダブルクリックしてページめくりを一時停止します",
  226. sortTitle:"並べ替えは、次のルールの更新後に有効になります",
  227. showPageUpDown:"ページめくりボタンを表示",
  228. pageUp:"ページアップ",
  229. pageDown:"ページダウン",
  230. showRealPage:"実際のページ数を表示する",
  231. modifyImage:"ボタンアイコンを変更し、[toTop][toBottom][pageUp][pageDown]の順に1行に1つのアイコンを書き込みます",
  232. btnCss:"ボタンCSSを追加",
  233. autoRun:"自動的に有効"
  234. };
  235. break;
  236. default:
  237. config={
  238. disable:"Disable",
  239. disableSite:"Disable on the site",
  240. enable:"Enable",
  241. toTop:"To Top",
  242. toBottom:"To Bottom",
  243. current:"Current Page",
  244. forceIframe:"Force to join",
  245. cancelForceIframe:"Cancel Force join",
  246. configure:"Configure",
  247. update:"Update rules from url now",
  248. passSec:"Updated #t# seconds ago",
  249. passMin:"Updated #t# minutes ago",
  250. passHour:"Updated #t# hours ago",
  251. passDay:"Updated #t# days ago",
  252. cantDel:"Can't delete buildin rules",
  253. confirmDel:"Are you sure you want to delete this rule?",
  254. updateSucc:"Update succeeded",
  255. beginUpdate:"Begin update, wait a minute please",
  256. customUrls:"Import rule url, One url per line, rules on AutoPagerize format need to start with \"0|\"",
  257. customRules:"Input custom rules with [Pagetual] format",
  258. save:"Save",
  259. loadingText:"Shojo Now Loading...",
  260. opacity:"Pagination spacer opacity",
  261. hideBar:"Double-click on the blank space to hide the paging spacer",
  262. dbClick2Stop:"Double-click on the blank space to stop",
  263. sortTitle:"Sorting takes effect after the next rule update",
  264. showPageUpDown:"Show pageUp/pageDown button",
  265. pageUp: "Page up",
  266. pageDown: "Page down",
  267. showRealPage:"Show real page count",
  268. modifyImage: "Modify button icons, one per line, in order of [toTop][toBottom][pageUp][pageDown]",
  269. btnCss:"Add button CSS",
  270. autoRun:"Auto run"
  271. };
  272. break;
  273. }
  274. return config[name]?config[name].replace("#t#",param):name;
  275. };
  276.  
  277. var enableDebug=true;
  278. var debug=str=>{
  279. if(enableDebug){
  280. console.debug(str);
  281. }
  282. };
  283.  
  284. var _GM_xmlhttpRequest,_GM_registerMenuCommand,_GM_notification,_GM_addStyle,_GM_openInTab;
  285. if(typeof GM_xmlhttpRequest!='undefined'){
  286. _GM_xmlhttpRequest=GM_xmlhttpRequest;
  287. }else if(typeof GM!='undefined' && typeof GM.xmlHttpRequest!='undefined'){
  288. _GM_xmlhttpRequest=GM.xmlHttpRequest;
  289. }
  290. if(typeof GM_registerMenuCommand!='undefined'){
  291. _GM_registerMenuCommand=GM_registerMenuCommand;
  292. }else if(typeof GM!='undefined' && typeof GM.registerMenuCommand!='undefined'){
  293. _GM_registerMenuCommand=GM.registerMenuCommand;
  294. }
  295. if(typeof GM_notification!='undefined'){
  296. _GM_notification=GM_notification;
  297. }else if(typeof GM!='undefined' && typeof GM.notification!='undefined'){
  298. _GM_notification=GM.notification;
  299. }
  300. if(typeof GM_openInTab!='undefined'){
  301. _GM_openInTab=GM_openInTab;
  302. }else if(typeof GM!='undefined' && typeof GM.openInTab!='undefined'){
  303. _GM_openInTab=GM.openInTab;
  304. }
  305. if(typeof GM_addStyle!='undefined'){
  306. _GM_addStyle=GM_addStyle;
  307. }else if(typeof GM!='undefined' && typeof GM.addStyle!='undefined'){
  308. _GM_addStyle=GM.addStyle;
  309. }else{
  310. _GM_addStyle=cssStr=>{
  311. let styleEle=document.createElement("style");
  312. styleEle.innerHTML=cssStr;
  313. document.head.appendChild(styleEle);
  314. };
  315. }
  316.  
  317. if(typeof _GM_xmlhttpRequest=='undefined')_GM_xmlhttpRequest=(f)=>{};
  318. if(typeof _GM_registerMenuCommand=='undefined')_GM_registerMenuCommand=(s,f)=>{};
  319. if(typeof _GM_notification=='undefined')_GM_notification=(s)=>{};
  320. if(typeof _GM_openInTab=='undefined')_GM_openInTab=(s)=>{window.open(s)};
  321. var _unsafeWindow=(typeof unsafeWindow=='undefined')?window:unsafeWindow;
  322. var storage={
  323. supportGM: typeof GM_getValue=='function' && typeof GM_getValue('a','b')!='undefined',
  324. supportGMPromise: typeof GM!='undefined' && typeof GM.getValue=='function' && typeof GM.getValue('a','b')!='undefined',
  325. mxAppStorage:(function(){
  326. try{
  327. return window.external.mxGetRuntime().storage;
  328. }catch(e){
  329. }
  330. })(),
  331. operaUJSStorage:(function(){
  332. try{
  333. return window.opera.scriptStorage;
  334. }catch(e){
  335. }
  336. })(),
  337. setItem:function(key,value){
  338. if(this.operaUJSStorage){
  339. this.operaUJSStorage.setItem(key,value);
  340. }else if(this.mxAppStorage){
  341. this.mxAppStorage.setConfig(key,value);
  342. }else if(this.supportGM){
  343. GM_setValue(key,value);
  344. if(value==="" && typeof GM_deleteValue!='undefined'){
  345. GM_deleteValue(key);
  346. }
  347. }else if(this.supportGMPromise){
  348. GM.setValue(key,value);
  349. if(value==="" && typeof GM!='undefined' && typeof GM.deleteValue!='undefined'){
  350. GM.deleteValue(key);
  351. }
  352. }else if(window.localStorage){
  353. window.localStorage.setItem(key,value);
  354. }
  355. },
  356. getItem:function(key,cb){
  357. var value;
  358. if(this.operaUJSStorage){
  359. value=this.operaUJSStorage.getItem(key);
  360. }else if(this.mxAppStorage){
  361. value=this.mxAppStorage.getConfig(key);
  362. }else if(this.supportGM){
  363. value=GM_getValue(key);
  364. }else if(this.supportGMPromise){
  365. value=GM.getValue(key).then(v=>{cb(v)});
  366. return;
  367. }else if(window.localStorage){
  368. value=window.localStorage.getItem(key);
  369. };
  370. cb(value);
  371. }
  372. };
  373. var rulesData={},ruleUrls,updateDate,configPage="https://github.com/hoothin/UserScripts/tree/master/Pagetual";
  374. _GM_registerMenuCommand(i18n("configure"), ()=>{
  375. _GM_openInTab(configPage,{active:true});
  376. });
  377.  
  378. function getElementByXpath(xpath, contextNode, doc){
  379. doc = doc || document;
  380. contextNode = contextNode || doc;
  381. try {
  382. var result = doc.evaluate(xpath, contextNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
  383. return result.singleNodeValue && result.singleNodeValue.nodeType === 1 && result.singleNodeValue;
  384. } catch (err) {
  385. throw new Error(`Invalid xpath: ${xpath}`);
  386. }
  387. }
  388.  
  389. function getAllElementsByXpath(xpath, contextNode, doc){
  390. doc = doc || document;
  391. contextNode = contextNode || doc;
  392. var result = [];
  393. try {
  394. var query = doc.evaluate(xpath, contextNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  395. for (var i = 0; i < query.snapshotLength; i++) {
  396. var node = query.snapshotItem(i);
  397. if (node.nodeType === 1) result.push(node);
  398. }
  399. } catch (err) {
  400. throw new Error(`Invalid xpath: ${xpath}`);
  401. }
  402. return result;
  403. }
  404.  
  405. class RuleParser {
  406. constructor() {
  407. this.hpRules=[];
  408. this.customRules=[];
  409. this.rules=[];
  410. this.pageDoc=document;
  411. this.nextLinkHref=null;
  412. this.curUrl=location.href;
  413. this.curSiteRule={};
  414. }
  415.  
  416. initSavedRules(callback){
  417. var self=this;
  418. storage.getItem("hpRules", hpRules=>{
  419. if(hpRules)self.hpRules=hpRules;
  420. storage.getItem("customRules", customRules=>{
  421. if(customRules)self.customRules=customRules;
  422. storage.getItem("rules", rules=>{
  423. if(rules)this.rules=rules;
  424. callback();
  425. });
  426. });
  427. });
  428. }
  429.  
  430. saveCurSiteRule(){
  431. if(!this.curSiteRule || !this.curSiteRule.url || this.curSiteRule.singleUrl)return;
  432. this.hpRules=this.hpRules.filter(item=>{return item&&item.url!=this.curSiteRule.url});
  433. this.hpRules.unshift(this.curSiteRule);
  434. if(this.hpRules.length>30){
  435. this.hpRules.pop();
  436. }
  437. storage.setItem("hpRules", this.hpRules);
  438. }
  439.  
  440. requestJSON(url, callback){
  441. _GM_xmlhttpRequest({
  442. url: url,
  443. method: 'GET',
  444. timeout: 10000,
  445. onload: function(res) {
  446. let json=null;
  447. try{
  448. json=JSON.parse(res.response);
  449. }catch(e){
  450. debug(e);
  451. }
  452. callback(json);
  453. },
  454. onerror: function() {
  455. callback(null);
  456. }
  457. });
  458. }
  459.  
  460. formatRule(item, type, from){
  461. switch(type){
  462. case 0:
  463. return {
  464. from:from,
  465. type:type,
  466. name:item.name,
  467. action:item.data.forceIframe=="true"?1:0,
  468. url:item.data.url,
  469. pageElement:item.data.pageElement,
  470. nextLink:item.data.nextLink,
  471. insert:item.data.insertBefore,
  472. insertPos:1,
  473. updatedAt:item.data.updated_at,
  474. css:item.data.Stylus+item.data.CSS,
  475. pageAction:item.data.bookmarklet
  476. };
  477. break;
  478. case 1:
  479. default:
  480. item.from=from;
  481. if(typeof(item.type) == "undefined")item.type=type;
  482. return item;
  483. break;
  484. }
  485. return null;
  486. }
  487.  
  488. addRuleByUrl(url, type, from, callback) {
  489. this.requestJSON(url, json=>{
  490. this.addRules(json, type, from);
  491. storage.setItem("rules", this.rules);
  492. callback();
  493. });
  494. }
  495.  
  496. addRules(rules, type, from) {
  497. if(rules && rules.length>0){
  498. this.rules=this.rules.filter(item=>{return item.from!=from});
  499. rules.forEach(item=>{
  500. let rule=this.formatRule(item, type, from);
  501. if(rule){
  502. this.rules.push(rule);
  503. }
  504. });
  505. }
  506. }
  507.  
  508. getRule(callback) {
  509. if(this.curSiteRule && this.curSiteRule.url){
  510. return this.curSiteRule;
  511. }
  512. var self=this;
  513.  
  514. function setRule(r){
  515. self.curSiteRule=r;
  516. debug(r);
  517. callback();
  518. }
  519.  
  520. function ruleMatch(r){
  521. let pageElement,nextLink,insert;
  522. if(r.pageElement)pageElement=r.type==0?getElementByXpath(r.pageElement):document.querySelector(r.pageElement);
  523. if(r.nextLink)nextLink=r.type==0?getElementByXpath(r.nextLink):document.querySelector(r.nextLink);
  524. if(r.insert)insert=r.type==0?getElementByXpath(r.insert):document.querySelector(r.insert);
  525. return !((r.pageElement && !pageElement) ||
  526. (r.nextLink && !nextLink) ||
  527. (r.insert && !insert));
  528. }
  529.  
  530. function checkRule(r){
  531. let urlReg=new RegExp(r.url, "i");
  532. if(urlReg.test(location.href)){
  533. if(r.wait){
  534. let waitTime=500,checkEval;
  535. if(isNaN(r.wait)){
  536. checkEval=Function("doc",'"use strict";' + r.wait);
  537. }else{
  538. waitTime=r.wait;
  539. }
  540. let waitTimes=10;
  541. let checkReady=()=>{
  542. if(waitTimes--<=0)return true;
  543. setTimeout(()=>{
  544. if(!ruleMatch(r) || (checkEval && !checkEval(document))){
  545. checkReady();
  546. }else{
  547. setRule(r);
  548. }
  549. },parseInt(waitTime));
  550. };
  551. checkReady();
  552. return true;
  553. }
  554. if(r.pinUrl){
  555. setRule(r);
  556. return true;
  557. }
  558. if(!ruleMatch(r)){
  559. return false;
  560. }
  561. setRule(r);
  562. return true;
  563. }
  564. return false;
  565. }
  566.  
  567. for(let i in this.hpRules){
  568. let rule=this.hpRules[i];
  569. if(!rule || !rule.url)continue;
  570. if(rule.singleUrl){
  571. if(location.origin+location.pathname==rule.url){
  572. setRule(rule);
  573. return;
  574. }
  575. continue;
  576. }
  577. if(checkRule(rule))return;
  578. }
  579. for(let i in this.customRules){
  580. let rule=this.customRules[i];
  581. if(!rule || !rule.url)continue;
  582. if(checkRule(rule))return;
  583. }
  584. let r=0;
  585. function searchByTime(){
  586. setTimeout(()=>{
  587. let end=r+80;
  588. end=end>self.rules.length?self.rules.length:end;
  589. for(;r<end;r++){
  590. let rule=self.rules[r];
  591. if(checkRule(rule))return;
  592. }
  593. if(end>=self.rules.length){
  594. self.curSiteRule={};
  595. self.curSiteRule.url=location.origin+location.pathname;
  596. self.curSiteRule.singleUrl=true;
  597. callback();
  598. return;
  599. }else{
  600. searchByTime();
  601. }
  602. },20);
  603. }
  604. searchByTime();
  605. }
  606.  
  607. geneSelector(ele){
  608. let selector=ele.tagName;
  609. //Google id class都是隨機。百度更過分,style script順序都是隨機的
  610. //if(ele.id) selector += '#' + ele.id;
  611. //if(ele.classList) selector += [].map.call(ele.classList,d=>'.'+d).join('');
  612. let parent = ele.parentElement;
  613. if(parent){
  614. let i,j=0;
  615. for(i=0;i<parent.children.length;i++){
  616. if(parent.children[i].tagName==selector){
  617. j++;
  618. if(parent.children[i]==ele){
  619. break;
  620. }
  621. }
  622. }
  623. selector = this.geneSelector(parent) + ' > ' + selector + (parent.tagName=="HTML"?"":`:nth-of-type(${j})`);
  624. }
  625. return selector;
  626. }
  627.  
  628. getPageElement(doc, curWin, dontFind) {
  629. let pageElement=null;
  630. let self=this;
  631. if(this.curSiteRule.pageElement){
  632. pageElement=this.curSiteRule.type==0?getAllElementsByXpath(this.curSiteRule.pageElement,doc,doc):doc.querySelectorAll(this.curSiteRule.pageElement);
  633. }
  634. if((!pageElement || pageElement.length==0) && curWin && !dontFind){
  635. let body=doc.body;
  636. if(!body)return null;
  637. let bodyHeight=parseInt(body.scrollHeight);
  638. let curHeight=bodyHeight;
  639. function checkElement(ele){
  640. if(curHeight/bodyHeight<=0.30)return null;
  641. if(ele.children.length==0 && !self.curSiteRule.pageElement){
  642. if(ele.parentNode.tagName=="P")ele=ele.parentNode;
  643. self.curSiteRule.pageElement=self.geneSelector(ele.parentNode)+">"+ele.tagName;
  644. self.curSiteRule.type=1;
  645. debug(self.curSiteRule.pageElement);
  646. return [ele];
  647. }
  648. let i,maxHeight=curHeight*0.6,curMaxEle=null,curMaxArea=0,maxWidth=0;
  649. let isHori=true;
  650. let offsetTop=ele.children[0].offsetTop;
  651. for(i=0;i<ele.children.length;i++){
  652. if(ele.children[i].offsetTop!=offsetTop){
  653. isHori=false;
  654. break;
  655. }
  656. }
  657. for(i=0;i<ele.children.length;i++){
  658. let curNode=ele.children[i];
  659. let comStyle=curWin.getComputedStyle(curNode);
  660. let h=parseInt(curNode.scrollHeight);
  661. let w=parseInt(curNode.scrollWidth);
  662. if(isNaN(h) || isNaN(w))continue;
  663. if(isHori && h==0)continue;
  664. let a=h*w+h,moreChild=curNode.children[0];
  665. while(moreChild){
  666. comStyle=curWin.getComputedStyle(moreChild);
  667. let ch=parseInt(moreChild.scrollHeight);
  668. let cw=parseInt(moreChild.scrollWidth);
  669. if(h<ch)h=ch;
  670. if(moreChild.innerText!="" && !isNaN(ch) && !isNaN(cw)){
  671. a+=ch*cw;
  672. }
  673. moreChild=moreChild.nextElementSibling;
  674. }
  675. let isMax=false;
  676. if(isHori){
  677. if(maxWidth<w){
  678. isMax=true;
  679. }
  680. if(maxWidth==w && curMaxArea<a){
  681. isMax=true;
  682. }
  683. }else{
  684. isMax=curMaxArea<a;
  685. }
  686. if(curMaxEle==null || isMax){
  687. if(h>0)curHeight=h;
  688. curMaxArea=a;
  689. maxWidth=w;
  690. curMaxEle=curNode;
  691. }
  692. }
  693. if(curMaxEle && (isHori || curHeight>maxHeight)){
  694. return checkElement(curMaxEle);
  695. }
  696. if(!self.curSiteRule.pageElement){
  697. if(ele.tagName=="P")ele=ele.parentNode;
  698. self.curSiteRule.pageElement=self.geneSelector(ele);
  699. if(ele.tagName!="UL")self.curSiteRule.pageElement+=">*";
  700. self.curSiteRule.type=1;
  701. debug(self.curSiteRule.pageElement);
  702. }
  703. return ele.tagName=="UL"?[ele]:ele.children;
  704. }
  705. pageElement=checkElement(body);
  706. if(pageElement)this.saveCurSiteRule();
  707. }
  708. return pageElement;
  709. }
  710.  
  711. getPage(doc){
  712. if(_unsafeWindow.Discourse)return {};
  713. let canSave=false;//發現頁碼選擇器在其他頁對不上,還是別保存了
  714. let url=this.curUrl.replace("#!","");
  715. let pageNum=1,preStr="",afterStr="";
  716. let pageMatch1=url.match(/(.*[a-z\/\-_](?:p|page)?\/?)(\d+)(\.s?html?$|\/?$)/i);
  717. let pageMatch2=url.match(/(.*[\?&]p(?:age)?=)(\d+)($|[#&].*)/i);
  718. if(pageMatch1){
  719. preStr=pageMatch1[1];
  720. pageNum=pageMatch1[2];
  721. afterStr=pageMatch1[3];
  722. }else if(pageMatch2){
  723. preStr=pageMatch2[1];
  724. pageNum=pageMatch2[2];
  725. afterStr=pageMatch2[3];
  726. }
  727. let curPage=doc,i,cur,jsNext;
  728. let next=curPage.querySelector("a.next");
  729. if(!next)next=curPage.querySelector("a#next");
  730. if(!next)next=curPage.querySelector("a#rightFix");
  731. if(!next)next=curPage.querySelector("a.next_page");
  732. if(!next)next=curPage.querySelector(".next>a");
  733. if(!next)next=curPage.querySelector("#next_page");
  734. if(!next)next=curPage.querySelector(".next>button");
  735. if(!next)next=curPage.querySelector("a[alt=next]");
  736. if(!next)next=curPage.querySelector("[title=next]");
  737. if(!next){
  738. next=curPage.querySelectorAll("[aria-label='Next']");
  739. if(next && next.length==1){
  740. next=next[0];
  741. }else{
  742. next=null;
  743. }
  744. }
  745. if(!next){
  746. next=curPage.querySelectorAll("[aria-label='Next page']");
  747. if(next && next.length==1){
  748. next=next[0];
  749. }else{
  750. next=null;
  751. }
  752. }
  753. if(!next)next=curPage.querySelector(".nextPage");
  754. if(next && (!next.href || /^javascript:/.test(next.href))){
  755. jsNext=next;
  756. next=null;
  757. }
  758. if(!next){
  759. let pageDiv=curPage.querySelector("div.wp-pagenavi");
  760. if(pageDiv){
  761. cur=pageDiv.querySelector("span.current");
  762. next=cur.nextSibling;
  763. }else{
  764. cur=curPage.querySelector("div.article-paging>span");
  765. if(cur){
  766. next=cur.nextElementSibling;
  767. }
  768. }
  769. }
  770. if(!next){
  771. let pageDiv=curPage.querySelector("div.pages>ul");
  772. if(pageDiv){
  773. cur=pageDiv.querySelector("li>b");
  774. if(cur)next=cur.parentNode.nextElementSibling.querySelector("a");
  775. }
  776. }
  777. if(!next){
  778. let aTags=curPage.querySelectorAll("a");
  779. let next1,next2,next3,next4,nextJs1,nextJs2,nextJs3;
  780. for(i=aTags.length-1;i>=0;i--){
  781. let aTag=aTags[i];
  782. if(aTag.style.display=="none")continue;
  783. if(next1 && next2 && next3 && next4)break;
  784. if(!next1){
  785. if(/^\s*下[一1]?[页頁张張]|^next( page)?\s*$|次のページ/i.test(aTag.innerText)){
  786. if(!aTag.href || /^javascript:/.test(aTag.href)){
  787. if(!nextJs1)nextJs1=aTag;
  788. }else{
  789. next1=aTag;
  790. }
  791. }
  792. }
  793. if(!next2){
  794. if(/^\s*下[一1]?[章话話]/i.test(aTag.innerText)){
  795. if(!aTag.href || /^javascript:/.test(aTag.href)){
  796. if(!nextJs2)nextJs2=aTag;
  797. }else{
  798. next2=aTag;
  799. }
  800. }
  801. }
  802. if(!next3){
  803. if(aTag.innerText=="&gt;" || aTag.innerText=="▶" || aTag.innerText=="»"){
  804. if(!aTag.href || /^javascript:/.test(aTag.href)){
  805. if(!nextJs3)nextJs3=aTag;
  806. }else{
  807. next3=aTag;
  808. }
  809. }
  810. }
  811. if(!aTag.href || /^javascript:/.test(aTag.href))continue;
  812. if(!next4){
  813. if(aTag.href.replace("?&","?").replace("#!","").replace(preStr,"").replace(afterStr,"")==parseInt(pageNum)+1){
  814. next4=aTag;
  815. }else if(aTag.href.replace("?&","?").indexOf(url)!=-1 && /^[\/\?&]?[_-]?(p|page)?=?\/?2(\/|\?|&|$)/i.test(aTag.href.replace(url,"").replace(/\.s?html?$/i,""))){
  816. next4=aTag;
  817. }
  818. }
  819. }
  820. next=next1||next3||next4||next2||nextJs1||nextJs3||nextJs2;
  821. }
  822. if(!next)next=jsNext;
  823. return {next:next,canSave:canSave};
  824. }
  825.  
  826. getNextLink(doc) {
  827. let nextLink=null,page;
  828. if(this.curSiteRule.pageElementByJs){
  829. this.nextLinkHref="#";
  830. return true;
  831. }else if(this.curSiteRule.nextLinkByJs){
  832. try{
  833. let targetUrl=Function("doc",'"use strict";' + this.curSiteRule.nextLinkByJs)(doc);
  834. if(targetUrl)nextLink={href:targetUrl};
  835. }catch(e){}
  836. }else if(this.curSiteRule.nextLinkByUrl){
  837. let targetUrl=this.curUrl.replace(new RegExp(this.curSiteRule.nextLinkByUrl[0]), this.curSiteRule.nextLinkByUrl[1]);
  838. if(targetUrl != this.curUrl){
  839. let reps=targetUrl.match(/{.*?}/g);
  840. if(reps){
  841. reps.forEach(rep=>{
  842. let code=rep.replace("{","").replace("}","");
  843. let result=code.match(/^(\d+)\+1$/);
  844. if(result){
  845. result=parseInt(result[1])+1;
  846. }else{
  847. try{
  848. result=Function('"use strict";return ' + code)();;
  849. }catch(e){}
  850. }
  851. targetUrl=targetUrl.replace(rep, result);
  852. });
  853. }
  854. }
  855. nextLink={href:targetUrl};
  856. }else if(this.curSiteRule.nextLink){
  857. nextLink=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.nextLink,doc,doc):doc.querySelector(this.curSiteRule.nextLink);
  858. }else{
  859. page=this.getPage(doc);
  860. nextLink=page.next;
  861. if(nextLink && nextLink.classList.contains("noClick")){
  862. self.nextLinkHref=false;
  863. return null;
  864. }else if(nextLink && doc==document){
  865. if(!isVisible(nextLink, _unsafeWindow)){
  866. self.nextLinkHref=false;
  867. return null;
  868. }else{
  869. let nextLinkCs=_unsafeWindow.getComputedStyle(nextLink);
  870. if(nextLinkCs.cursor=="not-allowed"){
  871. self.nextLinkHref=false;
  872. return null;
  873. }
  874. }
  875. }
  876. }
  877. if(nextLink){
  878. if(nextLink.href=="javascript:;" && (this.curSiteRule.action==0 || this.curSiteRule.action==1)){
  879. nextLink=null;
  880. }
  881. /*if(!this.curSiteRule.nextLink && page && page.canSave){
  882. this.curSiteRule.nextLink=this.geneSelector(nextLink);
  883. this.curSiteRule.type=1;
  884. this.saveCurSiteRule();
  885. }*/
  886. }
  887. if(nextLink){
  888. this.nextLinkHref=nextLink.href?nextLink.href:"#";
  889. debug(nextLink);
  890. }else{
  891. this.nextLinkHref=false;
  892. }
  893. return nextLink;
  894. }
  895.  
  896. getInsert(refresh) {
  897. if(this.insert && !refresh){
  898. let parent=this.insert;
  899. while(parent && parent.nodeName!="BODY"){
  900. parent=parent.parentNode;
  901. }
  902. if(parent && parent.nodeName=="BODY"){
  903. return this.insert;
  904. }
  905. }
  906. if(this.curSiteRule.insert){
  907. this.insert=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.insert,document):document.querySelector(this.curSiteRule.insert);
  908. }else{
  909. let pageElement=this.getPageElement(document, _unsafeWindow);
  910. if(pageElement && pageElement.length>0){
  911. var pELast = pageElement[pageElement.length - 1];
  912. this.insert = pELast.nextSibling ? pELast.nextSibling : pELast.parentNode.appendChild(document.createTextNode(' '));
  913. }
  914. }
  915. return this.insert;
  916. }
  917.  
  918. pageAction(doc,eles){
  919. let code=this.curSiteRule.pageAction;
  920. if(code){
  921. try{
  922. Function("doc","eles",'"use strict";' + code)(doc,eles);
  923. }catch(e){}
  924. }
  925. [].forEach.call(eles, ele=>{
  926. [].forEach.call(ele.querySelectorAll("img"), img=>{
  927. let realSrc;
  928. if(img.dataset && img.dataset.original){
  929. realSrc=img.dataset.original;
  930. }else if(img.dataset && img.dataset.src){
  931. realSrc=img.dataset.src;
  932. }else if(img._lazyrias && img._lazyrias.srcset){
  933. realSrc=img._lazyrias.srcset[img._lazyrias.srcset.length-1];
  934. }else if(img.dataset && img.dataset.origFile){
  935. realSrc=img.dataset.origFile;
  936. }else if(img.srcset){
  937. var srcs=img.srcset.split(","),largeSize=0;
  938. srcs.forEach(srci=>{
  939. let srcInfo=srci.trim().split(" "),curSize=parseInt(srcInfo[1]);
  940. if(srcInfo[1] && curSize>largeSize){
  941. largeSize=curSize;
  942. realSrc=srcInfo[0];
  943. }
  944. });
  945. }
  946. if(realSrc)img.src=realSrc;
  947. });
  948. [].forEach.call(ele.querySelectorAll("a.lazyload"), a=>{
  949. if(a.dataset.original){
  950. a.style.backgroundImage='url("'+a.dataset.original+'")';
  951. }
  952. });
  953. });
  954. let lazyImgSrc=this.curSiteRule.lazyImgSrc;
  955. if(lazyImgSrc){
  956. [].forEach.call(eles, ele=>{
  957. [].forEach.call(ele.querySelectorAll("img"), img=>{
  958. if(img[lazyImgSrc]){
  959. img.src=img[lazyImgSrc];
  960. }
  961. });
  962. });
  963. }
  964. }
  965.  
  966. initPage(callback){
  967. let self=this;
  968. curPage=1;
  969. //if(this.curSiteRule.url && !this.curSiteRule.singleUrl)return;
  970. this.curSiteRule={};
  971. this.pageDoc=document;
  972. this.nextLinkHref=null;
  973. this.curUrl=location.href;
  974. this.getRule(()=>{
  975. if(self.curSiteRule.enable==0){
  976. debug("Stop as rule disable");
  977. isPause=true;
  978. return;
  979. }
  980. if(self.curSiteRule && !self.curSiteRule.singleUrl){
  981. self.hpRules=self.hpRules.filter(item=>{return item&&item.url!=self.curSiteRule.url});
  982. self.hpRules.unshift(self.curSiteRule);
  983. if(self.hpRules.length>30){
  984. self.hpRules.pop();
  985. }
  986. storage.setItem("hpRules", self.hpRules);
  987. }
  988. let css=self.curSiteRule.css;
  989. if(css){
  990. _GM_addStyle(css);
  991. }
  992. let code=self.curSiteRule.init;
  993. if(code){
  994. try{
  995. Function('"use strict";' + code)();
  996. }catch(e){}
  997. }
  998. self.getNextLink(document);
  999. callback();
  1000. });
  1001. }
  1002.  
  1003. insertPage(doc, eles, url, callback, tried){
  1004. this.pageDoc=doc;
  1005. this.curUrl=url;
  1006. this.pageAction(doc, eles);
  1007. let nextLink=this.getNextLink(doc);
  1008. if(curPage==1 && !tried && !this.nextLinkHref && this.curSiteRule.singleUrl && this.curSiteRule.pageElement){
  1009. this.curSiteRule.action=1;
  1010. return false;
  1011. }
  1012. if(callback)callback(eles);
  1013. this.getInsert();
  1014. var self=this;
  1015. if(!eles || eles.length==0 || !self.insert || !self.insert.parentNode){
  1016. }else{
  1017. [].forEach.call(eles, ele=>{
  1018. let newEle=ele.cloneNode(true);
  1019. let oldCanvass=ele.querySelectorAll("canvas");
  1020. let newCanvass=newEle.querySelectorAll("canvas");
  1021. for(let i=0;i<oldCanvass.length;i++){
  1022. let oldCanvas=oldCanvass[i];
  1023. let newCanvas=newCanvass[i];
  1024. newCanvas.getContext('2d').drawImage(oldCanvas, 0, 0);
  1025. }
  1026. if(self.curSiteRule.insertPos==2){
  1027. self.insert.appendChild(newEle);
  1028. }else{
  1029. self.insert.parentNode.insertBefore(newEle, self.insert);
  1030. }
  1031. });
  1032. }
  1033. if(nextLink && nextLink.tagName){
  1034. let nextLinkCs=_unsafeWindow.getComputedStyle(nextLink);
  1035. if(nextLinkCs.cursor=="not-allowed" || !isVisible(nextLink, _unsafeWindow)){
  1036. self.nextLinkHref=false;
  1037. }
  1038. }
  1039. return true;
  1040. }
  1041. }
  1042. var ruleParser = new RuleParser();
  1043.  
  1044. function initConfig(){
  1045. _GM_registerMenuCommand(i18n(forceState==1?"enable":"disableSite"), ()=>{
  1046. storage.setItem("forceState_"+location.host, (forceState==1?0:1));
  1047. location.reload();
  1048. });
  1049.  
  1050. _GM_registerMenuCommand(i18n(forceState==2?"cancelForceIframe":"forceIframe"), ()=>{
  1051. storage.setItem("forceState_"+location.host, (forceState==2?"":2));
  1052. location.reload();
  1053. });
  1054. var configCon,insertPos;
  1055. if(location.href==configPage){
  1056. _GM_addStyle(`
  1057. p>span:nth-child(1),p>span:nth-child(2),p>span:nth-child(3){
  1058. cursor: pointer;
  1059. user-select: none;
  1060. }
  1061. p>span:nth-child(1):hover,p>span:nth-child(2):hover,p>span:nth-child(3):hover{
  1062. color:red;
  1063. }
  1064. .updateDate{
  1065. cursor: pointer;
  1066. user-select: none;
  1067. }
  1068. .updateDate:hover{
  1069. color:red;
  1070. }
  1071. `);
  1072. configCon=document.querySelector(".markdown-body");
  1073. insertPos=configCon.querySelector("hr");
  1074. }else if(location.href==configPage){
  1075. }else return false;
  1076. class Rulebar {
  1077. init(ruleUrl){
  1078. this.ruleUrl=ruleUrl;
  1079. this.item=document.createElement("p");
  1080. this.item.title=ruleUrl.type==0?"AutoPagerize Rules":"Pagetual Rules";
  1081. this.item.dataset.id=this.ruleUrl.id;
  1082. let url=document.createElement("span");
  1083. url.innerHTML=ruleUrl.url;
  1084. let up=document.createElement("span");
  1085. up.innerHTML="↑ ";
  1086. up.title=i18n("sortTitle");
  1087. let down=document.createElement("span");
  1088. down.innerHTML="↓ ";
  1089. down.title=i18n("sortTitle");
  1090. let del=document.createElement("span");
  1091. del.innerHTML="× ";
  1092. up.onclick=e=>{
  1093. this.moveUp();
  1094. };
  1095. down.onclick=e=>{
  1096. this.moveDown();
  1097. };
  1098. del.onclick=e=>{
  1099. this.del();
  1100. };
  1101. this.item.appendChild(up);
  1102. this.item.appendChild(down);
  1103. this.item.appendChild(del);
  1104. this.item.appendChild(url);
  1105. configCon.insertBefore(this.item, insertPos);
  1106. }
  1107. saveSort(){
  1108. let sort=[];
  1109. [].forEach.call(this.item.parentNode.querySelectorAll("p[data-id]"), i=>{
  1110. sort.push(i.dataset.id);
  1111. });
  1112. rulesData.sort=sort;
  1113. storage.setItem("rulesData", rulesData);
  1114. }
  1115. moveUp(){
  1116. let preE=this.item.previousElementSibling;
  1117. if(preE.tagName=="P" && preE.children.length>1){
  1118. this.item.parentNode.insertBefore(this.item,preE);
  1119. this.saveSort();
  1120. }
  1121. }
  1122. moveDown(){
  1123. let nextE=this.item.nextElementSibling;
  1124. if(nextE.tagName=="P" && nextE.children.length>1){
  1125. this.item.parentNode.insertBefore(nextE,this.item);
  1126. this.saveSort();
  1127. }
  1128. }
  1129. del(){
  1130. if(this.ruleUrl.id<2){
  1131. alert(i18n("cantDel"));
  1132. }else if(window.confirm(i18n("confirmDel"))){
  1133. for(let u=0;u<rulesData.urls.length;u++){
  1134. if(this.ruleUrl.id==rulesData.urls[u].id){
  1135. rulesData.urls.splice(u,1);
  1136. break;
  1137. }
  1138. }
  1139. for(let u=0;u<rulesData.sort.length;u++){
  1140. if(this.ruleUrl.id==rulesData.sort[u]){
  1141. rulesData.sort.splice(u,1);
  1142. break;
  1143. }
  1144. }
  1145. storage.setItem("rulesData", rulesData);
  1146. ruleParser.rules=ruleParser.rules.filter(item=>{return item.from!=this.ruleUrl.id});
  1147. storage.setItem("rules", ruleParser.rules);
  1148. this.item.parentNode.removeChild(this.item);
  1149. //location.reload();
  1150. }
  1151. }
  1152. }
  1153. let updateP=document.createElement("p"),i=0;
  1154. let now=new Date().getTime(),inUpdate=false;
  1155.  
  1156.  
  1157. let pastDate=(new Date(updateDate)).toString(),passStr;
  1158. let passTime=(now-updateDate)/1000;
  1159. if(passTime<60){
  1160. passStr=i18n("passSec", passTime);
  1161. }else if(passTime<60*60){
  1162. passStr=i18n("passMin", parseInt(passTime/60));
  1163. }else if(passTime<60*60*24){
  1164. passStr=i18n("passHour", parseInt(passTime/3600));
  1165. }else{
  1166. passStr=i18n("passDay", parseInt(passTime/86400));
  1167. }
  1168.  
  1169.  
  1170. updateP.className="updateDate";
  1171. updateP.innerHTML=passStr;
  1172. updateP.title=i18n("update")+" - "+pastDate;
  1173. updateP.onclick=e=>{
  1174. if(inUpdate)return;
  1175. inUpdate=true;
  1176. let ruleIndex=0;
  1177. storage.setItem("hpRules", []);
  1178. function addNextRule(){
  1179. if(ruleIndex>=ruleUrls.length){
  1180. storage.setItem("ruleLastUpdate", now);
  1181. alert(i18n("updateSucc"));
  1182. inUpdate=false;
  1183. updateP.innerHTML=i18n("passSec", 0);
  1184. updateP.title=i18n("update");
  1185. }else{
  1186. let rule=ruleUrls[ruleIndex++];
  1187. ruleParser.addRuleByUrl(rule.url, rule.type, rule.id, ()=>{
  1188. addNextRule();
  1189. })
  1190. }
  1191. }
  1192. addNextRule();
  1193. alert(i18n("beginUpdate"));
  1194. };
  1195. configCon.insertBefore(updateP, insertPos);
  1196. if(ruleUrls){
  1197. ruleUrls.forEach(ruleUrl=>{
  1198. var rulebar=new Rulebar();
  1199. rulebar.init(ruleUrl);
  1200. });
  1201. }
  1202. let customUrlsTitle=document.createElement("h2");
  1203. customUrlsTitle.innerHTML=i18n("customUrls");
  1204. configCon.insertBefore(customUrlsTitle, insertPos);
  1205. let customUrlsInput=document.createElement("textarea");
  1206. customUrlsInput.style.width="100%";
  1207. customUrlsInput.placeholder="0|http://wedata.net/databases/AutoPagerize/items_all.json";
  1208. configCon.insertBefore(customUrlsInput, insertPos);
  1209.  
  1210. let opacityTitle=document.createElement("h2");
  1211. opacityTitle.innerHTML=i18n("opacity");
  1212. let opacityInput=document.createElement("input");
  1213. opacityInput.value=rulesData.opacity*100;
  1214. opacityInput.type="number";
  1215. opacityInput.style.width="50px";
  1216. opacityInput.style.margin="0 0 0 10px";
  1217. opacityTitle.appendChild(opacityInput);
  1218. configCon.insertBefore(opacityTitle, insertPos);
  1219.  
  1220.  
  1221. let hideBarTitle=document.createElement("h2");
  1222. hideBarTitle.innerHTML=i18n("hideBar");
  1223. let hideBarInput=document.createElement("input");
  1224. hideBarInput.type="checkbox";
  1225. hideBarInput.style.width="50px";
  1226. hideBarInput.style.height="20px";
  1227. hideBarInput.checked=rulesData.hideBar;
  1228. hideBarTitle.appendChild(hideBarInput);
  1229. configCon.insertBefore(hideBarTitle, insertPos);
  1230.  
  1231. let dbClick2StopTitle=document.createElement("h2");
  1232. dbClick2StopTitle.innerHTML=i18n("dbClick2Stop");
  1233. let dbClick2StopInput=document.createElement("input");
  1234. dbClick2StopInput.type="checkbox";
  1235. dbClick2StopInput.style.width="50px";
  1236. dbClick2StopInput.style.height="20px";
  1237. dbClick2StopInput.checked=rulesData.dbClick2Stop;
  1238. dbClick2StopTitle.appendChild(dbClick2StopInput);
  1239. configCon.insertBefore(dbClick2StopTitle, insertPos);
  1240.  
  1241. let enableWhiteListTitle=document.createElement("h2");
  1242. enableWhiteListTitle.innerHTML=i18n("autoRun");
  1243. let enableWhiteListInput=document.createElement("input");
  1244. enableWhiteListInput.type="checkbox";
  1245. enableWhiteListInput.style.width="50px";
  1246. enableWhiteListInput.style.height="20px";
  1247. enableWhiteListInput.checked=rulesData.enableWhiteList!=true;
  1248. enableWhiteListTitle.appendChild(enableWhiteListInput);
  1249. configCon.insertBefore(enableWhiteListTitle, insertPos);
  1250.  
  1251. let customRulesTitle=document.createElement("h2");
  1252. customRulesTitle.innerHTML=i18n("customRules")
  1253. configCon.insertBefore(customRulesTitle, insertPos);
  1254. let customRulesInput=document.createElement("textarea");
  1255. customRulesInput.style.width="100%";
  1256. customRulesInput.style.height="500px";
  1257. 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]`;
  1258. customRulesInput.value=getFormatJSON(ruleParser.customRules);
  1259. configCon.insertBefore(customRulesInput, insertPos);
  1260. let saveBtn=document.createElement("button");
  1261. saveBtn.innerHTML=i18n("save");
  1262. saveBtn.style.width="100%";
  1263. configCon.insertBefore(saveBtn, insertPos);
  1264. saveBtn.onclick=e=>{
  1265. try{
  1266. storage.setItem("hpRules", []);
  1267. if(customRulesInput.value==""){
  1268. storage.setItem("customRules", "");
  1269. }else{
  1270. let customRules=JSON.parse(customRulesInput.value);
  1271. if(Array && Array.isArray && !Array.isArray(customRules)){
  1272. alert("Rules must be a Array!");
  1273. return;
  1274. }
  1275. debug(customRules);
  1276. storage.setItem("customRules", customRules);
  1277. }
  1278. }catch(e){
  1279. debug(e);
  1280. alert("JSON error, check again!");
  1281. return;
  1282. }
  1283. rulesData.opacity=opacityInput.value/100;
  1284. rulesData.hideBar=hideBarInput.checked;
  1285. rulesData.dbClick2Stop=dbClick2StopInput.checked;
  1286. rulesData.enableWhiteList=!enableWhiteListInput.checked;
  1287. storage.setItem("rulesData", rulesData);
  1288. let customUrls=customUrlsInput.value.trim();
  1289. if(customUrls){
  1290. customUrls=customUrls.split(/\n/);
  1291. for(let c=0;c<customUrls.length;c++){
  1292. let urlArr=customUrls[c].split("|"),url,type=1;
  1293. if(urlArr.length==1){
  1294. url=urlArr[0].trim();
  1295. if(!/^http/.test(url)){
  1296. alert("Wrong url, check again!");
  1297. return;
  1298. }
  1299. }else if(urlArr.length==2){
  1300. type=urlArr[0].trim();
  1301. url=urlArr[1].trim();
  1302. if(!/^http/.test(url)){
  1303. alert("Wrong url, check again!");
  1304. return;
  1305. }
  1306. }else{
  1307. break;
  1308. }
  1309. let maxId=0,hasUrl=false;;
  1310. if(!rulesData.urls){
  1311. rulesData.urls=[];
  1312. maxId=1;
  1313. }else{
  1314. rulesData.urls.forEach(u=>{
  1315. if(maxId<u.id){
  1316. maxId=u.id;
  1317. }
  1318. if(u.url==url){
  1319. hasUrl=true;
  1320. }
  1321. });
  1322. if(hasUrl)break;
  1323. }
  1324. rulesData.urls.push({id:maxId+1,url:url,type:type});
  1325. rulesData.sort.push(maxId+1);
  1326. storage.setItem("rulesData", rulesData);
  1327. }
  1328. }
  1329. alert("Modified successfully");
  1330. location.reload();
  1331. };
  1332. return true;
  1333. }
  1334.  
  1335. function objIsArr(obj) {
  1336. return obj &&
  1337. typeof obj === 'object' &&
  1338. typeof obj.length === 'number' &&
  1339. !(obj.propertyIsEnumerable('length'));
  1340. }
  1341.  
  1342. function isVisible(el, win) {
  1343. var loopable = true,
  1344. visible = win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  1345. while(loopable && visible) {
  1346. el = el.parentNode;
  1347.  
  1348. if(el && el.tagName!="BODY") {
  1349. visible = win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  1350. }else {
  1351. loopable = false;
  1352. }
  1353. }
  1354. return visible;
  1355. }
  1356.  
  1357. function getFormatJSON(obj){
  1358. if(!objIsArr(obj))return "";
  1359. let ret="[\n";
  1360. let len=obj.length,i=0,isLast;
  1361. obj.forEach(item=>{
  1362. ret+=" {\n";
  1363. let iLen=Object.keys(item).length,j=0;
  1364. for(let key in item){
  1365. isLast=(++j)==iLen;
  1366. let value=item[key];
  1367. if(objIsArr(value)){
  1368. let vstr="[",v=0,vIsLast=false;
  1369. value.forEach(vi=>{
  1370. vIsLast=(++v)==value.length;
  1371. vstr+="\""+vi.replace(/\\/g,"\\\\")+"\""+(vIsLast?"":",");
  1372. });
  1373. vstr+="]";
  1374. ret+=" \""+key+"\":"+vstr+""+(isLast?"":",")+"\n";
  1375. }else{
  1376. if(typeof value=="string"){
  1377. value=value.replace(/\\/g,"\\\\").replace(/"/g,"\\\"");
  1378. value="\""+value+"\"";
  1379. }
  1380. ret+=" \""+key+"\":"+value+""+(isLast?"":",")+"\n";
  1381. }
  1382. }
  1383. isLast=(++i)==len;
  1384. ret+=" }"+(isLast?"":",")+"\n";
  1385. });
  1386. ret+="]";
  1387. return ret;
  1388. }
  1389.  
  1390. function initRules(callback) {
  1391. /*0 wedata格式,1 pagetual格式*/
  1392. ruleUrls=[
  1393. {
  1394. id:0,
  1395. url:'https://raw.githubusercontent.com/hoothin/UserScripts/master/Pagetual/pagetualRules.json',
  1396. type:1
  1397. },
  1398. {
  1399. id:1,
  1400. url:'http://wedata.net/databases/AutoPagerize/items_all.json',
  1401. type:0,
  1402. }
  1403. ];var i=0,j=0;
  1404.  
  1405. ruleParser.initSavedRules(()=>{
  1406. storage.getItem("rulesData", data=>{
  1407. if(data){
  1408. rulesData=data;
  1409. if(data.urls)ruleUrls=ruleUrls.concat(data.urls);
  1410. if(data.sort){
  1411. let urls=[];
  1412. data.sort.forEach(id=>{
  1413. for(let s=0;s<ruleUrls.length;s++){
  1414. if(id==ruleUrls[s].id){
  1415. urls.push(ruleUrls[s]);
  1416. break;
  1417. }
  1418. }
  1419. });
  1420. ruleUrls=urls;
  1421. }
  1422. }
  1423. if(typeof(rulesData.opacity)=="undefined"){
  1424. rulesData.opacity=0.3;
  1425. }
  1426. if(typeof(rulesData.hideBar)=="undefined"){
  1427. rulesData.hideBar=true;
  1428. }
  1429. if(typeof(rulesData.dbClick2Stop)=="undefined"){
  1430. rulesData.dbClick2Stop=true;
  1431. }
  1432. if(typeof(rulesData.enableWhiteList)=="undefined"){
  1433. rulesData.enableWhiteList=false;
  1434. }
  1435. storage.getItem("forceState_"+location.host, v=>{
  1436. storage.getItem("ruleLastUpdate", date=>{
  1437. if(typeof(v)=="undefined"){
  1438. v=(rulesData.enableWhiteList?1:0);
  1439. }
  1440. forceState=v;
  1441. updateDate=date;
  1442. if(initConfig())return;
  1443. if(forceState==1)return;
  1444. let now=new Date().getTime();
  1445. if(!date || now-date>2*24*60*60*1000){
  1446. storage.setItem("ruleLastUpdate", now);
  1447. storage.setItem("hpRules", []);
  1448. let ruleIndex=0;
  1449. function addNextRule(){
  1450. if(ruleIndex>=ruleUrls.length){
  1451. callback();
  1452. }else{
  1453. let rule=ruleUrls[ruleIndex++];
  1454. ruleParser.addRuleByUrl(rule.url, rule.type, rule.id, ()=>{
  1455. addNextRule();
  1456. })
  1457. }
  1458. }
  1459. addNextRule();
  1460. }else{
  1461. callback();
  1462. }
  1463. });
  1464. });
  1465. });
  1466. });
  1467. }
  1468.  
  1469. function requestDoc(url, callback){
  1470. _GM_xmlhttpRequest({
  1471. url: url,
  1472. method: 'GET',
  1473. overrideMimeType: 'text/html;charset='+document.charset,
  1474. headers: {
  1475. 'Referer': location.href
  1476. },
  1477. timeout: 5000,
  1478. onload: function(res) {
  1479. var doc=null;
  1480. try {
  1481. doc=document.implementation.createHTMLDocument('');
  1482. doc.documentElement.innerHTML=res.response;
  1483. }
  1484. catch (e) {
  1485. debug('parse error'+e.toString());
  1486. }
  1487. let pageElement=ruleParser.getPageElement(doc);
  1488. //只有1的話怕不是圖片哦
  1489. if(pageElement && (pageElement.length>1 || (pageElement.length==1 && pageElement[0].tagName!="IMG") )){
  1490. let result=ruleParser.insertPage(doc, pageElement, url, callback, false);
  1491. if(!result){
  1492. requestFromIframe(url, (doc, eles)=>{
  1493. if(eles){
  1494. ruleParser.insertPage(doc, eles, url, callback, true);
  1495. }
  1496. });
  1497. }
  1498. }else if(ruleParser.curSiteRule.singleUrl){
  1499. requestFromIframe(url, (doc, eles)=>{
  1500. if(eles){
  1501. ruleParser.insertPage(doc, eles, url, callback, true);
  1502. }
  1503. });
  1504. }
  1505. },
  1506. onerror: function(e){
  1507. debug(e);
  1508. callback(false);
  1509. }
  1510. });
  1511. }
  1512.  
  1513. var failFromIframe=0;
  1514. function requestFromIframe(url, callback){
  1515. let orgPage,curPage;
  1516. let iframe = document.createElement('iframe');
  1517. iframe.name = 'pagetual-iframe';
  1518. iframe.width = '100%';
  1519. iframe.height = '0';
  1520. iframe.frameBorder = '0';
  1521. if(ruleParser.curSiteRule.sandbox){
  1522. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1523. }
  1524. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1525. iframe.addEventListener("load", e=>{
  1526. let waitTime=500,checkEval;
  1527. if(ruleParser.curSiteRule.wait){
  1528. if(isNaN(ruleParser.curSiteRule.wait)){
  1529. checkEval=Function("doc",'"use strict";' + ruleParser.curSiteRule.wait);
  1530. }else{
  1531. waitTime=ruleParser.curSiteRule.wait;
  1532. }
  1533. }
  1534. setTimeout(()=>{
  1535. let tryTimes=0;
  1536. function checkIframe(){
  1537. try{
  1538. let doc=iframe.contentDocument || iframe.contentWindow.document;
  1539. let eles=ruleParser.getPageElement(doc, iframe.contentWindow);
  1540. if(eles && eles.length>0 && (!checkEval || checkEval(doc))){
  1541. callback(doc, eles);
  1542. }else if(tryTimes++ < 10){
  1543. setTimeout(()=>{
  1544. checkIframe();
  1545. },waitTime);
  1546. return;
  1547. }else{
  1548. if(failFromIframe++ > 2){
  1549. failFromIframe=0;
  1550. debug("Stop as failFromIframe");
  1551. isPause=true;
  1552. callback(false, false);
  1553. }else{
  1554. callback(false, false);
  1555. }
  1556. }
  1557. }catch(e){
  1558. debug("Stop as cors");
  1559. isPause=true;
  1560. callback(false, false);
  1561. }
  1562. document.body.removeChild(iframe);
  1563. }
  1564. checkIframe();
  1565. },waitTime);
  1566. });
  1567. iframe.src=url;
  1568. document.body.appendChild(iframe);
  1569. }
  1570.  
  1571. function initPage(){
  1572. ruleParser.initPage(()=>{
  1573. initListener();
  1574. nextPage();
  1575. });
  1576. }
  1577.  
  1578. function initView(){
  1579. _GM_addStyle(`
  1580. .pagetual_pageBar.stop {
  1581. -webkit-filter: invert(100%);
  1582. filter: invert(100%);
  1583. opacity: 1!important;
  1584. }
  1585. .pagetual_pageBar.hide {
  1586. display: none!important;
  1587. }
  1588. .pagetual_pageBar:hover {
  1589. opacity: 1!important;
  1590. }
  1591. .pagetual_pageBar span {
  1592. vertical-align: super;
  1593. }
  1594.  
  1595. .pagetual_pageBar span>svg:hover {
  1596. animation: touhouAni 1s infinite;
  1597. }
  1598.  
  1599. @keyframes touhouAni{
  1600. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  1601. to {transform: rotate(360deg);}
  1602. }
  1603. @-webkit-keyframes touhouAni{
  1604. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  1605. to {transform: rotate(360deg);}
  1606. }
  1607. `);
  1608. 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;`;
  1609. }
  1610. var loading=document.createElement("div");
  1611. loading.className="pagetual_loading";
  1612. loading.style.cssText="display:none;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;";
  1613. loading.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><svg width="120" height="30" viewBox="0 0 120 30" fill="#000000A0" style="display: block;position: initial;margin: auto;shape-rendering: auto;vertical-align: middle;visibility: visible;width: initial;height: initial;"><circle cx="15" cy="15" r="15"><animate attributeName="r" from="15" to="15" begin="0s" dur="0.8s" values="15;9;15" calcMode="linear" repeatCount="indefinite"></animate><animate attributeName="fill-opacity" from="1" to="1" begin="0s" dur="0.8s" values="1;.5;1" calcMode="linear" repeatCount="indefinite"></animate></circle><circle cx="60" cy="15" r="9" fill-opacity="0.3"><animate attributeName="r" from="9" to="9" begin="0s" dur="0.8s" values="9;15;9" calcMode="linear" repeatCount="indefinite"></animate><animate attributeName="fill-opacity" from="0.5" to="0.5" begin="0s" dur="0.8s" values=".5;1;.5" calcMode="linear" repeatCount="indefinite"></animate></circle><circle cx="105" cy="15" r="15"><animate attributeName="r" from="15" to="15" begin="0s" dur="0.8s" values="15;9;15" calcMode="linear" repeatCount="indefinite"></animate><animate attributeName="fill-opacity" from="1" to="1" begin="0s" dur="0.8s" values="1;.5;1" calcMode="linear" repeatCount="indefinite"></animate></circle></svg>`;
  1614. document.body.appendChild(loading);
  1615.  
  1616. var upSvg=`<svg 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>`;
  1617. var downSvg=`<svg 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>`;
  1618. var pageBarStyle;
  1619. var initStyle=`display: initial;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: 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;`;
  1620. 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);`;
  1621.  
  1622. var isPause=false,isLoading=false,curPage=1,forceState=0,bottomGap=1000;
  1623.  
  1624. function changeStop(stop, hide){
  1625. isPause=stop;
  1626. [].forEach.call(document.querySelectorAll(".pagetual_pageBar"), bar=>{
  1627. if(isPause){
  1628. bar.classList.add("stop");
  1629. if(hide)bar.classList.add("hide");
  1630. }else{
  1631. bar.classList.remove("stop");
  1632. if(hide)bar.classList.remove("hide");
  1633. }
  1634. });
  1635. }
  1636.  
  1637. function isInViewPort(element) {
  1638. if(!element.parentNode)return false;
  1639. if(_unsafeWindow.getComputedStyle(element).display=="none")return false;
  1640. const viewWidth = window.innerWidth || document.documentElement.clientWidth;
  1641. const viewHeight = window.innerHeight || document.documentElement.clientHeight;
  1642. const {
  1643. top,
  1644. right,
  1645. bottom,
  1646. left,
  1647. } = element.getBoundingClientRect();
  1648.  
  1649. return (
  1650. top >= 0 &&
  1651. left >= 0 &&
  1652. right <= viewWidth &&
  1653. bottom <= viewHeight
  1654. );
  1655. }
  1656.  
  1657. var urlChanged=false;
  1658. var _wr = function(type) {
  1659. var orig = history[type];
  1660. return function() {
  1661. var rv = orig.apply(this, arguments);
  1662. var e = new Event(type);
  1663. e.arguments = arguments;
  1664. window.dispatchEvent(e);
  1665. return rv;
  1666. };
  1667. };
  1668. history.pushState = _wr('pushState');
  1669. window.addEventListener('pushState', function(e) {
  1670. urlChanged=true;
  1671. setTimeout(()=>{
  1672. if(location.href==configPage){
  1673. location.reload();
  1674. }
  1675. },1);
  1676. });
  1677.  
  1678. function initListener(){
  1679. let loadmoreBtn,loading=true;
  1680. setTimeout(()=>{
  1681. loadmoreBtn=getLoadMore(document);
  1682. if(loadmoreBtn){
  1683. loading=false;
  1684. }
  1685. },300);
  1686. document.addEventListener('scroll', e=>{
  1687. if(urlChanged){
  1688. ruleParser.initPage(()=>{});
  1689. initView();
  1690. urlChanged=false;
  1691. isPause=false;
  1692. }
  1693. if(!loading){
  1694. loading=true;
  1695. if(!loadmoreBtn || !loadmoreBtn.parentNode){
  1696. loadmoreBtn=getLoadMore(document);
  1697. }
  1698. if(loadmoreBtn){
  1699. loading=false;
  1700. if(isInViewPort(loadmoreBtn)){
  1701. emuClick(loadmoreBtn);
  1702. }
  1703. }else{
  1704. setTimeout(()=>{loading=false},500);
  1705. }
  1706. }
  1707. setTimeout(()=>{
  1708. if(!isPause && !isLoading){
  1709. let scrolly=window.scrollY;
  1710. let windowHeight=window.innerHeight;
  1711. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  1712. if(scrollH-scrolly-windowHeight<bottomGap){
  1713. nextPage();
  1714. }
  1715. }
  1716. },100);
  1717. }, true);
  1718. document.addEventListener('dblclick', e=>{
  1719. if(rulesData.dbClick2Stop){
  1720. setTimeout(()=>{
  1721. changeStop(!isPause, rulesData.hideBar);
  1722. if(!isPause){
  1723. let scrolly=window.scrollY;
  1724. let windowHeight=window.innerHeight;
  1725. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  1726. if(scrollH-scrolly-windowHeight<bottomGap){
  1727. nextPage();
  1728. }
  1729. }
  1730. },200);
  1731. }
  1732. });
  1733. }
  1734.  
  1735. function getLoadMore(doc){
  1736. let btnSel=ruleParser.curSiteRule.loadMore||".LoadMore,.load-more";
  1737. let loadmoreBtn=doc.querySelector(btnSel);
  1738. if(!loadmoreBtn){
  1739. let buttons=doc.querySelectorAll("input,button,a,div[onclick]"),loadmoreReg=/^\s*(加载更多|加載更多|load\s*more|もっと読み込む)\s*$/i;
  1740. for(let i=0;i<buttons.length;i++){
  1741. let button=buttons[i];
  1742. if(button && loadmoreReg.test(button.innerText)){
  1743. loadmoreBtn=button;
  1744. break;
  1745. }
  1746. }
  1747. }
  1748. return loadmoreBtn;
  1749. }
  1750.  
  1751. function createPageBar(url){
  1752. let insert=ruleParser.getInsert();
  1753. if(!insert || !insert.parentNode)return;
  1754. curPage++;
  1755. let inTable=insert.tagName=="TR" ||
  1756. (insert.previousElementSibling && insert.previousElementSibling.tagName=="TR") ||
  1757. insert.tagName=="TBODY" || (insert.previousElementSibling && insert.previousElementSibling.tagName=="TBODY");
  1758. let inLi=insert.tagName=="LI" || (insert.previousElementSibling && insert.previousElementSibling.tagName=="LI");
  1759. let pageBar=document.createElement(inTable?"tr":"div");
  1760. let upSpan=document.createElement("span");
  1761. let downSpan=document.createElement("span");
  1762. let pageText=document.createElement("a");
  1763. pageBar.className="pagetual_pageBar";
  1764. pageBar.id="pagetual_pageBar";
  1765. if(isPause){
  1766. pageBar.classList.add("stop");
  1767. }
  1768. pageBar.style.cssText=pageBarStyle;
  1769. pageBar.title=i18n(isPause?"enable":"disable");
  1770. upSpan.innerHTML=upSvg;
  1771. upSpan.title=i18n("toTop");
  1772. downSpan.innerHTML=downSvg;
  1773. downSpan.title=i18n("toBottom");
  1774. upSpan.style.cssText=initStyle;
  1775. downSpan.style.cssText=initStyle;
  1776. pageText.href=url;
  1777. pageText.style=pageTextStyle;
  1778. pageText.innerHTML="Page "+curPage;
  1779. pageText.title=i18n("current");
  1780. pageBar.appendChild(upSpan);
  1781. pageBar.appendChild(pageText);
  1782. pageBar.appendChild(downSpan);
  1783. if(inTable){
  1784. let example=(insert.tagName=="TR" || insert.tagName=="TBODY")?insert:insert.previousElementSibling;
  1785. let tdNum=0;
  1786. [].forEach.call(example.querySelectorAll("td,th"), td=>{
  1787. tdNum+=td.colSpan||1;
  1788. });
  1789. pageBar.style.display="table-row";
  1790. pageBar.style.backgroundColor="unset";
  1791. let td=document.createElement("td");
  1792. td.style.backgroundColor="rgb(240 240 240 / 80%)";
  1793. td.style.borderRadius="20px";
  1794. td.colSpan=tdNum||1;
  1795. td.style.padding="0 0";
  1796. td.style.textAlign="center";
  1797. td.appendChild(upSpan);
  1798. td.appendChild(pageText);
  1799. td.appendChild(downSpan);
  1800. pageBar.appendChild(td);
  1801. }
  1802.  
  1803. upSpan.addEventListener("click", e=>{
  1804. //changeStop(true);
  1805. //pageBar.title=i18n(isPause?"enable":"disable");
  1806. document.body.scrollTop=0;
  1807. document.documentElement.scrollTop=0;
  1808. e.preventDefault();
  1809. e.stopPropagation();
  1810. });
  1811. downSpan.addEventListener("click", e=>{
  1812. changeStop(true);
  1813. pageBar.title=i18n(isPause?"enable":"disable");
  1814. document.body.scrollTop=9999999;
  1815. document.documentElement.scrollTop=9999999;
  1816. e.preventDefault();
  1817. e.stopPropagation();
  1818. });
  1819. pageBar.addEventListener("click", e=>{
  1820. changeStop(!isPause);
  1821. pageBar.title=i18n(isPause?"enable":"disable");
  1822. });
  1823. pageText.addEventListener("click", e=>{
  1824. e.stopPropagation();
  1825. });
  1826. let parentStyle=_unsafeWindow.getComputedStyle(insert.parentNode);
  1827. pageBar.style.width=parseInt(parentStyle.width)*.99-parseInt(parentStyle.paddingLeft)-parseInt(parentStyle.paddingRight)+"px";
  1828. if(inLi){
  1829. pageBar.style.width="90%";
  1830. pageBar.style.minWidth="150px";
  1831. pageBar.style.display="inline-block";
  1832. let line=document.createElement("li");
  1833. line.style.textAlign="center";
  1834. line.appendChild(pageBar);
  1835. if(ruleParser.curSiteRule.insertPos==2){
  1836. insert.appendChild(line);
  1837. }else{
  1838. insert.parentNode.insertBefore(line, insert);
  1839. }
  1840. }else{
  1841. if(ruleParser.curSiteRule.insertPos==2){
  1842. insert.appendChild(pageBar);
  1843. }else{
  1844. insert.parentNode.insertBefore(pageBar, insert);
  1845. }
  1846. }
  1847.  
  1848. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  1849. let actualTop = pageBar.offsetTop;
  1850. let current = pageBar.parentNode.offsetParent;
  1851. while (current !== null){
  1852. actualTop += current.offsetTop;
  1853. current = current.offsetParent;
  1854. }
  1855. bottomGap=scrollH-actualTop+800;
  1856. return pageBar;
  1857. }
  1858.  
  1859. function emuClick(btn){
  1860. if(!PointerEvent)return btn.click();
  1861. let eventParam={
  1862. isTrusted: true,
  1863. altKey: false,
  1864. azimuthAngle: 0,
  1865. bubbles: true,
  1866. button: 0,
  1867. buttons: 0,
  1868. clientX: 1,
  1869. clientY: 1,
  1870. cancelBubble: false,
  1871. cancelable: true,
  1872. composed: true,
  1873. ctrlKey: false,
  1874. defaultPrevented: false,
  1875. detail: 1,
  1876. eventPhase: 2,
  1877. fromElement: null,
  1878. height: 1,
  1879. isPrimary: false,
  1880. metaKey: false,
  1881. pointerId: 1,
  1882. pointerType: "mouse",
  1883. pressure: 0,
  1884. relatedTarget: null,
  1885. returnValue: true,
  1886. shiftKey: false,
  1887. toElement: null,
  1888. twist: 0,
  1889. type: "click",
  1890. which: 1
  1891. };
  1892. var mouseclick = new PointerEvent("click",eventParam);
  1893. btn.dispatchEvent(mouseclick);
  1894. }
  1895.  
  1896. var emuIframe;
  1897. function emuPage(callback){
  1898. let orgPage,curPage,iframeDoc,times=0,loadmoreBtn,loadmoreEnd=false,waitTimes=10;
  1899. function checkPage(){
  1900. if(isPause)return;
  1901. try{
  1902. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  1903. }catch(e){
  1904. debug("Stop as cors");
  1905. isPause=true;
  1906. callback(false, false);
  1907. return;
  1908. }
  1909.  
  1910. let nextLink=ruleParser.getNextLink(iframeDoc);
  1911. let waitTime=500,checkEval;
  1912. if(ruleParser.curSiteRule.wait){
  1913. if(isNaN(ruleParser.curSiteRule.wait)){
  1914. checkEval=Function("doc",'"use strict";' + ruleParser.curSiteRule.wait);
  1915. }else{
  1916. waitTime=ruleParser.curSiteRule.wait;
  1917. }
  1918. }
  1919.  
  1920. if(!orgPage){
  1921. if(!loadmoreEnd){
  1922. loadmoreBtn=getLoadMore(iframeDoc);
  1923. if(loadmoreBtn){
  1924. emuClick(loadmoreBtn);
  1925. let intv=setInterval(()=>{
  1926. loadmoreBtn=getLoadMore(iframeDoc);
  1927. if(!loadmoreBtn || !loadmoreBtn.parentNode || !isVisible(loadmoreBtn, iframeDoc.defaultView)){
  1928. clearInterval(intv);
  1929. loadmoreEnd=true;
  1930. setTimeout(()=>{
  1931. checkPage();
  1932. },500);
  1933. }else{
  1934. emuClick(loadmoreBtn);
  1935. }
  1936. },200);
  1937. return;
  1938. }else{
  1939. loadmoreEnd=true;
  1940. }
  1941. }
  1942. let pageEle=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true);
  1943. if(!nextLink || !pageEle || (checkEval && !checkEval(iframeDoc))){
  1944. if(ruleParser.curSiteRule.wait && waitTimes-->0){
  1945. setTimeout(()=>{
  1946. checkPage();
  1947. },waitTime);
  1948. return;
  1949. }
  1950. }
  1951. orgPage=pageEle;
  1952. if(!orgPage || orgPage.length==0){
  1953. debug("Stop as no page when emu");
  1954. isPause=true;
  1955. callback(false, false);
  1956. return;
  1957. }
  1958. if(orgPage && orgPage[0].tagName=="UL")orgPage=orgPage[0].children;
  1959. if(orgPage && nextLink){
  1960. orgPage=orgPage[parseInt(orgPage.length/2)];
  1961. if(!isVisible(nextLink, iframeDoc.defaultView)){
  1962. debug("Stop as next hide when emu");
  1963. isPause=true;
  1964. callback(false, false);
  1965. }else{
  1966. emuClick(nextLink);
  1967. setTimeout(()=>{
  1968. checkPage();
  1969. },500);
  1970. }
  1971. }else{
  1972. debug("Stop as no next when emu");
  1973. isPause=true;
  1974. callback(false, false);
  1975. }
  1976. return;
  1977. }
  1978. if(times++ > 20){
  1979. //emuClick(nextLink);
  1980. debug("Stop as timeout when emu");
  1981. isPause=true;
  1982. callback(false, false);
  1983. return;
  1984. }
  1985. let eles=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true),checkItem=eles;
  1986. if(eles && eles[0].tagName=="UL")checkItem=eles[0].children;
  1987. if(!eles || eles.length==0 || orgPage == checkItem[parseInt(checkItem.length/2)] || (checkEval && !checkEval(iframeDoc))){
  1988. setTimeout(()=>{
  1989. checkPage();
  1990. },waitTime);
  1991. }else{
  1992. callback(iframeDoc, eles);
  1993. }
  1994. }
  1995. if(!emuIframe){
  1996. emuIframe = document.createElement('iframe');
  1997. emuIframe.name = 'pagetual-iframe';
  1998. if(ruleParser.curSiteRule.sandbox){
  1999. emuIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  2000. }
  2001. emuIframe.width = '100%';
  2002. emuIframe.height = '0';
  2003. emuIframe.frameBorder = '0';
  2004. emuIframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  2005. emuIframe.addEventListener("load", e=>{
  2006. setTimeout(()=>{
  2007. checkPage();
  2008. },500);
  2009. });
  2010. emuIframe.src=location.href;
  2011. document.body.appendChild(emuIframe);
  2012. }else{
  2013. checkPage();
  2014. }
  2015. }
  2016.  
  2017. function forceIframe(url, callback){
  2018. let curIframe = document.createElement('iframe');
  2019. curIframe.name = 'pagetual-iframe';
  2020. curIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  2021. curIframe.frameBorder = '0';
  2022. curIframe.scrolling="no";
  2023. 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;';
  2024. curIframe.addEventListener("load", e=>{
  2025. let iframeDoc;
  2026. try{
  2027. iframeDoc=curIframe.contentDocument || curIframe.contentWindow.document;
  2028. }catch(e){
  2029. debug("Stop as cors");
  2030. isPause=true;
  2031. callback(false, false);
  2032. return;
  2033. }
  2034. ruleParser.insertPage(iframeDoc, [], url, null, true);
  2035. callback(curIframe, true);
  2036. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  2037. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  2038. setTimeout(()=>{
  2039. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  2040. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  2041. },300);
  2042. });
  2043. curIframe.src=url;
  2044. let insert=ruleParser.getInsert();
  2045. document.body.insertBefore(curIframe, loading);
  2046. return curIframe;
  2047. }
  2048.  
  2049. function nextPage(){
  2050. if(isPause || isLoading)return;
  2051. let nextLink=ruleParser.nextLinkHref;
  2052. if(!nextLink)return;
  2053. let insert=ruleParser.getInsert();
  2054. if(insert){
  2055. let isJs=/^(javascript|#)/.test(nextLink.replace(location.href,""));
  2056. if(location.protocol=="https:" && /^http:/.test(nextLink)){
  2057. nextLink=nextLink.replace(/^http/,"https");
  2058. }
  2059. isLoading=true;
  2060. loading.style.display="";
  2061. if(ruleParser.curSiteRule.pageElementByJs){
  2062. var over=ele=>{
  2063. isLoading=false;
  2064. loading.style.display="none";
  2065. if(ele){
  2066. createPageBar(nextLink);
  2067. ruleParser.insertPage(null, ele, nextLink, null, true);
  2068. }else{
  2069. debug("Stop as no page when get by js");
  2070. isPause=true;
  2071. }
  2072. };
  2073. try{
  2074. Function("over",'"use strict";' + ruleParser.curSiteRule.pageElementByJs)(over);
  2075. }catch(e){}
  2076. }else if(ruleParser.curSiteRule.action==1 && !isJs){
  2077. requestFromIframe(nextLink, (doc, eles)=>{
  2078. isLoading=false;
  2079. loading.style.display="none";
  2080. if(eles){
  2081. createPageBar(nextLink);
  2082. ruleParser.insertPage(doc, eles, nextLink, null, true);
  2083. }
  2084. });
  2085. }else if(forceState==2 && !isJs){
  2086. forceIframe(nextLink, (iframe, eles)=>{
  2087. isLoading=false;
  2088. loading.style.display="none";
  2089. let pageBar=createPageBar(nextLink);
  2090. iframe.parentNode.insertBefore(pageBar, iframe);
  2091. });
  2092. }else{
  2093. if(!isJs){
  2094. requestDoc(nextLink, (eles)=>{
  2095. isLoading=false;
  2096. loading.style.display="none";
  2097. if(eles){
  2098. createPageBar(nextLink);
  2099. }
  2100. });
  2101. }else{
  2102. emuPage((doc, eles)=>{
  2103. isLoading=false;
  2104. loading.style.display="none";
  2105. if(eles){
  2106. createPageBar(nextLink);
  2107. ruleParser.insertPage(doc, eles, "", null, true);
  2108. }
  2109. });
  2110. }
  2111. }
  2112. }
  2113. }
  2114.  
  2115. function init(){
  2116. initRules(()=>{
  2117. initView();
  2118. initPage();
  2119. });
  2120. }
  2121. setTimeout(()=>{
  2122. init();
  2123. },300);
  2124. })();

QingJ © 2025

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