If I had a website processing information or sending links as https://example.com
, how would I change all network requests as https://example.org
? This includes ANY information being taken by the website.
I attempted to find the attributes href
and src
using getAttribute
but still missed some requests. how would I find a way to do this?
My current code is this:
<!DOCTYPE html>
<html>
<head>
<title>NoGuardian</title>
<style>
body {
margin: 0;
}
iframe#page {
border: 0;
width: 100%;
height: 100vh;
position: fixed;
}
</style>
</head>
<body>
<iframe id="page"></iframe>
<script>
`use strict`;
if (window.location.search.charAt(window.location.search.length - 1) === `/`) {
window.location.search = window.location.search.slice(0, window.location.search.length - 1);
}
if (window.location.search.slice(1, 9) == `https://`) {
window.location.search = window.location.search.slice(9);
}
else if (window.location.search.slice(1, 8) == `http://`) {
window.location.search = window.location.search.slice(8);
}
fetch(`https://api.codetabs.com/v1/proxy?quest=${window.location.search.slice(1)}`).then((response) => response.text()).then((text) => {
const iframe = document.getElementById(`page`);
iframe.setAttribute(`srcdoc`, text);
iframe.addEventListener(`load`, function() {
for (let elements = 0; elements < iframe.contentWindow.document.getElementsByTagName(`*`).length; elements++) {
if (iframe.contentWindow.document.getElementsByTagName(`*`)[elements].getAttribute(`src`) != null) {
if (iframe.contentWindow.document.getElementsByTagName(`*`)[elements].getAttribute(`src`).slice(0, 1) == `/`) {
iframe.contentWindow.document.getElementsByTagName(`*`)[elements].setAttribute(`src`, `${window.location.search.slice(1)}${iframe.contentWindow.document.getElementsByTagName(`*`)[elements].getAttribute(`src`)}`);
}
else if (iframe.contentWindow.document.getElementsByTagName(`*`)[elements].getAttribute(`src`).slice(0, 2) == `./`) {
iframe.contentWindow.document.getElementsByTagName(`*`)[elements].setAttribute(`src`, `${window.location.search.slice(1)}${iframe.contentWindow.document.getElementsByTagName(`*`)[elements].getAttribute(`src`).slice(1, iframe.contentWindow.document.getElementsByTagName(`*`)[elements].getAttribute(`src`).length - 1)}`);
}
// console.log(`href: ${iframe.contentWindow.document.getElementsByTagName(`*`)[elements].getAttribute(`src`)}`)
}
if (iframe.contentWindow.document.getElementsByTagName(`*`)[elements].getAttribute(`href`) != null) {
// console.log(`src: ${iframe.contentWindow.document.getElementsByTagName(`*`)[elements].getAttribute(`href`)}`)
}
}
});
});
</script>
</body>
</html>
I am also detecting href
with the code but removed the section to minimize it.