MCPcopy Index your code
hub / github.com/hoothin/UserScripts / getNextLink

Method getNextLink

Pagetual/pagetual.user.js:6726–6981  ·  view source on GitHub ↗
(doc, exist)

Source from the content-addressed store, hash-verified

6724 }
6725
6726 async getNextLink(doc, exist) {
6727 let nextLink = null, page, href;
6728 let getNextLinkByForm = (form, submitBtn, n) => {
6729 let params = [];
6730 let formData = new FormData(form);
6731 if (submitBtn && submitBtn.getAttribute) {
6732 let btnValue, btnName;
6733 btnName = submitBtn.getAttribute("name");
6734 btnValue = submitBtn.getAttribute("value");
6735 if (btnName && btnValue) params = [btnName + "=" + encodeURIComponent(btnValue)];
6736 }
6737 for (let [key, value] of formData) {
6738 if (n && /^(p|page)$/i.test(key)) {
6739 params.push(key + '=' + n);
6740 } else {
6741 params.push(key + '=' + encodeURIComponent(value));
6742 }
6743 }
6744 params = params.join('&');
6745 return form.action + (form.action.indexOf('?') === -1 ? '?' : '&') + params + (form.method === 'post' ? '#p{' + params + '}' : '');
6746 };
6747 if (this.curSiteRule.pageElementByJs) {
6748 this.nextLinkHref = "#";
6749 return true;
6750 } else if (this.curSiteRule.nextLinkByJs) {
6751 try {
6752 let over = _url => {};
6753 let targetUrl = await ((typeof this.curSiteRule.nextLinkByJs === 'function') ? this.curSiteRule.nextLinkByJs : new AsyncFunction("doc", '"use strict";' + this.curSiteRule.nextLinkByJs))(doc);
6754 if (targetUrl) nextLink = {href: targetUrl};
6755 } catch(e) {
6756 debug(e);
6757 }
6758 } else if (this.curSiteRule.nextLinkByUrl) {
6759 let urlReg = new RegExp(this.curSiteRule.nextLinkByUrl[0], "i");
6760 let targetUrl;
6761 if (urlReg.test(this.curUrl)) {
6762 targetUrl = this.curUrl.replace(urlReg, this.curSiteRule.nextLinkByUrl[1])
6763 } else {
6764 if (this.curSiteRule.nextLinkByUrl[0].indexOf("&") != -1) {
6765 urlReg = new RegExp(this.curSiteRule.nextLinkByUrl[0].replace("&", "\\?"), "i");
6766 }
6767 if (urlReg.test(this.curUrl)) {
6768 targetUrl = this.curUrl.replace(urlReg, this.curSiteRule.nextLinkByUrl[1]);
6769 } else {
6770 targetUrl = this.curUrl + this.curSiteRule.nextLinkByUrl[1].replace(/\$\d+/g, "");
6771 }
6772 }
6773 if (targetUrl !== this.curUrl) {
6774 let includeSel = this.curSiteRule.nextLinkByUrl[2];
6775 let excludeSel = this.curSiteRule.nextLinkByUrl[3];
6776 if (includeSel) {
6777 includeSel = includeSel.trim();
6778 if (!getElement(includeSel, doc)) {
6779 this.nextLinkHref=false;
6780 return null;
6781 }
6782 }
6783 if (excludeSel) {

Callers 8

insertPageMethod · 0.95
initPageMethod · 0.80
initMethod · 0.80
initMethod · 0.80
clickNextFunction · 0.80
checkPageFunction · 0.80
forceRefreshFunction · 0.80
nextPageFunction · 0.80

Calls 15

getPageMethod · 0.95
linkHasHrefMethod · 0.95
clearAddedElementsMethod · 0.95
checkStopSignMethod · 0.95
reachedLastPageMethod · 0.95
canonicalUriMethod · 0.95
compareUrlMethod · 0.95
preloadMethod · 0.95
debugFunction · 0.85
getElementFunction · 0.85
compareNodeNameFunction · 0.85
isVisibleFunction · 0.85

Tested by

no test coverage detected