东方永页机

自动翻页

目前为 2022-02-10 提交的版本,查看 最新版本

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