Fixed bugs present in the previous commit
This commit is contained in:
parent
be78f86a67
commit
9560cfc3e7
|
@ -211,7 +211,7 @@
|
||||||
"lbryDesktop": {
|
"lbryDesktop": {
|
||||||
"message": "LBRY Desktop"
|
"message": "LBRY Desktop"
|
||||||
},
|
},
|
||||||
"bypassTab": {
|
"toggleTab": {
|
||||||
"message": "Toggle redirects in this tab",
|
"message": "Toggle redirects in this tab",
|
||||||
"description": "Used in context menus when right clicking on a page/tab"
|
"description": "Used in context menus when right clicking on a page/tab"
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,12 +60,12 @@ function regexArray(service, url, config) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
function redirect(url, type, initiator) {
|
function redirect(url, type, initiator, forceRedirection) {
|
||||||
if (type != "main_frame" && type != "sub_frame") return
|
if (type != "main_frame" && type != "sub_frame") return
|
||||||
let randomInstance
|
let randomInstance
|
||||||
let frontend
|
let frontend
|
||||||
for (const service in config.services) {
|
for (const service in config.services) {
|
||||||
if (!options[service].enabled) continue
|
if (!forceRedirection && !options[service].enabled) continue
|
||||||
if (config.services[service].embeddable && type != options[service].redirectType && options[service].redirectType != "both") continue
|
if (config.services[service].embeddable && type != options[service].redirectType && options[service].redirectType != "both") continue
|
||||||
if (!config.services[service].embeddable && type != "main_frame") continue
|
if (!config.services[service].embeddable && type != "main_frame") continue
|
||||||
// let targets = new RegExp(config.services[service].targets.join("|"), "i")
|
// let targets = new RegExp(config.services[service].targets.join("|"), "i")
|
||||||
|
@ -407,6 +407,7 @@ function redirect(url, type, initiator) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function computeService(url, returnFrontend) {
|
function computeService(url, returnFrontend) {
|
||||||
|
console.log(url)
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
fetch("/config/config.json")
|
fetch("/config/config.json")
|
||||||
.then(response => response.text())
|
.then(response => response.text())
|
||||||
|
|
|
@ -188,7 +188,9 @@
|
||||||
},
|
},
|
||||||
"targets": ["^https?:\\/{2}(www\\.)?instagram\\.com\\/p\\/"],
|
"targets": ["^https?:\\/{2}(www\\.)?instagram\\.com\\/p\\/"],
|
||||||
"name": "Instagram",
|
"name": "Instagram",
|
||||||
"options": { "enabled": true },
|
"options": {
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
"imageType": "png",
|
"imageType": "png",
|
||||||
"embeddable": false,
|
"embeddable": false,
|
||||||
"url": "https://instagram.com"
|
"url": "https://instagram.com"
|
||||||
|
@ -205,7 +207,9 @@
|
||||||
},
|
},
|
||||||
"targets": ["^https?:\\/{2}(www\\.|)tiktok\\.com.*"],
|
"targets": ["^https?:\\/{2}(www\\.|)tiktok\\.com.*"],
|
||||||
"name": "TikTok",
|
"name": "TikTok",
|
||||||
"options": { "enabled": true },
|
"options": {
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
"imageType": "png",
|
"imageType": "png",
|
||||||
"embeddable": false,
|
"embeddable": false,
|
||||||
"url": "https://tiktok.com"
|
"url": "https://tiktok.com"
|
||||||
|
@ -223,6 +227,7 @@
|
||||||
"preferences": {
|
"preferences": {
|
||||||
"cookies": [
|
"cookies": [
|
||||||
"collapse_child_comments",
|
"collapse_child_comments",
|
||||||
|
"default_comment_sort",
|
||||||
"domain_instagram",
|
"domain_instagram",
|
||||||
"domain_twitter",
|
"domain_twitter",
|
||||||
"domain_youtube",
|
"domain_youtube",
|
||||||
|
@ -230,8 +235,11 @@
|
||||||
"highlight_controversial",
|
"highlight_controversial",
|
||||||
"nsfw_enabled",
|
"nsfw_enabled",
|
||||||
"post_media_max_height",
|
"post_media_max_height",
|
||||||
|
"prefer_frontpage",
|
||||||
|
"show_large_gallery_images",
|
||||||
"show_upvoted_percentage",
|
"show_upvoted_percentage",
|
||||||
"show_upvotes",
|
"show_upvotes",
|
||||||
|
"subbed_subreddits",
|
||||||
"theme",
|
"theme",
|
||||||
"videos_muted"
|
"videos_muted"
|
||||||
]
|
]
|
||||||
|
@ -280,7 +288,9 @@
|
||||||
},
|
},
|
||||||
"targets": ["^https?:\\/{2}(?:[a-z]+\\.)*wikipedia\\.org"],
|
"targets": ["^https?:\\/{2}(?:[a-z]+\\.)*wikipedia\\.org"],
|
||||||
"name": "Wikipedia",
|
"name": "Wikipedia",
|
||||||
"options": { "enabled": false },
|
"options": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
"imageType": "svg",
|
"imageType": "svg",
|
||||||
"embeddable": false,
|
"embeddable": false,
|
||||||
"url": "https://wikipedia.org"
|
"url": "https://wikipedia.org"
|
||||||
|
@ -313,7 +323,9 @@
|
||||||
"^writingcooperative\\.com"
|
"^writingcooperative\\.com"
|
||||||
],
|
],
|
||||||
"name": "Medium",
|
"name": "Medium",
|
||||||
"options": { "enabled": true },
|
"options": {
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
"imageType": "svgMono",
|
"imageType": "svgMono",
|
||||||
"embeddable": false,
|
"embeddable": false,
|
||||||
"url": "https://medium.com"
|
"url": "https://medium.com"
|
||||||
|
@ -330,7 +342,9 @@
|
||||||
},
|
},
|
||||||
"targets": ["^https?:\\/{2}([a-z]+\\.)*quora\\.com.*"],
|
"targets": ["^https?:\\/{2}([a-z]+\\.)*quora\\.com.*"],
|
||||||
"name": "Quora",
|
"name": "Quora",
|
||||||
"options": { "enabled": true },
|
"options": {
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
"imageType": "png",
|
"imageType": "png",
|
||||||
"embeddable": false,
|
"embeddable": false,
|
||||||
"url": "https://quora.com"
|
"url": "https://quora.com"
|
||||||
|
@ -345,9 +359,11 @@
|
||||||
"instanceList": true
|
"instanceList": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"targets": ["^https?:\\/{2}(?:www\\.|)imdb\\.com.*"],
|
"targets": ["^https?:\\/{2}(?:www\\.|)imdb\\.com\\/title"],
|
||||||
"name": "IMDb",
|
"name": "IMDb",
|
||||||
"options": { "enabled": false },
|
"options": {
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
"imageType": "svg",
|
"imageType": "svg",
|
||||||
"embeddable": false,
|
"embeddable": false,
|
||||||
"url": "https://imdb.com"
|
"url": "https://imdb.com"
|
||||||
|
@ -361,7 +377,9 @@
|
||||||
},
|
},
|
||||||
"targets": ["^https?:\\/{2}(www\\.|)reuters\\.com.*"],
|
"targets": ["^https?:\\/{2}(www\\.|)reuters\\.com.*"],
|
||||||
"name": "Reuters",
|
"name": "Reuters",
|
||||||
"options": { "enabled": false },
|
"options": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
"imageType": "svg",
|
"imageType": "svg",
|
||||||
"embeddable": false,
|
"embeddable": false,
|
||||||
"url": "https://reuters.com"
|
"url": "https://reuters.com"
|
||||||
|
@ -375,7 +393,9 @@
|
||||||
},
|
},
|
||||||
"targets": ["^https?:\\/{2}(?:[a-zA-Z0-9]+\\.)?fandom\\.com(?=(?:\\/wiki)|(?:\\/?$))"],
|
"targets": ["^https?:\\/{2}(?:[a-zA-Z0-9]+\\.)?fandom\\.com(?=(?:\\/wiki)|(?:\\/?$))"],
|
||||||
"name": "Fandom",
|
"name": "Fandom",
|
||||||
"options": { "enabled": true },
|
"options": {
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
"imageType": "svg",
|
"imageType": "svg",
|
||||||
"embeddable": false,
|
"embeddable": false,
|
||||||
"url": "https://fandom.com"
|
"url": "https://fandom.com"
|
||||||
|
@ -389,7 +409,9 @@
|
||||||
},
|
},
|
||||||
"targets": "datajson",
|
"targets": "datajson",
|
||||||
"name": "PeerTube",
|
"name": "PeerTube",
|
||||||
"options": { "enabled": false },
|
"options": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
"imageType": "svg",
|
"imageType": "svg",
|
||||||
"embeddable": false,
|
"embeddable": false,
|
||||||
"url": "https://search.joinpeertube.org"
|
"url": "https://search.joinpeertube.org"
|
||||||
|
@ -414,7 +436,7 @@
|
||||||
"targets": ["^https?:\\/{2}odysee\\.com", "^https?:\\/{2}lbry\\.tv"],
|
"targets": ["^https?:\\/{2}odysee\\.com", "^https?:\\/{2}lbry\\.tv"],
|
||||||
"name": "LBRY",
|
"name": "LBRY",
|
||||||
"options": {
|
"options": {
|
||||||
"enabled": false,
|
"enabled": true,
|
||||||
"frontend": "librarian",
|
"frontend": "librarian",
|
||||||
"redirectType": "both",
|
"redirectType": "both",
|
||||||
"embedFrontend": "librarian"
|
"embedFrontend": "librarian"
|
||||||
|
@ -455,6 +477,7 @@
|
||||||
"cookies": [
|
"cookies": [
|
||||||
"autocomplete",
|
"autocomplete",
|
||||||
"categories",
|
"categories",
|
||||||
|
"center_alignment",
|
||||||
"disabled_engines",
|
"disabled_engines",
|
||||||
"disabled_plugins",
|
"disabled_plugins",
|
||||||
"doi_resolver",
|
"doi_resolver",
|
||||||
|
@ -561,15 +584,23 @@
|
||||||
},
|
},
|
||||||
"targets": ["^https?:\\/{2}send\\.libredirect\\.invalid", "^https?:\\/{2}send\\.firefox\\.com\\/?$", "^https?:\\/{2}sendfiles\\.online\\/?$"],
|
"targets": ["^https?:\\/{2}send\\.libredirect\\.invalid", "^https?:\\/{2}send\\.firefox\\.com\\/?$", "^https?:\\/{2}sendfiles\\.online\\/?$"],
|
||||||
"name": "Send Files",
|
"name": "Send Files",
|
||||||
"options": { "enabled": true },
|
"options": {
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
"imageType": "svgMono",
|
"imageType": "svgMono",
|
||||||
"embeddable": false,
|
"embeddable": false,
|
||||||
"url": "https://send.libredirect.invalid"
|
"url": "https://send.libredirect.invalid"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"blacklist": {
|
"blacklist": {
|
||||||
"cloudflare": { "color": "red" },
|
"cloudflare": {
|
||||||
"authenticate": { "color": "orange" },
|
"color": "red"
|
||||||
"offline": { "color": "grey" }
|
},
|
||||||
|
"authenticate": {
|
||||||
|
"color": "orange"
|
||||||
|
},
|
||||||
|
"offline": {
|
||||||
|
"color": "grey"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ function initDefaults() {
|
||||||
}
|
}
|
||||||
|
|
||||||
browser.runtime.onInstalled.addListener(details => {
|
browser.runtime.onInstalled.addListener(details => {
|
||||||
|
if (details.previousVersion != browser.runtime.getManifest().version) {
|
||||||
switch (details.reason) {
|
switch (details.reason) {
|
||||||
case "install":
|
case "install":
|
||||||
initDefaults()
|
initDefaults()
|
||||||
|
@ -42,9 +43,11 @@ browser.runtime.onInstalled.addListener(details => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
let BYPASSTABs = []
|
let tabIdRedirects = {}
|
||||||
|
// true == Always redirect, false == Never redirect, null/undefined == follow options for services
|
||||||
browser.webRequest.onBeforeRequest.addListener(
|
browser.webRequest.onBeforeRequest.addListener(
|
||||||
details => {
|
details => {
|
||||||
const url = new URL(details.url)
|
const url = new URL(details.url)
|
||||||
|
@ -57,23 +60,23 @@ browser.webRequest.onBeforeRequest.addListener(
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
let newUrl = servicesHelper.redirect(url, details.type, initiator)
|
if (tabIdRedirects[details.tabId] == false) return null
|
||||||
|
let newUrl = servicesHelper.redirect(url, details.type, initiator, tabIdRedirects[details.tabId])
|
||||||
|
|
||||||
if (details.frameAncestors && details.frameAncestors.length > 0 && generalHelper.isException(new URL(details.frameAncestors[0].url))) newUrl = null
|
if (details.frameAncestors && details.frameAncestors.length > 0 && generalHelper.isException(new URL(details.frameAncestors[0].url))) newUrl = null
|
||||||
|
|
||||||
if (generalHelper.isException(url)) newUrl = "BYPASSTAB"
|
if (generalHelper.isException(url)) newUrl = "BYPASSTAB"
|
||||||
if (BYPASSTABs.includes(details.tabId)) newUrl = null
|
|
||||||
|
|
||||||
if (newUrl) {
|
if (newUrl) {
|
||||||
if (newUrl === "CANCEL") {
|
if (newUrl === "CANCEL") {
|
||||||
console.log(`Canceled ${url}`)
|
console.log(`Canceled ${url}`)
|
||||||
return { cancel: true }
|
return { cancel: true }
|
||||||
}
|
}
|
||||||
// if (newUrl === "BYPASSTAB") {
|
if (newUrl === "BYPASSTAB") {
|
||||||
// console.log(`Bypassed ${details.tabId} ${url}`)
|
console.log(`Bypassed ${details.tabId} ${url}`)
|
||||||
// if (!BYPASSTABs.includes(details.tabId)) BYPASSTABs.push(details.tabId)
|
if (tabIdRedirects[details.tabId] != false) tabIdRedirects[details.tabId] = false
|
||||||
// return null
|
return null
|
||||||
// }
|
}
|
||||||
console.info("Redirecting", url.href, "=>", newUrl)
|
console.info("Redirecting", url.href, "=>", newUrl)
|
||||||
return { redirectUrl: newUrl }
|
return { redirectUrl: newUrl }
|
||||||
}
|
}
|
||||||
|
@ -84,10 +87,9 @@ browser.webRequest.onBeforeRequest.addListener(
|
||||||
)
|
)
|
||||||
|
|
||||||
browser.tabs.onRemoved.addListener(tabId => {
|
browser.tabs.onRemoved.addListener(tabId => {
|
||||||
const i = BYPASSTABs.indexOf(tabId)
|
if (tabIdRedirects[tabId] != undefined) {
|
||||||
if (i > -1) {
|
delete tabIdRedirects[tabId]
|
||||||
BYPASSTABs.splice(i, 1)
|
console.log("Removed tab " + tabId + " from tabIdRedirects")
|
||||||
console.log("Removed BYPASSTABs", tabId)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -159,11 +161,30 @@ browser.contextMenus.create({
|
||||||
})
|
})
|
||||||
|
|
||||||
browser.contextMenus.create({
|
browser.contextMenus.create({
|
||||||
id: "bypassTab",
|
id: "toggleTab",
|
||||||
title: browser.i18n.getMessage("bypassTab"),
|
title: browser.i18n.getMessage("toggleTab"),
|
||||||
contexts: ["page", "tab"],
|
contexts: ["page", "tab"],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function handleToggleTab(tab) {
|
||||||
|
return new Promise(async resolve => {
|
||||||
|
console.log(tabIdRedirects[tab.id])
|
||||||
|
switch (tabIdRedirects[tab.id]) {
|
||||||
|
case false:
|
||||||
|
console.log("kj")
|
||||||
|
const newUrl = await servicesHelper.reverse(tab.url, true)
|
||||||
|
if (newUrl) browser.tabs.update(tab.id, { url: newUrl })
|
||||||
|
resolve()
|
||||||
|
return
|
||||||
|
case true:
|
||||||
|
console.log("lsad")
|
||||||
|
browser.tabs.reload(tab.id)
|
||||||
|
resolve()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
browser.contextMenus.onClicked.addListener((info, tab) => {
|
browser.contextMenus.onClicked.addListener((info, tab) => {
|
||||||
return new Promise(async resolve => {
|
return new Promise(async resolve => {
|
||||||
switch (info.menuItemId) {
|
switch (info.menuItemId) {
|
||||||
|
@ -183,18 +204,33 @@ browser.contextMenus.onClicked.addListener((info, tab) => {
|
||||||
utils.unify()
|
utils.unify()
|
||||||
resolve()
|
resolve()
|
||||||
return
|
return
|
||||||
case "bypassTab":
|
case "toggleTab":
|
||||||
if (!BYPASSTABs.includes(tab.id)) {
|
if (tabIdRedirects[tab.id] != undefined) {
|
||||||
BYPASSTABs.push(tab.id)
|
tabIdRedirects[tab.id] = !tabIdRedirects[tab.id]
|
||||||
let newUrl = await servicesHelper.reverse(tab.url, true)
|
await handleToggleTab(tab)
|
||||||
if (newUrl) browser.tabs.update(tab.id, { url: newUrl })
|
|
||||||
resolve()
|
resolve()
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
BYPASSTABs.splice(BYPASSTABs.indexOf(tab.id), 1)
|
console.log("n")
|
||||||
browser.tabs.reload(tab.id)
|
const url = new URL(tab.url)
|
||||||
resolve()
|
const service = await servicesHelper.computeService(url)
|
||||||
return
|
console.log(service)
|
||||||
|
if (service) {
|
||||||
|
console.log("h")
|
||||||
|
browser.storage.local.get("options", async r => {
|
||||||
|
console.log(r.options[service])
|
||||||
|
if (r.options[service].enabled) tabIdRedirects[tab.id] = false
|
||||||
|
else tabIdRedirects[tab.id] = true
|
||||||
|
await handleToggleTab(tab)
|
||||||
|
resolve()
|
||||||
|
return
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
tabIdRedirects[tab.id] = false
|
||||||
|
await handleToggleTab(tab)
|
||||||
|
resolve()
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,59 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8" />
|
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
||||||
<title data-localise="__MSG_instanceIsOff__">Reset Warning</title>
|
|
||||||
<link href="../stylesheets/styles.css" rel="stylesheet" />
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
height: 100vh;
|
|
||||||
width: 100vw;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
font-size: 30px;
|
|
||||||
display: flex;
|
|
||||||
}
|
|
||||||
|
|
||||||
div {
|
|
||||||
width: 80%;
|
|
||||||
}
|
|
||||||
|
|
||||||
div.logo {
|
|
||||||
display: flex;
|
|
||||||
}
|
|
||||||
|
|
||||||
img {
|
|
||||||
width: 90px;
|
|
||||||
height: auto;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div>
|
|
||||||
<div class="logo">
|
|
||||||
<img src="/assets/images/libredirect.svg" alt="LibRedirect icon" />
|
|
||||||
<h1>LibRedirect</h1>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p data-localise="__MSG_instanceOffline__">All settings have been reset as they're incompatible with the previous version.</p>
|
|
||||||
<p>Sorry for the inconvenience, but we're going in a fast development process and can't support nor convert older settings. It will reach a stable plateau though.</p>
|
|
||||||
|
|
||||||
<a id="export-settings" class="button button-inline">
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor">
|
|
||||||
<path
|
|
||||||
d="M10.09 15.59L11.5 17l5-5-5-5-1.41 1.41L12.67 11H3v2h9.67l-2.58 2.59zM19 3H5c-1.11 0-2 .9-2 2v4h2V5h14v14H5v-4H3v4c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2z"
|
|
||||||
></path>
|
|
||||||
</svg>
|
|
||||||
|
|
||||||
<x data-localise="__MSG_exportSettings__">Export Settings</x>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
<script src="reset_warning.js"></script>
|
|
||||||
</html>
|
|
|
@ -1,7 +0,0 @@
|
||||||
let params = new URLSearchParams(location.search)
|
|
||||||
|
|
||||||
const resultString = JSON.stringify(JSON.parse(params.get("data")), null, " ")
|
|
||||||
|
|
||||||
let exportSettingsElement = document.getElementById("export-settings")
|
|
||||||
exportSettingsElement.href = "data:application/json;base64," + btoa(resultString)
|
|
||||||
exportSettingsElement.download = "libredirect-settings.json"
|
|
|
@ -477,3 +477,8 @@ input:disabled {
|
||||||
opacity: 0.6;
|
opacity: 0.6;
|
||||||
cursor: not-allowed;
|
cursor: not-allowed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div.about a {
|
||||||
|
width: 500px;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue