东方永页机

自动翻页

当前为 2022-01-31 提交的版本,查看 最新版本

  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.5
  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. onload: function(res) {
  409. let json=null;
  410. try{
  411. json=JSON.parse(res.response);
  412. }catch(e){
  413. debug(e);
  414. }
  415. callback(json);
  416. }
  417. });
  418. }
  419.  
  420. formatRule(item, type, from){
  421. switch(type){
  422. case 0:
  423. return {
  424. from:from,
  425. type:type,
  426. name:item.name,
  427. action:item.data.forceIframe=="true"?1:0,
  428. url:item.data.url,
  429. pageElement:item.data.pageElement,
  430. nextLink:item.data.nextLink,
  431. insert:item.data.insertBefore,
  432. insertPos:1,
  433. updatedAt:item.data.updated_at,
  434. css:item.data.Stylus+item.data.CSS,
  435. pageAction:item.data.bookmarklet
  436. };
  437. break;
  438. case 1:
  439. default:
  440. item.from=from;
  441. if(typeof(item.type) == "undefined")item.type=type;
  442. return item;
  443. break;
  444. }
  445. return null;
  446. }
  447.  
  448. addRuleByUrl(url, type, from, callback) {
  449. this.requestJSON(url, json=>{
  450. this.addRules(json, type, from);
  451. storage.setItem("rules", this.rules);
  452. callback();
  453. });
  454. }
  455.  
  456. addRules(rules, type, from) {
  457. if(rules && rules.length>0){
  458. this.rules=this.rules.filter(item=>{return item.from!=from});
  459. rules.forEach(item=>{
  460. let rule=this.formatRule(item, type, from);
  461. if(rule){
  462. this.rules.push(rule);
  463. }
  464. });
  465. }
  466. }
  467.  
  468. getRule(callback) {
  469. if(this.curSiteRule && this.curSiteRule.url){
  470. return this.curSiteRule;
  471. }
  472. var self=this;
  473. for(let i in this.hpRules){
  474. let rule=this.hpRules[i];
  475. if(!rule || !rule.url)continue;
  476. if(rule.singleUrl){
  477. if(location.origin+location.pathname==rule.url){
  478. this.curSiteRule=rule;
  479. debug(rule);
  480. callback();
  481. return rule;
  482. }
  483. continue;
  484. }
  485. let urlReg=new RegExp(rule.url, "i");
  486. if(urlReg.test(location.href)){
  487. if(rule.wait){
  488. let checkReady=()=>{
  489. setTimeout(()=>{
  490. if(rule.pageElement)pageElement=rule.type==0?getElementByXpath(rule.pageElement):document.querySelector(rule.pageElement);
  491. if(rule.nextLink)nextLink=rule.type==0?getElementByXpath(rule.nextLink):document.querySelector(rule.nextLink);
  492. if(rule.insert)insert=rule.type==0?getElementByXpath(rule.insert):document.querySelector(rule.insert);
  493. if((rule.pageElement && !pageElement) ||
  494. (rule.nextLink && !nextLink) ||
  495. (rule.insert && !insert)){
  496. checkReady();
  497. }else{
  498. self.curSiteRule=rule;
  499. debug(rule);
  500. callback();
  501. }
  502. },parseInt(rule.wait));
  503. };
  504. checkReady();
  505. return;
  506. }
  507. let pageElement,nextLink,insert;
  508. if(rule.pageElement)pageElement=rule.type==0?getElementByXpath(rule.pageElement):document.querySelector(rule.pageElement);
  509. if(rule.nextLink)nextLink=rule.type==0?getElementByXpath(rule.nextLink):document.querySelector(rule.nextLink);
  510. if(rule.insert)insert=rule.type==0?getElementByXpath(rule.insert):document.querySelector(rule.insert);
  511. if((rule.pageElement && !pageElement) ||
  512. (rule.nextLink && !nextLink) ||
  513. (rule.insert && !insert)){
  514. continue;
  515. }
  516. this.curSiteRule=rule;
  517. debug(rule);
  518. callback();
  519. return rule;
  520. }
  521. }
  522. for(let i in this.customRules){
  523. let rule=this.customRules[i];
  524. if(!rule || !rule.url)continue;
  525. let urlReg=new RegExp(rule.url, "i");
  526. if(urlReg.test(location.href)){
  527. if(rule.wait){
  528. let checkReady=()=>{
  529. setTimeout(()=>{
  530. if(rule.pageElement)pageElement=rule.type==0?getElementByXpath(rule.pageElement):document.querySelector(rule.pageElement);
  531. if(rule.nextLink)nextLink=rule.type==0?getElementByXpath(rule.nextLink):document.querySelector(rule.nextLink);
  532. if(rule.insert)insert=rule.type==0?getElementByXpath(rule.insert):document.querySelector(rule.insert);
  533. if((rule.pageElement && !pageElement) ||
  534. (rule.nextLink && !nextLink) ||
  535. (rule.insert && !insert)){
  536. checkReady();
  537. }else{
  538. self.curSiteRule=rule;
  539. debug(rule);
  540. callback();
  541. }
  542. },parseInt(rule.wait));
  543. };
  544. checkReady();
  545. return;
  546. }
  547. let pageElement,nextLink,insert;
  548. if(rule.pageElement)pageElement=rule.type==0?getElementByXpath(rule.pageElement):document.querySelector(rule.pageElement);
  549. if(rule.nextLink)nextLink=rule.type==0?getElementByXpath(rule.nextLink):document.querySelector(rule.nextLink);
  550. if(rule.insert)insert=rule.type==0?getElementByXpath(rule.insert):document.querySelector(rule.insert);
  551. if((rule.pageElement && !pageElement) ||
  552. (rule.nextLink && !nextLink) ||
  553. (rule.insert && !insert)){
  554. continue;
  555. }
  556. this.curSiteRule=rule;
  557. debug(rule);
  558. callback();
  559. return rule;
  560. }
  561. }
  562. let r=0;
  563. function searchByTime(){
  564. setTimeout(()=>{
  565. let end=r+80;
  566. end=end>self.rules.length?self.rules.length:end;
  567. for(;r<end;r++){
  568. let rule=self.rules[r];
  569. let urlReg=new RegExp(rule.url, "i");
  570. if(urlReg.test(location.href)){
  571. if(rule.wait){
  572. let checkReady=()=>{
  573. setTimeout(()=>{
  574. if(rule.pageElement)pageElement=rule.type==0?getElementByXpath(rule.pageElement):document.querySelector(rule.pageElement);
  575. if(rule.nextLink)nextLink=rule.type==0?getElementByXpath(rule.nextLink):document.querySelector(rule.nextLink);
  576. if(rule.insert)insert=rule.type==0?getElementByXpath(rule.insert):document.querySelector(rule.insert);
  577. if((rule.pageElement && !pageElement) ||
  578. (rule.nextLink && !nextLink) ||
  579. (rule.insert && !insert)){
  580. checkReady();
  581. }else{
  582. self.curSiteRule=rule;
  583. debug(rule);
  584. callback();
  585. }
  586. },parseInt(rule.wait));
  587. };
  588. checkReady();
  589. return;
  590. }
  591. let pageElement,nextLink,insert;
  592. if(rule.pageElement)pageElement=rule.type==0?getElementByXpath(rule.pageElement):document.querySelector(rule.pageElement);
  593. if(rule.nextLink)nextLink=rule.type==0?getElementByXpath(rule.nextLink):document.querySelector(rule.nextLink);
  594. if(rule.insert)insert=rule.type==0?getElementByXpath(rule.insert):document.querySelector(rule.insert);
  595. if((rule.pageElement && !pageElement) ||
  596. (rule.nextLink && !nextLink) ||
  597. (rule.insert && !insert)){
  598. continue;
  599. }
  600. self.curSiteRule=rule;
  601. debug(rule);
  602. callback();
  603. return;
  604. }
  605. }
  606. if(end>=self.rules.length){
  607. self.curSiteRule={};
  608. self.curSiteRule.url=location.origin+location.pathname;
  609. self.curSiteRule.singleUrl=true;
  610. callback();
  611. return;
  612. }else{
  613. searchByTime();
  614. }
  615. },20);
  616. }
  617. searchByTime();
  618. }
  619.  
  620. geneSelector(ele){
  621. let selector=ele.tagName;
  622. //Google id class都是隨機。百度更過分,style script順序都是隨機的
  623. //if(ele.id) selector += '#' + ele.id;
  624. //if(ele.classList) selector += [].map.call(ele.classList,d=>'.'+d).join('');
  625. let parent = ele.parentElement;
  626. if(parent){
  627. let i,j=0;
  628. for(i=0;i<parent.children.length;i++){
  629. if(parent.children[i].tagName==selector){
  630. j++;
  631. if(parent.children[i]==ele){
  632. break;
  633. }
  634. }
  635. }
  636. selector = this.geneSelector(parent) + ' > ' + selector + (parent.tagName=="HTML"?"":`:nth-of-type(${j})`);
  637. }
  638. return selector;
  639. }
  640.  
  641. getPageElement(doc, curWin, dontFind) {
  642. let pageElement=null;
  643. let self=this;
  644. if(this.curSiteRule.pageElement){
  645. pageElement=this.curSiteRule.type==0?getAllElementsByXpath(this.curSiteRule.pageElement,doc,doc):doc.querySelectorAll(this.curSiteRule.pageElement);
  646. }
  647. if((!pageElement || pageElement.length==0) && curWin && !dontFind){
  648. let body=doc.body;
  649. if(!body)return null;
  650. let bodyHeight=parseInt(body.scrollHeight);
  651. let curHeight=bodyHeight;
  652. function checkElement(ele){
  653. if(curHeight/bodyHeight<=0.30)return null;
  654. if(ele.children.length==0 && !self.curSiteRule.pageElement){
  655. if(ele.parentNode.tagName=="P")ele=ele.parentNode;
  656. self.curSiteRule.pageElement=self.geneSelector(ele.parentNode)+">"+ele.tagName;
  657. self.curSiteRule.type=1;
  658. debug(self.curSiteRule.pageElement);
  659. return [ele];
  660. }
  661. let i,maxHeight=curHeight*0.5,curMaxEle=null,curMaxArea=0,maxWidth=0;
  662. let isHori=true;
  663. let offsetTop=ele.children[0].offsetTop;
  664. for(i=0;i<ele.children.length;i++){
  665. if(ele.children[i].offsetTop!=offsetTop){
  666. isHori=false;
  667. break;
  668. }
  669. }
  670. for(i=0;i<ele.children.length;i++){
  671. let curNode=ele.children[i];
  672. let comStyle=curWin.getComputedStyle(curNode);
  673. let h=parseInt(curNode.scrollHeight);
  674. let w=parseInt(curNode.scrollWidth);
  675. if(isNaN(h) || isNaN(w))continue;
  676. let a=h*w+h,moreChild=curNode.children[0];
  677. while(moreChild){
  678. comStyle=curWin.getComputedStyle(moreChild);
  679. let ch=parseInt(moreChild.scrollHeight);
  680. let cw=parseInt(moreChild.scrollWidth);
  681. if(moreChild.innerText!="" && !isNaN(ch) && !isNaN(cw)){
  682. a+=ch*cw;
  683. }
  684. moreChild=moreChild.nextElementSibling;
  685. }
  686. if(curMaxEle==null || (isHori?maxWidth<w:curMaxArea<a)){
  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. self.curSiteRule.type=1;
  700. debug(self.curSiteRule.pageElement);
  701. }
  702. return ele.children;
  703. }
  704. pageElement=checkElement(body);
  705. if(pageElement)this.saveCurSiteRule();
  706. }
  707. return pageElement;
  708. }
  709.  
  710. getPage(doc){
  711. if(_unsafeWindow.Discourse)return {};
  712. let canSave=false;//發現頁碼選擇器在其他頁對不上,還是別保存了
  713. let url=this.curUrl.replace("#!","");
  714. let pageNum=1,preStr="",afterStr="";
  715. let pageMatch1=url.match(/(.*[a-z\/\-_](?:p|page)?\/?)(\d+)(\.s?html?$|\/?$)/i);
  716. let pageMatch2=url.match(/(.*[\?&]p(?:age)?=)(\d+)($|[#&].*)/i);
  717. if(pageMatch1){
  718. preStr=pageMatch1[1];
  719. pageNum=pageMatch1[2];
  720. afterStr=pageMatch1[3];
  721. }else if(pageMatch2){
  722. preStr=pageMatch2[1];
  723. pageNum=pageMatch2[2];
  724. afterStr=pageMatch2[3];
  725. }
  726. let curPage=doc,i,cur;
  727. let next=curPage.querySelector("a.next"),jsNext;
  728. if(!next)next=curPage.querySelector("a#next");
  729. if(!next)next=curPage.querySelector("a#rightFix");
  730. if(!next)next=curPage.querySelector("a.next_page");
  731. if(!next)next=curPage.querySelector(".next>a");
  732. if(!next)next=curPage.querySelector("#next_page");
  733. if(!next)next=curPage.querySelector(".next>button");
  734. if(!next)next=curPage.querySelector("a[alt=next]");
  735. if(!next)next=curPage.querySelector("[title=next]");
  736. if(next && (!next.href || /javascript:/.test(next.href))){
  737. jsNext=next;
  738. next=null;
  739. }
  740. if(!next){
  741. let pageDiv=curPage.querySelector("div.wp-pagenavi");
  742. if(pageDiv){
  743. cur=pageDiv.querySelector("span.current");
  744. next=cur.nextSibling;
  745. }else{
  746. cur=curPage.querySelector("div.article-paging>span");
  747. if(cur){
  748. next=cur.nextElementSibling;
  749. }
  750. }
  751. }
  752. if(!next){
  753. let pageDiv=curPage.querySelector("div.pages>ul");
  754. if(pageDiv){
  755. cur=pageDiv.querySelector("li>b");
  756. if(cur)next=cur.parentNode.nextElementSibling.querySelector("a");
  757. }
  758. }
  759. if(!next){
  760. let aTags=curPage.querySelectorAll("a");
  761. let nextf,nexts,nextt,nextfo;
  762. for(i=0;i<aTags.length;i++){
  763. let aTag=aTags[i];
  764. if(nextf && nexts && nextt)break;
  765. if(!nextf){
  766. if(/(\s|^)下[一1]?[页頁张張]|^next( page)?\s*$|次のページ/i.test(aTag.innerText)){
  767. if(!aTag.href || /javascript:/.test(aTag.href)){
  768. nextfo=aTag;
  769. }else{
  770. nextf=aTag;
  771. }
  772. }
  773. }
  774. if(!nexts){
  775. if(aTag.innerText=="&gt;"){
  776. if(!aTag.href || /javascript:/.test(aTag.href)){
  777. nextfo=aTag;
  778. }else{
  779. nexts=aTag;
  780. }
  781. }
  782. }
  783. if(!aTag.href || /javascript:/.test(aTag.href))continue;
  784. if(!nextt){
  785. aTag.href=aTag.href.replace(/\?&/,"?");
  786. if(aTag.innerText=="»"){
  787. nextt=aTag;
  788. }else if(aTag.href.replace("#!","").replace(preStr,"").replace(afterStr,"")==parseInt(pageNum)+1){
  789. nextt=aTag;
  790. }else if(aTag.href.indexOf(url)!=-1 && /^[\/\?&]?[_-]?(p|page)?=?\/?2(\/|\?|&|$)/i.test(aTag.href.replace(url,"").replace(/\.s?html?$/i,""))){
  791. nextt=aTag;
  792. }
  793. }
  794. }
  795. next=nextf||nexts||nextt||nextfo;
  796. }
  797. if(!next)next=jsNext||curPage.querySelector('a[rel="next"]');
  798. return {next:next,canSave:canSave};
  799. }
  800.  
  801. getNextLink(doc) {
  802. let nextLink=null,page;
  803. if(this.curSiteRule.pageElementByJs){
  804. this.nextLinkHref="#";
  805. return true;
  806. }else if(this.curSiteRule.nextLinkByJs){
  807. try{
  808. let targetUrl=Function("doc",'"use strict";' + this.curSiteRule.nextLinkByJs)(doc);;
  809. nextLink={href:targetUrl};
  810. }catch(e){}
  811. }else if(this.curSiteRule.nextLinkByUrl){
  812. let targetUrl=this.curUrl.replace(new RegExp(this.curSiteRule.nextLinkByUrl[0]), this.curSiteRule.nextLinkByUrl[1]);
  813. if(targetUrl != this.curUrl){
  814. let reps=targetUrl.match(/{.*?}/g);
  815. if(reps){
  816. reps.forEach(rep=>{
  817. let code=rep.replace("{","").replace("}","");
  818. let result=code.match(/^(\d+)\+1$/);
  819. if(result){
  820. result=parseInt(result[1])+1;
  821. }else{
  822. try{
  823. result=Function('"use strict";return ' + code)();;
  824. }catch(e){}
  825. }
  826. targetUrl=targetUrl.replace(rep, result);
  827. });
  828. }
  829. }
  830. nextLink={href:targetUrl};
  831. }else if(this.curSiteRule.nextLink){
  832. nextLink=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.nextLink,doc,doc):doc.querySelector(this.curSiteRule.nextLink);
  833. }
  834. if(!nextLink){
  835. page=this.getPage(doc);
  836. nextLink=page.next;
  837. if(nextLink && doc==document){
  838. let nextLinkCs=_unsafeWindow.getComputedStyle(nextLink);
  839. if(nextLinkCs.cursor=="not-allowed"){
  840. self.nextLinkHref=false;
  841. return null;
  842. }
  843. }
  844. }
  845. if(nextLink){
  846. if(!this.curSiteRule.nextLink && page && page.canSave){
  847. this.curSiteRule.nextLink=this.geneSelector(nextLink);
  848. this.curSiteRule.type=1;
  849. this.saveCurSiteRule();
  850. }
  851. }
  852. if(nextLink){
  853. this.nextLinkHref=nextLink.href?nextLink.href:"#";
  854. debug(nextLink);
  855. }else{
  856. this.nextLinkHref=false;
  857. }
  858. return nextLink;
  859. }
  860.  
  861. getInsert(refresh) {
  862. if(this.insert && !refresh){
  863. let parent=this.insert;
  864. while(parent && parent.nodeName!="BODY"){
  865. parent=parent.parentNode;
  866. }
  867. if(parent && parent.nodeName=="BODY"){
  868. return this.insert;
  869. }
  870. }
  871. if(this.curSiteRule.insert){
  872. this.insert=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.insert,document):document.querySelector(this.curSiteRule.insert);
  873. }else{
  874. let pageElement=this.getPageElement(document, _unsafeWindow);
  875. if(pageElement && pageElement.length>0){
  876. var pELast = pageElement[pageElement.length - 1];
  877. this.insert = pELast.nextSibling ? pELast.nextSibling : pELast.parentNode.appendChild(document.createTextNode(' '));
  878. }
  879. }
  880. return this.insert;
  881. }
  882.  
  883. pageAction(doc,eles){
  884. let code=this.curSiteRule.pageAction;
  885. if(code){
  886. try{
  887. Function("doc","eles",'"use strict";' + code)(doc,eles);
  888. }catch(e){}
  889. }
  890. let css=this.curSiteRule.css;
  891. if(css){
  892. _GM_addStyle(css);
  893. }
  894. [].forEach.call(eles, ele=>{
  895. [].forEach.call(ele.querySelectorAll("img"), img=>{
  896. //if(img.src==""){
  897. let realSrc;
  898. if(img.dataset && img.dataset.original){
  899. realSrc=img.dataset.original;
  900. }else if(img.dataset && img.dataset.src){
  901. realSrc=img.dataset.src;
  902. }else if(img._lazyrias && img._lazyrias.srcset){
  903. realSrc=img._lazyrias.srcset[img._lazyrias.srcset.length-1];
  904. }else if(img.dataset && img.dataset.origFile){
  905. realSrc=img.dataset.origFile;
  906. }else if(img.srcset){
  907. var srcs=img.srcset.split(","),largeSize=0;
  908. srcs.forEach(srci=>{
  909. let srcInfo=srci.trim().split(" "),curSize=parseInt(srcInfo[1]);
  910. if(srcInfo[1] && curSize>largeSize){
  911. largeSize=curSize;
  912. realSrc=srcInfo[0];
  913. }
  914. });
  915. }
  916. if(realSrc)img.src=realSrc;
  917. //}
  918. });
  919. [].forEach.call(ele.querySelectorAll("a.lazyload"), a=>{
  920. if(a.dataset.original){
  921. a.style.backgroundImage='url("'+a.dataset.original+'")';
  922. }
  923. });
  924. });
  925. let lazyImgSrc=this.curSiteRule.lazyImgSrc;
  926. if(lazyImgSrc){
  927. [].forEach.call(eles, ele=>{
  928. [].forEach.call(ele.querySelectorAll("img"), img=>{
  929. if(img[lazyImgSrc]){
  930. img.src=img[lazyImgSrc];
  931. }
  932. });
  933. });
  934. }
  935. }
  936.  
  937. initPage(callback){
  938. let self=this;
  939. curPage=1;
  940. //if(this.curSiteRule.url && !this.curSiteRule.singleUrl)return;
  941. this.curSiteRule={};
  942. this.pageDoc=document;
  943. this.nextLinkHref=null;
  944. this.curUrl=location.href;
  945. this.getRule(()=>{
  946. if(self.curSiteRule.enable==0){
  947. isPause=true;
  948. return;
  949. }
  950. if(self.curSiteRule && !self.curSiteRule.singleUrl){
  951. self.hpRules=self.hpRules.filter(item=>{return item&&item.url!=self.curSiteRule.url});
  952. self.hpRules.unshift(self.curSiteRule);
  953. if(self.hpRules.length>30){
  954. self.hpRules.pop();
  955. }
  956. storage.setItem("hpRules", self.hpRules);
  957. }
  958. let code=self.curSiteRule.init;
  959. if(code){
  960. try{
  961. Function('"use strict";' + code)();
  962. }catch(e){}
  963. }
  964. self.getNextLink(document);
  965. callback();
  966. });
  967. }
  968.  
  969. insertPage(doc, eles, url, callback, tried){
  970. this.pageDoc=doc;
  971. this.curUrl=url;
  972. this.pageAction(doc, eles);
  973. this.getNextLink(doc);
  974. if(curPage==1 && !tried && !this.nextLinkHref && this.curSiteRule.singleUrl && this.curSiteRule.pageElement){
  975. this.curSiteRule.action=1;
  976. return false;
  977. }
  978. if(callback)callback(eles);
  979. this.getInsert();
  980. var self=this;
  981. if(!eles || eles.length==0 || !self.insert || !self.insert.parentNode){
  982. }else{
  983. [].forEach.call(eles, ele=>{
  984. if(self.curSiteRule.insertPos==2){
  985. self.insert.appendChild(ele.cloneNode(true));
  986. }else{
  987. self.insert.parentNode.insertBefore(ele.cloneNode(true), self.insert);
  988. }
  989. });
  990. }
  991. return true;
  992. }
  993. }
  994. var ruleParser = new RuleParser();
  995.  
  996. var rulesData={},ruleUrls,updateDate;
  997. function initConfig(){
  998. _GM_registerMenuCommand(i18n(forceState==1?"enable":"disableSite"), ()=>{
  999. storage.setItem("forceState_"+location.host, (forceState==1?"":1));
  1000. location.reload();
  1001. });
  1002.  
  1003. _GM_registerMenuCommand(i18n(forceState==2?"cancelForceIframe":"forceIframe"), ()=>{
  1004. storage.setItem("forceState_"+location.host, (forceState==2?"":2));
  1005. location.reload();
  1006. });
  1007. var configCon,insertPos;
  1008. if(location.href=="https://github.com/hoothin/UserScripts/tree/master/Pagetual"){
  1009. _GM_addStyle(`
  1010. p>span:nth-child(1),p>span:nth-child(2),p>span:nth-child(3){
  1011. cursor: pointer;
  1012. user-select: none;
  1013. }
  1014. p>span:nth-child(1):hover,p>span:nth-child(2):hover,p>span:nth-child(3):hover{
  1015. color:red;
  1016. }
  1017. .updateDate{
  1018. cursor: pointer;
  1019. user-select: none;
  1020. }
  1021. .updateDate:hover{
  1022. color:red;
  1023. }
  1024. `);
  1025. configCon=document.querySelector(".markdown-body");
  1026. insertPos=configCon.querySelector("hr");
  1027. }else if(location.href=="https://github.com/hoothin/UserScripts/tree/master/Pagetual"){
  1028. }else return;
  1029. class Rulebar {
  1030. init(ruleUrl){
  1031. this.ruleUrl=ruleUrl;
  1032. this.item=document.createElement("p");
  1033. this.item.title=ruleUrl.type==0?"AutoPagerize Rules":"Pagetual Rules";
  1034. this.item.dataset.id=this.ruleUrl.id;
  1035. let url=document.createElement("span");
  1036. url.innerHTML=ruleUrl.url;
  1037. let up=document.createElement("span");
  1038. up.innerHTML="↑ ";
  1039. up.title=i18n("sortTitle");
  1040. let down=document.createElement("span");
  1041. down.innerHTML="↓ ";
  1042. down.title=i18n("sortTitle");
  1043. let del=document.createElement("span");
  1044. del.innerHTML="× ";
  1045. up.onclick=e=>{
  1046. this.moveUp();
  1047. };
  1048. down.onclick=e=>{
  1049. this.moveDown();
  1050. };
  1051. del.onclick=e=>{
  1052. this.del();
  1053. };
  1054. this.item.appendChild(up);
  1055. this.item.appendChild(down);
  1056. this.item.appendChild(del);
  1057. this.item.appendChild(url);
  1058. configCon.insertBefore(this.item, insertPos);
  1059. }
  1060. saveSort(){
  1061. let sort=[];
  1062. [].forEach.call(this.item.parentNode.querySelectorAll("p[data-id]"), i=>{
  1063. sort.push(i.dataset.id);
  1064. });
  1065. rulesData.sort=sort;
  1066. storage.setItem("rulesData", rulesData);
  1067. }
  1068. moveUp(){
  1069. let preE=this.item.previousElementSibling;
  1070. if(preE.tagName=="P" && preE.children.length>1){
  1071. this.item.parentNode.insertBefore(this.item,preE);
  1072. this.saveSort();
  1073. }
  1074. }
  1075. moveDown(){
  1076. let nextE=this.item.nextElementSibling;
  1077. if(nextE.tagName=="P" && nextE.children.length>1){
  1078. this.item.parentNode.insertBefore(nextE,this.item);
  1079. this.saveSort();
  1080. }
  1081. }
  1082. del(){
  1083. if(this.ruleUrl.id<2){
  1084. alert(i18n("cantDel"));
  1085. }else if(window.confirm(i18n("confirmDel"))){
  1086. for(let u=0;u<rulesData.urls.length;u++){
  1087. if(this.ruleUrl.id==rulesData.urls[u].id){
  1088. rulesData.urls.splice(u,1);
  1089. break;
  1090. }
  1091. }
  1092. for(let u=0;u<rulesData.sort.length;u++){
  1093. if(this.ruleUrl.id==rulesData.sort[u]){
  1094. rulesData.sort.splice(u,1);
  1095. break;
  1096. }
  1097. }
  1098. storage.setItem("rulesData", rulesData);
  1099. ruleParser.rules=ruleParser.rules.filter(item=>{return item.from!=this.ruleUrl.id});
  1100. storage.setItem("rules", ruleParser.rules);
  1101. this.item.parentNode.removeChild(this.item);
  1102. //location.reload();
  1103. }
  1104. }
  1105. }
  1106. let updateP=document.createElement("p"),i=0;
  1107. let now=new Date().getTime(),inUpdate=false;
  1108.  
  1109.  
  1110. let pastDate=(new Date(updateDate)).toString(),passStr;
  1111. let passTime=(now-updateDate)/1000;
  1112. if(passTime<60){
  1113. passStr=i18n("passSec", passTime);
  1114. }else if(passTime<60*60){
  1115. passStr=i18n("passMin", parseInt(passTime/60));
  1116. }else if(passTime<60*60*24){
  1117. passStr=i18n("passHour", parseInt(passTime/3600));
  1118. }else{
  1119. passStr=i18n("passDay", parseInt(passTime/86400));
  1120. }
  1121.  
  1122.  
  1123. updateP.className="updateDate";
  1124. updateP.innerHTML=passStr;
  1125. updateP.title=i18n("update")+" - "+pastDate;
  1126. updateP.onclick=e=>{
  1127. if(inUpdate)return;
  1128. inUpdate=true;
  1129. let ruleIndex=0;
  1130. storage.setItem("hpRules", []);
  1131. function addNextRule(){
  1132. if(ruleIndex>=ruleUrls.length){
  1133. storage.setItem("ruleLastUpdate", now);
  1134. alert(i18n("updateSucc"));
  1135. inUpdate=false;
  1136. updateP.innerHTML=i18n("passSec", 0);
  1137. updateP.title=i18n("update");
  1138. }else{
  1139. let rule=ruleUrls[ruleIndex++];
  1140. ruleParser.addRuleByUrl(rule.url, rule.type, rule.id, ()=>{
  1141. addNextRule();
  1142. })
  1143. }
  1144. }
  1145. addNextRule();
  1146. alert(i18n("beginUpdate"));
  1147. };
  1148. configCon.insertBefore(updateP, insertPos);
  1149. if(ruleUrls){
  1150. ruleUrls.forEach(ruleUrl=>{
  1151. var rulebar=new Rulebar();
  1152. rulebar.init(ruleUrl);
  1153. });
  1154. }
  1155. let customUrlsTitle=document.createElement("h2");
  1156. customUrlsTitle.innerHTML=i18n("customUrls");
  1157. configCon.insertBefore(customUrlsTitle, insertPos);
  1158. let customUrlsInput=document.createElement("textarea");
  1159. customUrlsInput.style.width="100%";
  1160. customUrlsInput.placeholder="0|http://wedata.net/databases/AutoPagerize/items_all.json";
  1161. configCon.insertBefore(customUrlsInput, insertPos);
  1162.  
  1163. let opacityTitle=document.createElement("h2");
  1164. opacityTitle.innerHTML=i18n("opacity");
  1165. let opacityInput=document.createElement("input");
  1166. opacityInput.value=rulesData.opacity*100;
  1167. opacityInput.type="number";
  1168. opacityInput.style.width="50px";
  1169. opacityInput.style.margin="0 0 0 10px";
  1170. opacityTitle.appendChild(opacityInput);
  1171. configCon.insertBefore(opacityTitle, insertPos);
  1172.  
  1173.  
  1174. let hideBarTitle=document.createElement("h2");
  1175. hideBarTitle.innerHTML=i18n("hideBar");
  1176. let hideBarInput=document.createElement("input");
  1177. hideBarInput.type="checkbox";
  1178. hideBarInput.style.width="50px";
  1179. hideBarInput.style.height="20px";
  1180. hideBarInput.checked=rulesData.hideBar;
  1181. hideBarTitle.appendChild(hideBarInput);
  1182. configCon.insertBefore(hideBarTitle, insertPos);
  1183.  
  1184. let customRulesTitle=document.createElement("h2");
  1185. customRulesTitle.innerHTML=i18n("customRules")
  1186. configCon.insertBefore(customRulesTitle, insertPos);
  1187. let customRulesInput=document.createElement("textarea");
  1188. customRulesInput.style.width="100%";
  1189. customRulesInput.style.height="500px";
  1190. 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]`;
  1191. customRulesInput.value=getFormatJSON(ruleParser.customRules);
  1192. configCon.insertBefore(customRulesInput, insertPos);
  1193. let saveBtn=document.createElement("button");
  1194. saveBtn.innerHTML=i18n("save");
  1195. saveBtn.style.width="100%";
  1196. configCon.insertBefore(saveBtn, insertPos);
  1197. saveBtn.onclick=e=>{
  1198. try{
  1199. storage.setItem("hpRules", []);
  1200. if(customRulesInput.value==""){
  1201. storage.setItem("customRules", "");
  1202. }else{
  1203. let customRules=JSON.parse(customRulesInput.value);
  1204. debug(customRules);
  1205. storage.setItem("customRules", customRules);
  1206. }
  1207. }catch(e){
  1208. debug(e);
  1209. alert("JSON error, check again!");
  1210. return;
  1211. }
  1212. rulesData.opacity=opacityInput.value/100;
  1213. rulesData.hideBar=hideBarInput.checked;
  1214. storage.setItem("rulesData", rulesData);
  1215. let customUrls=customUrlsInput.value.trim();
  1216. if(customUrls){
  1217. customUrls=customUrls.split(/\n/);
  1218. for(let c=0;c<customUrls.length;c++){
  1219. let urlArr=customUrls[c].split("|"),url,type=1;
  1220. if(urlArr.length==1){
  1221. url=urlArr[0].trim();
  1222. if(!/^http/.test(url)){
  1223. alert("Wrong url, check again!");
  1224. return;
  1225. }
  1226. }else if(urlArr.length==2){
  1227. type=urlArr[0].trim();
  1228. url=urlArr[1].trim();
  1229. if(!/^http/.test(url)){
  1230. alert("Wrong url, check again!");
  1231. return;
  1232. }
  1233. }else{
  1234. break;
  1235. }
  1236. let maxId=0,hasUrl=false;;
  1237. if(!rulesData.urls){
  1238. rulesData.urls=[];
  1239. maxId=1;
  1240. }else{
  1241. rulesData.urls.forEach(u=>{
  1242. if(maxId<u.id){
  1243. maxId=u.id;
  1244. }
  1245. if(u.url==url){
  1246. hasUrl=true;
  1247. }
  1248. });
  1249. if(hasUrl)break;
  1250. }
  1251. rulesData.urls.push({id:maxId+1,url:url,type:type});
  1252. rulesData.sort.push(maxId+1);
  1253. storage.setItem("rulesData", rulesData);
  1254. }
  1255. }
  1256. alert("Modified successfully");
  1257. location.reload();
  1258. };
  1259. }
  1260.  
  1261. function objIsArr(obj) {
  1262. return obj &&
  1263. typeof obj === 'object' &&
  1264. typeof obj.length === 'number' &&
  1265. !(obj.propertyIsEnumerable('length'));
  1266. }
  1267.  
  1268. function getFormatJSON(obj){
  1269. if(!objIsArr(obj))return "";
  1270. let ret="[\n";
  1271. let len=obj.length,i=0,isLast;
  1272. obj.forEach(item=>{
  1273. ret+=" {\n";
  1274. let iLen=Object.keys(item).length,j=0;
  1275. for(let key in item){
  1276. isLast=(++j)==iLen;
  1277. let value=item[key];
  1278. if(objIsArr(value)){
  1279. let vstr="[",v=0,vIsLast=false;
  1280. value.forEach(vi=>{
  1281. vIsLast=(++v)==value.length;
  1282. vstr+="\""+vi.replace(/\\/g,"\\\\")+"\""+(vIsLast?"":",");
  1283. });
  1284. vstr+="]";
  1285. ret+=" \""+key+"\":"+vstr+""+(isLast?"":",")+"\n";
  1286. }else{
  1287. if(typeof value=="string"){
  1288. value=value.replace(/\\/g,"\\\\");
  1289. }
  1290. ret+=" \""+key+"\":\""+value+"\""+(isLast?"":",")+"\n";
  1291. }
  1292. }
  1293. isLast=(++i)==len;
  1294. ret+=" }"+(isLast?"":",")+"\n";
  1295. });
  1296. ret+="]";
  1297. return ret;
  1298. }
  1299.  
  1300. function initRules(callback) {
  1301. /*0 wedata格式,1 pagetual格式*/
  1302. ruleUrls=[
  1303. {
  1304. id:0,
  1305. url:'https://raw.githubusercontent.com/hoothin/UserScripts/master/Pagetual/pagetualRules.json',
  1306. type:1
  1307. },
  1308. {
  1309. id:1,
  1310. url:'http://wedata.net/databases/AutoPagerize/items_all.json',
  1311. type:0,
  1312. }
  1313. ];var i=0,j=0;
  1314.  
  1315. ruleParser.initSavedRules(()=>{
  1316. storage.getItem("rulesData", data=>{
  1317. if(data){
  1318. rulesData=data;
  1319. if(data.urls)ruleUrls=ruleUrls.concat(data.urls);
  1320. if(data.sort){
  1321. let urls=[];
  1322. data.sort.forEach(id=>{
  1323. for(let s=0;s<ruleUrls.length;s++){
  1324. if(id==ruleUrls[s].id){
  1325. urls.push(ruleUrls[s]);
  1326. break;
  1327. }
  1328. }
  1329. });
  1330. ruleUrls=urls;
  1331. }
  1332. }
  1333. if(typeof(rulesData.opacity)=="undefined"){
  1334. rulesData.opacity=0.3;
  1335. }
  1336. if(typeof(rulesData.hideBar)=="undefined"){
  1337. rulesData.hideBar=true;
  1338. }
  1339. storage.getItem("forceState_"+location.host, v=>{
  1340. storage.getItem("ruleLastUpdate", date=>{
  1341. forceState=v||0;
  1342. updateDate=date;
  1343. initConfig();
  1344. if(forceState==1)return;
  1345. let now=new Date().getTime();
  1346. if(!date || now-date>2*24*60*60*1000){
  1347. storage.setItem("ruleLastUpdate", now);
  1348. storage.setItem("hpRules", []);
  1349. let ruleIndex=0;
  1350. function addNextRule(){
  1351. if(ruleIndex>=ruleUrls.length){
  1352. callback();
  1353. }else{
  1354. let rule=ruleUrls[ruleIndex++];
  1355. ruleParser.addRuleByUrl(rule.url, rule.type, rule.id, ()=>{
  1356. addNextRule();
  1357. })
  1358. }
  1359. }
  1360. addNextRule();
  1361. }else{
  1362. callback();
  1363. }
  1364. });
  1365. });
  1366. });
  1367. });
  1368. }
  1369.  
  1370. function requestDoc(url, callback){
  1371. _GM_xmlhttpRequest({
  1372. url: url,
  1373. method: 'GET',
  1374. overrideMimeType:"text/html;charset="+document.charset,
  1375. onload: function(res) {
  1376. var doc=null;
  1377. try {
  1378. doc=document.implementation.createHTMLDocument('');
  1379. doc.documentElement.innerHTML=res.response;
  1380. }
  1381. catch (e) {
  1382. debug('parse error'+e.toString());
  1383. }
  1384. let pageElement=ruleParser.getPageElement(doc);
  1385. //只有1的話怕不是圖片哦
  1386. if(pageElement && (pageElement.length>1 || (pageElement.length==1 && pageElement[0].tagName!="IMG") )){
  1387. let result=ruleParser.insertPage(doc, pageElement, url, callback, false);
  1388. if(!result){
  1389. requestFromIframe(url, (doc, eles)=>{
  1390. if(eles){
  1391. ruleParser.insertPage(doc, eles, url, callback, true);
  1392. }
  1393. });
  1394. }
  1395. }else if(ruleParser.curSiteRule.singleUrl){
  1396. requestFromIframe(url, (doc, eles)=>{
  1397. if(eles){
  1398. ruleParser.insertPage(doc, eles, url, callback, true);
  1399. }
  1400. });
  1401. }
  1402. },
  1403. onerror: function(e){
  1404. debug(e);
  1405. callback(false);
  1406. }
  1407. });
  1408. }
  1409.  
  1410. var failFromIframe=0;
  1411. function requestFromIframe(url, callback){
  1412. let orgPage,curPage;
  1413. let iframe = document.createElement('iframe');
  1414. iframe.name = 'pagetual-iframe';
  1415. iframe.width = '100%';
  1416. iframe.height = '0';
  1417. iframe.frameBorder = '0';
  1418. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1419. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1420. iframe.addEventListener("load", e=>{
  1421. setTimeout(()=>{
  1422. let tryTimes=0;
  1423. function checkIframe(){
  1424. try{
  1425. let doc=iframe.contentDocument || iframe.contentWindow.document;
  1426. let eles=ruleParser.getPageElement(doc, iframe.contentWindow);
  1427. if(eles && eles.length>0){
  1428. callback(doc, eles);
  1429. }else if(tryTimes++ < 2){
  1430. setTimeout(()=>{
  1431. checkIframe();
  1432. },500);
  1433. return;
  1434. }else{
  1435. if(failFromIframe++ > 2){
  1436. failFromIframe=0;
  1437. isPause=true;
  1438. callback(false, false);
  1439. }else{
  1440. callback(false, false);
  1441. }
  1442. }
  1443. }catch(e){
  1444. isPause=true;
  1445. callback(false, false);
  1446. }
  1447. document.body.removeChild(iframe);
  1448. }
  1449. checkIframe();
  1450. },300);
  1451. });
  1452. iframe.src=url;
  1453. document.body.appendChild(iframe);
  1454. }
  1455.  
  1456. function initPage(){
  1457. ruleParser.initPage(()=>{
  1458. initListener();
  1459. nextPage();
  1460. });
  1461. }
  1462.  
  1463. function initView(){
  1464. _GM_addStyle(`
  1465. .pagetual_pageBar.stop {
  1466. -webkit-filter: invert(100%);
  1467. filter: invert(100%);
  1468. opacity: 1!important;
  1469. }
  1470. .pagetual_pageBar.hide {
  1471. display: none!important;
  1472. }
  1473. .pagetual_pageBar:hover {
  1474. opacity: 1!important;
  1475. }
  1476. .pagetual_pageBar>span {
  1477. vertical-align: super;
  1478. }
  1479.  
  1480. .pagetual_pageBar>span>svg:hover {
  1481. animation: touhouAni 1s infinite;
  1482. }
  1483.  
  1484. @keyframes touhouAni{
  1485. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  1486. to {transform: rotate(360deg);}
  1487. }
  1488. @-webkit-keyframes touhouAni{
  1489. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  1490. to {transform: rotate(360deg);}
  1491. }
  1492. `);
  1493. 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;`;
  1494. }
  1495. var loading=document.createElement("div");
  1496. 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;";
  1497. 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>`;
  1498. document.body.appendChild(loading);
  1499.  
  1500. 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>`;
  1501. 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>`;
  1502. var pageBarStyle;
  1503. 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;`;
  1504. 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);`;
  1505.  
  1506. var isPause=false,isLoading=false,curPage=1,forceState=0,bottomGap=1000;
  1507.  
  1508. function changeStop(stop, hide){
  1509. isPause=stop;
  1510. [].forEach.call(document.querySelectorAll(".pagetual_pageBar"), bar=>{
  1511. if(isPause){
  1512. bar.classList.add("stop");
  1513. if(hide)bar.classList.add("hide");
  1514. }else{
  1515. bar.classList.remove("stop");
  1516. if(hide)bar.classList.remove("hide");
  1517. }
  1518. });
  1519. }
  1520.  
  1521. function isInViewPort(element) {
  1522. const viewWidth = window.innerWidth || document.documentElement.clientWidth;
  1523. const viewHeight = window.innerHeight || document.documentElement.clientHeight;
  1524. const {
  1525. top,
  1526. right,
  1527. bottom,
  1528. left,
  1529. } = element.getBoundingClientRect();
  1530.  
  1531. return (
  1532. top >= 0 &&
  1533. left >= 0 &&
  1534. right <= viewWidth &&
  1535. bottom <= viewHeight
  1536. );
  1537. }
  1538.  
  1539. function initListener(){
  1540. var urlChanged=false;
  1541. var _wr = function(type) {
  1542. var orig = history[type];
  1543. return function() {
  1544. var rv = orig.apply(this, arguments);
  1545. var e = new Event(type);
  1546. e.arguments = arguments;
  1547. window.dispatchEvent(e);
  1548. return rv;
  1549. };
  1550. };
  1551. history.pushState = _wr('pushState');
  1552. window.addEventListener('pushState', function(e) {
  1553. urlChanged=true;
  1554. });
  1555. let loadmoreBtn,buttons=document.querySelectorAll("input,button,a"),loadmoreReg=/^\s*(加载更多|加載更多|load\s*more|もっと読み込む)\s*$/i,loading=true;
  1556. for(let i=0;i<buttons.length;i++){
  1557. let button=buttons[i];
  1558. if(button && loadmoreReg.test(button.innerText)){
  1559. loadmoreBtn=button;
  1560. loadmoreBtn.click();
  1561. break;
  1562. }
  1563. }
  1564. if(loadmoreBtn)setTimeout(()=>{loading=false},2000);
  1565. document.addEventListener('scroll', e=>{
  1566. if(urlChanged){
  1567. ruleParser.initPage(()=>{});
  1568. initView();
  1569. urlChanged=false;
  1570. }
  1571. if(!loading && loadmoreBtn && isInViewPort(loadmoreBtn)){
  1572. loadmoreBtn.click();
  1573. loading=true;
  1574. setTimeout(()=>{loading=false},2000);
  1575. }
  1576. setTimeout(()=>{
  1577. if(!isPause && !isLoading){
  1578. let scrolly=window.scrollY;
  1579. let windowHeight=window.innerHeight;
  1580. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  1581. if(scrollH-scrolly-windowHeight<bottomGap){
  1582. nextPage();
  1583. }
  1584. }
  1585. },100);
  1586. }, true);
  1587. document.addEventListener('dblclick', e=>{
  1588. setTimeout(()=>{
  1589. changeStop(!isPause, rulesData.hideBar);
  1590. if(!isPause){
  1591. nextPage();
  1592. }
  1593. },200);
  1594. });
  1595. }
  1596.  
  1597. function createPageBar(url){
  1598. let insert=ruleParser.getInsert();
  1599. if(!insert || !insert.parentNode)return;
  1600. curPage++;
  1601. let inTable=insert.tagName=="TR" ||
  1602. (insert.previousElementSibling && insert.previousElementSibling.tagName=="TR") ||
  1603. insert.tagName=="TBODY" || (insert.previousElementSibling && insert.previousElementSibling.tagName=="TBODY");
  1604. let inLi=insert.tagName=="LI" || (insert.previousElementSibling && insert.previousElementSibling.tagName=="LI");
  1605. let pageBar=document.createElement(inTable?"tr":"div");
  1606. let upSpan=document.createElement("span");
  1607. let downSpan=document.createElement("span");
  1608. let pageText=document.createElement("a");
  1609. pageBar.className="pagetual_pageBar";
  1610. pageBar.id="pagetual_pageBar";
  1611. if(isPause){
  1612. pageBar.classList.add("stop");
  1613. }
  1614. pageBar.style.cssText=pageBarStyle;
  1615. pageBar.title=i18n(isPause?"enable":"disable");
  1616. upSpan.innerHTML=upSvg;
  1617. upSpan.title=i18n("toTop");
  1618. downSpan.innerHTML=downSvg;
  1619. downSpan.title=i18n("toBottom");
  1620. upSpan.style.cssText=initStyle;
  1621. downSpan.style.cssText=initStyle;
  1622. pageText.href=url;
  1623. pageText.style=pageTextStyle;
  1624. pageText.innerHTML="Page "+curPage;
  1625. pageText.title=i18n("current");
  1626. pageBar.appendChild(upSpan);
  1627. pageBar.appendChild(pageText);
  1628. pageBar.appendChild(downSpan);
  1629. if(inTable){
  1630. let example=(insert.tagName=="TR" || insert.tagName=="TBODY")?insert:insert.previousElementSibling;
  1631. let tdNum=example.tagName=="TR"?example.children.length:example.querySelector("tr").children.length;
  1632. pageBar.style.display="table-row";
  1633. let td=document.createElement("td");
  1634. td.colSpan=tdNum;
  1635. td.style.textAlign="center";
  1636. td.appendChild(upSpan);
  1637. td.appendChild(pageText);
  1638. td.appendChild(downSpan);
  1639. pageBar.appendChild(td);
  1640. }
  1641.  
  1642. upSpan.addEventListener("click", e=>{
  1643. changeStop(true);
  1644. pageBar.title=i18n(isPause?"enable":"disable");
  1645. document.body.scrollTop=0;
  1646. document.documentElement.scrollTop=0;
  1647. e.preventDefault();
  1648. e.stopPropagation();
  1649. });
  1650. downSpan.addEventListener("click", e=>{
  1651. changeStop(true);
  1652. pageBar.title=i18n(isPause?"enable":"disable");
  1653. document.body.scrollTop=9999999;
  1654. document.documentElement.scrollTop=9999999;
  1655. e.preventDefault();
  1656. e.stopPropagation();
  1657. });
  1658. pageBar.addEventListener("click", e=>{
  1659. changeStop(!isPause);
  1660. pageBar.title=i18n(isPause?"enable":"disable");
  1661. });
  1662. pageText.addEventListener("click", e=>{
  1663. e.stopPropagation();
  1664. });
  1665. pageBar.style.width=parseInt(_unsafeWindow.getComputedStyle(insert.parentNode).width)*.99+"px";
  1666. if(inLi){
  1667. pageBar.style.width="90%";
  1668. pageBar.style.minWidth="150px";
  1669. pageBar.style.display="inline-block";
  1670. let line=document.createElement("li");
  1671. line.appendChild(pageBar);
  1672. if(ruleParser.curSiteRule.insertPos==2){
  1673. insert.appendChild(line);
  1674. }else{
  1675. insert.parentNode.insertBefore(line, insert);
  1676. }
  1677. }else{
  1678. if(ruleParser.curSiteRule.insertPos==2){
  1679. insert.appendChild(pageBar);
  1680. }else{
  1681. insert.parentNode.insertBefore(pageBar, insert);
  1682. }
  1683. }
  1684.  
  1685. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  1686. let actualTop = pageBar.offsetTop;
  1687. let current = pageBar.parentNode.offsetParent;
  1688. while (current !== null){
  1689. actualTop += current.offsetTop;
  1690. current = current.offsetParent;
  1691. }
  1692. bottomGap=scrollH-actualTop+800;
  1693. return pageBar;
  1694. }
  1695.  
  1696. var emuIframe;
  1697. function emuPage(callback){
  1698. let orgPage,curPage,iframeDoc,times=0;
  1699. function checkPage(){
  1700. if(isPause)return;
  1701. try{
  1702. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  1703. }catch(e){
  1704. isPause=true;
  1705. callback(false, false);
  1706. return;
  1707. }
  1708. if(!orgPage){
  1709. orgPage=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true);
  1710. if(orgPage)orgPage=orgPage[0];
  1711. let nextLink=ruleParser.getNextLink(iframeDoc);
  1712. if(orgPage && nextLink){
  1713. let display=iframeDoc.defaultView.getComputedStyle(nextLink).display;
  1714. if(display=="none"){
  1715. isPause=true;
  1716. callback(false, false);
  1717. }else{
  1718. nextLink.click();
  1719. setTimeout(()=>{
  1720. checkPage();
  1721. },500);
  1722. }
  1723. }else{
  1724. isPause=true;
  1725. callback(false, false);
  1726. }
  1727. return;
  1728. }
  1729. if(times++ > 10){
  1730. isPause=true;
  1731. callback(false, false);
  1732. return;
  1733. }
  1734. let eles=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true);
  1735. if(!eles || eles.length==0 || orgPage == eles[0]){
  1736. setTimeout(()=>{
  1737. checkPage();
  1738. },500);
  1739. }else{
  1740. callback(iframeDoc, eles);
  1741. }
  1742. }
  1743. if(!emuIframe){
  1744. emuIframe = document.createElement('iframe');
  1745. emuIframe.name = 'pagetual-iframe';
  1746. emuIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1747. emuIframe.width = '100%';
  1748. emuIframe.height = '0';
  1749. emuIframe.frameBorder = '0';
  1750. emuIframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1751. emuIframe.addEventListener("load", e=>{
  1752. setTimeout(()=>{
  1753. checkPage();
  1754. },300);
  1755. });
  1756. emuIframe.src=location.href;
  1757. document.body.appendChild(emuIframe);
  1758. }else{
  1759. checkPage();
  1760. }
  1761. }
  1762.  
  1763. function forceIframe(url, callback){
  1764. let curIframe = document.createElement('iframe');
  1765. curIframe.name = 'pagetual-iframe';
  1766. curIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1767. curIframe.frameBorder = '0';
  1768. curIframe.scrolling="no";
  1769. 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;';
  1770. curIframe.addEventListener("load", e=>{
  1771. let iframeDoc;
  1772. try{
  1773. iframeDoc=curIframe.contentDocument || curIframe.contentWindow.document;
  1774. }catch(e){
  1775. isPause=true;
  1776. callback(false, false);
  1777. return;
  1778. }
  1779. ruleParser.insertPage(iframeDoc, [], url, null, true);
  1780. callback(curIframe, true);
  1781. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  1782. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  1783. setTimeout(()=>{
  1784. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  1785. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  1786. },300);
  1787. });
  1788. curIframe.src=url;
  1789. let insert=ruleParser.getInsert();
  1790. document.body.insertBefore(curIframe, loading);
  1791. return curIframe;
  1792. }
  1793.  
  1794. function nextPage(){
  1795. if(isPause || isLoading)return;
  1796. let nextLink=ruleParser.nextLinkHref;
  1797. let insert;
  1798. if(nextLink)insert=ruleParser.getInsert();
  1799. if(nextLink && insert){
  1800. let isJs=/^(javascript|#)/.test(nextLink.replace(location.href,""));
  1801. if(location.protocol=="https:" && /^http:/.test(nextLink)){
  1802. nextLink=nextLink.replace(/^http/,"https");
  1803. }
  1804. isLoading=true;
  1805. loading.style.display="";
  1806. if(ruleParser.curSiteRule.pageElementByJs){
  1807. var over=ele=>{
  1808. isLoading=false;
  1809. loading.style.display="none";
  1810. if(ele){
  1811. createPageBar(nextLink);
  1812. ruleParser.insertPage(null, ele, nextLink, null, true);
  1813. }else{
  1814. isPause=true;
  1815. }
  1816. };
  1817. try{
  1818. Function("over",'"use strict";' + ruleParser.curSiteRule.pageElementByJs)(over);
  1819. }catch(e){}
  1820. }else if(ruleParser.curSiteRule.action==1 && !isJs){
  1821. requestFromIframe(nextLink, (doc, eles)=>{
  1822. isLoading=false;
  1823. loading.style.display="none";
  1824. if(eles){
  1825. createPageBar(nextLink);
  1826. ruleParser.insertPage(doc, eles, nextLink, null, true);
  1827. }
  1828. });
  1829. }else if(forceState==2 && !isJs){
  1830. forceIframe(nextLink, (iframe, eles)=>{
  1831. isLoading=false;
  1832. loading.style.display="none";
  1833. let pageBar=createPageBar(nextLink);
  1834. iframe.parentNode.insertBefore(pageBar, iframe);
  1835. });
  1836. }else{
  1837. if(!isJs){
  1838. requestDoc(nextLink, (eles)=>{
  1839. isLoading=false;
  1840. loading.style.display="none";
  1841. if(eles){
  1842. createPageBar(nextLink);
  1843. }
  1844. });
  1845. }else{
  1846. emuPage((doc, eles)=>{
  1847. isLoading=false;
  1848. loading.style.display="none";
  1849. if(eles){
  1850. createPageBar(nextLink);
  1851. ruleParser.insertPage(doc, eles, "", null, true);
  1852. }
  1853. });
  1854. }
  1855. }
  1856. }
  1857. }
  1858.  
  1859. function init(){
  1860. initRules(()=>{
  1861. initView();
  1862. initPage();
  1863. });
  1864. }
  1865. setTimeout(()=>{
  1866. init();
  1867. },300);
  1868. })();

QingJ © 2025

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