Add absolute URL conversion to bookmarklet

Also add explanatory comments
This commit is contained in:
Jacob Strieb 2020-07-21 16:57:11 -04:00
parent f725e3e48d
commit f3653f8bc7
2 changed files with 17 additions and 4 deletions

3
.gitignore vendored
View File

@ -4,3 +4,6 @@
# Backed up copies of old files
*.bak
# Old HTML example files
*-old.html

View File

@ -1,4 +1,5 @@
(() => {
javascript:(() => {
/* Generate the b64 API functions */
var b64 = (() => {
function generateIndexDict(a) {
let result = {};
@ -47,7 +48,7 @@
}
})();
/* Generate the page -> base64 API functions */
var api = {
VERSION: "0.2.0",
@ -63,7 +64,16 @@
},
};
/* Replace all relative URLs with absolute ones */
Array.from(document.querySelectorAll("[src],[href]")).map(l => {
if ("src" in l) {
l.src = (new URL(l.src, document.baseURI)).href;
} else if ("href" in l) {
l.href = (new URL(l.href, document.baseURI)).href;
}
return l;
});
javascript:window.open(api.getViewLink(document.documentElement.outerHTML), "_blank");
/* Redirect to the URL Page in a new tab */
window.open(api.getViewLink(document.documentElement.outerHTML), "_blank");
})();