Dmitrii Selivanov 3 éve
szülő
commit
0df5bb75e7

+ 1 - 1
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"

+ 4 - 1
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."
     }
 }

+ 2 - 2
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": "Προσαρμοζόμενη μορφή αριθμών."
     }
-}
+}

+ 1 - 1
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"

+ 4 - 1
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": "Единственный источник доходов позволяющий расширению продолжать работу - ваши пожертвования. Пожалуйста, поддержите нас и помогите нам развиваться."
     }
 }

+ 3 - 1
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__

+ 7 - 0
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"
+//    }
+//  }
 }

+ 62 - 70
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
+    );
   }
 }
 

+ 8 - 0
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":