41 Zeilen
1.1 KiB
TypeScript
41 Zeilen
1.1 KiB
TypeScript
|
function replacehttp(url: string) {
|
||
|
const u = new URL(url);
|
||
|
console.debug(u.protocol, "http:" == u.protocol);
|
||
|
if (u.protocol == "http:") {
|
||
|
const old = u.href;
|
||
|
u.protocol = "https:";
|
||
|
console.debug("fixed url", old, u.href);
|
||
|
}
|
||
|
return u.toString();
|
||
|
}
|
||
|
|
||
|
console.debug("http replacer loaded");
|
||
|
const elements = document.getElementsByTagName("a");
|
||
|
console.info("found", elements.length, "links");
|
||
|
for (let i = 0; i < elements.length; i++) {
|
||
|
const el = elements[i];
|
||
|
console.debug("checking", el);
|
||
|
if (el.href == undefined || el.href == "") {
|
||
|
continue;
|
||
|
}
|
||
|
el.href = replacehttp(el.href);
|
||
|
console.debug("edited", el);
|
||
|
}
|
||
|
const ielements = document.getElementsByTagName("img");
|
||
|
console.info("found", ielements.length, "images");
|
||
|
for (let i = 0; i < ielements.length; i++) {
|
||
|
const el = ielements[i];
|
||
|
console.debug("checking", el);
|
||
|
if (el.src == undefined || el.src == "") {
|
||
|
console.debug(
|
||
|
"href == undefined",
|
||
|
el.src == undefined,
|
||
|
"src == ''",
|
||
|
el.src == "",
|
||
|
);
|
||
|
continue;
|
||
|
}
|
||
|
el.src = replacehttp(el.src);
|
||
|
console.debug("edited", el);
|
||
|
}
|