This commit is contained in:
Dmitrii Selivanov committed 2022-04-27 00:56:05 +02:00
1 parent c3c13738e7
commit 0df5bb75e7
9 files changed
+92 -77

No files matched your search

@@ -33,7 +33,7 @@
"message": "aktualisieren auf" "message": "aktualisieren auf"
}, },
"version30installed": { "version30installed": {
"message": "Version 4.0.0.0 installiert" "message": "Version 3.0.0.1 installiert"
}, },
"whatsnew": { "whatsnew": {
"message": "Was ist neu" "message": "Was ist neu"
@@ -39,7 +39,7 @@
"message": "update to" "message": "update to"
}, },
"version30installed": { "version30installed": {
"message": "Version 4.0.0.0 installed" "message": "Version 3.0.0.1 installed"
}, },
"whatsnew": { "whatsnew": {
"message": "What's new" "message": "What's new"
@@ -52,5 +52,8 @@
}, },
"customNumberFormats": { "customNumberFormats": {
"message": "Custom number formats" "message": "Custom number formats"
},
"considerDonating": {
"message": "The only thing that keeps the extension running is your donations, please consider supporting the project."
} }
} }
@@ -33,7 +33,7 @@
"message": "ενημέρωση σε" "message": "ενημέρωση σε"
}, },
"version30installed": { "version30installed": {
"message": "Εκδοση 4.0.0.0 εγκαταστάθηκε" "message": "Εκδοση 3.0.0.1 εγκαταστάθηκε"
}, },
"whatsnew": { "whatsnew": {
"message": "Τι είναι νέο;" "message": "Τι είναι νέο;"
@@ -47,4 +47,4 @@
"customNumberFormats": { "customNumberFormats": {
"message": "Προσαρμοζόμενη μορφή αριθμών." "message": "Προσαρμοζόμενη μορφή αριθμών."
} }
} }
@@ -33,7 +33,7 @@
"message": "aggiorna a" "message": "aggiorna a"
}, },
"version30installed": { "version30installed": {
"message": "Versione 4.0.0.0 installata" "message": "Versione 3.0.0.1 installata"
}, },
"whatsnew": { "whatsnew": {
"message": "Cosa c'è di nuovo" "message": "Cosa c'è di nuovo"
@@ -33,7 +33,7 @@
"message": "обновление до" "message": "обновление до"
}, },
"version30installed": { "version30installed": {
"message": "Версия 4.0.0.0 установлена" "message": "Версия 3.0.0.1 установлена"
}, },
"whatsnew": { "whatsnew": {
"message": "Что нового" "message": "Что нового"
@@ -46,5 +46,8 @@
}, },
"customNumberFormats": { "customNumberFormats": {
"message": "Выбор формата чисел" "message": "Выбор формата чисел"
},
"considerDonating": {
"message": "Единственный источник доходов позволяющий расширению продолжать работу - ваши пожертвования. Пожалуйста, поддержите нас и помогите нам развиваться."
} }
} }
@@ -31,7 +31,7 @@
<h2>__MSG_whatsnew__:</h2> <h2>__MSG_whatsnew__:</h2>
<div> <div style="margin-bottom: 5rem">
<ul style="margin-bottom: 5rem"> <ul style="margin-bottom: 5rem">
<li>__MSG_shortsSupport__</li> <li>__MSG_shortsSupport__</li>
<li>__MSG_customColors__</li> <li>__MSG_customColors__</li>
@@ -40,6 +40,8 @@
<li>__MSG_customNumberFormats__</li> <li>__MSG_customNumberFormats__</li>
<img src="/changelog/images/number_format.jpg"/> <img src="/changelog/images/number_format.jpg"/>
</ul> </ul>
<p>__MSG_considerDonating__</p>
<center> <center>
<button id="link_website" title="__MSG_linkWebsite__"> <button id="link_website" title="__MSG_linkWebsite__">
__MSG_linkWebsite__ __MSG_linkWebsite__
@@ -24,4 +24,11 @@
"js": ["ryd.content-script.js"] "js": ["ryd.content-script.js"]
} }
] ]
// ,
// "browser_specific_settings": {
// "gecko": {
// "id": "addon@example.com",
// "strict_min_version": "42.0"
// }
// }
} }
+62 -70
View File
@@ -78,12 +78,13 @@ api.runtime.onInstalled.addListener((details) => {
// No need to show changelog if its was a browser update (and not extension update) // No need to show changelog if its was a browser update (and not extension update)
details.reason === "browser_update" || details.reason === "browser_update" ||
// No need to show changelog if developer just reloaded the extension // No need to show changelog if developer just reloaded the extension
(details.reason === "update" && details.reason === "update"
details.previousVersion === chrome.runtime.getManifest().version)
) )
return; return;
api.tabs.create({url: api.runtime.getURL("/changelog/3/changelog_3.0.html")}); api.tabs.create({
}) url: api.runtime.getURL("/changelog/3/changelog_3.0.html"),
});
});
// api.storage.sync.get(['lastShowChangelogVersion'], (details) => { // api.storage.sync.get(['lastShowChangelogVersion'], (details) => {
// if (extConfig.showUpdatePopup === true && // if (extConfig.showUpdatePopup === true &&
@@ -96,14 +97,12 @@ api.runtime.onInstalled.addListener((details) => {
// } // }
// }); // });
async function sendVote(videoId, vote) { async function sendVote(videoId, vote) {
api.storage.sync.get(null, async (storageResult) => { api.storage.sync.get(null, async (storageResult) => {
if (!storageResult.userId || !storageResult.registrationConfirmed) { if (!storageResult.userId || !storageResult.registrationConfirmed) {
await register(); await register();
return;
} }
fetch(`${apiUrl}/interact/vote`, { let voteResponse = await fetch(`${apiUrl}/interact/vote`, {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
@@ -113,82 +112,72 @@ async function sendVote(videoId, vote) {
videoId, videoId,
value: vote, value: vote,
}), }),
}) });
.then(async (response) => {
if (response.status == 401) { if (voteResponse.status == 401) {
await register(); await register();
await sendVote(videoId, vote); await sendVote(videoId, vote);
return; return;
} }
return response.json(); const voteResponseJson = await voteResponse.json();
}) const solvedPuzzle = await solvePuzzle(voteResponseJson);
.then((response) => { if (!solvedPuzzle.solution) {
solvePuzzle(response).then((solvedPuzzle) => { await sendVote(videoId, vote);
fetch(`${apiUrl}/interact/confirmVote`, { return;
method: "POST", }
headers: {
"Content-Type": "application/json", await fetch(`${apiUrl}/interact/confirmVote`, {
}, method: "POST",
body: JSON.stringify({ headers: {
...solvedPuzzle, "Content-Type": "application/json",
userId: storageResult.userId, },
videoId, body: JSON.stringify({
}), ...solvedPuzzle,
}); userId: storageResult.userId,
}); videoId,
}); }),
});
}); });
} }
function register() { async function register() {
let userId = generateUserID(); const userId = generateUserID();
api.storage.sync.set({ userId }); api.storage.sync.set({ userId });
return fetch(`${apiUrl}/puzzle/registration?userId=${userId}`, { const registrationResponse = await fetch(
method: "GET", `${apiUrl}/puzzle/registration?userId=${userId}`,
{
method: "GET",
headers: {
Accept: "application/json",
},
}
).then((response) => response.json());
const solvedPuzzle = await solvePuzzle(registrationResponse);
if (!solvedPuzzle.solution) {
await register();
return;
}
const result = await fetch(`${apiUrl}/puzzle/registration?userId=${userId}`, {
method: "POST",
headers: { headers: {
Accept: "application/json", "Content-Type": "application/json",
}, },
}) body: JSON.stringify(solvedPuzzle),
.then((response) => response.json()) }).then((response) => response.json());
.then((response) => { if (result === true) {
return solvePuzzle(response).then((solvedPuzzle) => { return api.storage.sync.set({ registrationConfirmed: true });
return fetch(`${apiUrl}/puzzle/registration?userId=${userId}`, { }
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(solvedPuzzle),
}).then((response) =>
response.json().then((result) => {
if (result === true) {
return api.storage.sync.set({ registrationConfirmed: true });
}
})
);
});
})
.catch();
} }
api.storage.sync.get(null, (res) => { api.storage.sync.get(null, async (res) => {
if (!res || !res.userId || !res.registrationConfirmed) { if (!res || !res.userId || !res.registrationConfirmed) {
register(); await register();
} }
}); });
const sentIds = new Set(); const sentIds = new Set();
let toSend = []; let toSend = [];
function sendUserSubmittedStatisticsToApi(statistics) {
fetch(`${apiUrl}/votes/user-submitted`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(statistics),
});
}
function countLeadingZeroes(uInt8View, limit) { function countLeadingZeroes(uInt8View, limit) {
let zeroes = 0; let zeroes = 0;
let value = 0; let value = 0;
@@ -223,7 +212,7 @@ async function solvePuzzle(puzzle) {
let buffer = new ArrayBuffer(20); let buffer = new ArrayBuffer(20);
let uInt8View = new Uint8Array(buffer); let uInt8View = new Uint8Array(buffer);
let uInt32View = new Uint32Array(buffer); let uInt32View = new Uint32Array(buffer);
let maxCount = Math.pow(2, puzzle.difficulty) * 5; let maxCount = Math.pow(2, puzzle.difficulty) * 3;
for (let i = 4; i < 20; i++) { for (let i = 4; i < 20; i++) {
uInt8View[i] = challenge[i - 4]; uInt8View[i] = challenge[i - 4];
} }
@@ -238,6 +227,7 @@ async function solvePuzzle(puzzle) {
}; };
} }
} }
return {};
} }
function generateUserID(length = 36) { function generateUserID(length = 36) {
@@ -283,7 +273,9 @@ function storageChangeHandler(changes, area) {
handleNumberDisplayFormatChangeEvent(changes.numberDisplayFormat.newValue); handleNumberDisplayFormatChangeEvent(changes.numberDisplayFormat.newValue);
} }
if (changes.numberDisplayReformatLikes !== undefined) { if (changes.numberDisplayReformatLikes !== undefined) {
handleNumberDisplayReformatLikesChangeEvent(changes.numberDisplayReformatLikes.newValue); handleNumberDisplayReformatLikesChangeEvent(
changes.numberDisplayReformatLikes.newValue
);
} }
} }
+8
View File
@@ -36,6 +36,14 @@ function localize(localeString) {
function getNumberFormatter(optionSelect) { function getNumberFormatter(optionSelect) {
let formatterNotation; let formatterNotation;
let formatterCompactDisplay; let formatterCompactDisplay;
let userLocales;
try {
userLocales = new URL(
Array.from(document.querySelectorAll("head > link[rel='search']"))
?.find((n) => n?.getAttribute("href")?.includes("?locale="))
?.getAttribute("href")
)?.searchParams?.get("locale");
} catch {}
switch (optionSelect) { switch (optionSelect) {
case "compactLong": case "compactLong":