东方永页机

自动翻页

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

  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.23
  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. debug("Stop as rule disable");
  957. isPause=true;
  958. return;
  959. }
  960. if(self.curSiteRule && !self.curSiteRule.singleUrl){
  961. self.hpRules=self.hpRules.filter(item=>{return item&&item.url!=self.curSiteRule.url});
  962. self.hpRules.unshift(self.curSiteRule);
  963. if(self.hpRules.length>30){
  964. self.hpRules.pop();
  965. }
  966. storage.setItem("hpRules", self.hpRules);
  967. }
  968. let css=self.curSiteRule.css;
  969. if(css){
  970. _GM_addStyle(css);
  971. }
  972. let code=self.curSiteRule.init;
  973. if(code){
  974. try{
  975. Function('"use strict";' + code)();
  976. }catch(e){}
  977. }
  978. self.getNextLink(document);
  979. callback();
  980. });
  981. }
  982.  
  983. insertPage(doc, eles, url, callback, tried){
  984. this.pageDoc=doc;
  985. this.curUrl=url;
  986. this.pageAction(doc, eles);
  987. let nextLink=this.getNextLink(doc);
  988. if(curPage==1 && !tried && !this.nextLinkHref && this.curSiteRule.singleUrl && this.curSiteRule.pageElement){
  989. this.curSiteRule.action=1;
  990. return false;
  991. }
  992. if(callback)callback(eles);
  993. this.getInsert();
  994. var self=this;
  995. if(!eles || eles.length==0 || !self.insert || !self.insert.parentNode){
  996. }else{
  997. [].forEach.call(eles, ele=>{
  998. let newEle=ele.cloneNode(true);
  999. let oldCanvass=ele.querySelectorAll("canvas");
  1000. let newCanvass=newEle.querySelectorAll("canvas");
  1001. for(let i=0;i<oldCanvass.length;i++){
  1002. let oldCanvas=oldCanvass[i];
  1003. let newCanvas=newCanvass[i];
  1004. newCanvas.getContext('2d').drawImage(oldCanvas, 0, 0);
  1005. }
  1006. if(self.curSiteRule.insertPos==2){
  1007. self.insert.appendChild(newEle);
  1008. }else{
  1009. self.insert.parentNode.insertBefore(newEle, self.insert);
  1010. }
  1011. });
  1012. }
  1013. if(nextLink.tagName){
  1014. let nextLinkCs=_unsafeWindow.getComputedStyle(nextLink);
  1015. if(nextLinkCs.cursor=="not-allowed" || !isVisible(nextLink, _unsafeWindow)){
  1016. self.nextLinkHref=false;
  1017. }
  1018. }
  1019. return true;
  1020. }
  1021. }
  1022. var ruleParser = new RuleParser();
  1023.  
  1024. var rulesData={},ruleUrls,updateDate;
  1025. function initConfig(){
  1026. _GM_registerMenuCommand(i18n(forceState==1?"enable":"disableSite"), ()=>{
  1027. storage.setItem("forceState_"+location.host, (forceState==1?"":1));
  1028. location.reload();
  1029. });
  1030.  
  1031. _GM_registerMenuCommand(i18n(forceState==2?"cancelForceIframe":"forceIframe"), ()=>{
  1032. storage.setItem("forceState_"+location.host, (forceState==2?"":2));
  1033. location.reload();
  1034. });
  1035. var configCon,insertPos;
  1036. if(location.href=="https://github.com/hoothin/UserScripts/tree/master/Pagetual"){
  1037. _GM_addStyle(`
  1038. p>span:nth-child(1),p>span:nth-child(2),p>span:nth-child(3){
  1039. cursor: pointer;
  1040. user-select: none;
  1041. }
  1042. p>span:nth-child(1):hover,p>span:nth-child(2):hover,p>span:nth-child(3):hover{
  1043. color:red;
  1044. }
  1045. .updateDate{
  1046. cursor: pointer;
  1047. user-select: none;
  1048. }
  1049. .updateDate:hover{
  1050. color:red;
  1051. }
  1052. `);
  1053. configCon=document.querySelector(".markdown-body");
  1054. insertPos=configCon.querySelector("hr");
  1055. }else if(location.href=="https://github.com/hoothin/UserScripts/tree/master/Pagetual"){
  1056. }else return;
  1057. class Rulebar {
  1058. init(ruleUrl){
  1059. this.ruleUrl=ruleUrl;
  1060. this.item=document.createElement("p");
  1061. this.item.title=ruleUrl.type==0?"AutoPagerize Rules":"Pagetual Rules";
  1062. this.item.dataset.id=this.ruleUrl.id;
  1063. let url=document.createElement("span");
  1064. url.innerHTML=ruleUrl.url;
  1065. let up=document.createElement("span");
  1066. up.innerHTML="↑ ";
  1067. up.title=i18n("sortTitle");
  1068. let down=document.createElement("span");
  1069. down.innerHTML="↓ ";
  1070. down.title=i18n("sortTitle");
  1071. let del=document.createElement("span");
  1072. del.innerHTML="× ";
  1073. up.onclick=e=>{
  1074. this.moveUp();
  1075. };
  1076. down.onclick=e=>{
  1077. this.moveDown();
  1078. };
  1079. del.onclick=e=>{
  1080. this.del();
  1081. };
  1082. this.item.appendChild(up);
  1083. this.item.appendChild(down);
  1084. this.item.appendChild(del);
  1085. this.item.appendChild(url);
  1086. configCon.insertBefore(this.item, insertPos);
  1087. }
  1088. saveSort(){
  1089. let sort=[];
  1090. [].forEach.call(this.item.parentNode.querySelectorAll("p[data-id]"), i=>{
  1091. sort.push(i.dataset.id);
  1092. });
  1093. rulesData.sort=sort;
  1094. storage.setItem("rulesData", rulesData);
  1095. }
  1096. moveUp(){
  1097. let preE=this.item.previousElementSibling;
  1098. if(preE.tagName=="P" && preE.children.length>1){
  1099. this.item.parentNode.insertBefore(this.item,preE);
  1100. this.saveSort();
  1101. }
  1102. }
  1103. moveDown(){
  1104. let nextE=this.item.nextElementSibling;
  1105. if(nextE.tagName=="P" && nextE.children.length>1){
  1106. this.item.parentNode.insertBefore(nextE,this.item);
  1107. this.saveSort();
  1108. }
  1109. }
  1110. del(){
  1111. if(this.ruleUrl.id<2){
  1112. alert(i18n("cantDel"));
  1113. }else if(window.confirm(i18n("confirmDel"))){
  1114. for(let u=0;u<rulesData.urls.length;u++){
  1115. if(this.ruleUrl.id==rulesData.urls[u].id){
  1116. rulesData.urls.splice(u,1);
  1117. break;
  1118. }
  1119. }
  1120. for(let u=0;u<rulesData.sort.length;u++){
  1121. if(this.ruleUrl.id==rulesData.sort[u]){
  1122. rulesData.sort.splice(u,1);
  1123. break;
  1124. }
  1125. }
  1126. storage.setItem("rulesData", rulesData);
  1127. ruleParser.rules=ruleParser.rules.filter(item=>{return item.from!=this.ruleUrl.id});
  1128. storage.setItem("rules", ruleParser.rules);
  1129. this.item.parentNode.removeChild(this.item);
  1130. //location.reload();
  1131. }
  1132. }
  1133. }
  1134. let updateP=document.createElement("p"),i=0;
  1135. let now=new Date().getTime(),inUpdate=false;
  1136.  
  1137.  
  1138. let pastDate=(new Date(updateDate)).toString(),passStr;
  1139. let passTime=(now-updateDate)/1000;
  1140. if(passTime<60){
  1141. passStr=i18n("passSec", passTime);
  1142. }else if(passTime<60*60){
  1143. passStr=i18n("passMin", parseInt(passTime/60));
  1144. }else if(passTime<60*60*24){
  1145. passStr=i18n("passHour", parseInt(passTime/3600));
  1146. }else{
  1147. passStr=i18n("passDay", parseInt(passTime/86400));
  1148. }
  1149.  
  1150.  
  1151. updateP.className="updateDate";
  1152. updateP.innerHTML=passStr;
  1153. updateP.title=i18n("update")+" - "+pastDate;
  1154. updateP.onclick=e=>{
  1155. if(inUpdate)return;
  1156. inUpdate=true;
  1157. let ruleIndex=0;
  1158. storage.setItem("hpRules", []);
  1159. function addNextRule(){
  1160. if(ruleIndex>=ruleUrls.length){
  1161. storage.setItem("ruleLastUpdate", now);
  1162. alert(i18n("updateSucc"));
  1163. inUpdate=false;
  1164. updateP.innerHTML=i18n("passSec", 0);
  1165. updateP.title=i18n("update");
  1166. }else{
  1167. let rule=ruleUrls[ruleIndex++];
  1168. ruleParser.addRuleByUrl(rule.url, rule.type, rule.id, ()=>{
  1169. addNextRule();
  1170. })
  1171. }
  1172. }
  1173. addNextRule();
  1174. alert(i18n("beginUpdate"));
  1175. };
  1176. configCon.insertBefore(updateP, insertPos);
  1177. if(ruleUrls){
  1178. ruleUrls.forEach(ruleUrl=>{
  1179. var rulebar=new Rulebar();
  1180. rulebar.init(ruleUrl);
  1181. });
  1182. }
  1183. let customUrlsTitle=document.createElement("h2");
  1184. customUrlsTitle.innerHTML=i18n("customUrls");
  1185. configCon.insertBefore(customUrlsTitle, insertPos);
  1186. let customUrlsInput=document.createElement("textarea");
  1187. customUrlsInput.style.width="100%";
  1188. customUrlsInput.placeholder="0|http://wedata.net/databases/AutoPagerize/items_all.json";
  1189. configCon.insertBefore(customUrlsInput, insertPos);
  1190.  
  1191. let opacityTitle=document.createElement("h2");
  1192. opacityTitle.innerHTML=i18n("opacity");
  1193. let opacityInput=document.createElement("input");
  1194. opacityInput.value=rulesData.opacity*100;
  1195. opacityInput.type="number";
  1196. opacityInput.style.width="50px";
  1197. opacityInput.style.margin="0 0 0 10px";
  1198. opacityTitle.appendChild(opacityInput);
  1199. configCon.insertBefore(opacityTitle, insertPos);
  1200.  
  1201.  
  1202. let hideBarTitle=document.createElement("h2");
  1203. hideBarTitle.innerHTML=i18n("hideBar");
  1204. let hideBarInput=document.createElement("input");
  1205. hideBarInput.type="checkbox";
  1206. hideBarInput.style.width="50px";
  1207. hideBarInput.style.height="20px";
  1208. hideBarInput.checked=rulesData.hideBar;
  1209. hideBarTitle.appendChild(hideBarInput);
  1210. configCon.insertBefore(hideBarTitle, insertPos);
  1211.  
  1212. let dbClick2StopTitle=document.createElement("h2");
  1213. dbClick2StopTitle.innerHTML=i18n("dbClick2Stop");
  1214. let dbClick2StopInput=document.createElement("input");
  1215. dbClick2StopInput.type="checkbox";
  1216. dbClick2StopInput.style.width="50px";
  1217. dbClick2StopInput.style.height="20px";
  1218. dbClick2StopInput.checked=rulesData.dbClick2Stop;
  1219. dbClick2StopTitle.appendChild(dbClick2StopInput);
  1220. configCon.insertBefore(dbClick2StopTitle, insertPos);
  1221.  
  1222. let customRulesTitle=document.createElement("h2");
  1223. customRulesTitle.innerHTML=i18n("customRules")
  1224. configCon.insertBefore(customRulesTitle, insertPos);
  1225. let customRulesInput=document.createElement("textarea");
  1226. customRulesInput.style.width="100%";
  1227. customRulesInput.style.height="500px";
  1228. 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]`;
  1229. customRulesInput.value=getFormatJSON(ruleParser.customRules);
  1230. configCon.insertBefore(customRulesInput, insertPos);
  1231. let saveBtn=document.createElement("button");
  1232. saveBtn.innerHTML=i18n("save");
  1233. saveBtn.style.width="100%";
  1234. configCon.insertBefore(saveBtn, insertPos);
  1235. saveBtn.onclick=e=>{
  1236. try{
  1237. storage.setItem("hpRules", []);
  1238. if(customRulesInput.value==""){
  1239. storage.setItem("customRules", "");
  1240. }else{
  1241. let customRules=JSON.parse(customRulesInput.value);
  1242. debug(customRules);
  1243. storage.setItem("customRules", customRules);
  1244. }
  1245. }catch(e){
  1246. debug(e);
  1247. alert("JSON error, check again!");
  1248. return;
  1249. }
  1250. rulesData.opacity=opacityInput.value/100;
  1251. rulesData.hideBar=hideBarInput.checked;
  1252. rulesData.dbClick2Stop=dbClick2StopInput.checked;
  1253. storage.setItem("rulesData", rulesData);
  1254. let customUrls=customUrlsInput.value.trim();
  1255. if(customUrls){
  1256. customUrls=customUrls.split(/\n/);
  1257. for(let c=0;c<customUrls.length;c++){
  1258. let urlArr=customUrls[c].split("|"),url,type=1;
  1259. if(urlArr.length==1){
  1260. url=urlArr[0].trim();
  1261. if(!/^http/.test(url)){
  1262. alert("Wrong url, check again!");
  1263. return;
  1264. }
  1265. }else if(urlArr.length==2){
  1266. type=urlArr[0].trim();
  1267. url=urlArr[1].trim();
  1268. if(!/^http/.test(url)){
  1269. alert("Wrong url, check again!");
  1270. return;
  1271. }
  1272. }else{
  1273. break;
  1274. }
  1275. let maxId=0,hasUrl=false;;
  1276. if(!rulesData.urls){
  1277. rulesData.urls=[];
  1278. maxId=1;
  1279. }else{
  1280. rulesData.urls.forEach(u=>{
  1281. if(maxId<u.id){
  1282. maxId=u.id;
  1283. }
  1284. if(u.url==url){
  1285. hasUrl=true;
  1286. }
  1287. });
  1288. if(hasUrl)break;
  1289. }
  1290. rulesData.urls.push({id:maxId+1,url:url,type:type});
  1291. rulesData.sort.push(maxId+1);
  1292. storage.setItem("rulesData", rulesData);
  1293. }
  1294. }
  1295. alert("Modified successfully");
  1296. location.reload();
  1297. };
  1298. }
  1299.  
  1300. function objIsArr(obj) {
  1301. return obj &&
  1302. typeof obj === 'object' &&
  1303. typeof obj.length === 'number' &&
  1304. !(obj.propertyIsEnumerable('length'));
  1305. }
  1306.  
  1307. function isVisible(el, win) {
  1308. var loopable = true,
  1309. visible = win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  1310. while(loopable && visible) {
  1311. el = el.parentNode;
  1312.  
  1313. if(el && el.tagName!="BODY") {
  1314. visible = win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  1315. }else {
  1316. loopable = false;
  1317. }
  1318. }
  1319. return visible;
  1320. }
  1321.  
  1322. function getFormatJSON(obj){
  1323. if(!objIsArr(obj))return "";
  1324. let ret="[\n";
  1325. let len=obj.length,i=0,isLast;
  1326. obj.forEach(item=>{
  1327. ret+=" {\n";
  1328. let iLen=Object.keys(item).length,j=0;
  1329. for(let key in item){
  1330. isLast=(++j)==iLen;
  1331. let value=item[key];
  1332. if(objIsArr(value)){
  1333. let vstr="[",v=0,vIsLast=false;
  1334. value.forEach(vi=>{
  1335. vIsLast=(++v)==value.length;
  1336. vstr+="\""+vi.replace(/\\/g,"\\\\")+"\""+(vIsLast?"":",");
  1337. });
  1338. vstr+="]";
  1339. ret+=" \""+key+"\":"+vstr+""+(isLast?"":",")+"\n";
  1340. }else{
  1341. if(typeof value=="string"){
  1342. value=value.replace(/\\/g,"\\\\").replace(/"/g,"\\\"");
  1343. value="\""+value+"\"";
  1344. }
  1345. ret+=" \""+key+"\":"+value+""+(isLast?"":",")+"\n";
  1346. }
  1347. }
  1348. isLast=(++i)==len;
  1349. ret+=" }"+(isLast?"":",")+"\n";
  1350. });
  1351. ret+="]";
  1352. return ret;
  1353. }
  1354.  
  1355. function initRules(callback) {
  1356. /*0 wedata格式,1 pagetual格式*/
  1357. ruleUrls=[
  1358. {
  1359. id:0,
  1360. url:'https://raw.githubusercontent.com/hoothin/UserScripts/master/Pagetual/pagetualRules.json',
  1361. type:1
  1362. },
  1363. {
  1364. id:1,
  1365. url:'http://wedata.net/databases/AutoPagerize/items_all.json',
  1366. type:0,
  1367. }
  1368. ];var i=0,j=0;
  1369.  
  1370. ruleParser.initSavedRules(()=>{
  1371. storage.getItem("rulesData", data=>{
  1372. if(data){
  1373. rulesData=data;
  1374. if(data.urls)ruleUrls=ruleUrls.concat(data.urls);
  1375. if(data.sort){
  1376. let urls=[];
  1377. data.sort.forEach(id=>{
  1378. for(let s=0;s<ruleUrls.length;s++){
  1379. if(id==ruleUrls[s].id){
  1380. urls.push(ruleUrls[s]);
  1381. break;
  1382. }
  1383. }
  1384. });
  1385. ruleUrls=urls;
  1386. }
  1387. }
  1388. if(typeof(rulesData.opacity)=="undefined"){
  1389. rulesData.opacity=0.3;
  1390. }
  1391. if(typeof(rulesData.hideBar)=="undefined"){
  1392. rulesData.hideBar=true;
  1393. }
  1394. if(typeof(rulesData.dbClick2Stop)=="undefined"){
  1395. rulesData.dbClick2Stop=true;
  1396. }
  1397. storage.getItem("forceState_"+location.host, v=>{
  1398. storage.getItem("ruleLastUpdate", date=>{
  1399. forceState=v||0;
  1400. updateDate=date;
  1401. initConfig();
  1402. if(forceState==1)return;
  1403. let now=new Date().getTime();
  1404. if(!date || now-date>2*24*60*60*1000){
  1405. storage.setItem("ruleLastUpdate", now);
  1406. storage.setItem("hpRules", []);
  1407. let ruleIndex=0;
  1408. function addNextRule(){
  1409. if(ruleIndex>=ruleUrls.length){
  1410. callback();
  1411. }else{
  1412. let rule=ruleUrls[ruleIndex++];
  1413. ruleParser.addRuleByUrl(rule.url, rule.type, rule.id, ()=>{
  1414. addNextRule();
  1415. })
  1416. }
  1417. }
  1418. addNextRule();
  1419. }else{
  1420. callback();
  1421. }
  1422. });
  1423. });
  1424. });
  1425. });
  1426. }
  1427.  
  1428. function requestDoc(url, callback){
  1429. _GM_xmlhttpRequest({
  1430. url: url,
  1431. method: 'GET',
  1432. overrideMimeType: 'text/html;charset='+document.charset,
  1433. headers: {
  1434. 'Referer': location.href
  1435. },
  1436. timeout: 5000,
  1437. onload: function(res) {
  1438. var doc=null;
  1439. try {
  1440. doc=document.implementation.createHTMLDocument('');
  1441. doc.documentElement.innerHTML=res.response;
  1442. }
  1443. catch (e) {
  1444. debug('parse error'+e.toString());
  1445. }
  1446. let pageElement=ruleParser.getPageElement(doc);
  1447. //只有1的話怕不是圖片哦
  1448. if(pageElement && (pageElement.length>1 || (pageElement.length==1 && pageElement[0].tagName!="IMG") )){
  1449. let result=ruleParser.insertPage(doc, pageElement, url, callback, false);
  1450. if(!result){
  1451. requestFromIframe(url, (doc, eles)=>{
  1452. if(eles){
  1453. ruleParser.insertPage(doc, eles, url, callback, true);
  1454. }
  1455. });
  1456. }
  1457. }else if(ruleParser.curSiteRule.singleUrl){
  1458. requestFromIframe(url, (doc, eles)=>{
  1459. if(eles){
  1460. ruleParser.insertPage(doc, eles, url, callback, true);
  1461. }
  1462. });
  1463. }
  1464. },
  1465. onerror: function(e){
  1466. debug(e);
  1467. callback(false);
  1468. }
  1469. });
  1470. }
  1471.  
  1472. var failFromIframe=0;
  1473. function requestFromIframe(url, callback){
  1474. let orgPage,curPage;
  1475. let iframe = document.createElement('iframe');
  1476. iframe.name = 'pagetual-iframe';
  1477. iframe.width = '100%';
  1478. iframe.height = '0';
  1479. iframe.frameBorder = '0';
  1480. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1481. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1482. iframe.addEventListener("load", e=>{
  1483. setTimeout(()=>{
  1484. let tryTimes=0;
  1485. function checkIframe(){
  1486. try{
  1487. let doc=iframe.contentDocument || iframe.contentWindow.document;
  1488. let eles=ruleParser.getPageElement(doc, iframe.contentWindow);
  1489. if(eles && eles.length>0){
  1490. callback(doc, eles);
  1491. }else if(tryTimes++ < 2){
  1492. setTimeout(()=>{
  1493. checkIframe();
  1494. },500);
  1495. return;
  1496. }else{
  1497. if(failFromIframe++ > 2){
  1498. failFromIframe=0;
  1499. debug("Stop as failFromIframe");
  1500. isPause=true;
  1501. callback(false, false);
  1502. }else{
  1503. callback(false, false);
  1504. }
  1505. }
  1506. }catch(e){
  1507. debug("Stop as cors");
  1508. isPause=true;
  1509. callback(false, false);
  1510. }
  1511. document.body.removeChild(iframe);
  1512. }
  1513. checkIframe();
  1514. },ruleParser.curSiteRule.wait);
  1515. });
  1516. iframe.src=url;
  1517. document.body.appendChild(iframe);
  1518. }
  1519.  
  1520. function initPage(){
  1521. ruleParser.initPage(()=>{
  1522. initListener();
  1523. nextPage();
  1524. });
  1525. }
  1526.  
  1527. function initView(){
  1528. _GM_addStyle(`
  1529. .pagetual_pageBar.stop {
  1530. -webkit-filter: invert(100%);
  1531. filter: invert(100%);
  1532. opacity: 1!important;
  1533. }
  1534. .pagetual_pageBar.hide {
  1535. display: none!important;
  1536. }
  1537. .pagetual_pageBar:hover {
  1538. opacity: 1!important;
  1539. }
  1540. .pagetual_pageBar span {
  1541. vertical-align: super;
  1542. }
  1543.  
  1544. .pagetual_pageBar span>svg:hover {
  1545. animation: touhouAni 1s infinite;
  1546. }
  1547.  
  1548. @keyframes touhouAni{
  1549. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  1550. to {transform: rotate(360deg);}
  1551. }
  1552. @-webkit-keyframes touhouAni{
  1553. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  1554. to {transform: rotate(360deg);}
  1555. }
  1556. `);
  1557. 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;`;
  1558. }
  1559. var loading=document.createElement("div");
  1560. loading.className="pagetual_loading";
  1561. 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;";
  1562. 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>`;
  1563. document.body.appendChild(loading);
  1564.  
  1565. 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>`;
  1566. 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>`;
  1567. var pageBarStyle;
  1568. 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;`;
  1569. 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);`;
  1570.  
  1571. var isPause=false,isLoading=false,curPage=1,forceState=0,bottomGap=1000;
  1572.  
  1573. function changeStop(stop, hide){
  1574. isPause=stop;
  1575. [].forEach.call(document.querySelectorAll(".pagetual_pageBar"), bar=>{
  1576. if(isPause){
  1577. bar.classList.add("stop");
  1578. if(hide)bar.classList.add("hide");
  1579. }else{
  1580. bar.classList.remove("stop");
  1581. if(hide)bar.classList.remove("hide");
  1582. }
  1583. });
  1584. }
  1585.  
  1586. function isInViewPort(element) {
  1587. if(!element.parentNode)return false;
  1588. if(_unsafeWindow.getComputedStyle(element).display=="none")return false;
  1589. const viewWidth = window.innerWidth || document.documentElement.clientWidth;
  1590. const viewHeight = window.innerHeight || document.documentElement.clientHeight;
  1591. const {
  1592. top,
  1593. right,
  1594. bottom,
  1595. left,
  1596. } = element.getBoundingClientRect();
  1597.  
  1598. return (
  1599. top >= 0 &&
  1600. left >= 0 &&
  1601. right <= viewWidth &&
  1602. bottom <= viewHeight
  1603. );
  1604. }
  1605.  
  1606. function initListener(){
  1607. var urlChanged=false;
  1608. var _wr = function(type) {
  1609. var orig = history[type];
  1610. return function() {
  1611. var rv = orig.apply(this, arguments);
  1612. var e = new Event(type);
  1613. e.arguments = arguments;
  1614. window.dispatchEvent(e);
  1615. return rv;
  1616. };
  1617. };
  1618. history.pushState = _wr('pushState');
  1619. window.addEventListener('pushState', function(e) {
  1620. urlChanged=true;
  1621. });
  1622. let loadmoreBtn=getLoadMore(document),loading=true;
  1623. if(loadmoreBtn){
  1624. //emuClick(loadmoreBtn);
  1625. setTimeout(()=>{loading=false},500);
  1626. }
  1627. document.addEventListener('scroll', e=>{
  1628. if(urlChanged){
  1629. ruleParser.initPage(()=>{});
  1630. initView();
  1631. urlChanged=false;
  1632. isPause=false;
  1633. }
  1634. if(!loading){
  1635. loading=true;
  1636. if(!loadmoreBtn || !loadmoreBtn.parentNode){
  1637. loadmoreBtn=getLoadMore(document);
  1638. }
  1639. if(loadmoreBtn){
  1640. loading=false;
  1641. if(isInViewPort(loadmoreBtn)){
  1642. emuClick(loadmoreBtn);
  1643. }
  1644. }else{
  1645. setTimeout(()=>{loading=false},500);
  1646. }
  1647. }
  1648. setTimeout(()=>{
  1649. if(!isPause && !isLoading){
  1650. let scrolly=window.scrollY;
  1651. let windowHeight=window.innerHeight;
  1652. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  1653. if(scrollH-scrolly-windowHeight<bottomGap){
  1654. nextPage();
  1655. }
  1656. }
  1657. },100);
  1658. }, true);
  1659. document.addEventListener('dblclick', e=>{
  1660. if(rulesData.dbClick2Stop){
  1661. setTimeout(()=>{
  1662. changeStop(!isPause, rulesData.hideBar);
  1663. if(!isPause){
  1664. let scrolly=window.scrollY;
  1665. let windowHeight=window.innerHeight;
  1666. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  1667. if(scrollH-scrolly-windowHeight<bottomGap){
  1668. nextPage();
  1669. }
  1670. }
  1671. },200);
  1672. }
  1673. });
  1674. }
  1675.  
  1676. function getLoadMore(doc){
  1677. let btnSel=ruleParser.curSiteRule.loadMore||".LoadMore";
  1678. let loadmoreBtn=doc.querySelector(btnSel);
  1679. if(!loadmoreBtn){
  1680. let buttons=doc.querySelectorAll("input,button,a"),loadmoreReg=/^\s*(加载更多|加載更多|load\s*more|もっと読み込む)\s*$/i;
  1681. for(let i=0;i<buttons.length;i++){
  1682. let button=buttons[i];
  1683. if(button && loadmoreReg.test(button.innerText)){
  1684. loadmoreBtn=button;
  1685. break;
  1686. }
  1687. }
  1688. }
  1689. return loadmoreBtn;
  1690. }
  1691.  
  1692. function createPageBar(url){
  1693. let insert=ruleParser.getInsert();
  1694. if(!insert || !insert.parentNode)return;
  1695. curPage++;
  1696. let inTable=insert.tagName=="TR" ||
  1697. (insert.previousElementSibling && insert.previousElementSibling.tagName=="TR") ||
  1698. insert.tagName=="TBODY" || (insert.previousElementSibling && insert.previousElementSibling.tagName=="TBODY");
  1699. let inLi=insert.tagName=="LI" || (insert.previousElementSibling && insert.previousElementSibling.tagName=="LI");
  1700. let pageBar=document.createElement(inTable?"tr":"div");
  1701. let upSpan=document.createElement("span");
  1702. let downSpan=document.createElement("span");
  1703. let pageText=document.createElement("a");
  1704. pageBar.className="pagetual_pageBar";
  1705. pageBar.id="pagetual_pageBar";
  1706. if(isPause){
  1707. pageBar.classList.add("stop");
  1708. }
  1709. pageBar.style.cssText=pageBarStyle;
  1710. pageBar.title=i18n(isPause?"enable":"disable");
  1711. upSpan.innerHTML=upSvg;
  1712. upSpan.title=i18n("toTop");
  1713. downSpan.innerHTML=downSvg;
  1714. downSpan.title=i18n("toBottom");
  1715. upSpan.style.cssText=initStyle;
  1716. downSpan.style.cssText=initStyle;
  1717. pageText.href=url;
  1718. pageText.style=pageTextStyle;
  1719. pageText.innerHTML="Page "+curPage;
  1720. pageText.title=i18n("current");
  1721. pageBar.appendChild(upSpan);
  1722. pageBar.appendChild(pageText);
  1723. pageBar.appendChild(downSpan);
  1724. if(inTable){
  1725. let example=(insert.tagName=="TR" || insert.tagName=="TBODY")?insert:insert.previousElementSibling;
  1726. let tdNum=0;
  1727. [].forEach.call(example.querySelectorAll("td,th"), td=>{
  1728. tdNum+=td.colSpan||1;
  1729. });
  1730. pageBar.style.display="table-row";
  1731. pageBar.style.backgroundColor="unset";
  1732. let td=document.createElement("td");
  1733. td.style.backgroundColor="rgb(240 240 240 / 80%)";
  1734. td.style.borderRadius="20px";
  1735. td.colSpan=tdNum||1;
  1736. td.style.padding="0 0";
  1737. td.style.textAlign="center";
  1738. td.appendChild(upSpan);
  1739. td.appendChild(pageText);
  1740. td.appendChild(downSpan);
  1741. pageBar.appendChild(td);
  1742. }
  1743.  
  1744. upSpan.addEventListener("click", e=>{
  1745. //changeStop(true);
  1746. //pageBar.title=i18n(isPause?"enable":"disable");
  1747. document.body.scrollTop=0;
  1748. document.documentElement.scrollTop=0;
  1749. e.preventDefault();
  1750. e.stopPropagation();
  1751. });
  1752. downSpan.addEventListener("click", e=>{
  1753. changeStop(true);
  1754. pageBar.title=i18n(isPause?"enable":"disable");
  1755. document.body.scrollTop=9999999;
  1756. document.documentElement.scrollTop=9999999;
  1757. e.preventDefault();
  1758. e.stopPropagation();
  1759. });
  1760. pageBar.addEventListener("click", e=>{
  1761. changeStop(!isPause);
  1762. pageBar.title=i18n(isPause?"enable":"disable");
  1763. });
  1764. pageText.addEventListener("click", e=>{
  1765. e.stopPropagation();
  1766. });
  1767. let parentStyle=_unsafeWindow.getComputedStyle(insert.parentNode);
  1768. pageBar.style.width=parseInt(parentStyle.width)*.99-parseInt(parentStyle.paddingLeft)-parseInt(parentStyle.paddingRight)+"px";
  1769. if(inLi){
  1770. pageBar.style.width="90%";
  1771. pageBar.style.minWidth="150px";
  1772. pageBar.style.display="inline-block";
  1773. let line=document.createElement("li");
  1774. line.style.textAlign="center";
  1775. line.appendChild(pageBar);
  1776. if(ruleParser.curSiteRule.insertPos==2){
  1777. insert.appendChild(line);
  1778. }else{
  1779. insert.parentNode.insertBefore(line, insert);
  1780. }
  1781. }else{
  1782. if(ruleParser.curSiteRule.insertPos==2){
  1783. insert.appendChild(pageBar);
  1784. }else{
  1785. insert.parentNode.insertBefore(pageBar, insert);
  1786. }
  1787. }
  1788.  
  1789. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  1790. let actualTop = pageBar.offsetTop;
  1791. let current = pageBar.parentNode.offsetParent;
  1792. while (current !== null){
  1793. actualTop += current.offsetTop;
  1794. current = current.offsetParent;
  1795. }
  1796. bottomGap=scrollH-actualTop+800;
  1797. return pageBar;
  1798. }
  1799.  
  1800. function emuClick(btn){
  1801. if(!PointerEvent)return btn.click();
  1802. let eventParam={
  1803. isTrusted: true,
  1804. altKey: false,
  1805. azimuthAngle: 0,
  1806. bubbles: true,
  1807. button: 0,
  1808. buttons: 0,
  1809. clientX: 1,
  1810. clientY: 1,
  1811. cancelBubble: false,
  1812. cancelable: true,
  1813. composed: true,
  1814. ctrlKey: false,
  1815. defaultPrevented: false,
  1816. detail: 1,
  1817. eventPhase: 2,
  1818. fromElement: null,
  1819. height: 1,
  1820. isPrimary: false,
  1821. metaKey: false,
  1822. pointerId: 1,
  1823. pointerType: "mouse",
  1824. pressure: 0,
  1825. relatedTarget: null,
  1826. returnValue: true,
  1827. shiftKey: false,
  1828. toElement: null,
  1829. twist: 0,
  1830. type: "click",
  1831. which: 1
  1832. };
  1833. var mouseclick = new PointerEvent("click",eventParam);
  1834. btn.dispatchEvent(mouseclick);
  1835. }
  1836.  
  1837. var emuIframe;
  1838. function emuPage(callback){
  1839. let orgPage,curPage,iframeDoc,times=0,loadmoreBtn,loadmoreEnd=false,waitTimes=10;
  1840. function checkPage(){
  1841. if(isPause)return;
  1842. try{
  1843. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  1844. }catch(e){
  1845. debug("Stop as cors");
  1846. isPause=true;
  1847. callback(false, false);
  1848. return;
  1849. }
  1850. let nextLink=ruleParser.getNextLink(iframeDoc);
  1851. if(!orgPage){
  1852. if(!loadmoreEnd){
  1853. loadmoreBtn=getLoadMore(iframeDoc);
  1854. if(loadmoreBtn){
  1855. emuClick(loadmoreBtn);
  1856. let intv=setInterval(()=>{
  1857. loadmoreBtn=getLoadMore(iframeDoc);
  1858. if(!loadmoreBtn || !loadmoreBtn.parentNode || !isVisible(loadmoreBtn, iframeDoc.defaultView)){
  1859. clearInterval(intv);
  1860. loadmoreEnd=true;
  1861. setTimeout(()=>{
  1862. checkPage();
  1863. },500);
  1864. }else{
  1865. emuClick(loadmoreBtn);
  1866. }
  1867. },200);
  1868. return;
  1869. }else{
  1870. loadmoreEnd=true;
  1871. }
  1872. }
  1873. let pageEle=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true);
  1874. if(!nextLink || !pageEle){
  1875. if(ruleParser.curSiteRule.wait && waitTimes-->0){
  1876. setTimeout(()=>{
  1877. checkPage();
  1878. },parseInt(ruleParser.curSiteRule.wait));
  1879. return;
  1880. }
  1881. }
  1882. orgPage=pageEle;
  1883. if(!orgPage || orgPage.length==0){
  1884. debug("Stop as no page when emu");
  1885. isPause=true;
  1886. callback(false, false);
  1887. return;
  1888. }
  1889. orgPage=orgPage[parseInt(orgPage.length/2)];
  1890. if(orgPage && orgPage.tagName=="UL")orgPage=orgPage.children[0];
  1891. if(orgPage && nextLink){
  1892. if(!isVisible(nextLink, iframeDoc.defaultView)){
  1893. debug("Stop as next hide when emu");
  1894. isPause=true;
  1895. callback(false, false);
  1896. }else{
  1897. emuClick(nextLink);
  1898. setTimeout(()=>{
  1899. checkPage();
  1900. },500);
  1901. }
  1902. }else{
  1903. debug("Stop as no next when emu");
  1904. isPause=true;
  1905. callback(false, false);
  1906. }
  1907. return;
  1908. }
  1909. if(times++ > 20){
  1910. //emuClick(nextLink);
  1911. debug("Stop as timeout when emu");
  1912. isPause=true;
  1913. callback(false, false);
  1914. return;
  1915. }
  1916. iframeDoc.body.scrollTop=9999999;
  1917. iframeDoc.documentElement.scrollTop=9999999;
  1918. let eles=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true);
  1919. if(!eles || eles.length==0 || orgPage == eles[parseInt(eles.length/2)]){
  1920. setTimeout(()=>{
  1921. checkPage();
  1922. },500);
  1923. }else{
  1924. if(ruleParser.curSiteRule.wait){
  1925. setTimeout(()=>{
  1926. let eles=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true);
  1927. callback(iframeDoc, eles);
  1928. },parseInt(ruleParser.curSiteRule.wait));
  1929. }else{
  1930. callback(iframeDoc, eles);
  1931. }
  1932. }
  1933. }
  1934. if(!emuIframe){
  1935. emuIframe = document.createElement('iframe');
  1936. emuIframe.name = 'pagetual-iframe';
  1937. //emuIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1938. emuIframe.width = '100%';
  1939. emuIframe.height = '0';
  1940. emuIframe.frameBorder = '0';
  1941. emuIframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1942. emuIframe.addEventListener("load", e=>{
  1943. setTimeout(()=>{
  1944. checkPage();
  1945. },300);
  1946. });
  1947. emuIframe.src=location.href;
  1948. document.body.appendChild(emuIframe);
  1949. }else{
  1950. checkPage();
  1951. }
  1952. }
  1953.  
  1954. function forceIframe(url, callback){
  1955. let curIframe = document.createElement('iframe');
  1956. curIframe.name = 'pagetual-iframe';
  1957. curIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1958. curIframe.frameBorder = '0';
  1959. curIframe.scrolling="no";
  1960. 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;';
  1961. curIframe.addEventListener("load", e=>{
  1962. let iframeDoc;
  1963. try{
  1964. iframeDoc=curIframe.contentDocument || curIframe.contentWindow.document;
  1965. }catch(e){
  1966. debug("Stop as cors");
  1967. isPause=true;
  1968. callback(false, false);
  1969. return;
  1970. }
  1971. ruleParser.insertPage(iframeDoc, [], url, null, true);
  1972. callback(curIframe, true);
  1973. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  1974. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  1975. setTimeout(()=>{
  1976. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  1977. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  1978. },300);
  1979. });
  1980. curIframe.src=url;
  1981. let insert=ruleParser.getInsert();
  1982. document.body.insertBefore(curIframe, loading);
  1983. return curIframe;
  1984. }
  1985.  
  1986. function nextPage(){
  1987. if(isPause || isLoading)return;
  1988. let nextLink=ruleParser.nextLinkHref;
  1989. if(!nextLink)return;
  1990. let insert=ruleParser.getInsert();
  1991. if(insert){
  1992. let isJs=/^(javascript|#)/.test(nextLink.replace(location.href,""));
  1993. if(location.protocol=="https:" && /^http:/.test(nextLink)){
  1994. nextLink=nextLink.replace(/^http/,"https");
  1995. }
  1996. isLoading=true;
  1997. loading.style.display="";
  1998. if(ruleParser.curSiteRule.pageElementByJs){
  1999. var over=ele=>{
  2000. isLoading=false;
  2001. loading.style.display="none";
  2002. if(ele){
  2003. createPageBar(nextLink);
  2004. ruleParser.insertPage(null, ele, nextLink, null, true);
  2005. }else{
  2006. debug("Stop as no page when get by js");
  2007. isPause=true;
  2008. }
  2009. };
  2010. try{
  2011. Function("over",'"use strict";' + ruleParser.curSiteRule.pageElementByJs)(over);
  2012. }catch(e){}
  2013. }else if(ruleParser.curSiteRule.action==1 && !isJs){
  2014. requestFromIframe(nextLink, (doc, eles)=>{
  2015. isLoading=false;
  2016. loading.style.display="none";
  2017. if(eles){
  2018. createPageBar(nextLink);
  2019. ruleParser.insertPage(doc, eles, nextLink, null, true);
  2020. }
  2021. });
  2022. }else if(forceState==2 && !isJs){
  2023. forceIframe(nextLink, (iframe, eles)=>{
  2024. isLoading=false;
  2025. loading.style.display="none";
  2026. let pageBar=createPageBar(nextLink);
  2027. iframe.parentNode.insertBefore(pageBar, iframe);
  2028. });
  2029. }else{
  2030. if(!isJs){
  2031. requestDoc(nextLink, (eles)=>{
  2032. isLoading=false;
  2033. loading.style.display="none";
  2034. if(eles){
  2035. createPageBar(nextLink);
  2036. }
  2037. });
  2038. }else{
  2039. emuPage((doc, eles)=>{
  2040. isLoading=false;
  2041. loading.style.display="none";
  2042. if(eles){
  2043. createPageBar(nextLink);
  2044. ruleParser.insertPage(doc, eles, "", null, true);
  2045. }
  2046. });
  2047. }
  2048. }
  2049. }
  2050. }
  2051.  
  2052. function init(){
  2053. initRules(()=>{
  2054. initView();
  2055. initPage();
  2056. });
  2057. }
  2058. setTimeout(()=>{
  2059. init();
  2060. },300);
  2061. })();