MCPcopy Create free account
hub / github.com/hoothin/UserScripts / canonicalUri

Function canonicalUri

DownloadAllContent/DownloadAllContent.user.js:1484–1507  ·  view source on GitHub ↗
(src, baseUrl)

Source from the content-addressed store, hash-verified

1482 }
1483
1484 function canonicalUri(src, baseUrl) {
1485 if (!src) {
1486 return "";
1487 }
1488 if (src.charAt(0) == "#") return baseUrl + src;
1489 if (src.charAt(0) == "?") return baseUrl.replace(/^([^\?#]+).*/, "$1" + src);
1490 let origin = location.protocol + '//' + location.host;
1491 let url = baseUrl || origin;
1492 url = url.replace(/(\?|#).*/, "");
1493 if (/https?:\/\/[^\/]+$/.test(url)) url = url + '/';
1494 if (url.indexOf("http") !== 0) url = origin + url;
1495 var root_page = /^[^\?#]*\//.exec(url)[0],
1496 root_domain = /^\w+\:\/\/\/?[^\/]+/.exec(root_page)[0],
1497 absolute_regex = /^\w+\:\/\//;
1498 while (src.indexOf("../") === 0) {
1499 src = src.substr(3);
1500 root_page = root_page.replace(/\/[^\/]+\/$/, "/");
1501 }
1502 src = src.replace(/\.\//, "");
1503 if (/^\/\/\/?/.test(src)) {
1504 src = location.protocol + src;
1505 }
1506 return (absolute_regex.test(src) ? src : ((src.charAt(0) == "/" ? root_domain : root_page) + src));
1507 }
1508
1509 async function checkNextPage(doc, baseUrl) {
1510 let nextPage = null;

Callers 3

checkNextPageFunction · 0.70
getRightStrFunction · 0.70
customDownFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected