东方永页机

自动翻页

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

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

QingJ © 2025

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