Implement build

This commit is contained in:
Rebecca Rogers 2022-12-05 02:10:00 +01:00 committed by Reporter [Android]
parent 291b292aa9
commit 1866547fd3

View File

@ -1,6 +1,7 @@
let timr, memcache = {}, let timr, memcache = {},
forcePurge = false, 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) { function get_matrix_cat(domain) {
if (memcache[domain]) { if (memcache[domain]) {
return new Promise((g, b) => { return new Promise((g, b) => {
@ -13,7 +14,7 @@ function get_matrix_cat(domain) {
memcache[domain] = c[domain]; memcache[domain] = c[domain];
g(memcache[domain]); g(memcache[domain]);
} else { } else {
fetch(apiurl, { fetch(apiBase + '/api/mypdns/cat/', {
method: 'POST', method: 'POST',
mode: 'cors', mode: 'cors',
headers: { headers: {
@ -44,7 +45,7 @@ function get_matrix_cat(domain) {
} }
function forget_cache(x) { function forget_cache(x) {
if (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(); browser.storage.local.clear();
memcache = {}; memcache = {};
browser.storage.local.set({ browser.storage.local.set({
@ -59,6 +60,9 @@ function forget_cache(x) {
browser.storage.local.set({ browser.storage.local.set({
'opt03': (g.opt03 == 'y' ? 'y' : 'n') 'opt03': (g.opt03 == 'y' ? 'y' : 'n')
}); });
browser.storage.local.set({
'opt04': (g.opt04 == 'y' ? 'y' : 'n')
});
browser.storage.local.set({ browser.storage.local.set({
'lastU': Math.round((new Date()).getTime() / 1000) 'lastU': Math.round((new Date()).getTime() / 1000)
}); });
@ -72,12 +76,15 @@ function forget_cache(x) {
forget_cache(true); forget_cache(true);
}, 1814400000); }, 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) { 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); forget_cache(true);
} else { } else {
forget_cache(false); forget_cache(false);
} }
if (g.opt04 == 'y') {
apiBase = apiHost[1];
}
}); });
browser.runtime.onMessage.addListener((requests, sender, sendResponse) => { browser.runtime.onMessage.addListener((requests, sender, sendResponse) => {
if (requests) { if (requests) {
@ -85,6 +92,14 @@ browser.runtime.onMessage.addListener((requests, sender, sendResponse) => {
forget_cache(true); forget_cache(true);
return; return;
} }
if (requests == 'abase-y') {
apiBase = apiHost[1];
return;
}
if (requests == 'abase-n') {
apiBase = apiHost[0];
return;
}
requests.forEach(request => { requests.forEach(request => {
get_matrix_cat(request).then((r) => { get_matrix_cat(request).then((r) => {
browser.tabs.sendMessage(sender.tab.id, [request, r]); browser.tabs.sendMessage(sender.tab.id, [request, r]);