东方永页机

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

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

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

QingJ © 2025

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