diff --git a/src/assets/javascripts/general.js b/src/assets/javascripts/general.js index d85f308..b6bf825 100644 --- a/src/assets/javascripts/general.js +++ b/src/assets/javascripts/general.js @@ -44,6 +44,7 @@ async function initDefaults() { "maps", ], autoRedirect: false, + firstPartyIsolate: false, }, () => resolve()) ) } diff --git a/src/assets/javascripts/maps.js b/src/assets/javascripts/maps.js index a0dbcae..7d886ea 100644 --- a/src/assets/javascripts/maps.js +++ b/src/assets/javascripts/maps.js @@ -46,6 +46,9 @@ init(); browser.storage.onChanged.addListener(init) function redirect(url, initiator) { + if (disableMaps) return; + if (initiator && initiator.host === "earth.google.com") return; + if (!url.href.match(targets)) return; const mapCentreRegex = /@(-?\d[0-9.]*),(-?\d[0-9.]*),(\d{1,2})[.z]/; const dataLatLngRegex = /!3d(-?[0-9]{1,}.[0-9]{1,})!4d(-?[0-9]{1,}.[0-9]{1,})/; const placeRegex = /\/place\/(.*)\//; @@ -67,7 +70,6 @@ function redirect(url, initiator) { traffic: "S", // not implemented on OSM, default to standard. bicycling: "C", }; - function addressToLatLng(address) { const xmlhttp = new XMLHttpRequest(); xmlhttp.open("GET", `https://nominatim.openstreetmap.org/search/${address}?format=json&limit=1`, false); @@ -85,10 +87,6 @@ function redirect(url, initiator) { console.info("Error: Status is " + xmlhttp.status); } - if (disableMaps) return; - if (initiator && initiator.host === "earth.google.com") return; - if (!url.href.match(targets)) return; - let randomInstance; if (mapsFrontend == 'osm') randomInstance = utils.getRandomInstance(redirects.osm.normal); if (mapsFrontend == 'facil') randomInstance = utils.getRandomInstance([...facilNormalRedirectsChecks, ...facilNormalCustomRedirects]); diff --git a/src/assets/javascripts/utils.js b/src/assets/javascripts/utils.js index 113f4e2..6fb4c11 100644 --- a/src/assets/javascripts/utils.js +++ b/src/assets/javascripts/utils.js @@ -283,78 +283,68 @@ async function testLatency(element, instances) { resolve(myList); }) } - +// Complete on getting cookies working in Tor, maybe delete all the other same name cookies to prevent overlapping, see ya :) function copyCookie(frontend, targetUrl, urls, name) { return new Promise(resolve => { - let query; - if (window.chrome) query = { url: protocolHost(targetUrl), name: name } - else query = { url: protocolHost(targetUrl), name: name, firstPartyDomain: null } - browser.cookies.getAll( - query, - async cookies => { - function setCookie(url, name, value, expirationDate, firstPartyIsolate) { - return new Promise(resolve => { - let query; - if (window.chrome) query = { - url: url, name: name, value: value, secure: true, - expirationDate: expirationDate, - }; - else query = { - url: url, name: name, value: value, secure: true, - firstPartyDomain: firstPartyIsolate.value ? new URL(url).hostname : '', - expirationDate: firstPartyIsolate.value ? null : expirationDate, - }; - browser.cookies.set(query, () => resolve()) - }) - } - if (window.chrome) { + browser.storage.local.get('firstPartyIsolate', r => { + console.log('r.firstPartyIsolate', r.firstPartyIsolate); + let query; + if (!r.firstPartyIsolate) query = { url: protocolHost(targetUrl), name: name } + else query = { url: protocolHost(targetUrl), name: name, firstPartyDomain: null } + browser.cookies.getAll( + query, + cookies => { for (const cookie of cookies) if (cookie.name == name) { - console.log('cookie', cookie); - for (const url of urls) await setCookie(url, cookie.name, cookie.value, cookie.expirationDate) - browser.storage.local.set({ [`${frontend}_${name}`]: cookie }, () => resolve()) + for (const url of urls) { + let setQuery; + let removeQuery; + if (!r.firstPartyIsolate) { + removeQuery = { url: url, name: name }; + setQuery = { + url: url, name: name, value: cookie.value, secure: true, + expirationDate: cookie.expirationDate, + }; + } + else { + removeQuery = { url: url, name: name, firstPartyDomain: new URL(url).hostname }; + setQuery = { + url: url, name: name, value: cookie.value, secure: true, + firstPartyDomain: new URL(url).hostname, + }; + } + browser.cookies.remove(removeQuery, () => { + browser.cookies.set(setQuery, () => { + browser.storage.local.set({ [`${frontend}_${name}`]: cookie }, () => resolve()) + }) + }); + } break; } resolve(); - } else { - browser.privacy.websites.firstPartyIsolate.get({}, - async firstPartyIsolate => { - for (const cookie of cookies) - if (cookie.name == name) { - console.log('cookie', cookie); - for (const url of urls) await setCookie(url, cookie.name, cookie.value, cookie.expirationDate, firstPartyIsolate) - browser.storage.local.set({ [`${frontend}_${name}`]: cookie }, () => resolve()) - break; - } - resolve(); - } - ) } - }); + ); + }) }) } function getCookiesFromStorage(frontend, urls, name) { let key = `${frontend}_${name}`; - browser.storage.local.get( - key, - r => { - const cookie = r[key]; - if (cookie !== undefined) - browser.privacy.websites.firstPartyIsolate.get({}, - firstPartyIsolate => { - for (const url of urls) - browser.cookies.set({ - url: url, - name: cookie.name, - value: cookie.value, - secure: true, - expirationDate: firstPartyIsolate.value ? null : cookie.expirationDate, - firstPartyDomain: firstPartyIsolate.value ? new URL(url).hostname : '', - }) - }) + browser.storage.local.get([key, 'firstPartyIsolate'], r => { + const cookie = r[key]; + if (cookie === undefined) return; + let query; + if (!r.firstPartyIsolate) query = { + url: url, name: cookie.name, value: cookie.value, secure: true, + expirationDate: cookie.expirationDate, + }; + else query = { + url: url, name: cookie.name, value: cookie.value, secure: true, + expirationDate: null, + firstPartyDomain: new URL(url).hostname, } - ) + for (const url of urls) browser.cookies.set(query) + }) } function copyRaw(test, copyRawElement) { diff --git a/src/manifest.json b/src/manifest.json index 269e00a..d52bc34 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -25,7 +25,6 @@ "storage", "unlimitedStorage", "cookies", - "privacy", "clipboardWrite", "contextMenus", "" diff --git a/src/pages/options/index.html b/src/pages/options/index.html index afd0b0d..8d19b3a 100644 --- a/src/pages/options/index.html +++ b/src/pages/options/index.html @@ -67,6 +67,10 @@ +
+

First-party isolation (Enable for Tor)

+ +

diff --git a/src/pages/options/index.js b/src/pages/options/index.js index b6fcf6b..39f9c8f 100644 --- a/src/pages/options/index.js +++ b/src/pages/options/index.js @@ -1,12 +1,3 @@ -import youtubeHelper from "../../assets/javascripts/youtube/youtube.js"; -import twitterHelper from "../../assets/javascripts/twitter.js"; -import redditHelper from "../../assets/javascripts/reddit.js"; -import searchHelper from "../../assets/javascripts/search.js"; -import translateHelper from "../../assets/javascripts/translate/translate.js"; -import wikipediaHelper from "../../assets/javascripts/wikipedia.js"; -import tiktokHelper from "../../assets/javascripts/tiktok.js"; - - for (const a of document.getElementById('links').getElementsByTagName('a')) { a.addEventListener('click', e => { const path = a.getAttribute('href').replace('#', ''); diff --git a/src/pages/options/widgets/general.js b/src/pages/options/widgets/general.js index a66e3b4..6fe01b2 100644 --- a/src/pages/options/widgets/general.js +++ b/src/pages/options/widgets/general.js @@ -176,16 +176,21 @@ for (const frontend of generalHelper.allPopupFrontends) } ) +const firstPartyIsolate = document.getElementById('firstPartyIsolate'); +firstPartyIsolate.addEventListener("change", () => browser.storage.local.set({ firstPartyIsolate: firstPartyIsolate.checked })) browser.storage.local.get( [ 'theme', 'autoRedirect', - 'exceptions' + 'exceptions', + 'firstPartyIsolate' ], r => { autoRedirectElement.checked = r.autoRedirect; themeElement.value = r.theme; + firstPartyIsolate.checked = r.firstPartyIsolate; + instanceTypeElement.addEventListener("change", event => { instanceType = event.target.options[instanceTypeElement.selectedIndex].value diff --git a/src/pages/options/widgets/general.pug b/src/pages/options/widgets/general.pug index b7714b7..ac9f663 100644 --- a/src/pages/options/widgets/general.pug +++ b/src/pages/options/widgets/general.pug @@ -10,6 +10,10 @@ section#general_page.option-block option(value="light" data-localise="__MSG_light__") Light option(value="dark" data-localise="__MSG_dark__") Dark + .some-block.option-block + h4() First-party isolation (Enable for Tor) + input#firstPartyIsolate(type="checkbox") + .some-block.option-block h4(data-localise="__MSG_autoRedirect__") input#auto-redirect(type="checkbox") @@ -39,7 +43,7 @@ section#general_page.option-block x(data-localise="__MSG_updateInstances__") Update Instances |    - + .buttons.buttons-inline label#import_settings_text.button.button-inline(for="import-settings")