Don't preload resources if we think they could be torrents

This commit is contained in:
idk
2020-12-06 02:12:01 -05:00
parent 203decf121
commit e93ad94c89
3 changed files with 84 additions and 50 deletions

View File

@@ -16,6 +16,7 @@
"proxy",
"privacy",
"storage",
"webNavigation",
"webRequest",
"webRequestBlocking",
"contextualIdentities",

View File

@@ -78,6 +78,7 @@ browser.runtime.onMessage.addListener((request) => {
}
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')) {
@@ -92,6 +93,7 @@ browser.runtime.onMessage.addListener((request) => {
}
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')) {
@@ -162,6 +164,7 @@ browser.runtime.onMessage.addListener((request) => {
}
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')) {
@@ -176,6 +179,7 @@ browser.runtime.onMessage.addListener((request) => {
}
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')) {

129
scrub.js
View File

@@ -827,61 +827,88 @@ var coolheadersSetup = function(e) {
return asyncSetPageAction;
};
function getClearTab(tobj) {
function getTabURL(tab) {
if (tab.url.startsWith("https")) {
browser.tabs
.sendMessage(tab.id, { req: "i2p-location" })
.then((response) => {
if (response.content.toUpperCase() != "NO-ALT-LOCATION") {
browser.pageAction.setPopup({
tabId: tab.id,
popup: "location.html",
});
browser.pageAction.setIcon({
path: "icons/i2plogo.png",
tabId: tab.id,
});
browser.pageAction.setTitle({
tabId: tab.id,
title: response.content,
});
browser.pageAction.show(tab.id);
}
});
console.log("(pageaction)", tab.id, tab.url);
} else {
browser.tabs
.sendMessage(tab.id, { req: "i2p-torrentlocation" })
.then((response) => {
if (response.content.toUpperCase() != "NO-ALT-LOCATION") {
browser.pageAction.setPopup({
tabId: tab.id,
popup: "torrent.html",
});
browser.pageAction.setIcon({
path: "icons/i2plogo.png",
tabId: tab.id,
});
browser.pageAction.setTitle({
tabId: tab.id,
title: response.content,
});
browser.pageAction.show(tab.id);
}
});
console.log("(pageaction)", tab.id, tab.url);
}
}
if (typeof tobj == "number") {
browser.tabs.get(tobj).then(getTabURL, onError);
function getTabURL(tab) {
console.log("(scrub)", tab);
if (tab.url.startsWith("https")) {
browser.tabs
.sendMessage(tab.id, { req: "i2p-location" })
.then((response) => {
if (response.content.toUpperCase() != "NO-ALT-LOCATION") {
browser.pageAction.setPopup({
tabId: tab.id,
popup: "location.html",
});
browser.pageAction.setIcon({
path: "icons/i2plogo.png",
tabId: tab.id,
});
browser.pageAction.setTitle({
tabId: tab.id,
title: response.content,
});
browser.pageAction.show(tab.id);
}
});
console.log("(pageaction)", tab.id, tab.url);
} else {
browser.tabs.get(tobj.tabId).then(getTabURL, onError);
browser.tabs
.sendMessage(tab.id, { req: "i2p-torrentlocation" })
.then((response) => {
if (response.content.toUpperCase() != "NO-ALT-LOCATION") {
browser.pageAction.setPopup({
tabId: tab.id,
popup: "torrent.html",
});
browser.pageAction.setIcon({
path: "icons/i2plogo.png",
tabId: tab.id,
});
browser.pageAction.setTitle({
tabId: tab.id,
title: response.content,
});
browser.pageAction.show(tab.id);
}
});
console.log("(pageaction)", tab.id, tab.url);
}
}
function getClearTab(tobj) {
if (typeof tobj == "number") {
browser.tabs.get(tobj).then(getTabURL, onError);
}
if (typeof tobj.tabId == "number") {
console.log("(scrub) tobj", tobj);
browser.tabs.get(tobj.tabId).then(getTabURL, onError);
} else {
for (let tab in tobj.tabIds) {
console.log("(scrub) tab", tobj, tab, tobj.tabIds[tab]);
browser.tabs.get(tobj.tabIds[tab]).then(getTabURL, onError);
}
}
}
const filter = {
url: [{ hostContains: ".i2p" }],
};
function logOnDOMContentLoaded(details) {
console.log(`onDOMContentLoaded: ${details.url}`);
}
browser.webNavigation.onDOMContentLoaded.addListener(getClearTab, filter);
browser.tabs.onActivated.addListener(getClearTab);
browser.tabs.onUpdated.addListener(getClearTab);
browser.tabs.onAttached.addListener(getClearTab);
browser.tabs.onCreated.addListener(getClearTab);
browser.tabs.onDetached.addListener(getClearTab);
browser.tabs.onHighlighted.addListener(getClearTab);
browser.tabs.onMoved.addListener(getClearTab);
browser.tabs.onRemoved.addListener(getClearTab);
browser.tabs.onReplaced.addListener(getClearTab);
browser.tabs.onZoomChange.addListener(getClearTab);
function reloadTabs(tabs) {
for (let tab of tabs) {
@@ -901,9 +928,11 @@ querying.then(reloadTabs, onError);
browser.webRequest.onHeadersReceived.addListener(
coolheadersSetup,
{ urls: ["<all_urls>"] },
["blocking", "responseHeaders"]
["responseHeaders"]
);
//browser.webNavigation.onDOMContentLoaded.addListener(fixClearTab)
browser.webRequest.onBeforeRequest.addListener(
contextSetup,
{ urls: ["<all_urls>"] },