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

Function parsePage

Picviewer CE+/dist.user.js:25501–25555  ·  view source on GitHub ↗

* @param q 图片的选择器或函数 * @param c 图片说明的选择器或函数

(url, q, c, post, cb, headers, after)

Source from the content-addressed store, hash-verified

25499 * @param c 图片说明的选择器或函数
25500 */
25501 function parsePage(url, q, c, post, cb, headers, after) {
25502 downloadPage(url, post, headers, async function(html) {
25503 var iurl, iurls = [], cap, caps, doc = createDoc(html);
25504
25505 if(typeof q == 'function') {
25506 iurl = await q(html, doc, url + (post ? `#p{${post}}` : ""), xhr, GM_fetch);
25507 if (iurl) {
25508 if(iurl.url) {
25509 cap = iurl.cap;
25510 iurl = iurl.url;
25511 }
25512 if (Array.isArray(iurl)) {
25513 iurl = iurl.map(u => after(u));
25514 iurls = iurl;
25515 iurl = iurls[0];
25516 } else iurl = after(iurl);
25517 }
25518 } else {
25519 var inodes = findNodes(q, doc);
25520 inodes.forEach(function(node) {
25521 iurls.push(after(findFile(node, url)));
25522 });
25523 iurl = iurls[0];
25524 }
25525
25526 if (c) {
25527 if(typeof c == 'function') {
25528 cap = await c(html, doc, url, xhr);
25529 } else {
25530 var cnodes = findNodes(c, doc);
25531 cap = cnodes.length ? findCaption(cnodes[0]) : false;
25532 }
25533 if (Array.isArray(cap)) {
25534 caps = cap;
25535 cap = caps[0];
25536 }
25537 }
25538
25539 // 缓存
25540 if (iurl) {
25541 let cacheData = {
25542 iurl: iurl,
25543 iurls: iurls,
25544 cap: cap,
25545 caps: caps
25546 };
25547 caches[url + (post || "")] = cacheData;
25548 if (cacheNum) {
25549 storage.setListItem("xhrCache", url + (post || ""), cacheData, cacheNum);
25550 }
25551 }
25552
25553 cb(iurl, iurls, cap, caps);
25554 });
25555 }
25556
25557 async function downloadPage(url, post, headers, cb) {
25558 var opts = {

Callers 1

initFunction · 0.70

Calls 6

cFunction · 0.85
downloadPageFunction · 0.70
createDocFunction · 0.70
findNodesFunction · 0.70
findFileFunction · 0.70
findCaptionFunction · 0.70

Tested by

no test coverage detected