diff --git a/README.md b/README.md index 4de39765..2c06b0a2 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Imgur => [Rimgo](https://codeberg.org/video-prize-ranch/rimgo)\ Wikipedia => [Wikiless](https://codeberg.org/orenom/wikiless)\ Medium => [Scribe](https://sr.ht/~edwardloveall/scribe/)\ Quora => [Quetre](https://github.com/zyachel/quetre)\ -IMDb => [Libremdb](https://github.com/zyachel/libremdb)\ +IMDb => [libremdb](https://github.com/zyachel/libremdb)\ PeerTube => [SimpleerTube](https://git.sr.ht/~metalune/simpleweb_peertube)\ LBRY/Odysee => [Librarian](https://codeberg.org/librarian/librarian), [LBRY Desktop](https://lbry.com/get)\ Search => [SearXNG](https://github.com/searxng/searxng), [SearX](https://searx.github.io/searx/), [Whoogle](https://benbusby.com/projects/whoogle-search/), [LibreX](https://github.com/hnhx/librex/)\ @@ -72,21 +72,19 @@ npm update npm install ``` -If you are modifying any files ending with .pug, the pug cli needs to be installed with the following command (with root privileges): +If you are modifying any files ending with .ejs, you need to run the following command to render html: ``` -npm install -g pug-cli +npm run ejs ``` -and then run `npm run pug` to generate pages in the background. - -### Build +### Build the extention zip archive: ``` npm run build ``` -### Test +### Run automated tests ``` npm run test @@ -120,4 +118,4 @@ select `load unpacked extension`\ select `src` folder [Privacy Policy](Privacy-Policy.md)\ -Credits: [Privacy Redirect](https://github.com/SimonBrazell/privacy-redirect) +Forked from [Privacy Redirect](https://github.com/SimonBrazell/privacy-redirect) diff --git a/package.json b/package.json index 76f57474..ec39aee4 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,6 @@ "start": "web-ext run --browser-console --source-dir ./src/", "build": "web-ext build --overwrite-dest --source-dir ./src/", "test": "web-ext lint --source-dir ./src/ || true", - "pug": "pug ./src/pages/options/*.pug ./src/pages/popup/ -P -w", - "prettier": "npx prettier --write .", "instances": "python3 src/instances/get_instances.py; git update-index --assume-unchanged src/instances/blacklist.json src/instances/data.json", "ejs": "npx ejs src/pages/options/index.ejs -f src/config/config.json -o src/pages/options/index.html; npx ejs src/pages/popup/popup.ejs -f src/config/config.json -o src/pages/popup/popup.html" }, diff --git a/src/assets/javascripts/general.js b/src/assets/javascripts/general.js index 3a8987ac..9dcba752 100644 --- a/src/assets/javascripts/general.js +++ b/src/assets/javascripts/general.js @@ -11,8 +11,8 @@ function isException(url) { function init() { return new Promise(resolve => { - browser.storage.local.get("exceptions", r => { - exceptions = r.exceptions + browser.storage.local.get("options", r => { + exceptions = r.options.exceptions resolve() }) }) @@ -30,7 +30,7 @@ async function initDefaults() { url: [], regex: [], }, - theme: "DEFAULT", + theme: "detect", popupServices: ["youtube", "twitter", "instagram", "tiktok", "imgur", "reddit", "quora", "translate", "maps"], autoRedirect: false, firstPartyIsolate: false, diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js index 9fc5a0a3..3db12595 100644 --- a/src/assets/javascripts/services.js +++ b/src/assets/javascripts/services.js @@ -19,25 +19,28 @@ function init() { return new Promise(async resolve => { // await getConfig() browser.storage.local.get(["options", "targets", "redirects", "blacklists"], r => { - blacklists = r.blacklists - redirects = r.redirects - targets = r.targets - options = r.options + if (r.options) { + blacklists = r.blacklists + redirects = r.redirects + targets = r.targets + options = r.options + } resolve() }) }) } -await init() await getConfig() +await init() function fetchFrontendInstanceList(service, frontend) { let tmp = [] - if (!config.services[service].frontends[frontend].singleInstance) { + if (config.services[service].frontends[frontend].instanceList) { for (const network in config.networks) { + if (!redirects[frontend]) console.log(frontend) tmp.push(...redirects[frontend][network], ...options[frontend][network].custom) } - } else if (config.services[service].frontends[frontend].singleInstance != undefined) tmp = config.services[service].frontends[frontend].singleInstance + } else if (config.services[service].frontends[frontend].singleInstance) tmp = config.services[service].frontends[frontend].singleInstance return tmp } @@ -58,8 +61,8 @@ function all(service, frontend) { function regexArray(service, url) { let targets if (config.services[service].targets == "datajson") { - browser.storage.local.get(`${service}Targets`, r => { - targets = r[service + "Targets"] + browser.storage.local.get("targets", r => { + targets = r.targets[service] }) } else { targets = config.services[service].targets @@ -397,8 +400,10 @@ function initDefaults() { let redirects = JSON.parse(data) let options = r.options let targets = {} + // let latency = {} for (const service in config.services) { options[service] = {} + // latency[service] = {} if (config.services[service].targets == "datajson") { targets[service] = redirects[service] //delete dataJson[service] @@ -423,19 +428,25 @@ function initDefaults() { } } } - browser.storage.local.set({ redirects, options, targets }) + browser.storage.local.set({ redirects, options, targets /*, latency*/ }) resolve() }) }) }) } -function computeService(url) { +function computeService(url, returnFrontend) { for (const service in config.services) { if (regexArray(service, url)) { - return service - } else if (all(service).includes(utils.protocolHost(url))) { - return service + if (returnFrontend) return [service, null] + else return service + } else { + for (const frontend in config.services[service].frontends) { + if (all(service, frontend).includes(utils.protocolHost(url))) { + if (returnFrontend) return [service, frontend] + else return service + } + } } } return null @@ -524,7 +535,7 @@ function unifyPreferences(url) { const frontend = config.services[currentService].frontends[currentFrontend] if ("cookies" in frontend.preferences) { - for (const cookie in frontend.preferences.cookies) { + for (const cookie of frontend.preferences.cookies) { await utils.copyCookie(currentFrontend, url, instancesList, cookie) } } diff --git a/src/assets/javascripts/utils.js b/src/assets/javascripts/utils.js index 0e8acb3c..70a93240 100644 --- a/src/assets/javascripts/utils.js +++ b/src/assets/javascripts/utils.js @@ -111,29 +111,27 @@ function protocolHost(url) { return `${url.protocol}//${url.host}` } -async function processDefaultCustomInstances(target, name, protocol, document) { - let latencyKey = `${name}Latency` +async function processDefaultCustomInstances(service, name, network, document) { let instancesLatency - let nameProtocolElement = document.getElementById(name).getElementsByClassName(protocol)[0] + let nameNetworkElement = document.getElementById(name).getElementsByClassName(network)[0] let nameCustomInstances = [] - let nameCheckListElement = nameProtocolElement.getElementsByClassName("checklist")[0] + let nameCheckListElement = nameNetworkElement.getElementsByClassName("checklist")[0] await initBlackList() let nameDefaultRedirects - let redirectsChecks = `${name}${camelCase(protocol)}RedirectsChecks` - let customRedirects = `${name}${camelCase(protocol)}CustomRedirects` - - let redirects + let redirects, options async function getFromStorage() { return new Promise(async resolve => - browser.storage.local.get([redirectsChecks, customRedirects, "redirects", latencyKey], r => { - nameDefaultRedirects = r[redirectsChecks] - nameCustomInstances = r[customRedirects] - instancesLatency = r[latencyKey] ?? [] + browser.storage.local.get(["options", "redirects", "latency"], r => { + nameDefaultRedirects = r.options[name][network].enabled + nameCustomInstances = r.options[name][network].custom + options = r.options + if (r.latency) instancesLatency = r.latency[name] ?? [] + else instancesLatency = [] redirects = r.redirects resolve() }) @@ -141,12 +139,11 @@ async function processDefaultCustomInstances(target, name, protocol, document) { } await getFromStorage() - if (nameCustomInstances === undefined) console.log(customRedirects) function calcNameCheckBoxes() { let isTrue = true - for (const item of redirects[name][protocol]) { - if (nameDefaultRedirects === undefined) console.log(name + protocol + " is undefined") + for (const item of redirects[name][network]) { + if (nameDefaultRedirects === undefined) console.log(name + network + " is undefined") if (!nameDefaultRedirects.includes(item)) { isTrue = false break @@ -156,14 +153,14 @@ async function processDefaultCustomInstances(target, name, protocol, document) { element.checked = nameDefaultRedirects.includes(element.className) } if (nameDefaultRedirects.length == 0) isTrue = false - nameProtocolElement.getElementsByClassName("toggle-all")[0].checked = isTrue + nameNetworkElement.getElementsByClassName("toggle-all")[0].checked = isTrue } nameCheckListElement.innerHTML = [ `