aboutsummaryrefslogtreecommitdiffhomepage
path: root/utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'utils.js')
-rw-r--r--utils.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/utils.js b/utils.js
index d9ce3a22..838769a2 100644
--- a/utils.js
+++ b/utils.js
@@ -66,3 +66,42 @@ function localizeHtmlPage() {
}
}
+function generateUserID(length = 36) {
+ let charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+ let result = "";
+ if (window.crypto && window.crypto.getRandomValues) {
+ values = new Uint32Array(length);
+ window.crypto.getRandomValues(values);
+ for (i = 0; i < length; i++) {
+ result += charset[values[i] % charset.length];
+ }
+ return result;
+ } else {
+ for (let i = 0; i < length; i++) {
+ result += charset[Math.floor(Math.random() * charset.length)];
+ }
+ return result;
+ }
+}
+
+/**
+ * Gets the error message in a nice string
+ *
+ * @param {int} statusCode
+ * @returns {string} errorMessage
+ */
+function getErrorMessage(statusCode) {
+ let errorMessage = "";
+
+ if([400, 429, 409, 502, 0].includes(statusCode)) {
+ //treat them the same
+ if (statusCode == 503) statusCode = 502;
+
+ errorMessage = chrome.i18n.getMessage(statusCode + "") + " " + chrome.i18n.getMessage("errorCode") + statusCode
+ + "\n\n" + chrome.i18n.getMessage("statusReminder");
+ } else {
+ errorMessage = chrome.i18n.getMessage("connectionError") + statusCode;
+ }
+
+ return errorMessage;
+} \ No newline at end of file