东方永页机

自动翻页

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