2020-11-10 21:48:08 -05:00
|
|
|
browser.runtime.onMessage.addListener((request) => {
|
2020-12-09 16:43:08 -05:00
|
|
|
var response = 'no-alt-location';
|
2020-12-06 11:39:14 -05:00
|
|
|
console.log(request);
|
2020-12-03 12:20:43 -05:00
|
|
|
if (request.req === 'i2p-location') {
|
2020-12-09 16:43:08 -05:00
|
|
|
var tag = document.querySelector('meta[http-equiv="i2p-location"]');
|
|
|
|
console.log(tag);
|
|
|
|
if (tag) response = tag.content;
|
2020-09-24 20:06:33 -04:00
|
|
|
}
|
2020-12-03 12:20:43 -05:00
|
|
|
if (request.req === 'i2p-torrentlocation') {
|
|
|
|
const metas = document.getElementsByTagName('meta');
|
2020-12-06 11:39:14 -05:00
|
|
|
var tag = document.querySelector('meta[http-equiv="i2p-torrentlocation"]');
|
2020-12-06 11:39:50 -05:00
|
|
|
console.log(tag);
|
2020-12-09 16:43:08 -05:00
|
|
|
response = i2pTorrent(tag);
|
|
|
|
}
|
|
|
|
return Promise.resolve({ content: response });
|
|
|
|
});
|
|
|
|
|
|
|
|
function i2pTorrent(tag) {
|
|
|
|
let response = "no-alt-location";
|
|
|
|
if (tag) {
|
|
|
|
response = tag.content;
|
|
|
|
var imgs = document.getElementsByTagName("img");
|
|
|
|
console.log("rewriting torrent link");
|
|
|
|
for (let img of imgs) {
|
|
|
|
let tmpsrc = new URL(img.src);
|
|
|
|
if (tmpsrc.host == location.host) {
|
|
|
|
img.src =
|
|
|
|
"http://127.0.0.1:7657/i2psnark/" + tmpsrc.host + tmpsrc.pathname;
|
|
|
|
img.onerror = function () {
|
|
|
|
img.src = tmpsrc;
|
|
|
|
};
|
2020-12-06 11:39:14 -05:00
|
|
|
}
|
2020-12-09 16:43:08 -05:00
|
|
|
}
|
|
|
|
var videos = document.getElementsByTagName("video");
|
|
|
|
for (let video of videos) {
|
|
|
|
video.setAttribute("preload", "none");
|
|
|
|
let tmpsrc = new URL(video.currentSrc);
|
|
|
|
if (tmpsrc.host == location.host) {
|
|
|
|
if (!video.innerHTML.includes("127.0.0.1")) {
|
|
|
|
innerHTML = video.innerHTML;
|
|
|
|
topInnerHTML = video.innerHTML.replace(
|
|
|
|
'src="',
|
|
|
|
'src="http://127.0.0.1:7657/i2psnark/' + location.host + "/"
|
|
|
|
);
|
|
|
|
video.innerHTML = topInnerHTML; // + innerHTML;
|
|
|
|
video.onerror = function () {
|
|
|
|
video.innerHTML = topInnerHTML + innerHTML;
|
|
|
|
};
|
2020-12-06 11:39:14 -05:00
|
|
|
}
|
|
|
|
}
|
2020-12-09 16:43:08 -05:00
|
|
|
}
|
|
|
|
var audios = document.getElementsByTagName("audio");
|
|
|
|
for (let audio of audios) {
|
|
|
|
audio.setAttribute("preload", "none");
|
|
|
|
let tmpsrc = new URL(audio.currentSrc);
|
|
|
|
if (tmpsrc.host == location.host) {
|
|
|
|
if (!audio.innerHTML.includes("127.0.0.1")) {
|
|
|
|
innerHTML = audio.innerHTML;
|
|
|
|
topInnerHTML = audio.innerHTML.replace(
|
|
|
|
'src="',
|
|
|
|
'src="http://127.0.0.1:7657/i2psnark/' + location.host + "/"
|
|
|
|
);
|
|
|
|
audio.innerHTML = topInnerHTML; // + innerHTML;
|
|
|
|
audio.onerror = function () {
|
|
|
|
audio.innerHTML = topInnerHTML + innerHTML;
|
|
|
|
};
|
2020-12-06 11:39:14 -05:00
|
|
|
}
|
|
|
|
}
|
2020-12-09 16:43:08 -05:00
|
|
|
}
|
|
|
|
var links = document.getElementsByTagName("a");
|
|
|
|
for (let link of links) {
|
|
|
|
let tmpsrc = new URL(link.href);
|
|
|
|
if (tmpsrc.host == location.host) {
|
|
|
|
if (
|
|
|
|
!tmpsrc.pathname.endsWith("html") &&
|
|
|
|
!tmpsrc.pathname.endsWith("htm") &&
|
|
|
|
!tmpsrc.pathname.endsWith("php") &&
|
|
|
|
!tmpsrc.pathname.endsWith("jsp") &&
|
|
|
|
!tmpsrc.pathname.endsWith("asp") &&
|
|
|
|
!tmpsrc.pathname.endsWith("aspx") &&
|
|
|
|
!tmpsrc.pathname.endsWith("atom") &&
|
|
|
|
!tmpsrc.pathname.endsWith("rss") &&
|
|
|
|
!tmpsrc.pathname.endsWith("/") &&
|
|
|
|
tmpsrc.pathname.includes(".")
|
|
|
|
) {
|
|
|
|
link.href =
|
|
|
|
"http://127.0.0.1:7657/i2psnark/" + tmpsrc.host + tmpsrc.pathname;
|
|
|
|
link.onerror = function () {
|
|
|
|
window.location.href = tmpsrc.href;
|
|
|
|
};
|
2020-09-25 23:20:30 -04:00
|
|
|
}
|
2020-12-06 11:39:14 -05:00
|
|
|
}
|
2020-09-25 23:20:30 -04:00
|
|
|
}
|
|
|
|
}
|
2020-12-09 16:43:08 -05:00
|
|
|
return response;
|
|
|
|
}
|