diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index 003a878..b8dccda 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -211,7 +211,7 @@ "lbryDesktop": { "message": "LBRY Desktop" }, - "bypassTab": { + "toggleTab": { "message": "Toggle redirects in this tab", "description": "Used in context menus when right clicking on a page/tab" } diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js index 7e0a76a..6614bf9 100644 --- a/src/assets/javascripts/services.js +++ b/src/assets/javascripts/services.js @@ -60,12 +60,12 @@ function regexArray(service, url, config) { return false } -function redirect(url, type, initiator) { +function redirect(url, type, initiator, forceRedirection) { if (type != "main_frame" && type != "sub_frame") return let randomInstance let frontend 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 != "main_frame") continue // let targets = new RegExp(config.services[service].targets.join("|"), "i") @@ -407,6 +407,7 @@ function redirect(url, type, initiator) { } function computeService(url, returnFrontend) { + console.log(url) return new Promise(resolve => { fetch("/config/config.json") .then(response => response.text()) diff --git a/src/config/config.json b/src/config/config.json index 9716826..642d90e 100644 --- a/src/config/config.json +++ b/src/config/config.json @@ -188,7 +188,9 @@ }, "targets": ["^https?:\\/{2}(www\\.)?instagram\\.com\\/p\\/"], "name": "Instagram", - "options": { "enabled": true }, + "options": { + "enabled": true + }, "imageType": "png", "embeddable": false, "url": "https://instagram.com" @@ -205,7 +207,9 @@ }, "targets": ["^https?:\\/{2}(www\\.|)tiktok\\.com.*"], "name": "TikTok", - "options": { "enabled": true }, + "options": { + "enabled": true + }, "imageType": "png", "embeddable": false, "url": "https://tiktok.com" @@ -223,6 +227,7 @@ "preferences": { "cookies": [ "collapse_child_comments", + "default_comment_sort", "domain_instagram", "domain_twitter", "domain_youtube", @@ -230,8 +235,11 @@ "highlight_controversial", "nsfw_enabled", "post_media_max_height", + "prefer_frontpage", + "show_large_gallery_images", "show_upvoted_percentage", "show_upvotes", + "subbed_subreddits", "theme", "videos_muted" ] @@ -280,7 +288,9 @@ }, "targets": ["^https?:\\/{2}(?:[a-z]+\\.)*wikipedia\\.org"], "name": "Wikipedia", - "options": { "enabled": false }, + "options": { + "enabled": false + }, "imageType": "svg", "embeddable": false, "url": "https://wikipedia.org" @@ -313,7 +323,9 @@ "^writingcooperative\\.com" ], "name": "Medium", - "options": { "enabled": true }, + "options": { + "enabled": true + }, "imageType": "svgMono", "embeddable": false, "url": "https://medium.com" @@ -330,7 +342,9 @@ }, "targets": ["^https?:\\/{2}([a-z]+\\.)*quora\\.com.*"], "name": "Quora", - "options": { "enabled": true }, + "options": { + "enabled": true + }, "imageType": "png", "embeddable": false, "url": "https://quora.com" @@ -345,9 +359,11 @@ "instanceList": true } }, - "targets": ["^https?:\\/{2}(?:www\\.|)imdb\\.com.*"], + "targets": ["^https?:\\/{2}(?:www\\.|)imdb\\.com\\/title"], "name": "IMDb", - "options": { "enabled": false }, + "options": { + "enabled": true + }, "imageType": "svg", "embeddable": false, "url": "https://imdb.com" @@ -361,7 +377,9 @@ }, "targets": ["^https?:\\/{2}(www\\.|)reuters\\.com.*"], "name": "Reuters", - "options": { "enabled": false }, + "options": { + "enabled": false + }, "imageType": "svg", "embeddable": false, "url": "https://reuters.com" @@ -375,7 +393,9 @@ }, "targets": ["^https?:\\/{2}(?:[a-zA-Z0-9]+\\.)?fandom\\.com(?=(?:\\/wiki)|(?:\\/?$))"], "name": "Fandom", - "options": { "enabled": true }, + "options": { + "enabled": true + }, "imageType": "svg", "embeddable": false, "url": "https://fandom.com" @@ -389,7 +409,9 @@ }, "targets": "datajson", "name": "PeerTube", - "options": { "enabled": false }, + "options": { + "enabled": false + }, "imageType": "svg", "embeddable": false, "url": "https://search.joinpeertube.org" @@ -414,7 +436,7 @@ "targets": ["^https?:\\/{2}odysee\\.com", "^https?:\\/{2}lbry\\.tv"], "name": "LBRY", "options": { - "enabled": false, + "enabled": true, "frontend": "librarian", "redirectType": "both", "embedFrontend": "librarian" @@ -455,6 +477,7 @@ "cookies": [ "autocomplete", "categories", + "center_alignment", "disabled_engines", "disabled_plugins", "doi_resolver", @@ -561,15 +584,23 @@ }, "targets": ["^https?:\\/{2}send\\.libredirect\\.invalid", "^https?:\\/{2}send\\.firefox\\.com\\/?$", "^https?:\\/{2}sendfiles\\.online\\/?$"], "name": "Send Files", - "options": { "enabled": true }, + "options": { + "enabled": true + }, "imageType": "svgMono", "embeddable": false, "url": "https://send.libredirect.invalid" } }, "blacklist": { - "cloudflare": { "color": "red" }, - "authenticate": { "color": "orange" }, - "offline": { "color": "grey" } + "cloudflare": { + "color": "red" + }, + "authenticate": { + "color": "orange" + }, + "offline": { + "color": "grey" + } } } diff --git a/src/pages/background/background.js b/src/pages/background/background.js index f53d7b9..54a8001 100644 --- a/src/pages/background/background.js +++ b/src/pages/background/background.js @@ -20,6 +20,7 @@ function initDefaults() { } browser.runtime.onInstalled.addListener(details => { + if (details.previousVersion != browser.runtime.getManifest().version) { switch (details.reason) { case "install": 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( details => { const url = new URL(details.url) @@ -57,23 +60,23 @@ browser.webRequest.onBeforeRequest.addListener( 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 (generalHelper.isException(url)) newUrl = "BYPASSTAB" - if (BYPASSTABs.includes(details.tabId)) newUrl = null if (newUrl) { if (newUrl === "CANCEL") { console.log(`Canceled ${url}`) return { cancel: true } } - // if (newUrl === "BYPASSTAB") { - // console.log(`Bypassed ${details.tabId} ${url}`) - // if (!BYPASSTABs.includes(details.tabId)) BYPASSTABs.push(details.tabId) - // return null - // } + if (newUrl === "BYPASSTAB") { + console.log(`Bypassed ${details.tabId} ${url}`) + if (tabIdRedirects[details.tabId] != false) tabIdRedirects[details.tabId] = false + return null + } console.info("Redirecting", url.href, "=>", newUrl) return { redirectUrl: newUrl } } @@ -84,10 +87,9 @@ browser.webRequest.onBeforeRequest.addListener( ) browser.tabs.onRemoved.addListener(tabId => { - const i = BYPASSTABs.indexOf(tabId) - if (i > -1) { - BYPASSTABs.splice(i, 1) - console.log("Removed BYPASSTABs", tabId) + if (tabIdRedirects[tabId] != undefined) { + delete tabIdRedirects[tabId] + console.log("Removed tab " + tabId + " from tabIdRedirects") } }) @@ -159,11 +161,30 @@ browser.contextMenus.create({ }) browser.contextMenus.create({ - id: "bypassTab", - title: browser.i18n.getMessage("bypassTab"), + id: "toggleTab", + title: browser.i18n.getMessage("toggleTab"), 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) => { return new Promise(async resolve => { switch (info.menuItemId) { @@ -183,18 +204,33 @@ browser.contextMenus.onClicked.addListener((info, tab) => { utils.unify() resolve() return - case "bypassTab": - if (!BYPASSTABs.includes(tab.id)) { - BYPASSTABs.push(tab.id) - let newUrl = await servicesHelper.reverse(tab.url, true) - if (newUrl) browser.tabs.update(tab.id, { url: newUrl }) + case "toggleTab": + if (tabIdRedirects[tab.id] != undefined) { + tabIdRedirects[tab.id] = !tabIdRedirects[tab.id] + await handleToggleTab(tab) resolve() return } else { - BYPASSTABs.splice(BYPASSTABs.indexOf(tab.id), 1) - browser.tabs.reload(tab.id) - resolve() - return + console.log("n") + const url = new URL(tab.url) + const service = await servicesHelper.computeService(url) + 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 + } } } }) diff --git a/src/pages/background/reset_warning.html b/src/pages/background/reset_warning.html deleted file mode 100644 index f1881ed..0000000 --- a/src/pages/background/reset_warning.html +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - - Reset Warning - - - - - -
- - -

All settings have been reset as they're incompatible with the previous version.

-

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.

- - - - - -   - Export Settings - -
- - - diff --git a/src/pages/background/reset_warning.js b/src/pages/background/reset_warning.js deleted file mode 100644 index 9ce49c9..0000000 --- a/src/pages/background/reset_warning.js +++ /dev/null @@ -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" diff --git a/src/pages/stylesheets/styles.css b/src/pages/stylesheets/styles.css index eb59965..072b5d5 100644 --- a/src/pages/stylesheets/styles.css +++ b/src/pages/stylesheets/styles.css @@ -477,3 +477,8 @@ input:disabled { opacity: 0.6; cursor: not-allowed; } + +div.about a { + width: 500px; + display: inline-block; +}