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

Method insertPage

Pagetual/pagetual.user.js:7768–7907  ·  view source on GitHub ↗
(doc, eles, url, callback, tried)

Source from the content-addressed store, hash-verified

7766 }
7767
7768 async insertPage(doc, eles, url, callback, tried) {
7769 this.oldUrl = this.curUrl;
7770 let oldTitle = document.title;
7771 try {
7772 let oldTitle = this.pageDoc.title;
7773 } catch (e) {}
7774 this.pageDoc = doc;
7775 this.curUrl = url;
7776 isLoading = true;
7777 let nextLink = await this.getNextLink(doc);
7778 this.nextTitle = "";
7779 if (this.curSiteRule.pageBarText) {
7780 if (this.curSiteRule.pageBarText == 1 || this.curSiteRule.pageBarText == true) {
7781 this.nextTitle = doc.title;
7782 } else {
7783 try {
7784 this.nextTitle = ((typeof this.curSiteRule.pageBarText == 'function') ? this.curSiteRule.pageBarText : Function("doc",'"use strict";' + this.curSiteRule.pageBarText))(doc);
7785 } catch(e) {
7786 debug(e);
7787 }
7788 }
7789 }
7790 if (curPage == 1 && !tried && !nextLink && this.curSiteRule.smart && this.curSiteRule.pageElement && this.curSiteRule.action != 0) {
7791 this.curSiteRule.action = 1;
7792 this.curUrl = location.href;
7793 isLoading = false;
7794 return false;
7795 }
7796
7797 if (targetY >= 0) {
7798 window.scrollTo({ top: targetY, behavior: 'instant'});
7799 targetY = -1;
7800 }
7801 this.getInsert();
7802 await this.pageInit(doc, eles);
7803 var self = this, newEles = [];
7804 if (!eles || eles.length == 0 || !self.insert || !self.insert.parentNode) {
7805 if (callback) callback(eles);
7806 loadPageOver();
7807 } else {
7808 if (callback) callback(eles);
7809 loadPageOver();
7810 const collection = document.createDocumentFragment();
7811 [].forEach.call(eles, ele => {
7812 let newEle = ele.cloneNode(true);
7813 let oldCanvass = ele.querySelectorAll("canvas");
7814 let newCanvass = newEle.querySelectorAll("canvas");
7815 if (self.updateUrl) {
7816 [].forEach.call(newEle.querySelectorAll("img"), img => {
7817 if (img.getAttribute("src")) img.src = self.canonicalUri(img.getAttribute("src"));
7818 });
7819 [].forEach.call(newEle.querySelectorAll("a"), a => {
7820 if (a.getAttribute("href")) a.href = self.canonicalUri(a.getAttribute("href"));
7821 });
7822 }
7823 for (let i = 0; i < oldCanvass.length; i++) {
7824 let oldCanvas = oldCanvass[i];
7825 let newCanvas = newCanvass[i];

Callers 4

requestDocFunction · 0.80
loadedHandlerFunction · 0.80
overFunction · 0.80
nextPageFunction · 0.80

Calls 11

getNextLinkMethod · 0.95
getInsertMethod · 0.95
pageInitMethod · 0.95
pageActionMethod · 0.95
hrefIsJsMethod · 0.95
debugFunction · 0.85
loadPageOverFunction · 0.85
compareNodeNameFunction · 0.85
canonicalUriMethod · 0.80
insertElementMethod · 0.80
addElementsInBatchesMethod · 0.80

Tested by

no test coverage detected