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

自动加载并拼接下一分页内容(适用于论坛、漫画站、小说站、资讯站、博客等),无需规则支持所有网页

当前为 2022-03-15 提交的版本,查看 最新版本

  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.6.22
  14. // @description Most compatible Auto Pager script ever. Auto loading next paginated web pages and inserting into current page.
  15. // @description:zh-CN 自动加载并拼接下一分页内容(适用于论坛、漫画站、小说站、资讯站、博客等),无需规则支持所有网页
  16. // @description:zh-TW 自動加載並拼接下一分頁內容(適用於論壇、漫畫站、小說站、資訊站、博客等),無需規則支持所有網頁
  17. // @description:ja Webページを自動で読み込み継ぎ足し表示を行うブラウザ拡張です
  18. // @description:ru Просто автоматически загрузите следующую страницу
  19. // @description:de Laden Sie einfach automatisch die nächste Seite
  20. // @description:es Carga automática de páginas web paginadas
  21. // @description:fr Chargement automatique des pages Web paginées
  22. // @description:it Caricamento automatico di pagine Web impaginate
  23. // @description:ko 다음 페이지를 자동으로 로드하세요
  24. // @author hoothin
  25. // @include http://*
  26. // @include https://*
  27. // @license MIT
  28. // @icon data:image/png;base64,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.pageElement)pageElement=r.type==0?getElementByXpath(r.pageElement):document.querySelector(r.pageElement);
  580. if(r.nextLink)nextLink=r.type==0?getElementByXpath(r.nextLink):document.querySelector(r.nextLink);
  581. if(r.insert)insert=r.type==0?getElementByXpath(r.insert):document.querySelector(r.insert);
  582. return !((r.pageElement && !pageElement) ||
  583. (r.nextLink && !nextLink) ||
  584. (r.insert && !insert));
  585. }
  586.  
  587. function checkRule(r){
  588. let urlReg=new RegExp(r.url, "i");
  589. if(urlReg.test(location.href)){
  590. if(r.wait){
  591. let waitTime=500,checkEval;
  592. if(isNaN(r.wait)){
  593. try{
  594. checkEval=Function("doc",'"use strict";' + r.wait);
  595. }catch(e){
  596. debug(e);
  597. }
  598. }else{
  599. waitTime=r.wait;
  600. }
  601. let checkReady=()=>{
  602. setTimeout(()=>{
  603. if(!ruleMatch(r) || (checkEval && !checkEval(document))){
  604. checkReady();
  605. }else{
  606. setRule(r);
  607. }
  608. },parseInt(waitTime));
  609. };
  610. checkReady();
  611. return true;
  612. }
  613. if(r.pinUrl){
  614. setRule(r);
  615. return true;
  616. }
  617. if(!ruleMatch(r)){
  618. return false;
  619. }
  620. setRule(r);
  621. return true;
  622. }
  623. return false;
  624. }
  625.  
  626. for(let i in this.hpRules){
  627. let rule=this.hpRules[i];
  628. if(!rule || !rule.url)continue;
  629. if(rule.singleUrl){
  630. if(location.origin+location.pathname==rule.url){
  631. setRule(rule);
  632. return;
  633. }
  634. continue;
  635. }
  636. if(checkRule(rule))return;
  637. }
  638. for(let i in this.customRules){
  639. let rule=this.customRules[i];
  640. if(!rule || !rule.url)continue;
  641. if(checkRule(rule))return;
  642. }
  643. let r=0;
  644. function searchByTime(){
  645. setTimeout(()=>{
  646. let end=r+80;
  647. end=end>self.rules.length?self.rules.length:end;
  648. for(;r<end;r++){
  649. let rule=self.rules[r];
  650. if(checkRule(rule))return;
  651. }
  652. if(end>=self.rules.length){
  653. self.curSiteRule={};
  654. self.curSiteRule.url=location.origin+location.pathname;
  655. self.curSiteRule.singleUrl=true;
  656. callback();
  657. return;
  658. }else{
  659. searchByTime();
  660. }
  661. },20);
  662. }
  663. searchByTime();
  664. }
  665.  
  666. geneSelector(ele){
  667. let selector=ele.tagName;
  668. //Google id class都是隨機。百度更過分,style script順序都是隨機的
  669. //if(ele.id) selector += '#' + ele.id;
  670. //if(ele.classList) selector += [].map.call(ele.classList,d=>'.'+d).join('');
  671. let parent = ele.parentElement;
  672. if(parent){
  673. let i,j=0;
  674. for(i=0;i<parent.children.length;i++){
  675. if(parent.children[i].tagName==selector){
  676. j++;
  677. if(parent.children[i]==ele){
  678. break;
  679. }
  680. }
  681. }
  682. selector = this.geneSelector(parent) + ' > ' + selector + (parent.tagName=="HTML"?"":`:nth-of-type(${j})`);
  683. }
  684. return selector;
  685. }
  686.  
  687. getPageElement(doc, curWin, dontFind) {
  688. let pageElement=null;
  689. let self=this;
  690. if(this.curSiteRule.pageElement){
  691. pageElement=this.curSiteRule.type==0?getAllElementsByXpath(this.curSiteRule.pageElement,doc,doc):doc.querySelectorAll(this.curSiteRule.pageElement);
  692. }
  693. if((!pageElement || pageElement.length==0) && curWin && !dontFind){
  694. let body=doc.body;
  695. if(!body)return null;
  696. let bodyHeight=parseInt(body.scrollHeight);
  697. let curHeight=bodyHeight;
  698. function checkElement(ele){
  699. if(ele.childNodes && ele.childNodes.length==1)ele=ele.childNodes[0];
  700. if(ele.tagName=="PICTURE"){
  701. self.curSiteRule.pageElement=self.geneSelector(ele.parentNode)+">"+ele.tagName;
  702. debug(self.curSiteRule.pageElement);
  703. return [ele];
  704. }
  705. if(curHeight/bodyHeight<=0.30){
  706. self.curSiteRule.pageElement=allOfBody;
  707. debug(self.curSiteRule.pageElement);
  708. return [body];
  709. }
  710. if(ele.tagName=="TBODY" || ele.tagName=="UL"){
  711. self.curSiteRule.pageElement=self.geneSelector(ele)+">*";
  712. if(ele.children.length>0 && ele.children[0].querySelector("th")){
  713. self.curSiteRule.pageElement+=":not(:first-child)";
  714. }
  715. debug(self.curSiteRule.pageElement);
  716. return ele.children;
  717. }
  718. if(ele.children.length==0 && !self.curSiteRule.pageElement){
  719. if(ele.parentNode.tagName=="P")ele=ele.parentNode;
  720. self.curSiteRule.pageElement=self.geneSelector(ele.parentNode)+">"+ele.tagName;
  721. debug(self.curSiteRule.pageElement);
  722. return [ele];
  723. }
  724. let i,maxHeight=curHeight*0.6,curMaxEle=null,curMaxArea=0,maxWidth=0;
  725. let isHori=true;
  726. let offsetTop=ele.children[0].offsetTop;
  727. for(i=1;i<ele.children.length;i++){
  728. if(ele.children[i].offsetTop!=offsetTop){
  729. isHori=false;
  730. break;
  731. }
  732. }
  733. for(i=0;i<ele.children.length;i++){
  734. let curNode=ele.children[i];
  735. if(curNode.tagName=="CANVAS")continue;
  736. if(curNode.tagName!="IMG" && curNode.innerHTML=="")continue;
  737. let comStyle=curWin.getComputedStyle(curNode);
  738. let h=parseInt(curNode.scrollHeight);
  739. let w=parseInt(curNode.scrollWidth);
  740. if(isNaN(h) || isNaN(w))continue;
  741. if(isHori && h==0)continue;
  742. let a=h*w+h,moreChild=curNode.children[0];
  743. while(moreChild){
  744. comStyle=curWin.getComputedStyle(moreChild);
  745. let ch=parseInt(moreChild.scrollHeight);
  746. let cw=parseInt(moreChild.scrollWidth);
  747. if(h<ch)h=ch;
  748. if(moreChild.innerText!="" && !isNaN(ch) && !isNaN(cw)){
  749. a+=ch*cw;
  750. }
  751. moreChild=moreChild.nextElementSibling;
  752. }
  753. let isMax=false;
  754. if(isHori){
  755. if(maxWidth<w){
  756. isMax=true;
  757. }else if(maxWidth==w && curMaxArea<a){
  758. isMax=true;
  759. }
  760. }else{
  761. isMax=curMaxArea<a;
  762. }
  763. if(curMaxEle==null || isMax){
  764. if(h>0 || !isHori)curHeight=h;
  765. curMaxArea=a;
  766. maxWidth=w;
  767. curMaxEle=curNode;
  768. }
  769. }
  770. if(curMaxEle && (isHori || curHeight>maxHeight)){
  771. return checkElement(curMaxEle);
  772. }
  773. if(ele.tagName=="P" || ele.tagName=="BR")ele=ele.parentNode;
  774. self.curSiteRule.pageElement=self.geneSelector(ele);
  775. if(ele.children.length>1){
  776. let middleChild=ele.children[parseInt(ele.children.length/2)];
  777. if((middleChild.style && middleChild.style.position=="absolute" && middleChild.style.left && middleChild.style.top) || ele.tagName=="UL" || curHeight==0){
  778. ele=[ele];
  779. }else{
  780. self.curSiteRule.pageElement+=">*";
  781. ele=ele.children;
  782. }
  783. }else{
  784. ele=[ele];
  785. }
  786. debug(self.curSiteRule.pageElement);
  787. return ele;
  788. }
  789. pageElement=checkElement(body);
  790. if(pageElement)this.saveCurSiteRule();
  791. }
  792. /*if(this.insert && this.insert.parentNode && pageElement && pageElement[0]){
  793. let example=this.insertPos==2?this.insert.children[0]:this.insert;
  794. let inTable=example.parentNode.tagName=="TABLE" ||
  795. example.tagName=="TR" ||
  796. example.tagName=="TBODY" ||
  797. (example.previousElementSibling && example.previousElementSibling.tagName=="TR") ||
  798. (example.previousElementSibling && example.previousElementSibling.tagName=="TBODY");
  799. if(inTable && pageElement[0].tagName!="TR" && pageElement[0].tagName!="TBODY"){
  800. pageElement=null;
  801. }
  802. }*/
  803. return pageElement;
  804. }
  805.  
  806. getPage(doc){
  807. if(_unsafeWindow.Discourse)return {};
  808. let canSave=false;//發現頁碼選擇器在其他頁對不上,還是別保存了
  809. let url=this.curUrl.replace("#!","").replace("index.php?","?");
  810. let pageNum=1,preStr="",afterStr="";
  811. let pageMatch1=url.match(/(.*[a-z\/\-_](?:p|page)?\/?)(\d+)(\.s?html?$|\/?$)/i);
  812. let pageMatch2=url.match(/(.*[\?&]p(?:age)?=)(\d+)($|[#&].*)/i);
  813. if(pageMatch1){
  814. preStr=pageMatch1[1];
  815. pageNum=parseInt(pageMatch1[2]);
  816. afterStr=pageMatch1[3];
  817. }else if(pageMatch2){
  818. preStr=pageMatch2[1];
  819. pageNum=parseInt(pageMatch2[2]);
  820. afterStr=pageMatch2[3];
  821. }
  822. let curPage=doc,i,cur,jsNext;
  823. let next1,next2,next3,next4,nextJs1,nextJs2,nextJs3;
  824. let next=curPage.querySelector(".page-next>a")||
  825. curPage.querySelector("a.next_page")||
  826. curPage.querySelector("#next_page")||
  827. curPage.querySelector(".nextPage")||
  828. curPage.querySelector("a[data-pagination=next]")||
  829. curPage.querySelector(".pagination a[rel=next]")||
  830. curPage.querySelector(".pagination-nav__item--next>a")||
  831. curPage.querySelector("a[title='Next page']")||
  832. curPage.querySelector("a.pageright")||
  833. curPage.querySelector("a#rightFix")||
  834. curPage.querySelector("a#next")||
  835. curPage.querySelector(".next>a")||
  836. curPage.querySelector(".next>button")||
  837. curPage.querySelector("a[alt=next]")||
  838. curPage.querySelector("[title=next]");
  839. if(!next){
  840. let nexts=curPage.querySelectorAll("a.next");
  841. for(i=0;i<nexts.length;i++){
  842. if(!/^([上前首尾][一1]?[页頁张張]|previous(\s*page)?\s*›?$|前のページ)/i.test(nexts[i].innerText.trim())){
  843. next=nexts[i];
  844. break;
  845. }
  846. }
  847. }
  848. if(next && (!next.href || /^javascript:/.test(next.href))){
  849. jsNext=next;
  850. next=null;
  851. }
  852. if(!next){
  853. next=curPage.querySelectorAll("[aria-label='Next']");
  854. if(next && next.length==1){
  855. next=next[0];
  856. if(!next.href || /^javascript:/.test(next.href)){
  857. jsNext=next;
  858. next=null;
  859. }
  860. }else{
  861. next=null;
  862. }
  863. }
  864. if(!next){
  865. next=curPage.querySelectorAll("[aria-label='Next page']");
  866. if(next && next.length==1){
  867. next=next[0];
  868. if(!next.href || /^javascript:/.test(next.href)){
  869. jsNext=next;
  870. next=null;
  871. }
  872. }else{
  873. next=null;
  874. }
  875. }
  876. if(!next){
  877. let pageDiv=curPage.querySelector("div.wp-pagenavi");
  878. if(pageDiv){
  879. cur=pageDiv.querySelector("span.current");
  880. if(cur){
  881. next=cur.nextSibling;
  882. }
  883. }else{
  884. cur=curPage.querySelector("div.article-paging>span");
  885. if(cur){
  886. next=cur.nextElementSibling;
  887. }
  888. }
  889. }
  890. if(!next){
  891. let pageDiv=curPage.querySelector("div.pages>ul");
  892. if(pageDiv){
  893. cur=pageDiv.querySelector("li>b");
  894. if(cur)next=cur.parentNode.nextElementSibling;
  895. if(next)next=next.querySelector("a");
  896. }
  897. }
  898. if(!next){
  899. cur=curPage.querySelector(".number>ul>li.active");
  900. if(cur)next=cur.nextElementSibling;
  901. if(next)next=next.querySelector("a");
  902. }
  903. if(next && /^[下后後][一1]?[章话話]/i.test(next.innerText.trim())){
  904. next2=next;
  905. next=null;
  906. }
  907. if(!next){
  908. let aTags=curPage.querySelectorAll("a");
  909. for(i=aTags.length-1;i>=0;i--){
  910. let aTag=aTags[i];
  911. if(aTag.innerText=="§")continue;
  912. if(aTag.style.display=="none")continue;
  913. if(next1 && next2 && next3 && next4)break;
  914. if(aTag.href && /next$/i.test(aTag.href))continue;
  915. if(!next1){
  916. if(/^[下后後][一1]?[页頁张張]|^next([ _-]?page)?\s*[›>→»]?$|次のページ|^次へ?$|/i.test(aTag.innerText.trim())){
  917. if(aTag.innerText.length>15)continue;
  918. if(!aTag.href || /^javascript:/.test(aTag.href)){
  919. if(!nextJs1)nextJs1=aTag;
  920. }else{
  921. next1=aTag;
  922. }
  923. }
  924. }
  925. if(!next2){
  926. if(/^[下后後][一1]?[章话話]/i.test(aTag.innerText.trim())){
  927. if(!aTag.href || /^javascript:/.test(aTag.href)){
  928. if(!nextJs2)nextJs2=aTag;
  929. }else{
  930. next2=aTag;
  931. }
  932. }
  933. }
  934. if(!next3){
  935. if(aTag.innerText=="&gt;" || aTag.innerText=="▶" || aTag.innerText==">" || aTag.innerText=="›" || aTag.innerText=="→" || aTag.innerText=="»" || /nextpage/i.test(aTag.className)){
  936. if(!aTag.href || /^javascript:/.test(aTag.href)){
  937. if(!nextJs3)nextJs3=aTag;
  938. }else{
  939. next3=aTag;
  940. }
  941. }
  942. }
  943. if(!aTag.href || /^javascript:/.test(aTag.href))continue;
  944. if(!next4){
  945. if(pageNum<999 && aTag.href.replace("?&","?").replace("#!","").replace("index.php?","?").replace(preStr,"").replace(afterStr,"")==pageNum+1){
  946. next4=aTag;
  947. }else if(this.curUrl!=aTag.href && aTag.href.replace("?&","?").replace("index.php?","?").indexOf(url)!=-1 && /^[\/\?&]?[_-]?(p|page)?=?\/?2(\/|\?|&|$)/i.test(aTag.href.replace(url,"").replace(/\.s?html?$/i,""))){
  948. let curHref=aTag.getAttribute("href");
  949. let pageOne=curHref.replace(/\/2(\/|\?|&|$)/,"/1$1");
  950. if(pageOne==curHref)pageOne=null;
  951. else pageOne=curPage.querySelector(`a[href='${pageOne}']`);
  952. if(!pageOne)next4=aTag;
  953. }
  954. }
  955. }
  956. next=next1||next4||next3||next2||nextJs1||nextJs3||nextJs2;
  957. }
  958. if(!next)next=jsNext;
  959. if(next && next.classList.contains("results-more"))next=null;
  960. return {next:next,canSave:canSave};
  961. }
  962.  
  963. canonicalUri(src, base_path) {
  964. if(src.charAt(0)=="#")return location.href+src;
  965. var root_page = /^[^?#]*\//.exec(location.href)[0],
  966. root_domain = /^\w+\:\/\/\/?[^\/]+/.exec(root_page)[0],
  967. absolute_regex = /^\w+\:\/\//;
  968. src=src.replace(/\.\//,"");
  969. if (/^\/\/\/?/.test(src)){
  970. src = location.protocol + src;
  971. }
  972. else if (!absolute_regex.test(src) && src.charAt(0) != "/"){
  973. src = (base_path || "") + src;
  974. }
  975. return (absolute_regex.test(src) ? src : ((src.charAt(0) == "/" ? root_domain : root_page) + src));
  976. }
  977.  
  978. getLinkByPage(url, pageNum) {
  979. if(!url)return;
  980. if(this.curSiteRule.pageNum){
  981. let result=this.curSiteRule.pageNum;
  982. let strMatch=result.match(/\{.*?}/);
  983. if(!strMatch)return null;
  984. let urlReg=new RegExp("("+result.replace(strMatch[0], ")\\d+(")+")","i");
  985. let code=strMatch[0].replace(/^{/,"").replace(/}$/,"").replace(/\$p/g,pageNum);
  986. if(code==pageNum){
  987. result=url.replace(urlReg,"$1"+code+"$2");
  988. }else{
  989. try{
  990. code=Function('"use strict";return ' + code)();
  991. result=url.replace(urlReg,"$1"+code+"$2");
  992. }catch(e){
  993. debug(e);
  994. }
  995. }
  996. return result==url?url.replace(/([&\/\?](p=|page[=\/]))\d+/i, "$1"+pageNum):result;
  997. }else{
  998. return url.replace(/([&\/\?](p=|page[=\/]))\d+/i, "$1"+pageNum);
  999. }
  1000. }
  1001.  
  1002. getNextLink(doc) {
  1003. let nextLink=null,page;
  1004. if(this.curSiteRule.pageElementByJs){
  1005. this.nextLinkHref="#";
  1006. return true;
  1007. }else if(this.curSiteRule.nextLinkByJs){
  1008. try{
  1009. let targetUrl=Function("doc",'"use strict";' + this.curSiteRule.nextLinkByJs)(doc);
  1010. if(targetUrl)nextLink={href:targetUrl};
  1011. }catch(e){
  1012. debug(e);
  1013. }
  1014. }else if(this.curSiteRule.nextLinkByUrl){
  1015. let targetUrl=this.curUrl.replace(new RegExp(this.curSiteRule.nextLinkByUrl[0],"i"), this.curSiteRule.nextLinkByUrl[1]);
  1016. if(targetUrl != this.curUrl){
  1017. let reps=targetUrl.match(/{.*?}/g);
  1018. if(reps){
  1019. reps.forEach(rep=>{
  1020. let code=rep.replace("{","").replace("}","");
  1021. let result=code.match(/^(\d+)\+1$/);
  1022. if(result){
  1023. result=parseInt(result[1])+1;
  1024. }else{
  1025. try{
  1026. result=Function('"use strict";return ' + code)();
  1027. }catch(e){
  1028. debug(e);
  1029. }
  1030. }
  1031. targetUrl=targetUrl.replace(rep, result);
  1032. });
  1033. }
  1034. }
  1035. nextLink={href:targetUrl};
  1036. }else if(this.curSiteRule.nextLink){
  1037. if(this.curSiteRule.nextLink!="0"){
  1038. nextLink=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.nextLink,doc,doc):doc.querySelector(this.curSiteRule.nextLink);
  1039. }
  1040. }else{
  1041. page=this.getPage(doc);
  1042. nextLink=page.next;
  1043. if(nextLink){
  1044. if(nextLink.tagName=="INPUT" && nextLink.parentNode.tagName=="FORM"){
  1045. let params=[];
  1046. let form=nextLink.parentNode;
  1047. [].forEach.call(form.querySelectorAll("input"), input=>{
  1048. params.push(input.name+'='+input.value);
  1049. });
  1050. nextLink.href=form.action+'?'+params.join('&');
  1051. }
  1052. if(nextLink.classList.contains("noClick")){
  1053. this.nextLinkHref=false;
  1054. return null;
  1055. }else if(doc==document){
  1056. if((!nextLink.href || /^javascript:/.test(nextLink.href)) && !isVisible(nextLink, _unsafeWindow)){
  1057. this.nextLinkHref=false;
  1058. return null;
  1059. }else{
  1060. let nextLinkCs=_unsafeWindow.getComputedStyle(nextLink);
  1061. if(nextLinkCs.cursor=="not-allowed"){
  1062. this.nextLinkHref=false;
  1063. return null;
  1064. }
  1065. }
  1066. }
  1067. }
  1068. }
  1069. if(nextLink){
  1070. let needUrl=(this.curSiteRule.action==0 || this.curSiteRule.action==1);
  1071. let href=nextLink.getAttribute?nextLink.getAttribute("href"):nextLink.href;
  1072. if(href==="" && needUrl){
  1073. this.nextLinkHref=false;
  1074. }else if(/^(javascript:|#)/.test(href) && needUrl){
  1075. this.nextLinkHref=false;
  1076. }else{
  1077. this.nextLinkHref=(href && !/^(javascript:|#)/.test(href) && nextLink.href!=location.href)?this.canonicalUri(nextLink.href):"#";
  1078. if(this.nextLinkHref!="#" && (this.nextLinkHref==this.curUrl || this.nextLinkHref==this.curUrl+"#" || this.nextLinkHref==this.oldUrl || this.nextLinkHref==this.oldUrl+"#")){
  1079. this.nextLinkHref=false;
  1080. }else if(doc==document)debug(nextLink);
  1081. }
  1082. }else{
  1083. this.nextLinkHref=false;
  1084. }
  1085. this.preload();
  1086. return nextLink;
  1087. }
  1088.  
  1089. preload(){
  1090. if(!rulesData.preload)return;
  1091. if(!this.nextLinkHref || this.nextLinkHref=="#")return;
  1092. let self=this;
  1093. if(this.curSiteRule && this.curSiteRule.action==1){
  1094. if(!this.preloadIframe){
  1095. this.preloadIframe = document.createElement('iframe');
  1096. let iframe = this.preloadIframe;
  1097. iframe.name = 'pagetual-iframe';
  1098. iframe.width = '100%';
  1099. iframe.height = '0';
  1100. iframe.frameBorder = '0';
  1101. if(ruleParser.curSiteRule.sandbox!=false){
  1102. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1103. }
  1104. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1105. iframe.addEventListener('load', function (e) {
  1106. try{
  1107. let doc=iframe.contentDocument || iframe.contentWindow.document;
  1108. var body = doc.body;
  1109. if (body && body.firstChild) {
  1110. self.lazyImgAction(body.children);
  1111. }
  1112. }catch(e){
  1113. return;
  1114. }
  1115. }, false);
  1116. document.body.appendChild(iframe);
  1117. }
  1118. this.preloadIframe.src = this.nextLinkHref;
  1119. }else{
  1120. _GM_xmlhttpRequest({
  1121. url: this.nextLinkHref,
  1122. method: 'GET',
  1123. overrideMimeType: 'text/html;charset='+document.charset,
  1124. headers: {
  1125. 'Referer': location.href
  1126. },
  1127. timeout: 5000,
  1128. onload: function(res) {
  1129. var doc=null;
  1130. try {
  1131. doc=document.implementation.createHTMLDocument('');
  1132. doc.documentElement.innerHTML=res.response;
  1133. var body = doc.body;
  1134. if (body && body.firstChild) {
  1135. self.lazyImgAction(body.children);
  1136. }
  1137. if(!self.preloadDiv){
  1138. self.preloadDiv = document.createElement('div');
  1139. self.preloadDiv.id = "pagetual-preload";
  1140. self.preloadDiv.style.cssText = 'display:none!important;';
  1141. document.body.appendChild(self.preloadDiv);
  1142. self.checkedImgs={};
  1143. }
  1144. [].forEach.call(doc.images, i=>{
  1145. let iSrc=i.src;
  1146. if(iSrc && !self.checkedImgs[iSrc]){
  1147. self.checkedImgs[iSrc] = true;
  1148. let img = document.createElement('img');
  1149. img.src = iSrc;
  1150. self.preloadDiv.appendChild(img);
  1151. }
  1152. });
  1153. }
  1154. catch (e) {
  1155. return;
  1156. }
  1157. }
  1158. });
  1159. }
  1160. }
  1161.  
  1162. getInsert(refresh) {
  1163. if(refresh){
  1164. this.insert=null;
  1165. }
  1166. if(this.insert && !refresh){
  1167. let parent=this.insert;
  1168. while(parent && parent.nodeName!="BODY"){
  1169. parent=parent.parentNode;
  1170. }
  1171. if(parent && parent.nodeName=="BODY"){
  1172. return this.insert;
  1173. }
  1174. }
  1175. if(this.curSiteRule.insert){
  1176. this.insert=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.insert,document):document.querySelector(this.curSiteRule.insert);
  1177. }else{
  1178. let pageElement=this.getPageElement(document, _unsafeWindow);
  1179. if(pageElement && pageElement.length>0){
  1180. var pELast = pageElement[pageElement.length - 1];
  1181. this.insert = pELast.nextSibling ? pELast.nextSibling : pELast.parentNode.appendChild(document.createTextNode(' '));
  1182. }
  1183. }
  1184. return this.insert;
  1185. }
  1186.  
  1187. pageInit(doc,eles){
  1188. let code=this.curSiteRule.pageInit;
  1189. if(code){
  1190. try{
  1191. Function("doc","eles",'"use strict";' + code)(doc,eles);
  1192. }catch(e){
  1193. debug(e);
  1194. }
  1195. }
  1196. }
  1197.  
  1198. pageAction(doc,eles){
  1199. let code=this.curSiteRule.pageAction;
  1200. if(code){
  1201. try{
  1202. Function("doc","eles",'"use strict";' + code)(doc,eles);
  1203. }catch(e){
  1204. debug(e);
  1205. }
  1206. }
  1207. this.lazyImgAction(eles);
  1208. }
  1209.  
  1210. lazyImgAction(eles){
  1211. let setLazyImg=img=>{
  1212. let realSrc;
  1213. if(img.getAttribute("_src") && !img.src){
  1214. realSrc=img.getAttribute("_src");
  1215. }else if(img.dataset && img.dataset.original){
  1216. realSrc=img.dataset.original;
  1217. }else if(img.dataset && img.dataset.src){
  1218. realSrc=img.dataset.src;
  1219. }else if(img._lazyrias && img._lazyrias.srcset){
  1220. realSrc=img._lazyrias.srcset[img._lazyrias.srcset.length-1];
  1221. }else if(img.dataset && img.dataset.origFile){
  1222. realSrc=img.dataset.origFile;
  1223. }else if(img.srcset){
  1224. var srcs=img.srcset.split(","),largeSize=0;
  1225. srcs.forEach(srci=>{
  1226. let srcInfo=srci.trim().split(" "),curSize=parseInt(srcInfo[1]);
  1227. if(srcInfo[1] && curSize>largeSize){
  1228. largeSize=curSize;
  1229. realSrc=srcInfo[0];
  1230. }
  1231. });
  1232. }
  1233. if(realSrc){
  1234. img.src=realSrc;
  1235. img.style.display="block";
  1236. }
  1237. };
  1238. [].forEach.call(eles, ele=>{
  1239. if(ele.tagName=="IMG"){
  1240. setLazyImg(ele);
  1241. }else{
  1242. [].forEach.call(ele.querySelectorAll("img"), img=>{
  1243. setLazyImg(img);
  1244. });
  1245. }
  1246. if(ele.tagName=="A" && ele.classList.contains("lazyload")){
  1247. if(ele.dataset.original){
  1248. ele.style.backgroundImage='url("'+ele.dataset.original+'")';
  1249. }
  1250. }else{
  1251. [].forEach.call(ele.querySelectorAll("a.lazyload"), a=>{
  1252. if(a.dataset.original){
  1253. a.style.backgroundImage='url("'+a.dataset.original+'")';
  1254. }
  1255. });
  1256. }
  1257. });
  1258. let lazyImgSrc=this.curSiteRule.lazyImgSrc;
  1259. if(lazyImgSrc){
  1260. [].forEach.call(eles, ele=>{
  1261. [].forEach.call(ele.querySelectorAll("img"), img=>{
  1262. if(img.getAttribute(lazyImgSrc)){
  1263. img.src=img.getAttribute(lazyImgSrc);
  1264. }
  1265. });
  1266. });
  1267. }
  1268. }
  1269.  
  1270. initPage(callback){
  1271. let self=this;
  1272. curPage=1;
  1273. //if(this.curSiteRule.url && !this.curSiteRule.singleUrl)return;
  1274. this.curSiteRule={};
  1275. this.pageDoc=document;
  1276. this.nextLinkHref=null;
  1277. this.curUrl=location.href;
  1278. this.getRule(()=>{
  1279. if(self.curSiteRule.enable==0){
  1280. debug("Stop as rule disable");
  1281. isPause=true;
  1282. return;
  1283. }
  1284. if(self.curSiteRule && !self.curSiteRule.singleUrl){
  1285. self.hpRules=self.hpRules.filter(item=>{return item&&item.url!=self.curSiteRule.url});
  1286. self.hpRules.unshift(self.curSiteRule);
  1287. if(self.hpRules.length>30){
  1288. self.hpRules.pop();
  1289. }
  1290. storage.setItem("hpRules", self.hpRules);
  1291. }
  1292. let css=self.curSiteRule.css;
  1293. if(css){
  1294. _GM_addStyle(css);
  1295. }
  1296. let code=self.curSiteRule.init;
  1297. if(code){
  1298. try{
  1299. Function('doc','win','"use strict";' + code)(null,null);
  1300. }catch(e){
  1301. debug(e);
  1302. }
  1303. }
  1304. self.getNextLink(document);
  1305. callback();
  1306. });
  1307. }
  1308.  
  1309. insertPage(doc, eles, url, callback, tried){
  1310. this.oldUrl=this.curUrl;
  1311. let oldTitle=this.pageDoc.title;
  1312. this.pageDoc=doc;
  1313. this.curUrl=url;
  1314. let nextLink=this.getNextLink(doc);
  1315. if(curPage==1 && !tried && !nextLink && this.curSiteRule.singleUrl && this.curSiteRule.pageElement && this.curSiteRule.action!=0){
  1316. this.curSiteRule.action=1;
  1317. this.curUrl=location.href;
  1318. return false;
  1319. }
  1320. if(callback)callback(eles);
  1321. this.getInsert();
  1322. var self=this,newEles=[];
  1323. if(!eles || eles.length==0 || !self.insert || !self.insert.parentNode){
  1324. }else{
  1325. this.pageInit(doc, eles);
  1326. [].forEach.call(eles, ele=>{
  1327. let newEle=ele.cloneNode(true);
  1328. let oldCanvass=ele.querySelectorAll("canvas");
  1329. let newCanvass=newEle.querySelectorAll("canvas");
  1330. for(let i=0;i<oldCanvass.length;i++){
  1331. let oldCanvas=oldCanvass[i];
  1332. let newCanvas=newCanvass[i];
  1333. newCanvas.getContext('2d').drawImage(oldCanvas, 0, 0);
  1334. }
  1335. if(self.curSiteRule.insertPos==2){
  1336. self.insert.appendChild(newEle);
  1337. }else{
  1338. self.insert.parentNode.insertBefore(newEle, self.insert);
  1339. }
  1340. newEles.push(newEle);
  1341. });
  1342. }
  1343. this.pageAction(doc, newEles);
  1344. if(this.oldUrl!=location.href){
  1345. let isJs=/^(javascript|#)/.test(this.oldUrl.replace(location.href,""));
  1346. if(rulesData.enableHistory && !isJs){
  1347. _unsafeWindow.history.replaceState(undefined, oldTitle, this.oldUrl);
  1348. document.title=oldTitle;
  1349. }
  1350. }
  1351. return true;
  1352. }
  1353. }
  1354. var ruleParser = new RuleParser();
  1355.  
  1356. function initConfig(){
  1357. _GM_registerMenuCommand(i18n(forceState==1?"enable":"disableSite"), ()=>{
  1358. storage.setItem("forceState_"+location.host, (forceState==1?0:1));
  1359. location.reload();
  1360. });
  1361. _GM_registerMenuCommand(i18n("update"), ()=>{
  1362. updateRules(()=>{
  1363. alert(i18n("updateSucc"));
  1364. location.reload();
  1365. },(rule,err)=>{
  1366. alert("Update "+rule.url+" rules fail!");
  1367. });
  1368. alert(i18n("beginUpdate"));
  1369. });
  1370.  
  1371. var configCon,insertPos;
  1372. if(ruleImportUrlReg.test(location.href)){
  1373. document.addEventListener("click", e=>{
  1374. if(e.target.tagName=="PRE"){
  1375. let nameAttr=e.target.getAttribute("name");
  1376. if(nameAttr=="pagetual" || nameAttr=="user-content-pagetual"){
  1377. let rules=e.target.innerText.trim().split("\n");
  1378. let diff=false;
  1379. for(let c=0;c<rules.length;c++){
  1380. let urlArr=rules[c].split("|"),url,type=1;
  1381. if(urlArr.length==1){
  1382. url=urlArr[0].trim();
  1383. if(!/^http/.test(url)){
  1384. alert("Wrong url, check again!");
  1385. return;
  1386. }
  1387. }else if(urlArr.length==2){
  1388. type=urlArr[0].trim();
  1389. url=urlArr[1].trim();
  1390. if(!/^http/.test(url)){
  1391. alert("Wrong url, check again!");
  1392. return;
  1393. }
  1394. }else{
  1395. break;
  1396. }
  1397. let maxId=0,hasUrl=false;
  1398. if(!rulesData.urls){
  1399. rulesData.urls=[];
  1400. maxId=1;
  1401. }else{
  1402. rulesData.urls.forEach(u=>{
  1403. if(maxId<u.id){
  1404. maxId=u.id;
  1405. }
  1406. if(u.url==url){
  1407. hasUrl=true;
  1408. }
  1409. });
  1410. if(hasUrl)break;
  1411. }
  1412. diff=true;
  1413. if(!rulesData.sort)rulesData.sort=[1];
  1414. rulesData.urls.push({id:maxId+1,url:url,type:type});
  1415. rulesData.sort.unshift(maxId+1);
  1416. }
  1417. if(!diff)return;
  1418. storage.setItem("rulesData", rulesData);
  1419.  
  1420. if(rulesData.urls)ruleUrls=ruleUrls.concat(rulesData.urls);
  1421. if(rulesData.sort){
  1422. let urls=[];
  1423. rulesData.sort.forEach(id=>{
  1424. for(let s=0;s<ruleUrls.length;s++){
  1425. if(id==ruleUrls[s].id){
  1426. urls.push(ruleUrls[s]);
  1427. break;
  1428. }
  1429. }
  1430. });
  1431. ruleUrls=urls;
  1432. }
  1433. alert("OK");
  1434. }
  1435. }
  1436. });
  1437. }
  1438. if(location.href==configPage){
  1439. _GM_addStyle(`
  1440. p>span:nth-child(1),p>span:nth-child(2),p>span:nth-child(3){
  1441. cursor: pointer;
  1442. user-select: none;
  1443. }
  1444. p>span:nth-child(1):hover,p>span:nth-child(2):hover,p>span:nth-child(3):hover{
  1445. color:red;
  1446. }
  1447. .updateDate{
  1448. cursor: pointer;
  1449. user-select: none;
  1450. }
  1451. .updateDate:hover{
  1452. color:red;
  1453. }
  1454. `);
  1455. document.querySelector("[name='user-content-click2import']").innerText=i18n("click2ImportRule")
  1456. configCon=document.querySelector(".markdown-body");
  1457. insertPos=configCon.querySelector("hr");
  1458.  
  1459. if(rulesData.urls && rulesData.urls.length>0){
  1460. document.querySelector("pre[name='user-content-pagetual']").style.display="none";
  1461. document.querySelector("p[name='user-content-click2import']").style.display="none";
  1462. }
  1463. }else return false;
  1464. class Rulebar {
  1465. init(ruleUrl){
  1466. this.ruleUrl=ruleUrl;
  1467. this.item=document.createElement("p");
  1468. this.item.title=ruleUrl.type==0?"AutoPagerize Rules":"Pagetual Rules";
  1469. this.item.dataset.id=this.ruleUrl.id;
  1470. let url=document.createElement("span");
  1471. url.innerHTML=ruleUrl.url;
  1472. let up=document.createElement("span");
  1473. up.innerHTML="↑ ";
  1474. up.title=i18n("sortTitle");
  1475. let down=document.createElement("span");
  1476. down.innerHTML="↓ ";
  1477. down.title=i18n("sortTitle");
  1478. let del=document.createElement("span");
  1479. del.innerHTML="× ";
  1480. up.onclick=e=>{
  1481. this.moveUp();
  1482. };
  1483. down.onclick=e=>{
  1484. this.moveDown();
  1485. };
  1486. del.onclick=e=>{
  1487. this.del();
  1488. };
  1489. this.item.appendChild(up);
  1490. this.item.appendChild(down);
  1491. this.item.appendChild(del);
  1492. this.item.appendChild(url);
  1493. configCon.insertBefore(this.item, insertPos);
  1494. }
  1495. saveSort(){
  1496. let sort=[];
  1497. [].forEach.call(this.item.parentNode.querySelectorAll("p[data-id]"), i=>{
  1498. sort.push(i.dataset.id);
  1499. });
  1500. rulesData.sort=sort;
  1501. storage.setItem("rulesData", rulesData);
  1502. }
  1503. moveUp(){
  1504. let preE=this.item.previousElementSibling;
  1505. if(preE.tagName=="P" && preE.children.length>1){
  1506. this.item.parentNode.insertBefore(this.item,preE);
  1507. this.saveSort();
  1508. }
  1509. }
  1510. moveDown(){
  1511. let nextE=this.item.nextElementSibling;
  1512. if(nextE.tagName=="P" && nextE.children.length>1){
  1513. this.item.parentNode.insertBefore(nextE,this.item);
  1514. this.saveSort();
  1515. }
  1516. }
  1517. del(){
  1518. if(this.ruleUrl.id<2){
  1519. alert(i18n("cantDel"));
  1520. }else if(window.confirm(i18n("confirmDel"))){
  1521. for(let u=0;u<rulesData.urls.length;u++){
  1522. if(this.ruleUrl.id==rulesData.urls[u].id){
  1523. rulesData.urls.splice(u,1);
  1524. break;
  1525. }
  1526. }
  1527. for(let u=0;u<rulesData.sort.length;u++){
  1528. if(this.ruleUrl.id==rulesData.sort[u]){
  1529. rulesData.sort.splice(u,1);
  1530. break;
  1531. }
  1532. }
  1533. storage.setItem("rulesData", rulesData);
  1534. ruleParser.rules=ruleParser.rules.filter(item=>{return item.from!=this.ruleUrl.id});
  1535. storage.setItem("rules", ruleParser.rules);
  1536. this.item.parentNode.removeChild(this.item);
  1537. //location.reload();
  1538. }
  1539. }
  1540. }
  1541. let updateP=document.createElement("p"),i=0;
  1542. let now=new Date().getTime(),inUpdate=false;
  1543.  
  1544.  
  1545. let pastDate=(new Date(updateDate)).toString(),passStr;
  1546. let passTime=(now-updateDate)/1000;
  1547. if(isNaN(passTime)){
  1548. passStr=i18n("firstUpdate");
  1549. }else if(passTime<60){
  1550. passStr=i18n("passSec", parseInt(passTime))+" ← "+i18n("click2update");
  1551. }else if(passTime<60*60){
  1552. passStr=i18n("passMin", parseInt(passTime/60))+" ← "+i18n("click2update");
  1553. }else if(passTime<60*60*24){
  1554. passStr=i18n("passHour", parseInt(passTime/3600))+" ← "+i18n("click2update");
  1555. }else{
  1556. passStr=i18n("passDay", parseInt(passTime/86400))+" ← "+i18n("click2update");
  1557. }
  1558.  
  1559.  
  1560. updateP.className="updateDate";
  1561. updateP.innerHTML=passStr;
  1562. updateP.title=i18n("update")+" - "+pastDate;
  1563. updateP.onclick=e=>{
  1564. updateRules(()=>{
  1565. alert(i18n("updateSucc"));
  1566. updateP.innerHTML=i18n("passSec", 0);
  1567. updateP.title=i18n("update");
  1568. },(rule,err)=>{
  1569. alert("Update "+rule.url+" rules fail!");
  1570. });
  1571. alert(i18n("beginUpdate"));
  1572. };
  1573. configCon.insertBefore(updateP, insertPos);
  1574. if(ruleUrls){
  1575. ruleUrls.forEach(ruleUrl=>{
  1576. var rulebar=new Rulebar();
  1577. rulebar.init(ruleUrl);
  1578. });
  1579. }
  1580. let customUrlsTitle=document.createElement("h2");
  1581. customUrlsTitle.innerHTML=i18n("customUrls");
  1582. configCon.insertBefore(customUrlsTitle, insertPos);
  1583. let customUrlsInput=document.createElement("textarea");
  1584. customUrlsInput.style.width="100%";
  1585. customUrlsInput.placeholder="0|http://wedata.net/databases/AutoPagerize/items_all.json";
  1586. configCon.insertBefore(customUrlsInput, insertPos);
  1587.  
  1588. let opacityTitle=document.createElement("h2");
  1589. opacityTitle.innerHTML=i18n("opacity");
  1590. let opacityInput=document.createElement("input");
  1591. opacityInput.value=rulesData.opacity*100;
  1592. opacityInput.type="number";
  1593. opacityInput.style.width="50px";
  1594. opacityInput.style.margin="0 0 0 10px";
  1595. opacityTitle.appendChild(opacityInput);
  1596. configCon.insertBefore(opacityTitle, insertPos);
  1597.  
  1598. function createCheckbox(innerText, val){
  1599. let title=document.createElement("h2");
  1600. title.innerHTML=innerText;
  1601. let input=document.createElement("input");
  1602. input.type="checkbox";
  1603. input.style.width="50px";
  1604. input.style.height="20px";
  1605. input.checked=val;
  1606. title.appendChild(input);
  1607. configCon.insertBefore(title, insertPos);
  1608. return input;
  1609. }
  1610.  
  1611. let hideBarInput=createCheckbox(i18n("hideBar"), rulesData.hideBar);
  1612. let dbClick2StopInput=createCheckbox(i18n("dbClick2Stop"), rulesData.dbClick2Stop);
  1613. let enableWhiteListInput=createCheckbox(i18n("autoRun"), rulesData.enableWhiteList!=true);
  1614. let enableDebugInput=createCheckbox(i18n("enableDebug"), rulesData.enableDebug!=false);
  1615. let enableHistoryInput=createCheckbox(i18n("enableHistory"), rulesData.enableHistory===true);
  1616. let initRunInput=createCheckbox(i18n("initRun"), rulesData.initRun!=false);
  1617. let preloadInput=createCheckbox(i18n("preload"), rulesData.preload);
  1618.  
  1619. let customRulesTitle=document.createElement("h2");
  1620. customRulesTitle.innerHTML=i18n("customRules")
  1621. configCon.insertBefore(customRulesTitle, insertPos);
  1622. let customRulesInput=document.createElement("textarea");
  1623. customRulesInput.style.width="100%";
  1624. customRulesInput.style.height="500px";
  1625. 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]`;
  1626. customRulesInput.value=getFormatJSON(ruleParser.customRules);
  1627. configCon.insertBefore(customRulesInput, insertPos);
  1628. let saveBtn=document.createElement("button");
  1629. saveBtn.innerHTML=i18n("save");
  1630. saveBtn.style.width="100%";
  1631. configCon.insertBefore(saveBtn, insertPos);
  1632. saveBtn.onclick=e=>{
  1633. try{
  1634. storage.setItem("hpRules", []);
  1635. if(customRulesInput.value==""){
  1636. storage.setItem("customRules", "");
  1637. }else{
  1638. let customRules=JSON.parse(customRulesInput.value);
  1639. if(Array && Array.isArray && !Array.isArray(customRules)){
  1640. alert("Rules must be a Array!");
  1641. return;
  1642. }
  1643. debug(customRules);
  1644. storage.setItem("customRules", customRules);
  1645. }
  1646. }catch(e){
  1647. debug(e);
  1648. alert("JSON error, check again!");
  1649. return;
  1650. }
  1651. rulesData.opacity=opacityInput.value/100;
  1652. rulesData.hideBar=hideBarInput.checked;
  1653. rulesData.dbClick2Stop=dbClick2StopInput.checked;
  1654. rulesData.enableWhiteList=!enableWhiteListInput.checked;
  1655. rulesData.enableDebug=enableDebugInput.checked;
  1656. rulesData.enableHistory=enableHistoryInput.checked;
  1657. rulesData.initRun=initRunInput.checked;
  1658. rulesData.preload=preloadInput.checked;
  1659. storage.setItem("rulesData", rulesData);
  1660. let customUrls=customUrlsInput.value.trim();
  1661. if(customUrls){
  1662. customUrls=customUrls.split(/\n/);
  1663. for(let c=0;c<customUrls.length;c++){
  1664. let urlArr=customUrls[c].split("|"),url,type=1;
  1665. if(urlArr.length==1){
  1666. url=urlArr[0].trim();
  1667. if(!/^http/.test(url)){
  1668. alert("Wrong url, check again!");
  1669. return;
  1670. }
  1671. }else if(urlArr.length==2){
  1672. type=urlArr[0].trim();
  1673. url=urlArr[1].trim();
  1674. if(!/^http/.test(url)){
  1675. alert("Wrong url, check again!");
  1676. return;
  1677. }
  1678. }else{
  1679. break;
  1680. }
  1681. let maxId=0,hasUrl=false;
  1682. if(!rulesData.urls){
  1683. rulesData.urls=[];
  1684. maxId=1;
  1685. }else{
  1686. rulesData.urls.forEach(u=>{
  1687. if(maxId<u.id){
  1688. maxId=u.id;
  1689. }
  1690. if(u.url==url){
  1691. hasUrl=true;
  1692. }
  1693. });
  1694. if(hasUrl)break;
  1695. }
  1696. if(!rulesData.sort)rulesData.sort=[1];
  1697. rulesData.urls.push({id:maxId+1,url:url,type:type});
  1698. rulesData.sort.push(maxId+1);
  1699. storage.setItem("rulesData", rulesData);
  1700. }
  1701. }
  1702. alert("The settings are saved");
  1703. location.reload();
  1704. };
  1705. return true;
  1706. }
  1707.  
  1708. var inUpdate=false;
  1709. function updateRules(success,fail){
  1710. if(inUpdate)return;
  1711. inUpdate=true;
  1712. let ruleIndex=ruleUrls.length-1;
  1713. storage.setItem("hpRules", []);
  1714. function addNextRule(){
  1715. if(ruleIndex<0){
  1716. let now=new Date().getTime();
  1717. storage.setItem("ruleLastUpdate", now);
  1718. storage.setItem("rules", ruleParser.rules);
  1719. inUpdate=false;
  1720. success();
  1721. }else{
  1722. let rule=ruleUrls[ruleIndex--];
  1723. ruleParser.addRuleByUrl(rule.url, rule.type, rule.id, (json,err)=>{
  1724. if(!json){
  1725. fail(rule,err);
  1726. }
  1727. addNextRule();
  1728. })
  1729. }
  1730. }
  1731. addNextRule();
  1732. }
  1733.  
  1734. function objIsArr(obj) {
  1735. return obj &&
  1736. typeof obj === 'object' &&
  1737. typeof obj.length === 'number' &&
  1738. !(obj.propertyIsEnumerable('length'));
  1739. }
  1740.  
  1741. function isVisible(el, win) {
  1742. if(!el.offsetParent)return false;
  1743. var loopable = true,
  1744. visible = el.tagName && win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  1745. while(loopable && visible) {
  1746. el = el.parentNode;
  1747.  
  1748. if(el && el.tagName && el.tagName!="BODY") {
  1749. visible = win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  1750. }else {
  1751. loopable = false;
  1752. }
  1753. }
  1754. return visible;
  1755. }
  1756.  
  1757. function getFormatJSON(obj){
  1758. if(!objIsArr(obj))return "";
  1759. let ret="[\n";
  1760. let len=obj.length,i=0,isLast;
  1761. obj.forEach(item=>{
  1762. ret+=" {\n";
  1763. let iLen=Object.keys(item).length,j=0;
  1764. for(let key in item){
  1765. isLast=(++j)==iLen;
  1766. let value=item[key];
  1767. if(objIsArr(value)){
  1768. let vstr="[",v=0,vIsLast=false;
  1769. value.forEach(vi=>{
  1770. vIsLast=(++v)==value.length;
  1771. vstr+="\""+vi.replace(/\\/g,"\\\\")+"\""+(vIsLast?"":",");
  1772. });
  1773. vstr+="]";
  1774. ret+=" \""+key+"\":"+vstr+""+(isLast?"":",")+"\n";
  1775. }else{
  1776. if(typeof value=="string"){
  1777. value=value.replace(/\\/g,"\\\\").replace(/"/g,"\\\"");
  1778. value="\""+value+"\"";
  1779. }
  1780. ret+=" \""+key+"\":"+value+""+(isLast?"":",")+"\n";
  1781. }
  1782. }
  1783. isLast=(++i)==len;
  1784. ret+=" }"+(isLast?"":",")+"\n";
  1785. });
  1786. ret+="]";
  1787. return ret;
  1788. }
  1789.  
  1790. function initRules(callback) {
  1791. /*0 wedata格式,1 pagetual格式*/
  1792. ruleUrls=[
  1793. {
  1794. id:1,
  1795. url:'http://wedata.net/databases/AutoPagerize/items_all.json',
  1796. type:0,
  1797. }
  1798. ];var i=0,j=0;
  1799.  
  1800. ruleParser.initSavedRules(()=>{
  1801. storage.getItem("rulesData", data=>{
  1802. if(data){
  1803. rulesData=data;
  1804. if(data.urls)ruleUrls=ruleUrls.concat(data.urls);
  1805. if(data.sort){
  1806. let urls=[];
  1807. data.sort.forEach(id=>{
  1808. for(let s=0;s<ruleUrls.length;s++){
  1809. if(id==ruleUrls[s].id){
  1810. urls.push(ruleUrls[s]);
  1811. break;
  1812. }
  1813. }
  1814. });
  1815. ruleUrls=urls;
  1816. }
  1817. }
  1818. if(typeof(rulesData.opacity)=="undefined"){
  1819. rulesData.opacity=0.3;
  1820. }
  1821. if(typeof(rulesData.hideBar)=="undefined"){
  1822. rulesData.hideBar=false;
  1823. }
  1824. if(typeof(rulesData.dbClick2Stop)=="undefined"){
  1825. rulesData.dbClick2Stop=true;
  1826. }
  1827. if(typeof(rulesData.enableWhiteList)=="undefined"){
  1828. rulesData.enableWhiteList=false;
  1829. }
  1830. if(typeof(rulesData.enableHistory)=="undefined"){
  1831. rulesData.enableHistory=false;
  1832. }
  1833. if(typeof(rulesData.enableDebug)=="undefined"){
  1834. rulesData.enableDebug=true;
  1835. }
  1836. if(typeof(rulesData.initRun)=="undefined"){
  1837. rulesData.initRun=true;
  1838. }
  1839. if(typeof(rulesData.preload)=="undefined"){
  1840. rulesData.preload=false;
  1841. }
  1842. enableDebug=rulesData.enableDebug;
  1843. storage.getItem("forceState_"+location.host, v=>{
  1844. storage.getItem("ruleLastUpdate", date=>{
  1845. if(typeof(v)=="undefined"){
  1846. v=(rulesData.enableWhiteList?1:0);
  1847. }
  1848. forceState=v;
  1849. updateDate=date;
  1850. if(initConfig())return;
  1851. if(forceState==1)return;
  1852. let now=new Date().getTime();
  1853. if(!date || now-date>2*24*60*60*1000){
  1854. //storage.setItem("ruleLastUpdate", now);
  1855. updateRules(()=>{
  1856. //callback();
  1857. },(rule,err)=>{});
  1858. }
  1859. callback();
  1860. });
  1861. });
  1862. });
  1863. });
  1864. }
  1865.  
  1866. function requestDoc(url, callback){
  1867. _GM_xmlhttpRequest({
  1868. url: url,
  1869. method: 'GET',
  1870. overrideMimeType: 'text/html;charset='+document.charset,
  1871. headers: {
  1872. 'Referer': location.href
  1873. },
  1874. timeout: 5000,
  1875. onload: function(res) {
  1876. var doc=null;
  1877. try {
  1878. doc=document.implementation.createHTMLDocument('');
  1879. doc.documentElement.innerHTML=res.response;
  1880. }
  1881. catch (e) {
  1882. debug('parse error'+e.toString());
  1883. }
  1884. let pageElement=ruleParser.getPageElement(doc);
  1885. //只有1的話怕不是圖片哦
  1886. if(pageElement && (pageElement.length>1 || (pageElement.length==1 && pageElement[0].tagName!="IMG") )){
  1887. let result=ruleParser.insertPage(doc, pageElement, url, callback, false);
  1888. if(!result){
  1889. ruleParser.curSiteRule.action=1;
  1890. requestFromIframe(url, (doc, eles)=>{
  1891. loadPageOver();
  1892. if(eles){
  1893. ruleParser.insertPage(doc, eles, url, callback, true);
  1894. }
  1895. });
  1896. }
  1897. }else if(ruleParser.curSiteRule.singleUrl || curPage==1){
  1898. ruleParser.curSiteRule.action=1;
  1899. requestFromIframe(url, (doc, eles)=>{
  1900. loadPageOver();
  1901. if(eles){
  1902. ruleParser.insertPage(doc, eles, url, callback, true);
  1903. }
  1904. });
  1905. }else{
  1906. isPause=true;
  1907. callback(false);
  1908. }
  1909. },
  1910. onerror: function(e){
  1911. debug(e);
  1912. callback(false);
  1913. },
  1914. ontimeout: function(e){
  1915. debug(e);
  1916. callback(false);
  1917. }
  1918. });
  1919. }
  1920.  
  1921. var failFromIframe=0;
  1922. function requestFromIframe(url, callback){
  1923. let orgPage,curPage;
  1924. let iframe = document.createElement('iframe');
  1925. iframe.name = 'pagetual-iframe';
  1926. iframe.width = '100%';
  1927. iframe.height = '0';
  1928. iframe.frameBorder = '0';
  1929. if(ruleParser.curSiteRule.sandbox!=false){
  1930. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1931. }
  1932. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1933. iframe.addEventListener("load", e=>{
  1934. let waitTime=500,checkEval;
  1935. if(ruleParser.curSiteRule.wait){
  1936. if(isNaN(ruleParser.curSiteRule.wait)){
  1937. try{
  1938. checkEval=Function("doc",'"use strict";' + ruleParser.curSiteRule.wait);
  1939. }catch(e){
  1940. debug(e);
  1941. }
  1942. }else{
  1943. waitTime=ruleParser.curSiteRule.wait;
  1944. }
  1945. }
  1946. setTimeout(()=>{
  1947. let tryTimes=0;
  1948. function checkIframe(){
  1949. try{
  1950. let doc=iframe.contentDocument || iframe.contentWindow.document;
  1951. let eles=ruleParser.getPageElement(doc, iframe.contentWindow);
  1952. if(eles && eles.length>0 && (!checkEval || checkEval(doc))){
  1953. callback(doc, eles);
  1954. }else if(tryTimes++ < 10){
  1955. setTimeout(()=>{
  1956. checkIframe();
  1957. },waitTime);
  1958. return;
  1959. }else{
  1960. if(failFromIframe++ > 2){
  1961. failFromIframe=0;
  1962. debug("Stop as failFromIframe");
  1963. isPause=true;
  1964. callback(false, false);
  1965. }else{
  1966. callback(false, false);
  1967. }
  1968. }
  1969. }catch(e){
  1970. debug("Stop as cors");
  1971. //isPause=true;
  1972. if(!ruleParser.curSiteRule.pageElement)ruleParser.curSiteRule.pageElement=allOfBody;
  1973. ruleParser.curSiteRule.action=0;
  1974. ruleParser.getInsert(true);
  1975. ruleParser.nextLinkHref=url;
  1976. callback(false, false);
  1977. nextPage();
  1978. }
  1979. document.body.removeChild(iframe);
  1980. }
  1981. checkIframe();
  1982. },waitTime);
  1983. });
  1984. iframe.src=url;
  1985. document.body.appendChild(iframe);
  1986. }
  1987.  
  1988. function initPage(){
  1989. ruleParser.initPage(()=>{
  1990. if(ruleParser.nextLinkHref){
  1991. initView();
  1992. let isJs=/^(javascript|#)/.test(ruleParser.nextLinkHref.replace(location.href,""));
  1993. if(!isJs){
  1994. let inForce=(forceState == 2 || forceState == 3);
  1995. _GM_registerMenuCommand(i18n(inForce?"cancelForceIframe":"forceIframe"), ()=>{
  1996. if(inForce){
  1997. storage.setItem("forceState_"+location.host, "");
  1998. }else{
  1999. let _state=confirm(i18n("forceAllBody"))?2:3;
  2000. storage.setItem("forceState_"+location.host, _state);
  2001. }
  2002. location.reload();
  2003. });
  2004. }
  2005. _GM_registerMenuCommand(i18n("loadNow"), ()=>{
  2006. let loadNum=window.prompt(i18n("loadConfirm"), "1");
  2007. if(loadNum==="" || loadNum===null)return;
  2008. autoLoadNum=Math.abs(parseInt(loadNum));
  2009. nextPage();
  2010. });
  2011. }
  2012. initListener();
  2013. if(rulesData.initRun && ruleParser.curSiteRule.initRun!=0)nextPage();
  2014. });
  2015. }
  2016.  
  2017. function initView(){
  2018. _GM_addStyle(`
  2019. .pagetual_pageBar.stop {
  2020. -webkit-filter: invert(100%);
  2021. filter: invert(100%);
  2022. opacity: 1!important;
  2023. }
  2024. .pagetual_pageBar.hide {
  2025. display: none!important;
  2026. }
  2027. .pagetual_pageBar:hover {
  2028. opacity: 1!important;
  2029. }
  2030. .pagetual_pageBar span {
  2031. vertical-align: super;
  2032. }
  2033.  
  2034. .pagetual_pageBar span>svg:hover {
  2035. animation: touhouAni 1s infinite;
  2036. }
  2037. .pagetual_pageBar .pagetual_pageNum{
  2038. color: #55555f;
  2039. }
  2040. .pagetual_pageBar .pagetual_pageNum:hover{
  2041. color: #ff6464;
  2042. }
  2043.  
  2044. @keyframes touhouAni{
  2045. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  2046. to {transform: rotate(360deg);}
  2047. }
  2048. @-webkit-keyframes touhouAni{
  2049. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  2050. to {transform: rotate(360deg);}
  2051. }
  2052. .pagetual_loading {
  2053. width: 50px;
  2054. height: 50px;
  2055. margin: 10px auto;
  2056. border-radius: 100%;
  2057. -webkit-animation: pagetual_loading_scaleout 1.0s infinite ease-in-out;
  2058. animation: pagetual_loading_scaleout 1.0s infinite ease-in-out;
  2059. }
  2060. @-webkit-keyframes pagetual_loading_scaleout {
  2061. 0% { -webkit-transform: scale(0.0) }
  2062. 100% {
  2063. -webkit-transform: scale(1.0);
  2064. opacity: 0;
  2065. }
  2066. }
  2067. @keyframes pagetual_loading_scaleout {
  2068. 0% {
  2069. transform: scale(0.0);
  2070. -webkit-transform: scale(0.0);
  2071. } 100% {
  2072. transform: scale(1.0);
  2073. -webkit-transform: scale(1.0);
  2074. opacity: 0;
  2075. }
  2076. }
  2077. `);
  2078. 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;`;
  2079. }
  2080. var loadingDiv=document.createElement("div");
  2081. //loadingDiv.className="pagetual_loading";
  2082. 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;";
  2083. //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><svg width="120" height="30" viewBox="0 0 120 30" fill="#000000A0" style="display: block;position: initial;margin: auto;shape-rendering: auto;vertical-align: middle;visibility: visible;width: initial;height: initial;"><circle cx="15" cy="15" r="15"><animate attributeName="r" from="15" to="15" begin="0s" dur="0.8s" values="15;9;15" calcMode="linear" repeatCount="indefinite"></animate><animate attributeName="fill-opacity" from="1" to="1" begin="0s" dur="0.8s" values="1;.5;1" calcMode="linear" repeatCount="indefinite"></animate></circle><circle cx="60" cy="15" r="9" fill-opacity="0.3"><animate attributeName="r" from="9" to="9" begin="0s" dur="0.8s" values="9;15;9" calcMode="linear" repeatCount="indefinite"></animate><animate attributeName="fill-opacity" from="0.5" to="0.5" begin="0s" dur="0.8s" values=".5;1;.5" calcMode="linear" repeatCount="indefinite"></animate></circle><circle cx="105" cy="15" r="15"><animate attributeName="r" from="15" to="15" begin="0s" dur="0.8s" values="15;9;15" calcMode="linear" repeatCount="indefinite"></animate><animate attributeName="fill-opacity" from="1" to="1" begin="0s" dur="0.8s" values="1;.5;1" calcMode="linear" repeatCount="indefinite"></animate></circle></svg>`;
  2084. 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>`;
  2085.  
  2086. 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>`;
  2087. 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>`;
  2088. var pageBarStyle;
  2089. 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;`;
  2090. 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);`;
  2091.  
  2092. var isPause=false,isLoading=false,curPage=1,forceState=0,bottomGap=1000,autoLoadNum=-1;
  2093.  
  2094. function changeStop(stop, hide){
  2095. isPause=stop;
  2096. [].forEach.call(document.querySelectorAll(".pagetual_pageBar"), bar=>{
  2097. if(isPause){
  2098. bar.classList.add("stop");
  2099. if(hide)bar.classList.add("hide");
  2100. }else{
  2101. bar.classList.remove("stop");
  2102. if(hide)bar.classList.remove("hide");
  2103. }
  2104. });
  2105. }
  2106.  
  2107. function isInViewPort(element) {
  2108. if(!element.parentNode)return false;
  2109. if(_unsafeWindow.getComputedStyle(element).display=="none")return false;
  2110. const viewWidth = window.innerWidth || document.documentElement.clientWidth;
  2111. const viewHeight = window.innerHeight || document.documentElement.clientHeight;
  2112. const {
  2113. top,
  2114. right,
  2115. bottom,
  2116. left,
  2117. } = element.getBoundingClientRect();
  2118.  
  2119. return (
  2120. top >= 0 &&
  2121. left >= 0 &&
  2122. right <= viewWidth &&
  2123. bottom <= viewHeight
  2124. );
  2125. }
  2126.  
  2127. var urlChanged=false;
  2128. var _wr = function(type) {
  2129. var orig = history[type];
  2130. return function() {
  2131. var rv = orig.apply(this, arguments);
  2132. var e = new Event(type);
  2133. e.arguments = arguments;
  2134. window.dispatchEvent(e);
  2135. return rv;
  2136. };
  2137. };
  2138. history.pushState = _wr('pushState');
  2139. window.addEventListener('pushState', function(e) {
  2140. urlChanged=true;
  2141. isPause=true;
  2142. setTimeout(()=>{
  2143. if(location.href==configPage){
  2144. location.reload();
  2145. }
  2146. },1);
  2147. });
  2148.  
  2149. function initListener(){
  2150. let loadmoreBtn,loading=true;
  2151. setTimeout(()=>{
  2152. loadmoreBtn=getLoadMore(document);
  2153. if(loadmoreBtn && isVisible(loadmoreBtn, _unsafeWindow)){
  2154. loading=false;
  2155. }
  2156. },500);
  2157. let checkScrollReach=()=>{
  2158. let scrolly=window.scrollY;
  2159. let windowHeight=window.innerHeight || document.documentElement.clientHeight;
  2160. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  2161. if(scrollH-scrolly-windowHeight<bottomGap){
  2162. nextPage();
  2163. }
  2164. };
  2165. document.addEventListener('scroll', e=>{
  2166. if(urlChanged){
  2167. ruleParser.initPage(()=>{
  2168. if(ruleParser.nextLinkHref)initView();
  2169. });
  2170. urlChanged=false;
  2171. isPause=false;
  2172. }
  2173. if(isPause)return;
  2174. if(!loading){
  2175. loading=true;
  2176. setTimeout(()=>{loading=false},200);
  2177. if(!loadmoreBtn || !loadmoreBtn.parentNode){
  2178. loadmoreBtn=getLoadMore(document);
  2179. }
  2180. if(loadmoreBtn){
  2181. if(isInViewPort(loadmoreBtn)){
  2182. emuClick(loadmoreBtn);
  2183. }
  2184. }
  2185. }
  2186. setTimeout(()=>{
  2187. if(!isLoading){
  2188. checkScrollReach();
  2189. }
  2190. },100);
  2191. }, true);
  2192. document.addEventListener('dblclick', e=>{
  2193. if(rulesData.dbClick2Stop){
  2194. setTimeout(()=>{
  2195. changeStop(!isPause, rulesData.hideBar);
  2196. if(!isPause){
  2197. checkScrollReach();
  2198. }
  2199. },200);
  2200. }
  2201. });
  2202. }
  2203.  
  2204. function getLoadMore(doc){
  2205. if(ruleParser.curSiteRule.loadMore==="")return null;
  2206. let btnSel=ruleParser.curSiteRule.loadMore||".LoadMore,.load-more";
  2207. let loadmoreBtn=doc.querySelector(btnSel);
  2208. if(!loadmoreBtn){
  2209. let buttons=doc.querySelectorAll("input,button,a,div[onclick]"),loadmoreReg=/^\s*(加载更多|加載更多|load\s*more|もっと読み込む)\s*$/i;
  2210. for(let i=0;i<buttons.length;i++){
  2211. let button=buttons[i];
  2212. if(button && loadmoreReg.test(button.innerText)){
  2213. loadmoreBtn=button;
  2214. break;
  2215. }
  2216. }
  2217. }
  2218. return loadmoreBtn;
  2219. }
  2220.  
  2221. var hasPageNum=true;
  2222. function createPageBar(url){
  2223. let insert=ruleParser.getInsert();
  2224. if(!insert || !insert.parentNode)return;
  2225. curPage++;
  2226. if(rulesData.opacity==0)return;
  2227. let example=ruleParser.curSiteRule.insertPos==2?insert.children[0]:(insert.previousElementSibling||insert);
  2228. if(!example || !example.parentNode)example=insert;
  2229. let inTable=example.parentNode.tagName=="TABLE" ||
  2230. example.tagName=="TR" ||
  2231. example.tagName=="TBODY" ||
  2232. (example.previousElementSibling && example.previousElementSibling.tagName=="TR") ||
  2233. (example.previousElementSibling && example.previousElementSibling.tagName=="TBODY");
  2234. let inLi=example.tagName=="LI" || (example.previousElementSibling && example.previousElementSibling.tagName=="LI");
  2235. if(forceState==2){
  2236. inTable=inLi=false;
  2237. }
  2238. let pageBar=document.createElement(inTable?"tr":(inLi?"li":"div"));
  2239. let upSpan=document.createElement("span");
  2240. let downSpan=document.createElement("span");
  2241. let pageText=document.createElement("a");
  2242. let pageNum;
  2243. pageBar.className="pagetual_pageBar";
  2244. pageBar.id="pagetual_pageBar";
  2245. if(isPause){
  2246. pageBar.classList.add("stop");
  2247. }
  2248. pageBar.style.cssText=pageBarStyle;
  2249. pageBar.title=i18n(isPause?"enable":"disable");
  2250. upSpan.innerHTML=upSvg;
  2251. upSpan.title=i18n("toTop");
  2252. downSpan.innerHTML=downSvg;
  2253. downSpan.title=i18n("toBottom");
  2254. upSpan.style.cssText=initStyle;
  2255. downSpan.style.cssText=initStyle;
  2256. pageText.href=url;
  2257. pageText.style.cssText=pageTextStyle;
  2258. pageText.title=i18n("current");
  2259. pageBar.appendChild(upSpan);
  2260. pageBar.appendChild(pageText);
  2261. if(ruleParser.curSiteRule.pageNum || (hasPageNum && /[&\/\?](p=|page[=\/])\d+/.test(url))){
  2262. pageText.innerHTML="Page ";
  2263. pageNum=document.createElement("span");
  2264. pageNum.innerText=curPage;
  2265. pageNum.className="pagetual_pageNum";
  2266. pageNum.title=i18n("inputPageNum");
  2267. pageNum.style.cssText=pageTextStyle;
  2268. pageNum.style.cursor="pointer";
  2269. pageNum.style.color="";
  2270. pageNum.addEventListener("click", e=>{
  2271. let pageInput=prompt(i18n("inputPageNum"), "1");
  2272. if(pageInput){
  2273. let pageLink=ruleParser.getLinkByPage(url, pageInput);
  2274. if(pageLink){
  2275. _GM_openInTab(pageLink,{active:true});
  2276. }
  2277. }
  2278. e.preventDefault();
  2279. e.stopPropagation();
  2280. });
  2281. pageBar.appendChild(pageNum);
  2282. }else{
  2283. pageText.innerHTML="Page "+curPage;
  2284. hasPageNum=false;
  2285. }
  2286. pageBar.appendChild(downSpan);
  2287. let parentStyle=_unsafeWindow.getComputedStyle(example.parentNode);
  2288. let parentWidth=example.parentNode.scrollWidth||parseInt(parentStyle.width);
  2289. pageBar.style.width=parentWidth-parseInt(parentStyle.paddingLeft)-parseInt(parentStyle.paddingRight)-10+"px";
  2290. if(parentStyle.display=="grid" || parentStyle.display=="inline-grid"){
  2291. pageBar.style.gridColumnStart=1;
  2292. pageBar.style.gridColumnEnd=1+parseInt(example.parentNode.offsetWidth/example.offsetWidth);
  2293. }
  2294. if(inTable){
  2295. example=(example.tagName=="TR" || example.tagName=="TBODY")?example:example.previousElementSibling;
  2296. if(example.previousElementSibling)example=example.previousElementSibling;
  2297. let tdNum=0;
  2298. [].forEach.call(example.querySelectorAll("td,th"), td=>{
  2299. tdNum+=td.colSpan||1;
  2300. });
  2301. pageBar.style.display="table-row";
  2302. pageBar.style.backgroundColor="unset";
  2303. let td=document.createElement("td");
  2304. td.style.backgroundColor="rgb(240 240 240 / 80%)";
  2305. td.style.borderRadius="20px";
  2306. td.colSpan=tdNum||1;
  2307. td.style.padding="0 0";
  2308. td.style.textAlign="center";
  2309. td.appendChild(upSpan);
  2310. td.appendChild(pageText);
  2311. if(pageNum)td.appendChild(pageNum);
  2312. td.appendChild(downSpan);
  2313. pageBar.appendChild(td);
  2314. }else if(inLi){
  2315. example=example.tagName=="LI"?example:example.previousElementSibling;
  2316. pageBar.style.display="table-row";
  2317. pageBar.style.backgroundColor="unset";
  2318. let td=document.createElement("td");
  2319. td.style.backgroundColor="rgb(240 240 240 / 80%)";
  2320. td.style.borderRadius="20px";
  2321. td.colSpan=example.children.length;
  2322. td.style.padding="0 0";
  2323. td.style.textAlign="center";
  2324. td.style.minWidth="150px";
  2325. td.appendChild(upSpan);
  2326. td.appendChild(pageText);
  2327. td.style.width=pageBar.style.width;
  2328. if(pageNum)td.appendChild(pageNum);
  2329. td.appendChild(downSpan);
  2330. pageBar.appendChild(td);
  2331. }
  2332.  
  2333. upSpan.addEventListener("click", e=>{
  2334. document.body.scrollTop=0;
  2335. document.documentElement.scrollTop=0;
  2336. e.preventDefault();
  2337. e.stopPropagation();
  2338. });
  2339. downSpan.addEventListener("click", e=>{
  2340. changeStop(true);
  2341. pageBar.title=i18n(isPause?"enable":"disable");
  2342. document.body.scrollTop=9999999;
  2343. document.documentElement.scrollTop=9999999;
  2344. e.preventDefault();
  2345. e.stopPropagation();
  2346. });
  2347. pageBar.addEventListener("click", e=>{
  2348. changeStop(!isPause);
  2349. pageBar.title=i18n(isPause?"enable":"disable");
  2350. });
  2351. pageText.addEventListener("click", e=>{
  2352. e.stopPropagation();
  2353. });
  2354. if(ruleParser.curSiteRule.insertPos==2){
  2355. insert.appendChild(pageBar);
  2356. }else{
  2357. insert.parentNode.insertBefore(pageBar, insert);
  2358. }
  2359. if(ruleParser.curSiteRule.pageBar){
  2360. try{
  2361. Function("pageBar",'"use strict";' + ruleParser.curSiteRule.pageBar)(pageBar);
  2362. }catch(e){
  2363. debug(e);
  2364. }
  2365. }
  2366.  
  2367. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  2368. let posEle=pageBar.nextElementSibling||pageBar;
  2369. while(posEle && !posEle.offsetParent){
  2370. posEle=posEle.previousElementSibling||posEle.parentNode;
  2371. }
  2372. if(posEle){
  2373. let actualTop = posEle.offsetTop;
  2374. let current = posEle.parentNode.offsetParent;
  2375. while (current !== null){
  2376. actualTop += current.offsetTop;
  2377. current = current.offsetParent;
  2378. }
  2379. bottomGap=scrollH-actualTop+(window.innerHeight||document.documentElement.clientHeight)*(ruleParser.curSiteRule.rate||1);
  2380. if(bottomGap<100)bottomGap=100;
  2381. }else{
  2382. bottomGap=1000;
  2383. }
  2384. return pageBar;
  2385. }
  2386.  
  2387. function emuClick(btn){
  2388. if(!PointerEvent)return btn.click();
  2389. let eventParam={
  2390. isTrusted: true,
  2391. altKey: false,
  2392. azimuthAngle: 0,
  2393. bubbles: true,
  2394. button: 0,
  2395. buttons: 0,
  2396. clientX: 1,
  2397. clientY: 1,
  2398. cancelBubble: false,
  2399. cancelable: true,
  2400. composed: true,
  2401. ctrlKey: false,
  2402. defaultPrevented: false,
  2403. detail: 1,
  2404. eventPhase: 2,
  2405. fromElement: null,
  2406. height: 1,
  2407. isPrimary: false,
  2408. metaKey: false,
  2409. pointerId: 1,
  2410. pointerType: "mouse",
  2411. pressure: 0,
  2412. relatedTarget: null,
  2413. returnValue: true,
  2414. shiftKey: false,
  2415. toElement: null,
  2416. twist: 0,
  2417. type: "click",
  2418. which: 1
  2419. };
  2420. var mouseclick = new PointerEvent("click",eventParam);
  2421. btn.dispatchEvent(mouseclick);
  2422. }
  2423.  
  2424. var emuIframe;
  2425. function emuPage(callback){
  2426. let orgPage=null,curPage,iframeDoc,times=0,loadmoreBtn,loadmoreEnd=false,waitTimes=10;
  2427. function checkPage(){
  2428. if(isPause)return;
  2429. try{
  2430. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  2431. }catch(e){
  2432. debug("Stop as cors");
  2433. isPause=true;
  2434. callback(false, false);
  2435. return;
  2436. }
  2437.  
  2438. let nextLink=ruleParser.getNextLink(iframeDoc);
  2439. let waitTime=500,checkEval;
  2440. if(ruleParser.curSiteRule.wait){
  2441. if(isNaN(ruleParser.curSiteRule.wait)){
  2442. try{
  2443. checkEval=Function("doc",'"use strict";' + ruleParser.curSiteRule.wait);
  2444. }catch(e){
  2445. debug(e);
  2446. }
  2447. }else{
  2448. waitTime=ruleParser.curSiteRule.wait;
  2449. }
  2450. }
  2451.  
  2452. if(!orgPage){
  2453. if(!loadmoreEnd){
  2454. loadmoreBtn=getLoadMore(iframeDoc);
  2455. if(loadmoreBtn && isVisible(loadmoreBtn, iframeDoc.defaultView)){
  2456. emuClick(loadmoreBtn);
  2457. let intv=setInterval(()=>{
  2458. loadmoreBtn=getLoadMore(iframeDoc);
  2459. if(!loadmoreBtn || !loadmoreBtn.parentNode || !isVisible(loadmoreBtn, iframeDoc.defaultView)){
  2460. clearInterval(intv);
  2461. loadmoreEnd=true;
  2462. setTimeout(()=>{
  2463. checkPage();
  2464. },500);
  2465. }else{
  2466. emuClick(loadmoreBtn);
  2467. }
  2468. },200);
  2469. return;
  2470. }else{
  2471. loadmoreEnd=true;
  2472. }
  2473. }
  2474. let pageEle=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true);
  2475. if(!nextLink || !pageEle || (checkEval && !checkEval(iframeDoc))){
  2476. if(ruleParser.curSiteRule.wait && waitTimes-->0){
  2477. setTimeout(()=>{
  2478. checkPage();
  2479. },waitTime);
  2480. return;
  2481. }
  2482. }
  2483. orgPage=pageEle;
  2484. if(!orgPage || orgPage.length==0){
  2485. debug("Stop as no page when emu");
  2486. isPause=true;
  2487. callback(false, false);
  2488. return;
  2489. }
  2490. if(orgPage && orgPage[0].tagName=="UL")orgPage=orgPage[0].children;
  2491. if(orgPage && nextLink){
  2492. orgPage=orgPage[parseInt(orgPage.length/2)];
  2493. if(!isVisible(nextLink, iframeDoc.defaultView)){
  2494. debug("Stop as next hide when emu");
  2495. isPause=true;
  2496. callback(false, false);
  2497. }else{
  2498. emuClick(nextLink);
  2499. setTimeout(()=>{
  2500. checkPage();
  2501. },500);
  2502. }
  2503. }else{
  2504. debug("Stop as no next when emu");
  2505. isPause=true;
  2506. callback(false, false);
  2507. }
  2508. return;
  2509. }
  2510. if(times++ > 20){
  2511. //emuClick(nextLink);
  2512. debug("Stop as timeout when emu");
  2513. isPause=true;
  2514. callback(false, false);
  2515. return;
  2516. }
  2517. let eles=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true),checkItem;
  2518. if(eles && eles.length>0){
  2519. checkItem=eles;
  2520. if(eles[0].tagName=="UL"){
  2521. checkItem=eles[0].children;
  2522. }
  2523. checkItem=checkItem[parseInt(checkItem.length/2)];
  2524. }
  2525. if(!checkItem || orgPage == checkItem || (checkEval && !checkEval(iframeDoc))){
  2526. setTimeout(()=>{
  2527. checkPage();
  2528. },waitTime);
  2529. }else{
  2530. callback(iframeDoc, eles);
  2531. }
  2532. }
  2533. if(!emuIframe){
  2534. let loaded=false;
  2535. emuIframe = document.createElement('iframe');
  2536. emuIframe.name = 'pagetual-iframe';
  2537. if(ruleParser.curSiteRule.sandbox!=false){
  2538. emuIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  2539. }
  2540. emuIframe.width = '100%';
  2541. emuIframe.height = '0';
  2542. emuIframe.frameBorder = '0';
  2543. emuIframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  2544. emuIframe.addEventListener("load", e=>{
  2545. setTimeout(()=>{
  2546. try{
  2547. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  2548. }catch(e){
  2549. debug("Stop as cors");
  2550. isPause=true;
  2551. callback(false, false);
  2552. return;
  2553. }
  2554. let code=ruleParser.curSiteRule.init;
  2555. if(code){
  2556. try{
  2557. Function('doc','win','"use strict";' + code)(iframeDoc, iframeDoc.defaultView);
  2558. }catch(e){
  2559. debug(e);
  2560. }
  2561. }
  2562. if(loaded)return;
  2563. loaded=true;
  2564. checkPage();
  2565. },500);
  2566. });
  2567. emuIframe.src=location.href;
  2568. document.body.appendChild(emuIframe);
  2569. }else{
  2570. checkPage();
  2571. }
  2572. }
  2573.  
  2574. function forceIframe(url, callback){
  2575. let curIframe = document.createElement('iframe'),iframeDoc;
  2576. curIframe.name = 'pagetual-iframe';
  2577. curIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  2578. curIframe.frameBorder = '0';
  2579. curIframe.scrolling="no";
  2580. 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;';
  2581. curIframe.addEventListener("load", e=>{
  2582. try{
  2583. iframeDoc=curIframe.contentDocument || curIframe.contentWindow.document;
  2584. }catch(e){
  2585. debug("Stop as cors");
  2586. isPause=true;
  2587. callback(false, false);
  2588. return;
  2589. }
  2590. ruleParser.insertPage(iframeDoc, [], url, null, true);
  2591. callback(curIframe, true);
  2592. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  2593. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  2594. });
  2595. let inAction=false;
  2596. let forceRefresh=e=>{
  2597. if(inAction || !iframeDoc)return;
  2598. inAction=true;
  2599. setTimeout(()=>{
  2600. inAction=false;
  2601. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  2602. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  2603. if(!ruleParser.nextLinkHref){
  2604. ruleParser.getNextLink(iframeDoc);
  2605. if(ruleParser.nextLinkHref){
  2606. document.removeEventListener("scroll", forceRefresh);
  2607. }
  2608. }else{
  2609. document.removeEventListener("scroll", forceRefresh);
  2610. }
  2611. },500);
  2612. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  2613. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  2614. };
  2615. document.addEventListener("scroll", forceRefresh);
  2616. curIframe.src=url;
  2617. let insert=ruleParser.getInsert();
  2618. document.body.appendChild(curIframe);
  2619. return curIframe;
  2620. }
  2621.  
  2622. function loadPageOver(){
  2623. isLoading=false;
  2624. if(loadingDiv.parentNode){
  2625. loadingDiv.parentNode.removeChild(loadingDiv);
  2626. }
  2627. setTimeout(()=>{
  2628. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  2629. if(scrollH < (window.innerHeight || document.documentElement.clientHeight)){
  2630. nextPage();
  2631. }
  2632. },1);
  2633. }
  2634.  
  2635. function nextPage(){
  2636. if(isPause || isLoading)return;
  2637. let nextLink=ruleParser.nextLinkHref;
  2638. if(!nextLink)return;
  2639. let pvGallery=document.querySelector("span.pv-gallery-container");
  2640. if(pvGallery && pvGallery.style.display!="none")return;
  2641. let insert=ruleParser.getInsert();
  2642. if(insert){
  2643. let isJs=/^(javascript|#)/.test(nextLink.replace(location.href,""));
  2644. if(location.protocol=="https:" && /^http:/.test(nextLink)){
  2645. nextLink=nextLink.replace(/^http/,"https");
  2646. }
  2647. isLoading=true;
  2648. document.body.appendChild(loadingDiv);
  2649. let sleep=ruleParser.curSiteRule.sleep||0;
  2650. setTimeout(()=>{
  2651. if(ruleParser.curSiteRule.pageElementByJs){
  2652. var over=ele=>{
  2653. loadPageOver();
  2654. if(ele){
  2655. createPageBar(nextLink);
  2656. ruleParser.insertPage(null, ele, nextLink, null, true);
  2657. if(autoLoadNum>=0){
  2658. if(autoLoadNum!=0 && --autoLoadNum==0){
  2659. autoLoadNum=-1;
  2660. }else{
  2661. nextPage();
  2662. }
  2663. }
  2664. }else{
  2665. debug("Stop as no page when get by js");
  2666. isPause=true;
  2667. }
  2668. };
  2669. try{
  2670. Function("over",'"use strict";' + ruleParser.curSiteRule.pageElementByJs)(over);
  2671. }catch(e){
  2672. debug(e);
  2673. }
  2674. }else if((forceState==3||ruleParser.curSiteRule.action==1) && !isJs){
  2675. requestFromIframe(nextLink, (doc, eles)=>{
  2676. loadPageOver();
  2677. if(eles){
  2678. createPageBar(nextLink);
  2679. ruleParser.insertPage(doc, eles, nextLink, null, true);
  2680. if(autoLoadNum>=0){
  2681. if(autoLoadNum!=0 && --autoLoadNum==0){
  2682. autoLoadNum=-1;
  2683. }else{
  2684. nextPage();
  2685. }
  2686. }
  2687. }
  2688. });
  2689. }else if((forceState==2||ruleParser.curSiteRule.action==2) && !isJs){
  2690. forceIframe(nextLink, (iframe, eles)=>{
  2691. loadPageOver();
  2692. let pageBar=createPageBar(nextLink);
  2693. if(pageBar)iframe.parentNode.insertBefore(pageBar, iframe);
  2694. if(autoLoadNum>=0){
  2695. if(autoLoadNum!=0 && --autoLoadNum==0){
  2696. autoLoadNum=-1;
  2697. }else{
  2698. nextPage();
  2699. }
  2700. }
  2701. });
  2702. }else{
  2703. if(!isJs){
  2704. requestDoc(nextLink, (eles)=>{
  2705. loadPageOver();
  2706. if(eles){
  2707. createPageBar(nextLink);
  2708. if(autoLoadNum>=0){
  2709. if(autoLoadNum!=0 && --autoLoadNum==0){
  2710. autoLoadNum=-1;
  2711. }else{
  2712. nextPage();
  2713. }
  2714. }
  2715. }
  2716. });
  2717. }else{
  2718. emuPage((doc, eles)=>{
  2719. loadPageOver();
  2720. if(eles){
  2721. createPageBar(nextLink);
  2722. ruleParser.insertPage(doc, eles, "", null, true);
  2723. if(autoLoadNum>=0){
  2724. if(autoLoadNum!=0 && --autoLoadNum==0){
  2725. autoLoadNum=-1;
  2726. }else{
  2727. nextPage();
  2728. }
  2729. }
  2730. }
  2731. });
  2732. }
  2733. }
  2734. },sleep);
  2735. }
  2736. }
  2737.  
  2738. function init(){
  2739. initRules(()=>{
  2740. initPage();
  2741. });
  2742. }
  2743. setTimeout(()=>{
  2744. init();
  2745. },300);
  2746. })();