东方永页机

自动翻页脚本 - 自动加载并拼接下一分页内容,无需规则驱动支持任意网页

当前为 2022-05-09 提交的版本,查看 最新版本

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址