Browser compatibility improvements. Tweak arguments of translate function, and try/catch navigator.hardwareconcurency

This commit is contained in:
Thomas Lynch
2024-01-20 20:32:29 +11:00
parent aec1aac1b9
commit 5a0b3bfabc
4 changed files with 20 additions and 5 deletions

View File

@ -1,6 +1,7 @@
let TRANSLATIONS;
function __(key, replacement=null) {
function __(key) {
let replacement = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
const translation = TRANSLATIONS[key] || key;
return replacement !== null ? translation.replace('%s', replacement) : translation;
}
@ -185,7 +186,14 @@ const powFinished = new Promise((resolve) => {
const diffString = "0".repeat(Math.floor(diff / 8));
const [userkey, challenge] = pow.split("#");
if (window.Worker) {
const cpuThreads = window.navigator.hardwareConcurrency;
let cpuThreads;
try {
cpuThreads = window.navigator.hardwareConcurrency || 2;
} catch(e) {
//catch just in case, and potentially fix an issue w safari
console.warn('navigator.hardwareConcurrency unavailable');
cpuThreads = 2;
}
const isTor = location.hostname.endsWith(".onion");
/* Try to use all threads on tor, because tor limits threads for anti fingerprinting but this
makes it awfully slow because workerThreads will always be = 1 */