MCPcopy
hub / github.com/hoothin/UserScripts / preload

Method preload

Pagetual/pagetual.user.js:7162–7239  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7160 }
7161
7162 preload() {
7163 if (!rulesData.preload) return;
7164 if (this.curSiteRule.preload === 0) return;
7165 if (!this.nextLinkHref || this.nextLinkHref == "#") return;
7166 if (this.readyStateUnComplete) return;
7167 if (document.readyState !== 'complete') {
7168 this.readyStateUnComplete = true;
7169 let self = this;
7170 window.addEventListener("load", e => {
7171 self.readyStateUnComplete = false;
7172 self.preload();
7173 });
7174 return;
7175 }
7176 let self = this, url = this.nextLinkHref;
7177 let postParams = url.match(/#p{(.*)}$/);
7178 if (postParams) {
7179 postParams = postParams[1];
7180 url = url.replace(/#p{.*/, "");
7181 }
7182 fetch(url, {
7183 method: postParams ? 'POST' : 'GET',
7184 body: postParams,
7185 headers: {
7186 'Referer': location.href,
7187 'User-Agent': navigator.userAgent,
7188 "Content-Type": (postParams ? "application/x-www-form-urlencoded" : "text/html") + ";charset=" + charset
7189 }
7190 }).then(response => response.text()).then(data => {
7191 var doc = null;
7192 try {
7193 doc = document.implementation.createHTMLDocument('');
7194 setHTML(doc.documentElement, data, doc);
7195 var body = getBody(doc);
7196 if (!self.preloadDiv) {
7197 self.preloadDiv = document.createElement('div');
7198 self.preloadDiv.id = "pagetual-preload";
7199 self.preloadDiv.style.cssText = 'display:none!important;';
7200 getBody(document).appendChild(self.preloadDiv);
7201 self.checkedImgs = {};
7202 self.unCheckedImgs = [];
7203 }
7204 let code = self.curSiteRule.preloadImages;
7205 if (code) {
7206 let imgSrcArr = new Function("doc", '"use strict";' + code)(doc);
7207 if (imgSrcArr && imgSrcArr.length) {
7208 imgSrcArr.forEach(imgSrc => {
7209 if (imgSrc && !self.checkedImgs[imgSrc]) {
7210 self.checkedImgs[imgSrc] = true;
7211 self.unCheckedImgs.push(imgSrc);
7212 }
7213 });
7214 }
7215 self.preloadImageHandler();
7216 } else if (code !== 0 && code !== false) {
7217 if (body && body.firstChild) {
7218 self.lazyImgAction(body.children, doc);
7219 }

Callers 5

getNextLinkMethod · 0.95
initFunction · 0.80
beginLoadImgFunction · 0.80
initFunction · 0.80
beginLoadImgFunction · 0.80

Calls 6

fetchFunction · 0.85
debugFunction · 0.85
preloadImageHandlerMethod · 0.80
lazyImgActionMethod · 0.80
setHTMLFunction · 0.70
getBodyFunction · 0.70

Tested by

no test coverage detected