东方永页机 - 自动翻页脚本

自动加载并拼接下一分页内容,无需规则支持所有网页 —— 适用于搜索引擎【谷歌/百度/必应等】、论坛【贴吧/豆瓣/水木社区等】、图站【deviantArt/Pixiv/Chevereto等】、漫画站【动漫之家/漫画柜/动漫屋等】、小说站【笔趣阁等】、资讯站【腾讯新闻/煎蛋等】、博客【异次元/小众软件等】及其他

目前为 2022-03-16 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Pagetual - Perpetual pages
  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.5.8.3
  14. // @description Most compatible Auto Pager script ever. Auto loading next paginated web pages and inserting into current page.
  15. // @description:zh-CN 自动加载并拼接下一分页内容,无需规则支持所有网页 —— 适用于搜索引擎【谷歌/百度/必应等】、论坛【贴吧/豆瓣/水木社区等】、图站【deviantArt/Pixiv/Chevereto等】、漫画站【动漫之家/漫画柜/动漫屋等】、小说站【笔趣阁等】、资讯站【腾讯新闻/煎蛋等】、博客【异次元/小众软件等】及其他
  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,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAAdVBMVEUAAAD3VU33VU32VEz8U073VU32VU33VU32VUz0Uk/3VE32VU32VUz2VU32VU32VU32VU33VU33U0z2VU34Wkv3VE32VUz/mpj/nJj2VUz2VU32VE33VEz2VU32VU32VUz3VE32VEz3VE3/mZf2Vkz2VU3/mpilFFolAAAAJXRSTlMA3Lp/GvTBT5YQLuawZ/DOyZwlPQeKc21N04+FX1bqpm9DNoB4T68ePwAAAitJREFUWMPt1tuasiAUBuCFCG5Rs3QybTPV1/1f4v/3PDkyIojn8x5qBrI+ltAfh32/yysmBKvyXb+njb6bDL9kzTd5SzjDAsYT8nFoGSxYe6BVqoNDp2jFDit25BRgVUAODB4YWcETWVTwVNGiGN5iWtBgg4YMCpsoI38dNunmmWyxUTvbPwwbsYR0fIzZLQ0pTG8eieRmBLMmpdH9uimQEf6TNRnXXKLZHixpJtywLzOgMHtFCqdM64DahHRnOE1dsrekm9wr2WtLcAlpdHwcp1pAJySXYnERclzp4+v19jXdmcTvQUJtz+ZaI4i05/V/UGYrCxbaAsOYoNfIKEQxpqQuzCgJJJ/3f42O8ywEZuMVWi/8hODxGj3GW2b0udkbGULLDOjimAG0S3fLGlBnXQM9irG1CiQdVQi0dqQsOSDlyEEz7Vy9OxxfR71VCXsSB23jMrKJYZXSjw57sqgLn5Z0wolsOCz0RyJkyeYjgz7pwwVq20eboZwtVUl2EnN5gJ50dQZFdryATvABRTr/tJXkUMdaAK5pwtCapwtFLskguwuyMh/Sd9WChQ4sIvIUYSk3PYqQvCQlOC04IfN7PkdjOyRKWhdKXMmiAFt9i3sJ5jxoRuR0vqAghxxwHuqfQE5OHGDKOrwEnqs1DgAZ2e4Eev1d45TN7JfhrQLKgfwMFYAsvp33dXII073aVQLI2gN5S58lfmGnKKFtah7nkgnBZB7zlP7Y/QNiTM6sYNzawwAAAABJRU5ErkJggg==
  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. // @supportURL https://github.com/hoothin/UserScripts/issues
  46. // @connect wedata.net
  47. // @connect githubusercontent.com
  48. // @run-at document-idle
  49. // @exclude http://www.toodledo.com/tasks/*
  50. // @exclude http*://maps.google.com*/*
  51. // @exclude *://www.google.*/_/chrome/newtab*
  52. // @exclude *://mega.*/*
  53. // @exclude *://*.mega.*/*
  54. // @exclude *://*.youku.com/v_*
  55. // @exclude *://*pan.baidu.com
  56. // @exclude *://*.iqiyi.com/v_*
  57. // @exclude *://*.iqiyi.com/w_*
  58. // @exclude *://*.iqiyi.com/a_*
  59. // @exclude *://*.le.com/ptv/vplay/*
  60. // @exclude *://v.qq.com/x/cover/*
  61. // @exclude *://v.qq.com/x/page/*
  62. // @exclude *://v.qq.com/tv/*
  63. // @exclude *://*.tudou.com/listplay/*
  64. // @exclude *://*.tudou.com/albumplay/*
  65. // @exclude *://*.tudou.com/programs/view/*
  66. // @exclude *://*.mgtv.com/b/*
  67. // @exclude *://film.sohu.com/album/*
  68. // @exclude *://tv.sohu.com/v/*
  69. // @exclude *://*.bilibili.com/video/*
  70. // @exclude *://*.bilibili.com/bangumi/play/*
  71. // @exclude *://*.baofeng.com/play/*
  72. // @exclude *://vip.pptv.com/show/*
  73. // @exclude *://v.pptv.com/show/*
  74. // @exclude *://www.le.com/ptv/vplay/*
  75. // @exclude *://www.wasu.cn/Play/show/*
  76. // @exclude *://m.v.qq.com/*
  77. // @exclude *://m.iqiyi.com/*
  78. // @exclude *://m.youku.com/alipay_video/*
  79. // @exclude *://m.mgtv.com/b/*
  80. // @exclude *://m.tv.sohu.com/v/*
  81. // @exclude *://m.film.sohu.com/album/*
  82. // @exclude *://m.le.com/ptv/vplay/*
  83. // @exclude *://m.pptv.com/show/*
  84. // @exclude *://m.acfun.cn/v/*
  85. // @exclude *://m.bilibili.com/video/*
  86. // @exclude *://m.bilibili.com/anime/*
  87. // @exclude *://m.bilibili.com/bangumi/play/*
  88. // @exclude *://m.wasu.cn/Play/show/*
  89. // @exclude *://www.youtube.com
  90. // @exclude *://www.youtube.com/
  91. // @exclude *://www.youtube.com/watch*
  92. // @exclude *://baike.baidu.com/*
  93. // @exclude *://*.instagram.com/*
  94. // @exclude *://order.jd.com/*
  95. // @exclude *://pagetual.hoothin.com/*
  96. // @exclude *://hoothin.github.io/PagetualGuide/*
  97. // @exclude *://wenku.baidu.com/view/*
  98. // @connect *
  99. // ==/UserScript==
  100.  
  101. (function() {
  102. 'use strict';
  103.  
  104. if (window.name === 'pagetual-iframe' || (window.frameElement && window.frameElement.name === 'pagetual-iframe')) {
  105. var domloaded = function (){
  106. window.scroll(window.scrollX, 999999);
  107. //window.parent.postMessage('pagetual-iframe:DOMLoaded', '*');
  108. };
  109. if(window.opera){
  110. document.addEventListener('DOMContentLoaded', domloaded, false);
  111. } else {
  112. domloaded();
  113. }
  114. return;
  115. }
  116.  
  117. if(window.top != window.self){
  118. try{
  119. if (top.location.hostname != window.location.hostname || window.top != window.parent) {
  120. return;
  121. }
  122. }catch(e){
  123. return;
  124. }
  125. }
  126.  
  127. const lang = navigator.appName=="Netscape"?navigator.language:navigator.userLanguage;
  128. var i18n=(name, param)=>{
  129. let config={};
  130. switch (lang){
  131. case "zh-CN":
  132. case "zh-SG":
  133. config={
  134. enableDebug:"调试模式,输出信息至控制台",
  135. disable:"暂时禁用",
  136. disableSite:"在此站禁用",
  137. enable:"启用翻页",
  138. toTop:"回到顶部",
  139. toBottom:"前往页尾",
  140. current:"当前页",
  141. forceIframe:"强制拼接",
  142. cancelForceIframe:"取消强制拼接",
  143. configure:"打开配置页",
  144. firstUpdate:"点击此处初始化规则",
  145. update:"更新规则",
  146. click2update:"点击立即更新规则",
  147. loadNow:"立即翻页",
  148. loadConfirm:"要翻几页?(0为不间断)",
  149. noNext:"没有找到下一页,请新建规则",
  150. passSec:"更新于 #t# 秒前",
  151. passMin:"更新于 #t# 分钟前",
  152. passHour:"更新于 #t# 小时前",
  153. passDay:"更新于 #t# 天前",
  154. cantDel:"无法删除内置规则",
  155. confirmDel:"是否确认要删除此规则?",
  156. updateSucc:"更新成功",
  157. beginUpdate:"正在更新,请稍候",
  158. customUrls:"导入规则url,一行一条,AutoPagerize 格式规则需要以\"0|\"开头",
  159. customRules:"输入【东方永页机】格式的自定义规则",
  160. save:"保存设置",
  161. loadingText:"少女祈祷中...",
  162. opacity:"分页隔条不透明值",
  163. hideBar:"空白处双击隐藏分页隔条",
  164. dbClick2Stop:"空白处双击暂停翻页",
  165. sortTitle:"排序在下次更新规则后生效",
  166. autoRun:"自动启用,否则为白名单模式",
  167. inputPageNum:"输入页码跳转",
  168. enableHistory:"翻页后写入历史记录",
  169. initRun:"打开页面后立即尝试翻页,否则滚动至页尾再翻页",
  170. preload:"翻页前预读下一页,加速浏览",
  171. click2ImportRule:"点击下方添加特殊规则库,添加后再行更新:",
  172. forceAllBody:"是否拼接整个页面?"
  173. };
  174. break;
  175. case "zh-TW":
  176. case "zh-HK":
  177. config={
  178. enableDebug:"調試模式,輸出信息至控制台",
  179. disable:"暫時禁用",
  180. disableSite:"在此站禁用",
  181. enable:"啟用翻頁",
  182. toTop:"回到頂部",
  183. toBottom:"前往頁尾",
  184. current:"當前頁",
  185. forceIframe:"強制拼接",
  186. cancelForceIframe:"取消强制拼接",
  187. configure:"打開配置頁",
  188. firstUpdate:"點擊此處初始化規則",
  189. update:"更新規則",
  190. click2update:"點擊立即更新規則",
  191. loadNow:"立即翻頁",
  192. loadConfirm:"要翻几頁?(0為不間斷)",
  193. noNext:"沒有找到下一頁,請新建規則",
  194. passSec:"更新于 #t# 秒前",
  195. passMin:"更新于 #t# 分鐘前",
  196. passHour:"更新于 #t# 小時前",
  197. passDay:"更新于 #t# 天前",
  198. cantDel:"無法刪除内置規則",
  199. confirmDel:"是否確認要刪除此規則?",
  200. updateSucc:"更新成功",
  201. beginUpdate:"正在更新,請稍候",
  202. customUrls:"導入規則url,一行一條,AutoPagerize 格式規則需要以\"0|\"開頭",
  203. customRules:"輸入【東方永頁機】格式的自定義規則",
  204. save:"存儲設置",
  205. loadingText:"少女祈禱中...",
  206. opacity:"分頁隔條不透明值",
  207. hideBar:"空白處雙擊隱藏分頁隔條",
  208. dbClick2Stop:"空白處雙擊暫停翻頁",
  209. sortTitle:"排序在下次更新規則後生效",
  210. autoRun:"自動啓用,否則為白名單模式",
  211. inputPageNum:"輸入頁碼跳轉",
  212. enableHistory:"翻頁后寫入歷史記錄",
  213. initRun:"打開頁面后立即嘗試翻頁,否則滾動至頁尾再翻頁",
  214. preload:"翻頁前預讀下一頁,加速瀏覽",
  215. click2ImportRule:"點擊下方添加特殊規則庫,添加後再行更新:",
  216. forceAllBody:"是否拼接整個頁面?"
  217. };
  218. break;
  219. case "ja":
  220. config = {
  221. enableDebug:"デバッグモード",
  222. disable: "一時的に無効にする",
  223. disableSite:"このサイト無効",
  224. enable: "ページめくりを有効にする",
  225. toTop: "トップに戻る",
  226. toBottom: "ページの下部に移動",
  227. current: "現在のページ",
  228. forceIframe: "強制ステッチ",
  229. cancelForceIframe: "強制ステッチをキャンセル",
  230. configure: "設定ページを開く",
  231. firstUpdate:"ここをクリックしてルールを初期化します",
  232. update: "更新ルール",
  233. click2update:"今すぐルールを更新してください",
  234. loadNow:"今すぐページをめくる",
  235. loadConfirm:"数ページめくりたいですか?(0は途切れない)",
  236. noNext:"次のページが見つかりません、新しいルールを作成してください",
  237. passSec: "#t#秒前に更新",
  238. passMin: "#t#分前に更新",
  239. passHour: "#t#時間前に更新",
  240. passDay: "#t#日前に更新",
  241. cantDel: "組み込みルールを削除できません",
  242. confirmDel: "このルールを削除してもよろしいですか?",
  243. updateSucc: "更新に成功しました",
  244. beginUpdate: "更新中、お待ちください",
  245. customUrls: "インポートルールのURL、1行に1つ、AutoPagerizeフォーマットルールは\"0|\"で始まる必要があります",
  246. customRules: "【東方永頁機】の形式でカスタムルールを入力してください",
  247. save: "設定を保存",
  248. loadingText: "少女祈祷中...",
  249. opacity:"ページネーションバーの不透明値",
  250. hideBar:"空白部分をダブルクリックして、ページ区切り文字を非表示にします",
  251. dbClick2Stop:"空白部分をダブルクリックしてページめくりを一時停止します",
  252. sortTitle:"並べ替えは、次のルールの更新後に有効になります",
  253. autoRun:"自動的に有効",
  254. inputPageNum:"ジャンプするページ番号を入力",
  255. enableHistory:"ページめくり後の履歴を書く",
  256. initRun:"Webページを開いた直後にページをめくる",
  257. preload:"事前に次のページを読む",
  258. click2ImportRule:"以下をクリックして、ルールベースを追加します:",
  259. forceAllBody:"フルページ埋め込み?"
  260. };
  261. break;
  262. default:
  263. config={
  264. enableDebug:"Enable debug output",
  265. disable:"Disable",
  266. disableSite:"Disable on the site",
  267. enable:"Enable",
  268. toTop:"To Top",
  269. toBottom:"To Bottom",
  270. current:"Current Page",
  271. forceIframe:"Force to join",
  272. cancelForceIframe:"Cancel Force join",
  273. configure:"Configure",
  274. firstUpdate:"Click here to initialize the rules",
  275. update:"Update rules",
  276. click2update:"Click to update rules from url now",
  277. loadNow:"Load next now",
  278. loadConfirm:"How much pages do you want to load? (0 means infinite)",
  279. noNext:"No next link found, please create a new rule",
  280. passSec:"Updated #t# seconds ago",
  281. passMin:"Updated #t# minutes ago",
  282. passHour:"Updated #t# hours ago",
  283. passDay:"Updated #t# days ago",
  284. cantDel:"Can't delete buildin rules",
  285. confirmDel:"Are you sure you want to delete this rule?",
  286. updateSucc:"Update succeeded",
  287. beginUpdate:"Begin update, wait a minute please",
  288. customUrls:"Import rule url, One url per line, rules on AutoPagerize format need to start with \"0|\"",
  289. customRules:"Input custom rules with [Pagetual] format",
  290. save:"Save",
  291. loadingText:"Shojo Now Loading...",
  292. opacity:"Pagination spacer opacity",
  293. hideBar:"Double-click on the blank space to hide the paging spacer",
  294. dbClick2Stop:"Double-click on the blank space to stop",
  295. sortTitle:"Sorting takes effect after the next rule update",
  296. autoRun:"Auto run (black list mode)",
  297. inputPageNum:"Enter page number to jump",
  298. enableHistory:"Write history after page turning",
  299. initRun:"Turn pages immediately after opening",
  300. preload:"Preload next page for speeding up",
  301. click2ImportRule:"Click to import base rules link, then click to update rules:",
  302. forceAllBody:"Join full body of page?"
  303. };
  304. break;
  305. }
  306. return config[name]?config[name].replace("#t#",param):name;
  307. };
  308.  
  309. var noRuleTest=false;
  310. var enableDebug=true;
  311. var debug=str=>{
  312. if(enableDebug){
  313. console.debug(str);
  314. }
  315. };
  316.  
  317. var _GM_xmlhttpRequest,_GM_registerMenuCommand,_GM_notification,_GM_addStyle,_GM_openInTab;
  318. if(typeof GM_xmlhttpRequest!='undefined'){
  319. _GM_xmlhttpRequest=GM_xmlhttpRequest;
  320. }else if(typeof GM!='undefined' && typeof GM.xmlHttpRequest!='undefined'){
  321. _GM_xmlhttpRequest=GM.xmlHttpRequest;
  322. }else{
  323. _GM_xmlhttpRequest=(f)=>{fetch(f.url).then(response=>response.text()).then(data=>{let res={response:data};f.onload(res)}).catch(f.onerror())};
  324. }
  325. if(typeof GM_registerMenuCommand!='undefined'){
  326. _GM_registerMenuCommand=GM_registerMenuCommand;
  327. }else if(typeof GM!='undefined' && typeof GM.registerMenuCommand!='undefined'){
  328. _GM_registerMenuCommand=GM.registerMenuCommand;
  329. }else{
  330. _GM_registerMenuCommand=(s,f)=>{};
  331. }
  332. if(typeof GM_notification!='undefined'){
  333. _GM_notification=GM_notification;
  334. }else if(typeof GM!='undefined' && typeof GM.notification!='undefined'){
  335. _GM_notification=GM.notification;
  336. }else{
  337. _GM_notification=(s)=>{alert(s)};
  338. }
  339. if(typeof GM_openInTab!='undefined'){
  340. _GM_openInTab=GM_openInTab;
  341. }else if(typeof GM!='undefined' && typeof GM.openInTab!='undefined'){
  342. _GM_openInTab=GM.openInTab;
  343. }else{
  344. _GM_openInTab=(s,t)=>{window.open(s)};
  345. }
  346. if(typeof GM_addStyle!='undefined'){
  347. _GM_addStyle=GM_addStyle;
  348. }else if(typeof GM!='undefined' && typeof GM.addStyle!='undefined'){
  349. _GM_addStyle=GM.addStyle;
  350. }else{
  351. _GM_addStyle=cssStr=>{
  352. let styleEle=document.createElement("style");
  353. styleEle.innerHTML=cssStr;
  354. document.head.appendChild(styleEle);
  355. };
  356. }
  357. var _unsafeWindow=(typeof unsafeWindow=='undefined')?window:unsafeWindow;//兼容 ios userscripts 的寫法
  358. var storage={
  359. supportGM: typeof GM_getValue=='function' && typeof GM_getValue('a','b')!='undefined',
  360. supportGMPromise: typeof GM!='undefined' && typeof GM.getValue=='function' && typeof GM.getValue('a','b')!='undefined',
  361. mxAppStorage:(function(){
  362. try{
  363. return window.external.mxGetRuntime().storage;
  364. }catch(e){
  365. }
  366. })(),
  367. operaUJSStorage:(function(){
  368. try{
  369. return window.opera.scriptStorage;
  370. }catch(e){
  371. }
  372. })(),
  373. setItem:function(key,value){
  374. if(this.operaUJSStorage){
  375. this.operaUJSStorage.setItem(key,value);
  376. }else if(this.mxAppStorage){
  377. this.mxAppStorage.setConfig(key,value);
  378. }else if(this.supportGM){
  379. GM_setValue(key,value);
  380. if(value==="" && typeof GM_deleteValue!='undefined'){
  381. GM_deleteValue(key);
  382. }
  383. }else if(this.supportGMPromise){
  384. GM.setValue(key,value);
  385. if(value==="" && typeof GM!='undefined' && typeof GM.deleteValue!='undefined'){
  386. GM.deleteValue(key);
  387. }
  388. }else if(window.localStorage){
  389. window.localStorage.setItem(key,value);
  390. }
  391. },
  392. getItem:function(key,cb){
  393. var value;
  394. if(this.operaUJSStorage){
  395. value=this.operaUJSStorage.getItem(key);
  396. }else if(this.mxAppStorage){
  397. value=this.mxAppStorage.getConfig(key);
  398. }else if(this.supportGM){
  399. value=GM_getValue(key);
  400. }else if(this.supportGMPromise){
  401. value=GM.getValue(key).then(v=>{cb(v)});
  402. return;
  403. }else if(window.localStorage){
  404. value=window.localStorage.getItem(key);
  405. };
  406. cb(value);
  407. }
  408. };
  409. var rulesData={},ruleUrls,updateDate,configPage="https://github.com/hoothin/UserScripts/tree/master/Pagetual";
  410. var ruleImportUrlReg=/greasyfork\.org\/.*scripts\/438684[^\/]*(\/discussions|\/?$)|github\.com\/hoothin\/UserScripts\/(tree\/master\/Pagetual|issues)/i;
  411. var allOfBody="body>*";
  412. _GM_registerMenuCommand(i18n("configure"), ()=>{
  413. _GM_openInTab(configPage,{active:true});
  414. });
  415.  
  416. function getElementByXpath(xpath, contextNode, doc){
  417. doc = doc || document;
  418. contextNode = contextNode || doc;
  419. try {
  420. var result = doc.evaluate(xpath, contextNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
  421. return result.singleNodeValue && result.singleNodeValue.nodeType === 1 && result.singleNodeValue;
  422. } catch (err) {
  423. throw new Error(`Invalid xpath: ${xpath}`);
  424. }
  425. }
  426.  
  427. function getAllElementsByXpath(xpath, contextNode, doc){
  428. doc = doc || document;
  429. contextNode = contextNode || doc;
  430. var result = [];
  431. try {
  432. var query = doc.evaluate(xpath, contextNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  433. for (var i = 0; i < query.snapshotLength; i++) {
  434. var node = query.snapshotItem(i);
  435. if (node.nodeType === 1) result.push(node);
  436. }
  437. } catch (err) {
  438. throw new Error(`Invalid xpath: ${xpath}`);
  439. }
  440. return result;
  441. }
  442.  
  443. class RuleParser {
  444. constructor() {
  445. this.hpRules=[];
  446. this.customRules=[];
  447. this.rules=[];
  448. this.pageDoc=document;
  449. this.nextLinkHref=null;
  450. this.oldUrl="";
  451. this.curUrl=location.href;
  452. this.curSiteRule={};
  453. }
  454.  
  455. initSavedRules(callback){
  456. var self=this;
  457. storage.getItem("hpRules", hpRules=>{
  458. if(hpRules)self.hpRules=hpRules;
  459. storage.getItem("customRules", customRules=>{
  460. if(customRules)self.customRules=customRules;
  461. storage.getItem("rules", rules=>{
  462. if(rules)self.rules=rules;
  463. callback();
  464. });
  465. });
  466. });
  467. }
  468.  
  469. saveCurSiteRule(){
  470. if(!this.curSiteRule || !this.curSiteRule.url || this.curSiteRule.singleUrl)return;
  471. this.hpRules=this.hpRules.filter(item=>{return item&&item.url!=this.curSiteRule.url});
  472. this.hpRules.unshift(this.curSiteRule);
  473. if(this.hpRules.length>30){
  474. this.hpRules.pop();
  475. }
  476. storage.setItem("hpRules", this.hpRules);
  477. }
  478.  
  479. requestJSON(url, callback){
  480. _GM_xmlhttpRequest({
  481. url: url,
  482. method: 'GET',
  483. timeout: 20000,
  484. onload: function(res) {
  485. let json=null;
  486. try{
  487. json=JSON.parse(res.response||res.responseText);
  488. }catch(e){
  489. debug(e);
  490. }
  491. callback(json);
  492. },
  493. onerror: function(e) {
  494. callback(null, e);
  495. },
  496. ontimeout: function(e) {
  497. callback(null, e);
  498. }
  499. });
  500. }
  501.  
  502. formatRule(item, type, from){
  503. switch(type){
  504. case 0:
  505. return {
  506. from:from,
  507. type:type,
  508. name:item.name,
  509. action:item.data.forceIframe=="true"?1:0,
  510. url:item.data.url,
  511. pageElement:item.data.pageElement,
  512. nextLink:item.data.nextLink,
  513. insert:item.data.insertBefore,
  514. insertPos:1,
  515. updatedAt:item.data.updated_at,
  516. css:item.data.Stylus+item.data.CSS,
  517. pageAction:item.data.bookmarklet
  518. };
  519. break;
  520. case 1:
  521. default:
  522. item.from=from;
  523. if(typeof(item.type) == "undefined")item.type=type;
  524. return item;
  525. break;
  526. }
  527. return null;
  528. }
  529.  
  530. addRuleByUrl(url, type, from, callback) {
  531. if(url.indexOf("?")==-1){
  532. url=url+"?"+Date.now();
  533. }else{
  534. url=url+"&"+Date.now();
  535. }
  536. this.requestJSON(url, (json,err)=>{
  537. if(!json){
  538. debug("Update "+url+" rules fail!");
  539. debug(err);
  540. }
  541. this.addRules(json, type, from);
  542. callback(json, err);
  543. });
  544. }
  545.  
  546. addRules(rules, type, from) {
  547. if(rules && rules.length>0){
  548. this.rules=this.rules.filter(item=>{return item.from!=from});
  549. rules.forEach(item=>{
  550. let rule=this.formatRule(item, type, from);
  551. if(rule){
  552. this.rules.unshift(rule);
  553. }
  554. });
  555. }
  556. }
  557.  
  558. getRule(callback) {
  559. if(noRuleTest){
  560. this.curSiteRule={};
  561. this.curSiteRule.url=location.origin+location.pathname;
  562. this.curSiteRule.singleUrl=true;
  563. callback();
  564. return;
  565. }
  566. if(this.curSiteRule && this.curSiteRule.url){
  567. return this.curSiteRule;
  568. }
  569. var self=this;
  570.  
  571. function setRule(r){
  572. self.curSiteRule=r;
  573. debug(r);
  574. callback();
  575. }
  576.  
  577. function ruleMatch(r){
  578. let pageElement,nextLink,insert;
  579. if(r.nextLink){
  580. nextLink=r.type==0?getElementByXpath(r.nextLink):document.querySelector(r.nextLink);
  581. if(!nextLink)return false;
  582. }
  583. if(r.pageElement){
  584. pageElement=r.type==0?getElementByXpath(r.pageElement):document.querySelector(r.pageElement);
  585. if(!pageElement)return false;
  586. }
  587. if(r.insert){
  588. insert=r.type==0?getElementByXpath(r.insert):document.querySelector(r.insert);
  589. if(!insert)return false;
  590. }
  591. return true;
  592. }
  593.  
  594. function checkRule(r){
  595. let urlReg=new RegExp(r.url, "i");
  596. if(urlReg.test(location.href)){
  597. if(r.wait){
  598. let waitTime=500,checkEval;
  599. if(isNaN(r.wait)){
  600. try{
  601. checkEval=Function("doc",'"use strict";' + r.wait);
  602. }catch(e){
  603. debug(e);
  604. }
  605. }else{
  606. waitTime=r.wait;
  607. }
  608. let checkReady=()=>{
  609. setTimeout(()=>{
  610. if(!ruleMatch(r) || (checkEval && !checkEval(document))){
  611. checkReady();
  612. }else{
  613. setRule(r);
  614. }
  615. },parseInt(waitTime));
  616. };
  617. checkReady();
  618. return true;
  619. }
  620. if(r.pinUrl){
  621. setRule(r);
  622. return true;
  623. }
  624. if(!ruleMatch(r)){
  625. return false;
  626. }
  627. setRule(r);
  628. return true;
  629. }
  630. return false;
  631. }
  632.  
  633. for(let i in this.hpRules){
  634. let rule=this.hpRules[i];
  635. if(!rule || !rule.url)continue;
  636. if(rule.singleUrl){
  637. if(location.origin+location.pathname==rule.url){
  638. setRule(rule);
  639. return;
  640. }
  641. continue;
  642. }
  643. if(checkRule(rule))return;
  644. }
  645. for(let i in this.customRules){
  646. let rule=this.customRules[i];
  647. if(!rule || !rule.url)continue;
  648. if(checkRule(rule))return;
  649. }
  650. let r=0;
  651. function searchByTime(){
  652. setTimeout(()=>{
  653. let end=r+80;
  654. end=end>self.rules.length?self.rules.length:end;
  655. for(;r<end;r++){
  656. let rule=self.rules[r];
  657. if(checkRule(rule))return;
  658. }
  659. if(end>=self.rules.length){
  660. self.curSiteRule={};
  661. self.curSiteRule.url=location.origin+location.pathname;
  662. self.curSiteRule.singleUrl=true;
  663. callback();
  664. return;
  665. }else{
  666. searchByTime();
  667. }
  668. },20);
  669. }
  670. searchByTime();
  671. }
  672.  
  673. geneSelector(ele){
  674. let selector=ele.tagName;
  675. //Google id class都是隨機。百度更過分,style script順序都是隨機的
  676. //if(ele.id) selector += '#' + ele.id;
  677. //if(ele.classList) selector += [].map.call(ele.classList,d=>'.'+d).join('');
  678. let parent = ele.parentElement;
  679. if(parent){
  680. let i,j=0;
  681. for(i=0;i<parent.children.length;i++){
  682. if(parent.children[i].tagName==selector){
  683. j++;
  684. if(parent.children[i]==ele){
  685. break;
  686. }
  687. }
  688. }
  689. selector = this.geneSelector(parent) + ' > ' + selector + (parent.tagName=="HTML"?"":`:nth-of-type(${j})`);
  690. }
  691. return selector;
  692. }
  693.  
  694. getPageElement(doc, curWin, dontFind) {
  695. let pageElement=null;
  696. let self=this;
  697. if(this.curSiteRule.pageElement){
  698. pageElement=this.curSiteRule.type==0?getAllElementsByXpath(this.curSiteRule.pageElement,doc,doc):doc.querySelectorAll(this.curSiteRule.pageElement);
  699. }
  700. if((!pageElement || pageElement.length==0) && curWin && !dontFind){
  701. let body=doc.body;
  702. if(!body)return null;
  703. let bodyHeight=parseInt(body.scrollHeight);
  704. let curHeight=bodyHeight;
  705. let windowHeight=window.innerHeight || document.documentElement.clientHeight;
  706. let needCheckNext=(doc==document && this.initNext);
  707. function checkElement(ele){
  708. if(ele.childNodes && ele.childNodes.length==1)ele=ele.childNodes[0];
  709. if(ele.tagName=="PICTURE"){
  710. self.curSiteRule.pageElement=self.geneSelector(ele.parentNode)+">"+ele.tagName;
  711. debug(self.curSiteRule.pageElement);
  712. return [ele];
  713. }
  714. if(curHeight/bodyHeight<=0.25){
  715. self.curSiteRule.pageElement=allOfBody;
  716. debug(self.curSiteRule.pageElement);
  717. return [body];
  718. }
  719. if(ele.tagName=="TBODY" || ele.tagName=="UL"){
  720. self.curSiteRule.pageElement=self.geneSelector(ele)+">*";
  721. if(ele.children.length>0 && ele.children[0].querySelector("th")){
  722. self.curSiteRule.pageElement+=":not(:first-child)";
  723. }
  724. debug(self.curSiteRule.pageElement);
  725. return ele.children;
  726. }
  727. if(ele.children.length==0 && !self.curSiteRule.pageElement){
  728. if(ele.parentNode.tagName=="P")ele=ele.parentNode;
  729. self.curSiteRule.pageElement=self.geneSelector(ele.parentNode)+">"+ele.tagName;
  730. debug(self.curSiteRule.pageElement);
  731. return [ele];
  732. }
  733. let i,maxHeight=curHeight*0.6,curMaxEle=null,curMaxArea=0,maxWidth=0;
  734. let isHori=true;
  735. let offsetTop=ele.children[0].offsetTop;
  736. for(i=1;i<ele.children.length;i++){
  737. if(ele.children[i].offsetTop!=offsetTop){
  738. isHori=false;
  739. break;
  740. }
  741. }
  742. for(i=0;i<ele.children.length;i++){
  743. let curNode=ele.children[i];
  744. if(curNode.tagName=="CANVAS")continue;
  745. if(curNode.tagName!="IMG" && curNode.innerHTML=="")continue;
  746. if(needCheckNext && !curNode.contains(self.initNext) && getElementTop(curNode)>windowHeight){
  747. continue;
  748. }
  749. let comStyle=curWin.getComputedStyle(curNode);
  750. let h=parseInt(curNode.scrollHeight);
  751. let w=parseInt(curNode.scrollWidth);
  752. if(isNaN(h) || isNaN(w))continue;
  753. if(isHori && h==0)continue;
  754. let a=h*w+h,moreChild=curNode.children[0];
  755. while(moreChild){
  756. comStyle=curWin.getComputedStyle(moreChild);
  757. let ch=parseInt(moreChild.scrollHeight);
  758. let cw=parseInt(moreChild.scrollWidth);
  759. if(h<ch)h=ch;
  760. if(moreChild.innerText!="" && !isNaN(ch) && !isNaN(cw)){
  761. a+=ch*cw;
  762. }
  763. moreChild=moreChild.nextElementSibling;
  764. }
  765. let isMax=false;
  766. if(isHori){
  767. if(maxWidth<w){
  768. isMax=true;
  769. }else if(maxWidth==w && curMaxArea<a){
  770. isMax=true;
  771. }
  772. }else{
  773. isMax=curMaxArea<a;
  774. }
  775. if(curMaxEle==null || isMax){
  776. if(h>0 || !isHori)curHeight=h;
  777. curMaxArea=a;
  778. maxWidth=w;
  779. curMaxEle=curNode;
  780. }
  781. }
  782. if(curMaxEle && (isHori || curHeight>maxHeight || (needCheckNext && curHeight>windowHeight && ele.contains(self.initNext)))){
  783. return checkElement(curMaxEle);
  784. }
  785. if(ele.tagName=="P" || ele.tagName=="BR")ele=ele.parentNode;
  786. self.curSiteRule.pageElement=self.geneSelector(ele);
  787. if(ele.children.length>1){
  788. let middleChild=ele.children[parseInt(ele.children.length/2)];
  789. if((middleChild.style && middleChild.style.position=="absolute" && middleChild.style.left && middleChild.style.top) || ele.tagName=="UL" || curHeight==0){
  790. ele=[ele];
  791. }else{
  792. self.curSiteRule.pageElement+=">*";
  793. ele=ele.children;
  794. }
  795. }else{
  796. ele=[ele];
  797. }
  798. debug(self.curSiteRule.pageElement);
  799. return ele;
  800. }
  801. pageElement=checkElement(body);
  802. if(pageElement)this.saveCurSiteRule();
  803. }
  804. /*if(this.insert && this.insert.parentNode && pageElement && pageElement[0]){
  805. let example=this.insertPos==2?this.insert.children[0]:this.insert;
  806. let inTable=example.parentNode.tagName=="TABLE" ||
  807. example.tagName=="TR" ||
  808. example.tagName=="TBODY" ||
  809. (example.previousElementSibling && example.previousElementSibling.tagName=="TR") ||
  810. (example.previousElementSibling && example.previousElementSibling.tagName=="TBODY");
  811. if(inTable && pageElement[0].tagName!="TR" && pageElement[0].tagName!="TBODY"){
  812. pageElement=null;
  813. }
  814. }*/
  815. return pageElement;
  816. }
  817.  
  818. getPage(doc){
  819. if(_unsafeWindow.Discourse)return {};
  820. let canSave=false;//發現頁碼選擇器在其他頁對不上,還是別保存了
  821. let url=this.curUrl.replace("#!","").replace("index.php?","?");
  822. let pageNum=1,preStr="",afterStr="";
  823. let pageMatch1=url.match(/(.*[a-z\/\-_](?:p|page)?\/?)(\d+)(\.s?html?$|\/?$)/i);
  824. let pageMatch2=url.match(/(.*[\?&]p(?:age)?=)(\d+)($|[#&].*)/i);
  825. if(pageMatch1){
  826. preStr=pageMatch1[1];
  827. pageNum=parseInt(pageMatch1[2]);
  828. afterStr=pageMatch1[3];
  829. }else if(pageMatch2){
  830. preStr=pageMatch2[1];
  831. pageNum=parseInt(pageMatch2[2]);
  832. afterStr=pageMatch2[3];
  833. }
  834. let curPage=doc,i,cur,jsNext;
  835. let next1,next2,next3,next4,nextJs1,nextJs2,nextJs3;
  836. let next=curPage.querySelector(".page-next>a")||
  837. curPage.querySelector("a.next_page")||
  838. curPage.querySelector("#next_page")||
  839. curPage.querySelector(".nextPage")||
  840. curPage.querySelector("a[data-pagination=next]")||
  841. curPage.querySelector(".pagination a[rel=next]")||
  842. curPage.querySelector(".pagination-nav__item--next>a")||
  843. curPage.querySelector("a[title='Next page']")||
  844. curPage.querySelector("a.pageright")||
  845. curPage.querySelector("a#rightFix")||
  846. curPage.querySelector("a#next")||
  847. curPage.querySelector(".next>a")||
  848. curPage.querySelector(".next>button")||
  849. curPage.querySelector("a[alt=next]")||
  850. curPage.querySelector("button.next")||
  851. curPage.querySelector("[title=next]");
  852. if(!next){
  853. let nexts=curPage.querySelectorAll("a.next");
  854. for(i=0;i<nexts.length;i++){
  855. if(!/^([上前首尾][一1]?[页頁张張]|previous(\s*page)?\s*›?$|前のページ)/i.test(nexts[i].innerText.trim())){
  856. next=nexts[i];
  857. break;
  858. }
  859. }
  860. }
  861. if(next && (!next.href || /^javascript:/.test(next.href))){
  862. jsNext=next;
  863. next=null;
  864. }
  865. if(!next){
  866. next=curPage.querySelectorAll("[aria-label='Next']");
  867. if(next && next.length==1){
  868. next=next[0];
  869. if(!next.href || /^javascript:/.test(next.href)){
  870. jsNext=next;
  871. next=null;
  872. }
  873. }else{
  874. next=null;
  875. }
  876. }
  877. if(!next){
  878. next=curPage.querySelectorAll("[aria-label='Next page']");
  879. if(next && next.length==1){
  880. next=next[0];
  881. if(!next.href || /^javascript:/.test(next.href)){
  882. jsNext=next;
  883. next=null;
  884. }
  885. }else{
  886. next=null;
  887. }
  888. }
  889. if(next && /^[下后後][一1]?[章话話]/i.test(next.innerText.trim())){
  890. next2=next;
  891. next=null;
  892. }
  893. if(!next){
  894. next=curPage.querySelector("a.curr");
  895. if(next){
  896. next=next.nextSibling;
  897. }
  898. }
  899. if(!next){
  900. let pageDiv=curPage.querySelector("div.wp-pagenavi");
  901. if(pageDiv){
  902. cur=pageDiv.querySelector("span.current");
  903. if(cur){
  904. next=cur.nextSibling;
  905. }
  906. }else{
  907. cur=curPage.querySelector("div.article-paging>span");
  908. if(cur){
  909. next=cur.nextElementSibling;
  910. }
  911. }
  912. }
  913. if(!next){
  914. let pageDiv=curPage.querySelector("div.pages>ul");
  915. if(pageDiv){
  916. cur=pageDiv.querySelector("li>b");
  917. if(cur)next=cur.parentNode.nextElementSibling;
  918. if(next)next=next.querySelector("a");
  919. }
  920. }
  921. if(!next){
  922. cur=curPage.querySelector(".number>ul>li.active");
  923. if(cur)next=cur.nextElementSibling;
  924. if(next)next=next.querySelector("a");
  925. }
  926. if(!next){
  927. let aTags=curPage.querySelectorAll("a,button");
  928. for(i=aTags.length-1;i>=0;i--){
  929. let aTag=aTags[i];
  930. if(aTag.innerText=="§")continue;
  931. if(aTag.style.display=="none")continue;
  932. if(next1 && next2 && next3 && next4)break;
  933. if(aTag.href && /next$/i.test(aTag.href))continue;
  934. if(!next1){
  935. if(/^[下后後][一1]?[页頁张張]|^next([ _-]?page)?\s*[›>→»]?$|次のページ|^次へ?$/i.test(aTag.innerText.trim())){
  936. if(aTag.innerText.length>15)continue;
  937. if(!aTag.href || /^javascript:/.test(aTag.href)){
  938. if(!nextJs1)nextJs1=aTag;
  939. }else{
  940. next1=aTag;
  941. }
  942. }
  943. }
  944. if(!next2){
  945. if(/^[下后後][一1]?[章话話]/i.test(aTag.innerText.trim())){
  946. if(!aTag.href || /^javascript:/.test(aTag.href)){
  947. if(!nextJs2)nextJs2=aTag;
  948. }else{
  949. next2=aTag;
  950. }
  951. }
  952. }
  953. if(!next3){
  954. if(aTag.innerText=="&gt;" || aTag.innerText=="▶" || aTag.innerText==">" || aTag.innerText=="›" || aTag.innerText=="→" || aTag.innerText=="»" || /nextpage/i.test(aTag.className)){
  955. if(!aTag.href || /^javascript:/.test(aTag.href)){
  956. if(!nextJs3)nextJs3=aTag;
  957. }else{
  958. next3=aTag;
  959. }
  960. }
  961. }
  962. if(!aTag.href || /^javascript:/.test(aTag.href))continue;
  963. if(!next4 && aTag.href.length<100){
  964. let _aHref=aTag.href.replace("?&","?").replace("#!","").replace("index.php?","?");
  965. if(pageNum<999 && _aHref.replace(preStr,"").replace(afterStr,"")==pageNum+1){
  966. next4=aTag;
  967. }else if(this.curUrl!=aTag.href){
  968. let _url=url.replace(/\.s?html?$/i,"");
  969. _aHref=_aHref.replace(/\.s?html?$/i,"");
  970. if(_aHref.indexOf(_url)!=-1 && /^[\/\?&]?[_-]?(p|page)?=?\/?2(\/|\?|&|$)/i.test(_aHref.replace(_url,""))){
  971. let curHref=aTag.getAttribute("href");
  972. let pageOne=curHref.replace(/\/2(\/|\?|&|$)/,"/1$1");
  973. if(pageOne==curHref)pageOne=null;
  974. else pageOne=curPage.querySelector(`a[href='${pageOne}']`);
  975. if(!pageOne || pageOne.className!=curHref.className)next4=aTag;
  976. }
  977. }
  978. }
  979. }
  980. next=next1||next4||next3||next2||nextJs1||nextJs3||nextJs2;
  981. }
  982. if(!next)next=jsNext;
  983. if(next && next.classList.contains("results-more"))next=null;
  984. return {next:next,canSave:canSave};
  985. }
  986.  
  987. canonicalUri(src, base_path) {
  988. if(src.charAt(0)=="#")return location.href+src;
  989. var root_page = /^[^?#]*\//.exec(location.href)[0],
  990. root_domain = /^\w+\:\/\/\/?[^\/]+/.exec(root_page)[0],
  991. absolute_regex = /^\w+\:\/\//;
  992. src=src.replace(/\.\//,"");
  993. if (/^\/\/\/?/.test(src)){
  994. src = location.protocol + src;
  995. }
  996. else if (!absolute_regex.test(src) && src.charAt(0) != "/"){
  997. src = (base_path || "") + src;
  998. }
  999. return (absolute_regex.test(src) ? src : ((src.charAt(0) == "/" ? root_domain : root_page) + src));
  1000. }
  1001.  
  1002. getLinkByPage(url, pageNum) {
  1003. if(!url)return;
  1004. if(this.curSiteRule.pageNum){
  1005. let result=this.curSiteRule.pageNum;
  1006. let strMatch=result.match(/\{.*?}/);
  1007. if(!strMatch)return null;
  1008. let urlReg=new RegExp("("+result.replace(strMatch[0], ")\\d+(")+")","i");
  1009. let code=strMatch[0].replace(/^{/,"").replace(/}$/,"").replace(/\$p/g,pageNum);
  1010. if(code==pageNum){
  1011. result=url.replace(urlReg,"$1"+code+"$2");
  1012. }else{
  1013. try{
  1014. code=Function('"use strict";return ' + code)();
  1015. result=url.replace(urlReg,"$1"+code+"$2");
  1016. }catch(e){
  1017. debug(e);
  1018. }
  1019. }
  1020. return result==url?url.replace(/([&\/\?](p=|page[=\/]))\d+/i, "$1"+pageNum).replace(/([_-])\d+\./i, "$1"+pageNum+"."):result;
  1021. }else{
  1022. return url.replace(/([&\/\?](p=|page[=\/]))\d+/i, "$1"+pageNum).replace(/([_-])\d+\./i, "$1"+pageNum+".");
  1023. }
  1024. }
  1025.  
  1026. getNextLink(doc) {
  1027. let nextLink=null,page;
  1028. if(this.curSiteRule.pageElementByJs){
  1029. this.nextLinkHref="#";
  1030. return true;
  1031. }else if(this.curSiteRule.nextLinkByJs){
  1032. try{
  1033. let targetUrl=Function("doc",'"use strict";' + this.curSiteRule.nextLinkByJs)(doc);
  1034. if(targetUrl)nextLink={href:targetUrl};
  1035. }catch(e){
  1036. debug(e);
  1037. }
  1038. }else if(this.curSiteRule.nextLinkByUrl){
  1039. let targetUrl=this.curUrl.replace(new RegExp(this.curSiteRule.nextLinkByUrl[0],"i"), this.curSiteRule.nextLinkByUrl[1]);
  1040. if(targetUrl != this.curUrl){
  1041. let reps=targetUrl.match(/{.*?}/g);
  1042. if(reps){
  1043. reps.forEach(rep=>{
  1044. let code=rep.replace("{","").replace("}","");
  1045. let result=code.match(/^(\d+)\+1$/);
  1046. if(result){
  1047. result=parseInt(result[1])+1;
  1048. }else{
  1049. try{
  1050. result=Function('"use strict";return ' + code)();
  1051. }catch(e){
  1052. debug(e);
  1053. }
  1054. }
  1055. targetUrl=targetUrl.replace(rep, result);
  1056. });
  1057. }
  1058. }
  1059. nextLink={href:targetUrl};
  1060. }else if(this.curSiteRule.nextLink){
  1061. if(this.curSiteRule.nextLink!="0"){
  1062. nextLink=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.nextLink,doc,doc):doc.querySelector(this.curSiteRule.nextLink);
  1063. }
  1064. }else{
  1065. page=this.getPage(doc);
  1066. nextLink=page.next;
  1067. if(nextLink){
  1068. if(nextLink.tagName=="INPUT" && nextLink.parentNode.tagName=="FORM"){
  1069. let params=[];
  1070. let form=nextLink.parentNode;
  1071. [].forEach.call(form.querySelectorAll("input"), input=>{
  1072. params.push(input.name+'='+input.value);
  1073. });
  1074. nextLink.href=form.action+'?'+params.join('&');
  1075. }
  1076. if(nextLink.classList.contains("noClick")){
  1077. this.nextLinkHref=false;
  1078. return null;
  1079. }else if(doc==document){
  1080. if((!nextLink.href || /^javascript:/.test(nextLink.href)) && !isVisible(nextLink, _unsafeWindow)){
  1081. this.nextLinkHref=false;
  1082. return null;
  1083. }else{
  1084. let nextLinkCs=_unsafeWindow.getComputedStyle(nextLink);
  1085. if(nextLinkCs.cursor=="not-allowed"){
  1086. this.nextLinkHref=false;
  1087. return null;
  1088. }
  1089. this.initNext=nextLink;
  1090. }
  1091. }
  1092. }
  1093. }
  1094. if(nextLink){
  1095. let needUrl=(this.curSiteRule.action==0 || this.curSiteRule.action==1);
  1096. let href=nextLink.getAttribute?nextLink.getAttribute("href"):nextLink.href;
  1097. if(href==="" && needUrl){
  1098. this.nextLinkHref=false;
  1099. }else if(/^(javascript:|#)/.test(href) && needUrl){
  1100. this.nextLinkHref=false;
  1101. }else{
  1102. this.nextLinkHref=(href && !/^(javascript:|#)/.test(href) && nextLink.href!=location.href)?this.canonicalUri(nextLink.href):"#";
  1103. if(this.nextLinkHref!="#" && (this.nextLinkHref==this.curUrl || this.nextLinkHref==this.curUrl+"#" || this.nextLinkHref==this.oldUrl || this.nextLinkHref==this.oldUrl+"#")){
  1104. this.nextLinkHref=false;
  1105. }else if(doc==document)debug(nextLink);
  1106. }
  1107. }else{
  1108. this.nextLinkHref=false;
  1109. }
  1110. this.preload();
  1111. return nextLink;
  1112. }
  1113.  
  1114. preload(){
  1115. if(!rulesData.preload)return;
  1116. if(!this.nextLinkHref || this.nextLinkHref=="#")return;
  1117. let self=this;
  1118. if(this.curSiteRule && this.curSiteRule.action==1){
  1119. if(!this.preloadIframe){
  1120. this.preloadIframe = document.createElement('iframe');
  1121. let iframe = this.preloadIframe;
  1122. iframe.name = 'pagetual-iframe';
  1123. iframe.width = '100%';
  1124. iframe.height = '0';
  1125. iframe.frameBorder = '0';
  1126. if(ruleParser.curSiteRule.sandbox!=false){
  1127. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1128. }
  1129. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1130. iframe.addEventListener('load', function (e) {
  1131. try{
  1132. let doc=iframe.contentDocument || iframe.contentWindow.document;
  1133. var body = doc.body;
  1134. if (body && body.firstChild) {
  1135. self.lazyImgAction(body.children);
  1136. }
  1137. }catch(e){
  1138. return;
  1139. }
  1140. }, false);
  1141. document.body.appendChild(iframe);
  1142. }
  1143. this.preloadIframe.src = this.nextLinkHref;
  1144. }else{
  1145. _GM_xmlhttpRequest({
  1146. url: this.nextLinkHref,
  1147. method: 'GET',
  1148. overrideMimeType: 'text/html;charset='+document.charset,
  1149. headers: {
  1150. 'Referer': location.href
  1151. },
  1152. timeout: 5000,
  1153. onload: function(res) {
  1154. var doc=null;
  1155. try {
  1156. doc=document.implementation.createHTMLDocument('');
  1157. doc.documentElement.innerHTML=res.response;
  1158. var body = doc.body;
  1159. if (body && body.firstChild) {
  1160. self.lazyImgAction(body.children);
  1161. }
  1162. if(!self.preloadDiv){
  1163. self.preloadDiv = document.createElement('div');
  1164. self.preloadDiv.id = "pagetual-preload";
  1165. self.preloadDiv.style.cssText = 'display:none!important;';
  1166. document.body.appendChild(self.preloadDiv);
  1167. self.checkedImgs={};
  1168. }
  1169. [].forEach.call(doc.images, i=>{
  1170. let iSrc=i.src;
  1171. if(iSrc && !self.checkedImgs[iSrc]){
  1172. self.checkedImgs[iSrc] = true;
  1173. let img = document.createElement('img');
  1174. img.src = iSrc;
  1175. self.preloadDiv.appendChild(img);
  1176. }
  1177. });
  1178. }
  1179. catch (e) {
  1180. return;
  1181. }
  1182. }
  1183. });
  1184. }
  1185. }
  1186.  
  1187. getInsert(refresh) {
  1188. if(refresh){
  1189. this.insert=null;
  1190. }
  1191. if(this.insert && !refresh){
  1192. let parent=this.insert;
  1193. while(parent && parent.nodeName!="BODY"){
  1194. parent=parent.parentNode;
  1195. }
  1196. if(parent && parent.nodeName=="BODY"){
  1197. return this.insert;
  1198. }
  1199. }
  1200. if(this.curSiteRule.insert){
  1201. this.insert=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.insert,document):document.querySelector(this.curSiteRule.insert);
  1202. }else{
  1203. let pageElement=this.getPageElement(document, _unsafeWindow);
  1204. if(pageElement && pageElement.length>0){
  1205. var pELast = pageElement[pageElement.length - 1];
  1206. this.insert = pELast.nextSibling ? pELast.nextSibling : pELast.parentNode.appendChild(document.createTextNode(' '));
  1207. }
  1208. }
  1209. return this.insert;
  1210. }
  1211.  
  1212. pageInit(doc,eles){
  1213. let code=this.curSiteRule.pageInit;
  1214. if(code){
  1215. try{
  1216. Function("doc","eles",'"use strict";' + code)(doc,eles);
  1217. }catch(e){
  1218. debug(e);
  1219. }
  1220. }
  1221. }
  1222.  
  1223. pageAction(doc,eles){
  1224. let code=this.curSiteRule.pageAction;
  1225. if(code){
  1226. try{
  1227. Function("doc","eles",'"use strict";' + code)(doc,eles);
  1228. }catch(e){
  1229. debug(e);
  1230. }
  1231. }
  1232. this.lazyImgAction(eles);
  1233. }
  1234.  
  1235. lazyImgAction(eles){
  1236. let setLazyImg=img=>{
  1237. let realSrc;
  1238. if(img.getAttribute("_src") && !img.src){
  1239. realSrc=img.getAttribute("_src");
  1240. }else if(img.dataset && img.dataset.original){
  1241. realSrc=img.dataset.original;
  1242. }else if(img.dataset && img.dataset.src){
  1243. realSrc=img.dataset.src;
  1244. }else if(img._lazyrias && img._lazyrias.srcset){
  1245. realSrc=img._lazyrias.srcset[img._lazyrias.srcset.length-1];
  1246. }else if(img.dataset && img.dataset.origFile){
  1247. realSrc=img.dataset.origFile;
  1248. }else if(img.srcset){
  1249. var srcs=img.srcset.split(/[xw],/),largeSize=0;
  1250. srcs.forEach(srci=>{
  1251. let srcInfo=srci.trim().split(" "),curSize=parseInt(srcInfo[1]);
  1252. if(srcInfo[1] && curSize>largeSize){
  1253. largeSize=curSize;
  1254. realSrc=srcInfo[0];
  1255. }
  1256. });
  1257. }
  1258. if(realSrc){
  1259. img.src=realSrc;
  1260. img.style.display="block";
  1261. }
  1262. };
  1263. [].forEach.call(eles, ele=>{
  1264. if(ele.tagName=="IMG"){
  1265. setLazyImg(ele);
  1266. }else{
  1267. [].forEach.call(ele.querySelectorAll("img"), img=>{
  1268. setLazyImg(img);
  1269. });
  1270. }
  1271. if(ele.tagName=="A" && ele.classList.contains("lazyload")){
  1272. if(ele.dataset.original){
  1273. ele.style.backgroundImage='url("'+ele.dataset.original+'")';
  1274. }
  1275. }else{
  1276. [].forEach.call(ele.querySelectorAll("a.lazyload"), a=>{
  1277. if(a.dataset.original){
  1278. a.style.backgroundImage='url("'+a.dataset.original+'")';
  1279. }
  1280. });
  1281. }
  1282. });
  1283. let lazyImgSrc=this.curSiteRule.lazyImgSrc;
  1284. if(lazyImgSrc){
  1285. [].forEach.call(eles, ele=>{
  1286. [].forEach.call(ele.querySelectorAll("img"), img=>{
  1287. if(img.getAttribute(lazyImgSrc)){
  1288. img.src=img.getAttribute(lazyImgSrc);
  1289. }
  1290. });
  1291. });
  1292. }
  1293. }
  1294.  
  1295. initPage(callback){
  1296. let self=this;
  1297. curPage=1;
  1298. //if(this.curSiteRule.url && !this.curSiteRule.singleUrl)return;
  1299. this.curSiteRule={};
  1300. this.pageDoc=document;
  1301. this.nextLinkHref=null;
  1302. this.curUrl=location.href;
  1303. this.getRule(()=>{
  1304. if(self.curSiteRule.enable==0){
  1305. debug("Stop as rule disable");
  1306. isPause=true;
  1307. return;
  1308. }
  1309. if(self.curSiteRule && !self.curSiteRule.singleUrl){
  1310. self.hpRules=self.hpRules.filter(item=>{return item&&item.url!=self.curSiteRule.url});
  1311. self.hpRules.unshift(self.curSiteRule);
  1312. if(self.hpRules.length>30){
  1313. self.hpRules.pop();
  1314. }
  1315. storage.setItem("hpRules", self.hpRules);
  1316. }
  1317. let css=self.curSiteRule.css;
  1318. if(css){
  1319. _GM_addStyle(css);
  1320. }
  1321. let code=self.curSiteRule.init;
  1322. if(code){
  1323. try{
  1324. Function('doc','win','"use strict";' + code)(null,null);
  1325. }catch(e){
  1326. debug(e);
  1327. }
  1328. }
  1329. self.getNextLink(document);
  1330. callback();
  1331. });
  1332. }
  1333.  
  1334. insertPage(doc, eles, url, callback, tried){
  1335. this.oldUrl=this.curUrl;
  1336. let oldTitle=this.pageDoc.title;
  1337. this.pageDoc=doc;
  1338. this.curUrl=url;
  1339. let nextLink=this.getNextLink(doc);
  1340. if(curPage==1 && !tried && !nextLink && this.curSiteRule.singleUrl && this.curSiteRule.pageElement && this.curSiteRule.action!=0){
  1341. this.curSiteRule.action=1;
  1342. this.curUrl=location.href;
  1343. return false;
  1344. }
  1345. if(callback)callback(eles);
  1346. this.getInsert();
  1347. var self=this,newEles=[];
  1348. if(!eles || eles.length==0 || !self.insert || !self.insert.parentNode){
  1349. }else{
  1350. this.pageInit(doc, eles);
  1351. [].forEach.call(eles, ele=>{
  1352. let newEle=ele.cloneNode(true);
  1353. let oldCanvass=ele.querySelectorAll("canvas");
  1354. let newCanvass=newEle.querySelectorAll("canvas");
  1355. for(let i=0;i<oldCanvass.length;i++){
  1356. let oldCanvas=oldCanvass[i];
  1357. let newCanvas=newCanvass[i];
  1358. newCanvas.getContext('2d').drawImage(oldCanvas, 0, 0);
  1359. }
  1360. if(self.curSiteRule.insertPos==2){
  1361. self.insert.appendChild(newEle);
  1362. }else{
  1363. self.insert.parentNode.insertBefore(newEle, self.insert);
  1364. }
  1365. newEles.push(newEle);
  1366. });
  1367. }
  1368. this.pageAction(doc, newEles);
  1369. if(this.oldUrl!=location.href){
  1370. let isJs=/^(javascript|#)/.test(this.oldUrl.replace(location.href,""));
  1371. if(rulesData.enableHistory && !isJs){
  1372. _unsafeWindow.history.replaceState(undefined, oldTitle, this.oldUrl);
  1373. document.title=oldTitle;
  1374. }
  1375. }
  1376. return true;
  1377. }
  1378. }
  1379. var ruleParser = new RuleParser();
  1380.  
  1381. function initConfig(){
  1382. _GM_registerMenuCommand(i18n(forceState==1?"enable":"disableSite"), ()=>{
  1383. storage.setItem("forceState_"+location.host, (forceState==1?0:1));
  1384. location.reload();
  1385. });
  1386. _GM_registerMenuCommand(i18n("update"), ()=>{
  1387. updateRules(()=>{
  1388. alert(i18n("updateSucc"));
  1389. location.reload();
  1390. },(rule,err)=>{
  1391. alert("Update "+rule.url+" rules fail!");
  1392. });
  1393. alert(i18n("beginUpdate"));
  1394. });
  1395.  
  1396. var configCon,insertPos;
  1397. if(ruleImportUrlReg.test(location.href)){
  1398. document.addEventListener("click", e=>{
  1399. if(e.target.tagName=="PRE"){
  1400. let nameAttr=e.target.getAttribute("name");
  1401. if(nameAttr=="pagetual" || nameAttr=="user-content-pagetual"){
  1402. let rules=e.target.innerText.trim().split("\n");
  1403. let diff=false;
  1404. for(let c=0;c<rules.length;c++){
  1405. let urlArr=rules[c].split("|"),url,type=1;
  1406. if(urlArr.length==1){
  1407. url=urlArr[0].trim();
  1408. if(!/^http/.test(url)){
  1409. alert("Wrong url, check again!");
  1410. return;
  1411. }
  1412. }else if(urlArr.length==2){
  1413. type=urlArr[0].trim();
  1414. url=urlArr[1].trim();
  1415. if(!/^http/.test(url)){
  1416. alert("Wrong url, check again!");
  1417. return;
  1418. }
  1419. }else{
  1420. break;
  1421. }
  1422. let maxId=0,hasUrl=false;
  1423. if(!rulesData.urls){
  1424. rulesData.urls=[];
  1425. maxId=1;
  1426. }else{
  1427. rulesData.urls.forEach(u=>{
  1428. if(maxId<u.id){
  1429. maxId=u.id;
  1430. }
  1431. if(u.url==url){
  1432. hasUrl=true;
  1433. }
  1434. });
  1435. if(hasUrl)break;
  1436. }
  1437. diff=true;
  1438. if(!rulesData.sort)rulesData.sort=[1];
  1439. rulesData.urls.push({id:maxId+1,url:url,type:type});
  1440. rulesData.sort.unshift(maxId+1);
  1441. }
  1442. if(!diff)return;
  1443. storage.setItem("rulesData", rulesData);
  1444.  
  1445. if(rulesData.urls)ruleUrls=ruleUrls.concat(rulesData.urls);
  1446. if(rulesData.sort){
  1447. let urls=[];
  1448. rulesData.sort.forEach(id=>{
  1449. for(let s=0;s<ruleUrls.length;s++){
  1450. if(id==ruleUrls[s].id){
  1451. urls.push(ruleUrls[s]);
  1452. break;
  1453. }
  1454. }
  1455. });
  1456. ruleUrls=urls;
  1457. }
  1458. alert("OK");
  1459. }
  1460. }
  1461. });
  1462. }
  1463. if(location.href==configPage){
  1464. _GM_addStyle(`
  1465. p>span:nth-child(1),p>span:nth-child(2),p>span:nth-child(3){
  1466. cursor: pointer;
  1467. user-select: none;
  1468. }
  1469. p>span:nth-child(1):hover,p>span:nth-child(2):hover,p>span:nth-child(3):hover{
  1470. color:red;
  1471. }
  1472. .updateDate{
  1473. cursor: pointer;
  1474. user-select: none;
  1475. }
  1476. .updateDate:hover{
  1477. color:red;
  1478. }
  1479. `);
  1480. document.querySelector("[name='user-content-click2import']").innerText=i18n("click2ImportRule")
  1481. configCon=document.querySelector(".markdown-body");
  1482. insertPos=configCon.querySelector("hr");
  1483.  
  1484. if(rulesData.urls && rulesData.urls.length>0){
  1485. document.querySelector("pre[name='user-content-pagetual']").style.display="none";
  1486. document.querySelector("p[name='user-content-click2import']").style.display="none";
  1487. }
  1488. }else return false;
  1489. class Rulebar {
  1490. init(ruleUrl){
  1491. this.ruleUrl=ruleUrl;
  1492. this.item=document.createElement("p");
  1493. this.item.title=ruleUrl.type==0?"AutoPagerize Rules":"Pagetual Rules";
  1494. this.item.dataset.id=this.ruleUrl.id;
  1495. let url=document.createElement("span");
  1496. url.innerHTML=ruleUrl.url;
  1497. let up=document.createElement("span");
  1498. up.innerHTML="↑ ";
  1499. up.title=i18n("sortTitle");
  1500. let down=document.createElement("span");
  1501. down.innerHTML="↓ ";
  1502. down.title=i18n("sortTitle");
  1503. let del=document.createElement("span");
  1504. del.innerHTML="× ";
  1505. up.onclick=e=>{
  1506. this.moveUp();
  1507. };
  1508. down.onclick=e=>{
  1509. this.moveDown();
  1510. };
  1511. del.onclick=e=>{
  1512. this.del();
  1513. };
  1514. this.item.appendChild(up);
  1515. this.item.appendChild(down);
  1516. this.item.appendChild(del);
  1517. this.item.appendChild(url);
  1518. configCon.insertBefore(this.item, insertPos);
  1519. }
  1520. saveSort(){
  1521. let sort=[];
  1522. [].forEach.call(this.item.parentNode.querySelectorAll("p[data-id]"), i=>{
  1523. sort.push(i.dataset.id);
  1524. });
  1525. rulesData.sort=sort;
  1526. storage.setItem("rulesData", rulesData);
  1527. }
  1528. moveUp(){
  1529. let preE=this.item.previousElementSibling;
  1530. if(preE.tagName=="P" && preE.children.length>1){
  1531. this.item.parentNode.insertBefore(this.item,preE);
  1532. this.saveSort();
  1533. }
  1534. }
  1535. moveDown(){
  1536. let nextE=this.item.nextElementSibling;
  1537. if(nextE.tagName=="P" && nextE.children.length>1){
  1538. this.item.parentNode.insertBefore(nextE,this.item);
  1539. this.saveSort();
  1540. }
  1541. }
  1542. del(){
  1543. if(this.ruleUrl.id<2){
  1544. alert(i18n("cantDel"));
  1545. }else if(window.confirm(i18n("confirmDel"))){
  1546. for(let u=0;u<rulesData.urls.length;u++){
  1547. if(this.ruleUrl.id==rulesData.urls[u].id){
  1548. rulesData.urls.splice(u,1);
  1549. break;
  1550. }
  1551. }
  1552. for(let u=0;u<rulesData.sort.length;u++){
  1553. if(this.ruleUrl.id==rulesData.sort[u]){
  1554. rulesData.sort.splice(u,1);
  1555. break;
  1556. }
  1557. }
  1558. storage.setItem("rulesData", rulesData);
  1559. ruleParser.rules=ruleParser.rules.filter(item=>{return item.from!=this.ruleUrl.id});
  1560. storage.setItem("rules", ruleParser.rules);
  1561. this.item.parentNode.removeChild(this.item);
  1562. //location.reload();
  1563. }
  1564. }
  1565. }
  1566. let updateP=document.createElement("p"),i=0;
  1567. let now=new Date().getTime(),inUpdate=false;
  1568.  
  1569.  
  1570. let pastDate=(new Date(updateDate)).toString(),passStr;
  1571. let passTime=(now-updateDate)/1000;
  1572. if(isNaN(passTime)){
  1573. passStr=i18n("firstUpdate");
  1574. }else if(passTime<60){
  1575. passStr=i18n("passSec", parseInt(passTime))+" ← "+i18n("click2update");
  1576. }else if(passTime<60*60){
  1577. passStr=i18n("passMin", parseInt(passTime/60))+" ← "+i18n("click2update");
  1578. }else if(passTime<60*60*24){
  1579. passStr=i18n("passHour", parseInt(passTime/3600))+" ← "+i18n("click2update");
  1580. }else{
  1581. passStr=i18n("passDay", parseInt(passTime/86400))+" ← "+i18n("click2update");
  1582. }
  1583.  
  1584.  
  1585. updateP.className="updateDate";
  1586. updateP.innerHTML=passStr;
  1587. updateP.title=i18n("update")+" - "+pastDate;
  1588. updateP.onclick=e=>{
  1589. updateRules(()=>{
  1590. alert(i18n("updateSucc"));
  1591. updateP.innerHTML=i18n("passSec", 0);
  1592. updateP.title=i18n("update");
  1593. },(rule,err)=>{
  1594. alert("Update "+rule.url+" rules fail!");
  1595. });
  1596. alert(i18n("beginUpdate"));
  1597. };
  1598. configCon.insertBefore(updateP, insertPos);
  1599. if(ruleUrls){
  1600. ruleUrls.forEach(ruleUrl=>{
  1601. var rulebar=new Rulebar();
  1602. rulebar.init(ruleUrl);
  1603. });
  1604. }
  1605. let customUrlsTitle=document.createElement("h2");
  1606. customUrlsTitle.innerHTML=i18n("customUrls");
  1607. configCon.insertBefore(customUrlsTitle, insertPos);
  1608. let customUrlsInput=document.createElement("textarea");
  1609. customUrlsInput.style.width="100%";
  1610. customUrlsInput.placeholder="0|http://wedata.net/databases/AutoPagerize/items_all.json";
  1611. configCon.insertBefore(customUrlsInput, insertPos);
  1612.  
  1613. let opacityTitle=document.createElement("h2");
  1614. opacityTitle.innerHTML=i18n("opacity");
  1615. let opacityInput=document.createElement("input");
  1616. opacityInput.value=rulesData.opacity*100;
  1617. opacityInput.type="number";
  1618. opacityInput.style.width="50px";
  1619. opacityInput.style.margin="0 0 0 10px";
  1620. opacityTitle.appendChild(opacityInput);
  1621. configCon.insertBefore(opacityTitle, insertPos);
  1622.  
  1623. function createCheckbox(innerText, val){
  1624. let title=document.createElement("h2");
  1625. title.innerHTML=innerText;
  1626. let input=document.createElement("input");
  1627. input.type="checkbox";
  1628. input.style.width="50px";
  1629. input.style.height="20px";
  1630. input.checked=val;
  1631. title.appendChild(input);
  1632. configCon.insertBefore(title, insertPos);
  1633. return input;
  1634. }
  1635.  
  1636. let hideBarInput=createCheckbox(i18n("hideBar"), rulesData.hideBar);
  1637. let dbClick2StopInput=createCheckbox(i18n("dbClick2Stop"), rulesData.dbClick2Stop);
  1638. let enableWhiteListInput=createCheckbox(i18n("autoRun"), rulesData.enableWhiteList!=true);
  1639. let enableDebugInput=createCheckbox(i18n("enableDebug"), rulesData.enableDebug!=false);
  1640. let enableHistoryInput=createCheckbox(i18n("enableHistory"), rulesData.enableHistory===true);
  1641. let initRunInput=createCheckbox(i18n("initRun"), rulesData.initRun!=false);
  1642. let preloadInput=createCheckbox(i18n("preload"), rulesData.preload);
  1643.  
  1644. let customRulesTitle=document.createElement("h2");
  1645. customRulesTitle.innerHTML=i18n("customRules")
  1646. configCon.insertBefore(customRulesTitle, insertPos);
  1647. let customRulesInput=document.createElement("textarea");
  1648. customRulesInput.style.width="100%";
  1649. customRulesInput.style.height="500px";
  1650. 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]`;
  1651. customRulesInput.value=getFormatJSON(ruleParser.customRules);
  1652. configCon.insertBefore(customRulesInput, insertPos);
  1653. let saveBtn=document.createElement("button");
  1654. saveBtn.innerHTML=i18n("save");
  1655. saveBtn.style.width="100%";
  1656. configCon.insertBefore(saveBtn, insertPos);
  1657. saveBtn.onclick=e=>{
  1658. try{
  1659. storage.setItem("hpRules", []);
  1660. if(customRulesInput.value==""){
  1661. storage.setItem("customRules", "");
  1662. }else{
  1663. let customRules=JSON.parse(customRulesInput.value);
  1664. if(Array && Array.isArray && !Array.isArray(customRules)){
  1665. alert("Rules must be a Array!");
  1666. return;
  1667. }
  1668. debug(customRules);
  1669. storage.setItem("customRules", customRules);
  1670. }
  1671. }catch(e){
  1672. debug(e);
  1673. alert("JSON error, check again!");
  1674. return;
  1675. }
  1676. rulesData.opacity=opacityInput.value/100;
  1677. rulesData.hideBar=hideBarInput.checked;
  1678. rulesData.dbClick2Stop=dbClick2StopInput.checked;
  1679. rulesData.enableWhiteList=!enableWhiteListInput.checked;
  1680. rulesData.enableDebug=enableDebugInput.checked;
  1681. rulesData.enableHistory=enableHistoryInput.checked;
  1682. rulesData.initRun=initRunInput.checked;
  1683. rulesData.preload=preloadInput.checked;
  1684. storage.setItem("rulesData", rulesData);
  1685. let customUrls=customUrlsInput.value.trim();
  1686. if(customUrls){
  1687. customUrls=customUrls.split(/\n/);
  1688. for(let c=0;c<customUrls.length;c++){
  1689. let urlArr=customUrls[c].split("|"),url,type=1;
  1690. if(urlArr.length==1){
  1691. url=urlArr[0].trim();
  1692. if(!/^http/.test(url)){
  1693. alert("Wrong url, check again!");
  1694. return;
  1695. }
  1696. }else if(urlArr.length==2){
  1697. type=urlArr[0].trim();
  1698. url=urlArr[1].trim();
  1699. if(!/^http/.test(url)){
  1700. alert("Wrong url, check again!");
  1701. return;
  1702. }
  1703. }else{
  1704. break;
  1705. }
  1706. let maxId=0,hasUrl=false;
  1707. if(!rulesData.urls){
  1708. rulesData.urls=[];
  1709. maxId=1;
  1710. }else{
  1711. rulesData.urls.forEach(u=>{
  1712. if(maxId<u.id){
  1713. maxId=u.id;
  1714. }
  1715. if(u.url==url){
  1716. hasUrl=true;
  1717. }
  1718. });
  1719. if(hasUrl)break;
  1720. }
  1721. if(!rulesData.sort)rulesData.sort=[1];
  1722. rulesData.urls.push({id:maxId+1,url:url,type:type});
  1723. rulesData.sort.push(maxId+1);
  1724. storage.setItem("rulesData", rulesData);
  1725. }
  1726. }
  1727. alert("The settings are saved");
  1728. location.reload();
  1729. };
  1730. return true;
  1731. }
  1732.  
  1733. var inUpdate=false;
  1734. function updateRules(success,fail){
  1735. if(inUpdate)return;
  1736. inUpdate=true;
  1737. let ruleIndex=ruleUrls.length-1;
  1738. storage.setItem("hpRules", []);
  1739. function addNextRule(){
  1740. if(ruleIndex<0){
  1741. let now=new Date().getTime();
  1742. storage.setItem("ruleLastUpdate", now);
  1743. storage.setItem("rules", ruleParser.rules);
  1744. inUpdate=false;
  1745. success();
  1746. }else{
  1747. let rule=ruleUrls[ruleIndex--];
  1748. ruleParser.addRuleByUrl(rule.url, rule.type, rule.id, (json,err)=>{
  1749. if(!json){
  1750. fail(rule,err);
  1751. }
  1752. addNextRule();
  1753. })
  1754. }
  1755. }
  1756. addNextRule();
  1757. }
  1758.  
  1759. function objIsArr(obj) {
  1760. return obj &&
  1761. typeof obj === 'object' &&
  1762. typeof obj.length === 'number' &&
  1763. !(obj.propertyIsEnumerable('length'));
  1764. }
  1765.  
  1766. function isVisible(el, win) {
  1767. if(!el.offsetParent)return false;
  1768. var loopable = true,
  1769. visible = el.tagName && win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  1770. while(loopable && visible) {
  1771. el = el.parentNode;
  1772.  
  1773. if(el && el.tagName && el.tagName!="BODY") {
  1774. visible = win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  1775. }else {
  1776. loopable = false;
  1777. }
  1778. }
  1779. return visible;
  1780. }
  1781.  
  1782. function getElementTop(ele) {
  1783. var actualTop = ele.offsetTop;
  1784. var current = ele.offsetParent;
  1785. while (current !== null) {
  1786. actualTop += current.offsetTop;
  1787. current = current.offsetParent;
  1788. }
  1789. return actualTop;
  1790. }
  1791.  
  1792. function getFormatJSON(obj){
  1793. if(!objIsArr(obj))return "";
  1794. let ret="[\n";
  1795. let len=obj.length,i=0,isLast;
  1796. obj.forEach(item=>{
  1797. ret+=" {\n";
  1798. let iLen=Object.keys(item).length,j=0;
  1799. for(let key in item){
  1800. isLast=(++j)==iLen;
  1801. let value=item[key];
  1802. if(objIsArr(value)){
  1803. let vstr="[",v=0,vIsLast=false;
  1804. value.forEach(vi=>{
  1805. vIsLast=(++v)==value.length;
  1806. vstr+="\""+vi.replace(/\\/g,"\\\\")+"\""+(vIsLast?"":",");
  1807. });
  1808. vstr+="]";
  1809. ret+=" \""+key+"\":"+vstr+""+(isLast?"":",")+"\n";
  1810. }else{
  1811. if(typeof value=="string"){
  1812. value=value.replace(/\\/g,"\\\\").replace(/"/g,"\\\"");
  1813. value="\""+value+"\"";
  1814. }
  1815. ret+=" \""+key+"\":"+value+""+(isLast?"":",")+"\n";
  1816. }
  1817. }
  1818. isLast=(++i)==len;
  1819. ret+=" }"+(isLast?"":",")+"\n";
  1820. });
  1821. ret+="]";
  1822. return ret;
  1823. }
  1824.  
  1825. function initRules(callback) {
  1826. /*0 wedata格式,1 pagetual格式*/
  1827. ruleUrls=[
  1828. {
  1829. id:1,
  1830. url:'http://wedata.net/databases/AutoPagerize/items_all.json',
  1831. type:0,
  1832. }
  1833. ];var i=0,j=0;
  1834.  
  1835. ruleParser.initSavedRules(()=>{
  1836. storage.getItem("rulesData", data=>{
  1837. if(data){
  1838. rulesData=data;
  1839. if(data.urls)ruleUrls=ruleUrls.concat(data.urls);
  1840. if(data.sort){
  1841. let urls=[];
  1842. data.sort.forEach(id=>{
  1843. for(let s=0;s<ruleUrls.length;s++){
  1844. if(id==ruleUrls[s].id){
  1845. urls.push(ruleUrls[s]);
  1846. break;
  1847. }
  1848. }
  1849. });
  1850. ruleUrls=urls;
  1851. }
  1852. }
  1853. if(typeof(rulesData.opacity)=="undefined"){
  1854. rulesData.opacity=0.3;
  1855. }
  1856. if(typeof(rulesData.hideBar)=="undefined"){
  1857. rulesData.hideBar=false;
  1858. }
  1859. if(typeof(rulesData.dbClick2Stop)=="undefined"){
  1860. rulesData.dbClick2Stop=true;
  1861. }
  1862. if(typeof(rulesData.enableWhiteList)=="undefined"){
  1863. rulesData.enableWhiteList=false;
  1864. }
  1865. if(typeof(rulesData.enableHistory)=="undefined"){
  1866. rulesData.enableHistory=false;
  1867. }
  1868. if(typeof(rulesData.enableDebug)=="undefined"){
  1869. rulesData.enableDebug=true;
  1870. }
  1871. if(typeof(rulesData.initRun)=="undefined"){
  1872. rulesData.initRun=true;
  1873. }
  1874. if(typeof(rulesData.preload)=="undefined"){
  1875. rulesData.preload=false;
  1876. }
  1877. enableDebug=rulesData.enableDebug;
  1878. storage.getItem("forceState_"+location.host, v=>{
  1879. storage.getItem("ruleLastUpdate", date=>{
  1880. if(typeof(v)=="undefined"){
  1881. v=(rulesData.enableWhiteList?1:0);
  1882. }
  1883. forceState=v;
  1884. updateDate=date;
  1885. if(initConfig())return;
  1886. if(forceState==1)return;
  1887. let now=new Date().getTime();
  1888. if(!date || now-date>2*24*60*60*1000){
  1889. //storage.setItem("ruleLastUpdate", now);
  1890. updateRules(()=>{
  1891. //callback();
  1892. },(rule,err)=>{});
  1893. }
  1894. callback();
  1895. });
  1896. });
  1897. });
  1898. });
  1899. }
  1900.  
  1901. function requestDoc(url, callback){
  1902. _GM_xmlhttpRequest({
  1903. url: url,
  1904. method: 'GET',
  1905. overrideMimeType: 'text/html;charset='+document.charset,
  1906. headers: {
  1907. 'Referer': location.href
  1908. },
  1909. timeout: 5000,
  1910. onload: function(res) {
  1911. var doc=null;
  1912. try {
  1913. doc=document.implementation.createHTMLDocument('');
  1914. doc.documentElement.innerHTML=res.response;
  1915. }
  1916. catch (e) {
  1917. debug('parse error'+e.toString());
  1918. }
  1919. let pageElement=ruleParser.getPageElement(doc);
  1920. //只有1的話怕不是圖片哦
  1921. ruleParser.curSiteRule.action=0;
  1922. if(pageElement && (pageElement.length>1 || (pageElement.length==1 && pageElement[0].tagName!="IMG") )){
  1923. let result=ruleParser.insertPage(doc, pageElement, url, callback, false);
  1924. if(!result){
  1925. ruleParser.curSiteRule.action=1;
  1926. requestFromIframe(url, (doc, eles)=>{
  1927. loadPageOver();
  1928. if(eles){
  1929. ruleParser.insertPage(doc, eles, url, callback, true);
  1930. }
  1931. });
  1932. }
  1933. }else if(ruleParser.curSiteRule.singleUrl || curPage==1){
  1934. ruleParser.curSiteRule.action=1;
  1935. requestFromIframe(url, (doc, eles)=>{
  1936. loadPageOver();
  1937. if(eles){
  1938. ruleParser.insertPage(doc, eles, url, callback, true);
  1939. }
  1940. });
  1941. }else{
  1942. isPause=true;
  1943. callback(false);
  1944. }
  1945. },
  1946. onerror: function(e){
  1947. debug(e);
  1948. callback(false);
  1949. },
  1950. ontimeout: function(e){
  1951. debug(e);
  1952. callback(false);
  1953. }
  1954. });
  1955. }
  1956.  
  1957. var failFromIframe=0;
  1958. function requestFromIframe(url, callback){
  1959. let orgPage,curPage;
  1960. let iframe = document.createElement('iframe');
  1961. iframe.name = 'pagetual-iframe';
  1962. iframe.width = '100%';
  1963. iframe.height = '0';
  1964. iframe.frameBorder = '0';
  1965. if(ruleParser.curSiteRule.sandbox!=false){
  1966. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1967. }
  1968. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1969. iframe.addEventListener("load", e=>{
  1970. let waitTime=500,checkEval;
  1971. if(ruleParser.curSiteRule.wait){
  1972. if(isNaN(ruleParser.curSiteRule.wait)){
  1973. try{
  1974. checkEval=Function("doc",'"use strict";' + ruleParser.curSiteRule.wait);
  1975. }catch(e){
  1976. debug(e);
  1977. }
  1978. }else{
  1979. waitTime=ruleParser.curSiteRule.wait;
  1980. }
  1981. }
  1982. setTimeout(()=>{
  1983. let tryTimes=0;
  1984. function checkIframe(){
  1985. try{
  1986. let doc=iframe.contentDocument || iframe.contentWindow.document;
  1987. let eles=ruleParser.getPageElement(doc, iframe.contentWindow);
  1988. if(eles && eles.length>0 && (!checkEval || checkEval(doc))){
  1989. callback(doc, eles);
  1990. }else if(tryTimes++ < 10){
  1991. setTimeout(()=>{
  1992. checkIframe();
  1993. },waitTime);
  1994. return;
  1995. }else{
  1996. if(failFromIframe++ > 2){
  1997. failFromIframe=0;
  1998. debug("Stop as failFromIframe");
  1999. isPause=true;
  2000. callback(false, false);
  2001. }else{
  2002. callback(false, false);
  2003. }
  2004. }
  2005. }catch(e){
  2006. debug("Stop as cors");
  2007. //isPause=true;
  2008. if(!ruleParser.curSiteRule.pageElement)ruleParser.curSiteRule.pageElement=allOfBody;
  2009. ruleParser.curSiteRule.action=0;
  2010. ruleParser.getInsert(true);
  2011. ruleParser.nextLinkHref=url;
  2012. callback(false, false);
  2013. nextPage();
  2014. }
  2015. document.body.removeChild(iframe);
  2016. }
  2017. checkIframe();
  2018. },waitTime);
  2019. });
  2020. iframe.src=url;
  2021. document.body.appendChild(iframe);
  2022. }
  2023.  
  2024. function initPage(){
  2025. ruleParser.initPage(()=>{
  2026. if(ruleParser.nextLinkHref){
  2027. initView();
  2028. let isJs=/^(javascript|#)/.test(ruleParser.nextLinkHref.replace(location.href,""));
  2029. if(!isJs){
  2030. let inForce=(forceState == 2 || forceState == 3);
  2031. _GM_registerMenuCommand(i18n(inForce?"cancelForceIframe":"forceIframe"), ()=>{
  2032. if(inForce){
  2033. storage.setItem("forceState_"+location.host, "");
  2034. }else{
  2035. let _state=confirm(i18n("forceAllBody"))?2:3;
  2036. storage.setItem("forceState_"+location.host, _state);
  2037. }
  2038. location.reload();
  2039. });
  2040. }
  2041. _GM_registerMenuCommand(i18n("loadNow"), ()=>{
  2042. let loadNum=window.prompt(i18n("loadConfirm"), "1");
  2043. if(loadNum==="" || loadNum===null)return;
  2044. autoLoadNum=Math.abs(parseInt(loadNum));
  2045. nextPage();
  2046. });
  2047. }
  2048. initListener();
  2049. if(rulesData.initRun && ruleParser.curSiteRule.initRun!=0)nextPage();
  2050. });
  2051. }
  2052.  
  2053. function initView(){
  2054. _GM_addStyle(`
  2055. .pagetual_pageBar.stop {
  2056. -webkit-filter: invert(100%);
  2057. filter: invert(100%);
  2058. opacity: 1!important;
  2059. }
  2060. .pagetual_pageBar.hide {
  2061. display: none!important;
  2062. }
  2063. .pagetual_pageBar:hover {
  2064. opacity: 1!important;
  2065. }
  2066. .pagetual_pageBar span {
  2067. vertical-align: super;
  2068. }
  2069.  
  2070. .pagetual_pageBar span>svg:hover {
  2071. animation: touhouAni 1s infinite;
  2072. }
  2073. .pagetual_pageBar .pagetual_pageNum{
  2074. color: #55555f;
  2075. }
  2076. .pagetual_pageBar .pagetual_pageNum:hover{
  2077. color: #ff6464;
  2078. }
  2079.  
  2080. @keyframes touhouAni{
  2081. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  2082. to {transform: rotate(360deg);}
  2083. }
  2084. @-webkit-keyframes touhouAni{
  2085. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  2086. to {transform: rotate(360deg);}
  2087. }
  2088. .pagetual_loading {
  2089. width: 50px;
  2090. height: 50px;
  2091. margin: 10px auto;
  2092. border-radius: 100%;
  2093. -webkit-animation: pagetual_loading_scaleout 1.0s infinite ease-in-out;
  2094. animation: pagetual_loading_scaleout 1.0s infinite ease-in-out;
  2095. }
  2096. @-webkit-keyframes pagetual_loading_scaleout {
  2097. 0% { -webkit-transform: scale(0.0) }
  2098. 100% {
  2099. -webkit-transform: scale(1.0);
  2100. opacity: 0;
  2101. }
  2102. }
  2103. @keyframes pagetual_loading_scaleout {
  2104. 0% {
  2105. transform: scale(0.0);
  2106. -webkit-transform: scale(0.0);
  2107. } 100% {
  2108. transform: scale(1.0);
  2109. -webkit-transform: scale(1.0);
  2110. opacity: 0;
  2111. }
  2112. }
  2113. `);
  2114. 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;`;
  2115. }
  2116. var loadingDiv=document.createElement("div");
  2117. loadingDiv.style.cssText="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;";
  2118. loadingDiv.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><div class="pagetual_loading"><svg width="50" height="50" style="position:absolute;cursor: pointer;width: 50px;height: 50px;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="#6e6e6e" 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="#6e6e6e" p-id="6366"></path></svg></div>`;
  2119.  
  2120. var upSvg=`<svg width="30" height="30" 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>`;
  2121. var downSvg=`<svg width="30" height="30" 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>`;
  2122. var pageBarStyle;
  2123. var initStyle=`display: contents;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: relative;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;`;
  2124. 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);`;
  2125.  
  2126. var isPause=false,isLoading=false,curPage=1,forceState=0,bottomGap=1000,autoLoadNum=-1;
  2127.  
  2128. function changeStop(stop, hide){
  2129. isPause=stop;
  2130. [].forEach.call(document.querySelectorAll(".pagetual_pageBar"), bar=>{
  2131. if(isPause){
  2132. bar.classList.add("stop");
  2133. if(hide)bar.classList.add("hide");
  2134. }else{
  2135. bar.classList.remove("stop");
  2136. if(hide)bar.classList.remove("hide");
  2137. }
  2138. });
  2139. }
  2140.  
  2141. function isInViewPort(element) {
  2142. if(!element.parentNode)return false;
  2143. if(_unsafeWindow.getComputedStyle(element).display=="none")return false;
  2144. const viewWidth = window.innerWidth || document.documentElement.clientWidth;
  2145. const viewHeight = window.innerHeight || document.documentElement.clientHeight;
  2146. const {
  2147. top,
  2148. right,
  2149. bottom,
  2150. left,
  2151. } = element.getBoundingClientRect();
  2152.  
  2153. return (
  2154. top >= 0 &&
  2155. left >= 0 &&
  2156. right <= viewWidth &&
  2157. bottom <= viewHeight
  2158. );
  2159. }
  2160.  
  2161. var urlChanged=false;
  2162. var _wr = function(type) {
  2163. var orig = history[type];
  2164. return function() {
  2165. var rv = orig.apply(this, arguments);
  2166. var e = new Event(type);
  2167. e.arguments = arguments;
  2168. window.dispatchEvent(e);
  2169. return rv;
  2170. };
  2171. };
  2172. history.pushState = _wr('pushState');
  2173. window.addEventListener('pushState', function(e) {
  2174. urlChanged=true;
  2175. isPause=true;
  2176. setTimeout(()=>{
  2177. if(location.href==configPage){
  2178. location.reload();
  2179. }
  2180. },1);
  2181. });
  2182.  
  2183. function initListener(){
  2184. let loadmoreBtn,loading=true;
  2185. setTimeout(()=>{
  2186. loadmoreBtn=getLoadMore(document);
  2187. if(loadmoreBtn && isVisible(loadmoreBtn, _unsafeWindow)){
  2188. loading=false;
  2189. }
  2190. },500);
  2191. let checkScrollReach=()=>{
  2192. let scrolly=window.scrollY;
  2193. let windowHeight=window.innerHeight || document.documentElement.clientHeight;
  2194. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  2195. if(scrollH-scrolly-windowHeight<bottomGap){
  2196. nextPage();
  2197. }
  2198. };
  2199. document.addEventListener('scroll', e=>{
  2200. if(urlChanged){
  2201. ruleParser.initPage(()=>{
  2202. if(ruleParser.nextLinkHref)initView();
  2203. });
  2204. urlChanged=false;
  2205. isPause=false;
  2206. }
  2207. if(isPause)return;
  2208. if(!loading){
  2209. loading=true;
  2210. setTimeout(()=>{loading=false},200);
  2211. if(!loadmoreBtn || !loadmoreBtn.parentNode){
  2212. loadmoreBtn=getLoadMore(document);
  2213. }
  2214. if(loadmoreBtn){
  2215. if(isInViewPort(loadmoreBtn)){
  2216. emuClick(loadmoreBtn);
  2217. }
  2218. }
  2219. }
  2220. setTimeout(()=>{
  2221. if(!isLoading){
  2222. checkScrollReach();
  2223. }
  2224. },100);
  2225. }, true);
  2226. document.addEventListener('dblclick', e=>{
  2227. if(rulesData.dbClick2Stop){
  2228. setTimeout(()=>{
  2229. changeStop(!isPause, rulesData.hideBar);
  2230. if(!isPause){
  2231. checkScrollReach();
  2232. }
  2233. },200);
  2234. }
  2235. });
  2236. }
  2237.  
  2238. function getLoadMore(doc){
  2239. if(ruleParser.curSiteRule.loadMore==="")return null;
  2240. let btnSel=ruleParser.curSiteRule.loadMore||".LoadMore,.load-more";
  2241. let loadmoreBtn=doc.querySelector(btnSel);
  2242. if(!loadmoreBtn){
  2243. let buttons=doc.querySelectorAll("input,button,a,div[onclick]"),loadmoreReg=/^\s*(加载更多|加載更多|load\s*more|もっと読み込む)\s*$/i;
  2244. for(let i=0;i<buttons.length;i++){
  2245. let button=buttons[i];
  2246. if(button && loadmoreReg.test(button.innerText)){
  2247. loadmoreBtn=button;
  2248. break;
  2249. }
  2250. }
  2251. }
  2252. return loadmoreBtn;
  2253. }
  2254.  
  2255. var hasPageNum=true;
  2256. function createPageBar(url){
  2257. let insert=ruleParser.getInsert();
  2258. if(!insert || !insert.parentNode)return;
  2259. curPage++;
  2260. if(rulesData.opacity==0)return;
  2261. let example=ruleParser.curSiteRule.insertPos==2?insert.children[0]:(insert.previousElementSibling||insert);
  2262. if(!example || !example.parentNode)example=insert;
  2263. let inTable=example.parentNode.tagName=="TABLE" ||
  2264. example.tagName=="TR" ||
  2265. example.tagName=="TBODY" ||
  2266. (example.previousElementSibling && example.previousElementSibling.tagName=="TR") ||
  2267. (example.previousElementSibling && example.previousElementSibling.tagName=="TBODY");
  2268. let inLi=example.tagName=="LI" || (example.previousElementSibling && example.previousElementSibling.tagName=="LI");
  2269. if(forceState==2){
  2270. inTable=inLi=false;
  2271. }
  2272. let pageBar=document.createElement(inTable?"tr":(inLi?"li":"div"));
  2273. let upSpan=document.createElement("span");
  2274. let downSpan=document.createElement("span");
  2275. let pageText=document.createElement("a");
  2276. let pageNum;
  2277. pageBar.className="pagetual_pageBar";
  2278. pageBar.id="pagetual_pageBar";
  2279. if(isPause){
  2280. pageBar.classList.add("stop");
  2281. }
  2282. pageBar.style.cssText=pageBarStyle;
  2283. pageBar.title=i18n(isPause?"enable":"disable");
  2284. upSpan.innerHTML=upSvg;
  2285. upSpan.title=i18n("toTop");
  2286. downSpan.innerHTML=downSvg;
  2287. downSpan.title=i18n("toBottom");
  2288. upSpan.style.cssText=initStyle;
  2289. downSpan.style.cssText=initStyle;
  2290. pageText.href=url;
  2291. pageText.style.cssText=pageTextStyle;
  2292. pageText.title=i18n("current");
  2293. pageBar.appendChild(upSpan);
  2294. pageBar.appendChild(pageText);
  2295. if(ruleParser.curSiteRule.pageNum || (hasPageNum && /[&\/\?](p=|page[=\/])\d+|[_-]\d+\./.test(url))){
  2296. pageText.innerHTML="Page ";
  2297. pageNum=document.createElement("span");
  2298. pageNum.innerText=curPage;
  2299. pageNum.className="pagetual_pageNum";
  2300. pageNum.title=i18n("inputPageNum");
  2301. pageNum.style.cssText=pageTextStyle;
  2302. pageNum.style.cursor="pointer";
  2303. pageNum.style.color="";
  2304. pageNum.addEventListener("click", e=>{
  2305. let pageInput=prompt(i18n("inputPageNum"), "1");
  2306. if(pageInput){
  2307. let pageLink=ruleParser.getLinkByPage(url, pageInput);
  2308. if(pageLink){
  2309. _GM_openInTab(pageLink,{active:true});
  2310. }
  2311. }
  2312. e.preventDefault();
  2313. e.stopPropagation();
  2314. });
  2315. pageBar.appendChild(pageNum);
  2316. }else{
  2317. pageText.innerHTML="Page "+curPage;
  2318. hasPageNum=false;
  2319. }
  2320. pageBar.appendChild(downSpan);
  2321. let parentStyle=_unsafeWindow.getComputedStyle(example.parentNode);
  2322. let parentWidth=example.parentNode.scrollWidth||parseInt(parentStyle.width);
  2323. pageBar.style.width=parentWidth-parseInt(parentStyle.paddingLeft)-parseInt(parentStyle.paddingRight)-10+"px";
  2324. if(parentStyle.display=="grid" || parentStyle.display=="inline-grid"){
  2325. pageBar.style.gridColumnStart=1;
  2326. pageBar.style.gridColumnEnd=1+parseInt(example.parentNode.offsetWidth/example.offsetWidth);
  2327. }
  2328. if(inTable){
  2329. example=(example.tagName=="TR" || example.tagName=="TBODY")?example:example.previousElementSibling;
  2330. if(example.previousElementSibling)example=example.previousElementSibling;
  2331. let tdNum=0;
  2332. [].forEach.call(example.querySelectorAll("td,th"), td=>{
  2333. tdNum+=td.colSpan||1;
  2334. });
  2335. pageBar.style.display="table-row";
  2336. pageBar.style.backgroundColor="unset";
  2337. let td=document.createElement("td");
  2338. td.style.backgroundColor="rgb(240 240 240 / 80%)";
  2339. td.style.borderRadius="20px";
  2340. td.colSpan=tdNum||1;
  2341. td.style.padding="0 0";
  2342. td.style.textAlign="center";
  2343. td.appendChild(upSpan);
  2344. td.appendChild(pageText);
  2345. if(pageNum)td.appendChild(pageNum);
  2346. td.appendChild(downSpan);
  2347. pageBar.appendChild(td);
  2348. }else if(inLi){
  2349. example=example.tagName=="LI"?example:example.previousElementSibling;
  2350. pageBar.style.display="table-row";
  2351. pageBar.style.backgroundColor="unset";
  2352. let td=document.createElement("td");
  2353. td.style.backgroundColor="rgb(240 240 240 / 80%)";
  2354. td.style.borderRadius="20px";
  2355. td.colSpan=example.children.length;
  2356. td.style.padding="0 0";
  2357. td.style.textAlign="center";
  2358. td.style.minWidth="150px";
  2359. td.appendChild(upSpan);
  2360. td.appendChild(pageText);
  2361. td.style.width=pageBar.style.width;
  2362. if(pageNum)td.appendChild(pageNum);
  2363. td.appendChild(downSpan);
  2364. pageBar.appendChild(td);
  2365. }
  2366.  
  2367. upSpan.addEventListener("click", e=>{
  2368. document.body.scrollTop=0;
  2369. document.documentElement.scrollTop=0;
  2370. e.preventDefault();
  2371. e.stopPropagation();
  2372. });
  2373. downSpan.addEventListener("click", e=>{
  2374. changeStop(true);
  2375. pageBar.title=i18n(isPause?"enable":"disable");
  2376. document.body.scrollTop=9999999;
  2377. document.documentElement.scrollTop=9999999;
  2378. e.preventDefault();
  2379. e.stopPropagation();
  2380. });
  2381. pageBar.addEventListener("click", e=>{
  2382. changeStop(!isPause);
  2383. pageBar.title=i18n(isPause?"enable":"disable");
  2384. });
  2385. pageText.addEventListener("click", e=>{
  2386. e.stopPropagation();
  2387. });
  2388. if(ruleParser.curSiteRule.insertPos==2){
  2389. insert.appendChild(pageBar);
  2390. }else{
  2391. insert.parentNode.insertBefore(pageBar, insert);
  2392. }
  2393. if(ruleParser.curSiteRule.pageBar){
  2394. try{
  2395. Function("pageBar",'"use strict";' + ruleParser.curSiteRule.pageBar)(pageBar);
  2396. }catch(e){
  2397. debug(e);
  2398. }
  2399. }
  2400.  
  2401. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  2402. let posEle=pageBar.nextElementSibling||pageBar;
  2403. while(posEle && !posEle.offsetParent){
  2404. posEle=posEle.previousElementSibling||posEle.parentNode;
  2405. }
  2406. if(posEle){
  2407. let actualTop = getElementTop(posEle);
  2408. bottomGap=scrollH-actualTop+(window.innerHeight||document.documentElement.clientHeight)*(ruleParser.curSiteRule.rate||1);
  2409. if(bottomGap<100)bottomGap=100;
  2410. }else{
  2411. bottomGap=1000;
  2412. }
  2413. return pageBar;
  2414. }
  2415.  
  2416. function emuClick(btn){
  2417. if(!PointerEvent)return btn.click();
  2418. let eventParam={
  2419. isTrusted: true,
  2420. altKey: false,
  2421. azimuthAngle: 0,
  2422. bubbles: true,
  2423. button: 0,
  2424. buttons: 0,
  2425. clientX: 1,
  2426. clientY: 1,
  2427. cancelBubble: false,
  2428. cancelable: true,
  2429. composed: true,
  2430. ctrlKey: false,
  2431. defaultPrevented: false,
  2432. detail: 1,
  2433. eventPhase: 2,
  2434. fromElement: null,
  2435. height: 1,
  2436. isPrimary: false,
  2437. metaKey: false,
  2438. pointerId: 1,
  2439. pointerType: "mouse",
  2440. pressure: 0,
  2441. relatedTarget: null,
  2442. returnValue: true,
  2443. shiftKey: false,
  2444. toElement: null,
  2445. twist: 0,
  2446. type: "click",
  2447. which: 1
  2448. };
  2449. var mouseclick = new PointerEvent("click",eventParam);
  2450. btn.dispatchEvent(mouseclick);
  2451. }
  2452.  
  2453. var emuIframe;
  2454. function emuPage(callback){
  2455. let orgPage=null,curPage,iframeDoc,times=0,loadmoreBtn,loadmoreEnd=false,waitTimes=10;
  2456. function checkPage(){
  2457. if(isPause)return;
  2458. try{
  2459. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  2460. }catch(e){
  2461. debug("Stop as cors");
  2462. isPause=true;
  2463. callback(false, false);
  2464. return;
  2465. }
  2466.  
  2467. let nextLink=ruleParser.getNextLink(iframeDoc);
  2468. let waitTime=500,checkEval;
  2469. if(ruleParser.curSiteRule.wait){
  2470. if(isNaN(ruleParser.curSiteRule.wait)){
  2471. try{
  2472. checkEval=Function("doc",'"use strict";' + ruleParser.curSiteRule.wait);
  2473. }catch(e){
  2474. debug(e);
  2475. }
  2476. }else{
  2477. waitTime=ruleParser.curSiteRule.wait;
  2478. }
  2479. }
  2480.  
  2481. if(!orgPage){
  2482. if(!loadmoreEnd){
  2483. loadmoreBtn=getLoadMore(iframeDoc);
  2484. if(loadmoreBtn && isVisible(loadmoreBtn, iframeDoc.defaultView)){
  2485. emuClick(loadmoreBtn);
  2486. let intv=setInterval(()=>{
  2487. loadmoreBtn=getLoadMore(iframeDoc);
  2488. if(!loadmoreBtn || !loadmoreBtn.parentNode || !isVisible(loadmoreBtn, iframeDoc.defaultView)){
  2489. clearInterval(intv);
  2490. loadmoreEnd=true;
  2491. setTimeout(()=>{
  2492. checkPage();
  2493. },500);
  2494. }else{
  2495. emuClick(loadmoreBtn);
  2496. }
  2497. },200);
  2498. return;
  2499. }else{
  2500. loadmoreEnd=true;
  2501. }
  2502. }
  2503. let pageEle=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true);
  2504. if(!nextLink || !pageEle || pageEle.length==0 || (checkEval && !checkEval(iframeDoc))){
  2505. if(waitTimes-->0){
  2506. setTimeout(()=>{
  2507. checkPage();
  2508. },waitTime);
  2509. return;
  2510. }
  2511. }
  2512. orgPage=pageEle;
  2513. if(!orgPage || orgPage.length==0){
  2514. debug("Stop as no page when emu");
  2515. isPause=true;
  2516. callback(false, false);
  2517. return;
  2518. }
  2519. if(orgPage && orgPage[0].tagName=="UL")orgPage=orgPage[0].children;
  2520. if(orgPage && nextLink){
  2521. orgPage=orgPage[parseInt(orgPage.length/2)];
  2522. if(!isVisible(nextLink, iframeDoc.defaultView)){
  2523. debug("Stop as next hide when emu");
  2524. isPause=true;
  2525. callback(false, false);
  2526. }else{
  2527. emuClick(nextLink);
  2528. setTimeout(()=>{
  2529. checkPage();
  2530. },500);
  2531. }
  2532. }else{
  2533. debug("Stop as no next when emu");
  2534. isPause=true;
  2535. callback(false, false);
  2536. }
  2537. return;
  2538. }
  2539. if(times++ > 20){
  2540. //emuClick(nextLink);
  2541. debug("Stop as timeout when emu");
  2542. isPause=true;
  2543. callback(false, false);
  2544. return;
  2545. }
  2546. let eles=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true),checkItem;
  2547. if(eles && eles.length>0){
  2548. checkItem=eles;
  2549. if(eles[0].tagName=="UL"){
  2550. checkItem=eles[0].children;
  2551. }
  2552. checkItem=checkItem[parseInt(checkItem.length/2)];
  2553. }
  2554. if(!checkItem || orgPage == checkItem || (checkEval && !checkEval(iframeDoc))){
  2555. setTimeout(()=>{
  2556. checkPage();
  2557. },waitTime);
  2558. }else{
  2559. callback(iframeDoc, eles);
  2560. }
  2561. }
  2562. if(!emuIframe){
  2563. let loaded=false;
  2564. emuIframe = document.createElement('iframe');
  2565. emuIframe.name = 'pagetual-iframe';
  2566. if(ruleParser.curSiteRule.sandbox!=false){
  2567. emuIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  2568. }
  2569. emuIframe.width = '100%';
  2570. emuIframe.height = '0';
  2571. emuIframe.frameBorder = '0';
  2572. emuIframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  2573. emuIframe.addEventListener("load", e=>{
  2574. setTimeout(()=>{
  2575. try{
  2576. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  2577. }catch(e){
  2578. debug("Stop as cors");
  2579. isPause=true;
  2580. callback(false, false);
  2581. return;
  2582. }
  2583. let code=ruleParser.curSiteRule.init;
  2584. if(code){
  2585. try{
  2586. Function('doc','win','"use strict";' + code)(iframeDoc, iframeDoc.defaultView);
  2587. }catch(e){
  2588. debug(e);
  2589. }
  2590. }
  2591. if(loaded)return;
  2592. loaded=true;
  2593. checkPage();
  2594. },500);
  2595. });
  2596. emuIframe.src=location.href;
  2597. document.body.appendChild(emuIframe);
  2598. }else{
  2599. checkPage();
  2600. }
  2601. }
  2602.  
  2603. function forceIframe(url, callback){
  2604. let curIframe = document.createElement('iframe'),iframeDoc;
  2605. curIframe.name = 'pagetual-iframe';
  2606. curIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  2607. curIframe.frameBorder = '0';
  2608. curIframe.scrolling="no";
  2609. 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;';
  2610. curIframe.addEventListener("load", e=>{
  2611. try{
  2612. iframeDoc=curIframe.contentDocument || curIframe.contentWindow.document;
  2613. }catch(e){
  2614. debug("Stop as cors");
  2615. isPause=true;
  2616. callback(false, false);
  2617. return;
  2618. }
  2619. ruleParser.insertPage(iframeDoc, [], url, null, true);
  2620. callback(curIframe, true);
  2621. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  2622. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  2623. });
  2624. let inAction=false;
  2625. let forceRefresh=e=>{
  2626. if(inAction || !iframeDoc)return;
  2627. inAction=true;
  2628. setTimeout(()=>{
  2629. inAction=false;
  2630. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  2631. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  2632. if(!ruleParser.nextLinkHref){
  2633. ruleParser.getNextLink(iframeDoc);
  2634. if(ruleParser.nextLinkHref){
  2635. document.removeEventListener("scroll", forceRefresh);
  2636. }
  2637. }else{
  2638. document.removeEventListener("scroll", forceRefresh);
  2639. }
  2640. },500);
  2641. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  2642. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  2643. };
  2644. document.addEventListener("scroll", forceRefresh);
  2645. curIframe.src=url;
  2646. let insert=ruleParser.getInsert();
  2647. document.body.appendChild(curIframe);
  2648. return curIframe;
  2649. }
  2650.  
  2651. function loadPageOver(){
  2652. isLoading=false;
  2653. if(loadingDiv.parentNode){
  2654. loadingDiv.parentNode.removeChild(loadingDiv);
  2655. }
  2656. setTimeout(()=>{
  2657. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  2658. if(scrollH < (window.innerHeight || document.documentElement.clientHeight)){
  2659. nextPage();
  2660. }
  2661. },1);
  2662. }
  2663.  
  2664. function nextPage(){
  2665. if(isPause || isLoading)return;
  2666. let nextLink=ruleParser.nextLinkHref;
  2667. if(!nextLink)return;
  2668. let pvGallery=document.querySelector("span.pv-gallery-container");
  2669. if(pvGallery && pvGallery.style.display!="none")return;
  2670. let insert=ruleParser.getInsert();
  2671. if(insert){
  2672. let isJs=/^(javascript|#)/.test(nextLink.replace(location.href,""));
  2673. if(location.protocol=="https:" && /^http:/.test(nextLink)){
  2674. nextLink=nextLink.replace(/^http/,"https");
  2675. }
  2676. isLoading=true;
  2677. document.body.appendChild(loadingDiv);
  2678. let sleep=ruleParser.curSiteRule.sleep||0;
  2679. setTimeout(()=>{
  2680. if(ruleParser.curSiteRule.pageElementByJs){
  2681. var over=ele=>{
  2682. loadPageOver();
  2683. if(ele){
  2684. createPageBar(nextLink);
  2685. ruleParser.insertPage(null, ele, nextLink, null, true);
  2686. if(autoLoadNum>=0){
  2687. if(autoLoadNum!=0 && --autoLoadNum==0){
  2688. autoLoadNum=-1;
  2689. }else{
  2690. nextPage();
  2691. }
  2692. }
  2693. }else{
  2694. debug("Stop as no page when get by js");
  2695. isPause=true;
  2696. }
  2697. };
  2698. try{
  2699. Function("over",'"use strict";' + ruleParser.curSiteRule.pageElementByJs)(over);
  2700. }catch(e){
  2701. debug(e);
  2702. }
  2703. }else if((forceState==3||ruleParser.curSiteRule.action==1) && !isJs){
  2704. requestFromIframe(nextLink, (doc, eles)=>{
  2705. loadPageOver();
  2706. if(eles){
  2707. createPageBar(nextLink);
  2708. ruleParser.insertPage(doc, eles, nextLink, null, true);
  2709. if(autoLoadNum>=0){
  2710. if(autoLoadNum!=0 && --autoLoadNum==0){
  2711. autoLoadNum=-1;
  2712. }else{
  2713. nextPage();
  2714. }
  2715. }
  2716. }
  2717. });
  2718. }else if((forceState==2||ruleParser.curSiteRule.action==2) && !isJs){
  2719. forceIframe(nextLink, (iframe, eles)=>{
  2720. loadPageOver();
  2721. let pageBar=createPageBar(nextLink);
  2722. if(pageBar)iframe.parentNode.insertBefore(pageBar, iframe);
  2723. if(autoLoadNum>=0){
  2724. if(autoLoadNum!=0 && --autoLoadNum==0){
  2725. autoLoadNum=-1;
  2726. }else{
  2727. nextPage();
  2728. }
  2729. }
  2730. });
  2731. }else{
  2732. if(!isJs){
  2733. requestDoc(nextLink, (eles)=>{
  2734. loadPageOver();
  2735. if(eles){
  2736. createPageBar(nextLink);
  2737. if(autoLoadNum>=0){
  2738. if(autoLoadNum!=0 && --autoLoadNum==0){
  2739. autoLoadNum=-1;
  2740. }else{
  2741. nextPage();
  2742. }
  2743. }
  2744. }
  2745. });
  2746. }else{
  2747. emuPage((doc, eles)=>{
  2748. loadPageOver();
  2749. if(eles){
  2750. createPageBar(nextLink);
  2751. ruleParser.insertPage(doc, eles, "", null, true);
  2752. if(autoLoadNum>=0){
  2753. if(autoLoadNum!=0 && --autoLoadNum==0){
  2754. autoLoadNum=-1;
  2755. }else{
  2756. nextPage();
  2757. }
  2758. }
  2759. }
  2760. });
  2761. }
  2762. }
  2763. },sleep);
  2764. }
  2765. }
  2766.  
  2767. function init(){
  2768. initRules(()=>{
  2769. initPage();
  2770. });
  2771. }
  2772. setTimeout(()=>{
  2773. init();
  2774. },300);
  2775. })();