Skip to content

Commit

Permalink
Merge branch 'torrent-3' into 'master'
Browse files Browse the repository at this point in the history
Retain much tighter control of x-i2p-torrentlocation priorities

See merge request idk/I2P-in-Private-Browsing-Mode-Firefox!15
  • Loading branch information
eyedeekay committed Dec 6, 2020
2 parents 58b874d + 84981fa commit 647c052
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 168 deletions.
2 changes: 1 addition & 1 deletion debian/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ i2psetproxy.js (0.87-1) UNRELEASED; urgency=low

* Disable searching for i2p sites in non-i2p search engines
* Add contexts for i2pbote and Dispatch
*
* Remain in tighter control of x-i2p-torrentlocation priority

-- idk <[email protected]> Sat, 10 NOV 2020 1:33:50 -0400

Expand Down
1 change: 1 addition & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"proxy",
"privacy",
"storage",
"webNavigation",
"webRequest",
"webRequestBlocking",
"contextualIdentities",
Expand Down
240 changes: 73 additions & 167 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
browser.runtime.onMessage.addListener((request) => {
var response = '';
console.log(request);
if (request.req === 'i2p-location') {
response = 'no-alt-location';
const metas = document.getElementsByTagName('meta');
Expand All @@ -15,181 +16,86 @@ browser.runtime.onMessage.addListener((request) => {
} catch {};
}
}

if (request.req === 'i2p-torrentlocation') {
response = 'no-alt-location';
const metas = document.getElementsByTagName('meta');
for (let i = 0; i < metas.length; i++) {
try {
tag = metas[i].getAttribute('http-equiv');
if (tag.toUpperCase() === 'I2P-TORRENTLOCATION') {
response = metas[i].getAttribute('content');
var imgs = document.getElementsByTagName('img');
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;
};
}
}
var links = document.getElementsByTagName('a');
console.log('Listing link', links);
for (let link of links) {
console.log('(Changing Link)', link);
let tmpsrc = new URL(link.href);
// console.log("link", tmpsrc.host, tmpsrc.pathname)
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('.')
) {
console.log('link', tmpsrc.host, tmpsrc.pathname);
link.href =
'http://127.0.0.1:7657/i2psnark/' +
tmpsrc.host +
tmpsrc.pathname;
link.onerror = function() {
window.location.href = tmpsrc.href;
};
}
//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.includes('.') && !tmpsrc..pathname.endsWith('/')) {
//console.log('http://127.0.0.1:7657/i2psnark/' + tmpsrc.host + tmpsrc.pathname;)
//link.href = 'http://127.0.0.1:7657/i2psnark/' + tmpsrc.host + tmpsrc.pathname;
//link.onerror = function() {
//link.src = tmpsrc;
//};
//}
}
}
var videos = document.getElementsByTagName('video');
for (let video of videos) {
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;
}
}
}
var audios = document.getElementsByTagName('audio');
for (let audio of audios) {
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;
}
}
}
var tag = document.querySelector('meta[http-equiv="i2p-torrentlocation"]');
console.log(tag);
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;
};
}
if (tag.toUpperCase() === 'X-I2P-TORRENTLOCATION') {
response = metas[i].getAttribute('content');
var imgs = document.getElementsByTagName('img');
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;
};
}
}
var links = document.getElementsByTagName('a');
console.log('Listing link', links);
for (let link of links) {
console.log('(Changing Link)', link);
let tmpsrc = new URL(link.href);
//console.log("link", tmpsrc.host, tmpsrc.pathname)
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('.')
) {
console.log('link', tmpsrc.host, tmpsrc.pathname);
link.href =
'http://127.0.0.1:7657/i2psnark/' +
tmpsrc.host +
tmpsrc.pathname;
link.onerror = function() {
window.location.href = tmpsrc.href;
};
}
//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.includes('.') && !tmpsrc..pathname.endsWith('/')) {
//console.log('http://127.0.0.1:7657/i2psnark/' + tmpsrc.host + tmpsrc.pathname;)
//link.href = 'http://127.0.0.1:7657/i2psnark/' + tmpsrc.host + tmpsrc.pathname;
//link.onerror = function() {
//link.src = tmpsrc;
//};
//}
}
}
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;
};
}
var videos = document.getElementsByTagName('video');
for (let video of videos) {
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;
}
}
}
}
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;
};
}
var audios = document.getElementsByTagName('audio');
for (let audio of audios) {
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;
}
}
}
}
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;
};
}
}
} catch {};
}
}
}
return Promise.resolve({ content: response });
Expand Down

0 comments on commit 647c052

Please sign in to comment.