diff options
author | Dmitrii Selivanov <selivano.d@gmail.com> | 2022-04-27 01:56:05 +0300 |
---|---|---|
committer | Dmitrii Selivanov <selivano.d@gmail.com> | 2022-04-27 01:56:05 +0300 |
commit | 0df5bb75e7f291797c62130a81ca64421611f179 (patch) | |
tree | 94e93e7e0fa6dc81b65c7e6bea2e44a24873cf92 | |
parent | c3c13738e7a49209c8a40852bbefd71ce6323400 (diff) |
3.0.0.1v3.0.0.1
-rw-r--r-- | Extensions/combined/_locales/de/messages.json | 2 | ||||
-rw-r--r-- | Extensions/combined/_locales/en/messages.json | 5 | ||||
-rw-r--r-- | Extensions/combined/_locales/gr/messages.json | 4 | ||||
-rw-r--r-- | Extensions/combined/_locales/it/messages.json | 2 | ||||
-rw-r--r-- | Extensions/combined/_locales/ru/messages.json | 5 | ||||
-rw-r--r-- | Extensions/combined/changelog/3/changelog_3.0.html | 4 | ||||
-rw-r--r-- | Extensions/combined/manifest-firefox.json | 7 | ||||
-rw-r--r-- | Extensions/combined/ryd.background.js | 132 | ||||
-rw-r--r-- | Extensions/combined/src/utils.js | 8 |
9 files changed, 92 insertions, 77 deletions
diff --git a/Extensions/combined/_locales/de/messages.json b/Extensions/combined/_locales/de/messages.json index b8588eb..cd7e3e3 100644 --- a/Extensions/combined/_locales/de/messages.json +++ b/Extensions/combined/_locales/de/messages.json @@ -33,7 +33,7 @@ "message": "aktualisieren auf" }, "version30installed": { - "message": "Version 4.0.0.0 installiert" + "message": "Version 3.0.0.1 installiert" }, "whatsnew": { "message": "Was ist neu" diff --git a/Extensions/combined/_locales/en/messages.json b/Extensions/combined/_locales/en/messages.json index f937645..24c6c69 100644 --- a/Extensions/combined/_locales/en/messages.json +++ b/Extensions/combined/_locales/en/messages.json @@ -39,7 +39,7 @@ "message": "update to" }, "version30installed": { - "message": "Version 4.0.0.0 installed" + "message": "Version 3.0.0.1 installed" }, "whatsnew": { "message": "What's new" @@ -52,5 +52,8 @@ }, "customNumberFormats": { "message": "Custom number formats" + }, + "considerDonating": { + "message": "The only thing that keeps the extension running is your donations, please consider supporting the project." } } diff --git a/Extensions/combined/_locales/gr/messages.json b/Extensions/combined/_locales/gr/messages.json index 80e64fb..92b810d 100644 --- a/Extensions/combined/_locales/gr/messages.json +++ b/Extensions/combined/_locales/gr/messages.json @@ -33,7 +33,7 @@ "message": "ενημέρωση σε" }, "version30installed": { - "message": "Εκδοση 4.0.0.0 εγκαταστάθηκε" + "message": "Εκδοση 3.0.0.1 εγκαταστάθηκε" }, "whatsnew": { "message": "Τι είναι νέο;" @@ -47,4 +47,4 @@ "customNumberFormats": { "message": "Προσαρμοζόμενη μορφή αριθμών." } -}
\ No newline at end of file +} diff --git a/Extensions/combined/_locales/it/messages.json b/Extensions/combined/_locales/it/messages.json index 9031ce0..4008a53 100644 --- a/Extensions/combined/_locales/it/messages.json +++ b/Extensions/combined/_locales/it/messages.json @@ -33,7 +33,7 @@ "message": "aggiorna a" }, "version30installed": { - "message": "Versione 4.0.0.0 installata" + "message": "Versione 3.0.0.1 installata" }, "whatsnew": { "message": "Cosa c'è di nuovo" diff --git a/Extensions/combined/_locales/ru/messages.json b/Extensions/combined/_locales/ru/messages.json index 1a2f59c..ce7002b 100644 --- a/Extensions/combined/_locales/ru/messages.json +++ b/Extensions/combined/_locales/ru/messages.json @@ -33,7 +33,7 @@ "message": "обновление до" }, "version30installed": { - "message": "Версия 4.0.0.0 установлена" + "message": "Версия 3.0.0.1 установлена" }, "whatsnew": { "message": "Что нового" @@ -46,5 +46,8 @@ }, "customNumberFormats": { "message": "Выбор формата чисел" + }, + "considerDonating": { + "message": "Единственный источник доходов позволяющий расширению продолжать работу - ваши пожертвования. Пожалуйста, поддержите нас и помогите нам развиваться." } } diff --git a/Extensions/combined/changelog/3/changelog_3.0.html b/Extensions/combined/changelog/3/changelog_3.0.html index d10562e..5cf4d58 100644 --- a/Extensions/combined/changelog/3/changelog_3.0.html +++ b/Extensions/combined/changelog/3/changelog_3.0.html @@ -31,7 +31,7 @@ <h2>__MSG_whatsnew__:</h2> - <div> + <div style="margin-bottom: 5rem"> <ul style="margin-bottom: 5rem"> <li>__MSG_shortsSupport__</li> <li>__MSG_customColors__</li> @@ -40,6 +40,8 @@ <li>__MSG_customNumberFormats__</li> <img src="/changelog/images/number_format.jpg"/> </ul> + + <p>__MSG_considerDonating__</p> <center> <button id="link_website" title="__MSG_linkWebsite__"> __MSG_linkWebsite__ diff --git a/Extensions/combined/manifest-firefox.json b/Extensions/combined/manifest-firefox.json index c80e98f..2bf548f 100644 --- a/Extensions/combined/manifest-firefox.json +++ b/Extensions/combined/manifest-firefox.json @@ -24,4 +24,11 @@ "js": ["ryd.content-script.js"] } ] +// , +// "browser_specific_settings": { +// "gecko": { +// "id": "addon@example.com", +// "strict_min_version": "42.0" +// } +// } } diff --git a/Extensions/combined/ryd.background.js b/Extensions/combined/ryd.background.js index 9e749cf..75f22ae 100644 --- a/Extensions/combined/ryd.background.js +++ b/Extensions/combined/ryd.background.js @@ -78,12 +78,13 @@ api.runtime.onInstalled.addListener((details) => { // No need to show changelog if its was a browser update (and not extension update) details.reason === "browser_update" || // No need to show changelog if developer just reloaded the extension - (details.reason === "update" && - details.previousVersion === chrome.runtime.getManifest().version) + details.reason === "update" ) 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) => { // if (extConfig.showUpdatePopup === true && @@ -96,14 +97,12 @@ api.runtime.onInstalled.addListener((details) => { // } // }); - async function sendVote(videoId, vote) { api.storage.sync.get(null, async (storageResult) => { if (!storageResult.userId || !storageResult.registrationConfirmed) { await register(); - return; } - fetch(`${apiUrl}/interact/vote`, { + let voteResponse = await fetch(`${apiUrl}/interact/vote`, { method: "POST", headers: { "Content-Type": "application/json", @@ -113,82 +112,72 @@ async function sendVote(videoId, vote) { videoId, value: vote, }), - }) - .then(async (response) => { - if (response.status == 401) { - await register(); - await sendVote(videoId, vote); - return; - } - return response.json(); - }) - .then((response) => { - solvePuzzle(response).then((solvedPuzzle) => { - fetch(`${apiUrl}/interact/confirmVote`, { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ - ...solvedPuzzle, - userId: storageResult.userId, - videoId, - }), - }); - }); - }); + }); + + if (voteResponse.status == 401) { + await register(); + await sendVote(videoId, vote); + return; + } + const voteResponseJson = await voteResponse.json(); + const solvedPuzzle = await solvePuzzle(voteResponseJson); + if (!solvedPuzzle.solution) { + await sendVote(videoId, vote); + return; + } + + await fetch(`${apiUrl}/interact/confirmVote`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + ...solvedPuzzle, + userId: storageResult.userId, + videoId, + }), + }); }); } -function register() { - let userId = generateUserID(); +async function register() { + const userId = generateUserID(); api.storage.sync.set({ userId }); - return fetch(`${apiUrl}/puzzle/registration?userId=${userId}`, { - method: "GET", + const registrationResponse = await fetch( + `${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: { - Accept: "application/json", + "Content-Type": "application/json", }, - }) - .then((response) => response.json()) - .then((response) => { - return solvePuzzle(response).then((solvedPuzzle) => { - 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(); + body: JSON.stringify(solvedPuzzle), + }).then((response) => response.json()); + if (result === true) { + return api.storage.sync.set({ registrationConfirmed: true }); + } } -api.storage.sync.get(null, (res) => { +api.storage.sync.get(null, async (res) => { if (!res || !res.userId || !res.registrationConfirmed) { - register(); + await register(); } }); const sentIds = new Set(); 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) { let zeroes = 0; let value = 0; @@ -223,7 +212,7 @@ async function solvePuzzle(puzzle) { let buffer = new ArrayBuffer(20); let uInt8View = new Uint8Array(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++) { uInt8View[i] = challenge[i - 4]; } @@ -238,6 +227,7 @@ async function solvePuzzle(puzzle) { }; } } + return {}; } function generateUserID(length = 36) { @@ -283,7 +273,9 @@ function storageChangeHandler(changes, area) { handleNumberDisplayFormatChangeEvent(changes.numberDisplayFormat.newValue); } if (changes.numberDisplayReformatLikes !== undefined) { - handleNumberDisplayReformatLikesChangeEvent(changes.numberDisplayReformatLikes.newValue); + handleNumberDisplayReformatLikesChangeEvent( + changes.numberDisplayReformatLikes.newValue + ); } } diff --git a/Extensions/combined/src/utils.js b/Extensions/combined/src/utils.js index b1acc54..a3fe790 100644 --- a/Extensions/combined/src/utils.js +++ b/Extensions/combined/src/utils.js @@ -36,6 +36,14 @@ function localize(localeString) { function getNumberFormatter(optionSelect) { let formatterNotation; 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) { case "compactLong": |