From 1866547fd35d81151a9094898402a9d5c3de7d76 Mon Sep 17 00:00:00 2001 From: Rebecca Rogers Date: Mon, 5 Dec 2022 02:10:00 +0100 Subject: [PATCH] Implement build --- tool/mypdns/ld/addon/firefox/main.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/tool/mypdns/ld/addon/firefox/main.js b/tool/mypdns/ld/addon/firefox/main.js index 9e2c6cbf18..350eed4b2f 100644 --- a/tool/mypdns/ld/addon/firefox/main.js +++ b/tool/mypdns/ld/addon/firefox/main.js @@ -1,6 +1,7 @@ let timr, memcache = {}, forcePurge = false, - apiurl = 'https://karma.crimeflare.eu.org:1984/api/mypdns/cat/'; + apiHost = ['https://karma.crimeflare.eu.org:1984', 'http://karma.im5wixghmfmt7gf7wb4xrgdm6byx2gj26zn47da6nwo7xvybgxnqryid.onion'], + apiBase = apiHost[0]; function get_matrix_cat(domain) { if (memcache[domain]) { return new Promise((g, b) => { @@ -13,7 +14,7 @@ function get_matrix_cat(domain) { memcache[domain] = c[domain]; g(memcache[domain]); } else { - fetch(apiurl, { + fetch(apiBase + '/api/mypdns/cat/', { method: 'POST', mode: 'cors', headers: { @@ -44,7 +45,7 @@ function get_matrix_cat(domain) { } function forget_cache(x) { if (x) { - browser.storage.local.get(['opt00', 'opt01', 'opt02', 'opt03', 'lastU', 'lastV']).then(g => { + browser.storage.local.get(['opt00', 'opt01', 'opt02', 'opt03', 'opt04', 'lastU', 'lastV']).then(g => { browser.storage.local.clear(); memcache = {}; browser.storage.local.set({ @@ -59,6 +60,9 @@ function forget_cache(x) { browser.storage.local.set({ 'opt03': (g.opt03 == 'y' ? 'y' : 'n') }); + browser.storage.local.set({ + 'opt04': (g.opt04 == 'y' ? 'y' : 'n') + }); browser.storage.local.set({ 'lastU': Math.round((new Date()).getTime() / 1000) }); @@ -72,12 +76,15 @@ function forget_cache(x) { forget_cache(true); }, 1814400000); } -browser.storage.local.get(['lastU', 'lastV']).then(g => { +browser.storage.local.get(['lastU', 'lastV', 'opt04']).then(g => { if (g.lastU == undefined || Math.abs(Math.round((new Date()).getTime() / 1000) - g.lastU) > 1814400 || g.lastV != (browser.runtime.getManifest()).version || forcePurge) { forget_cache(true); } else { forget_cache(false); } + if (g.opt04 == 'y') { + apiBase = apiHost[1]; + } }); browser.runtime.onMessage.addListener((requests, sender, sendResponse) => { if (requests) { @@ -85,6 +92,14 @@ browser.runtime.onMessage.addListener((requests, sender, sendResponse) => { forget_cache(true); return; } + if (requests == 'abase-y') { + apiBase = apiHost[1]; + return; + } + if (requests == 'abase-n') { + apiBase = apiHost[0]; + return; + } requests.forEach(request => { get_matrix_cat(request).then((r) => { browser.tabs.sendMessage(sender.tab.id, [request, r]);