diff --git a/gulpfile.js b/gulpfile.js index 8332b180e..ae853a534 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -90,6 +90,7 @@ const refactoredSrc = [ "./src/js/dom-util.js", "./src/js/cloud-functions.js", "./src/js/misc.js", + "./src/js/layouts.js", "./src/js/monkey.js", ]; @@ -99,7 +100,6 @@ const globalSrc = [ "./src/js/global-dependencies.js", "./src/js/simple-popups.js", "./src/js/words.js", - "./src/js/layouts.js", "./src/js/userconfig.js", "./src/js/commandline.js", "./src/js/leaderboards.js", diff --git a/src/js/db.js b/src/js/db.js index 2fce48365..a5ea6540d 100644 --- a/src/js/db.js +++ b/src/js/db.js @@ -103,7 +103,7 @@ export async function db_getUserResults() { .get() .then((data) => { dbSnapshot.results = []; - data.docs.forEach((doc, index) => { + data.docs.forEach((doc) => { let result = doc.data(); result.id = doc.id; dbSnapshot.results.push(result); @@ -181,6 +181,7 @@ export async function db_getLocalPB( let retval; if (dbSnapshot == null) { + retval = 0; } else { retval = cont(); } @@ -249,8 +250,7 @@ export async function db_saveLocalPB( } } - if (dbSnapshot == null) { - } else { + if (dbSnapshot != null) { cont(); } } diff --git a/src/js/global-dependencies.js b/src/js/global-dependencies.js index d9cf43f6a..7a23021f9 100644 --- a/src/js/global-dependencies.js +++ b/src/js/global-dependencies.js @@ -22,4 +22,5 @@ import { import { showBackgroundLoader, hideBackgroundLoader } from "./dom-util"; import * as Misc from "./misc"; import * as CloudFunctions from "./cloud-functions"; +import layouts from "./layouts"; import * as Monkey from "./monkey"; diff --git a/src/js/layouts.js b/src/js/layouts.js index 9505db1bb..43befd36a 100644 --- a/src/js/layouts.js +++ b/src/js/layouts.js @@ -236,3 +236,4 @@ const layouts = { ] }, } +export default layouts; diff --git a/src/js/misc.js b/src/js/misc.js index 11a0088a1..f9bf207b8 100644 --- a/src/js/misc.js +++ b/src/js/misc.js @@ -1,4 +1,52 @@ import { showBackgroundLoader, hideBackgroundLoader } from "./dom-util"; + +function hexToHSL(H) { + // Convert hex to RGB first + let r = 0, + g = 0, + b = 0; + if (H.length == 4) { + r = "0x" + H[1] + H[1]; + g = "0x" + H[2] + H[2]; + b = "0x" + H[3] + H[3]; + } else if (H.length == 7) { + r = "0x" + H[1] + H[2]; + g = "0x" + H[3] + H[4]; + b = "0x" + H[5] + H[6]; + } + // Then to HSL + r /= 255; + g /= 255; + b /= 255; + let cmin = Math.min(r, g, b), + cmax = Math.max(r, g, b), + delta = cmax - cmin, + h = 0, + s = 0, + l = 0; + + if (delta == 0) h = 0; + else if (cmax == r) h = ((g - b) / delta) % 6; + else if (cmax == g) h = (b - r) / delta + 2; + else h = (r - g) / delta + 4; + + h = Math.round(h * 60); + + if (h < 0) h += 360; + + l = (cmax + cmin) / 2; + s = delta == 0 ? 0 : delta / (1 - Math.abs(2 * l - 1)); + s = +(s * 100).toFixed(1); + l = +(l * 100).toFixed(1); + + return { + hue: h, + sat: s, + lgt: l, + string: "hsl(" + h + "," + s + "%," + l + "%)", + }; +} + let themesList = null; export async function getThemesList() { if (themesList == null) { @@ -96,8 +144,40 @@ export async function getChallengeList() { } } -let currentLanguage = null; +export function showNotification(text, time) { + let noti = $(".notification"); + noti.text(text); + noti.css("top", `-${noti.outerHeight()}px`); + noti.stop(true, false).animate( + { + top: "1rem", + }, + 250, + "swing", + () => { + noti.stop(true, false).animate( + { + opacity: 1, + }, + time, + () => { + noti.stop(true, false).animate( + { + top: `-${noti.outerHeight()}px`, + }, + 250, + "swing", + () => { + noti.text(""); + } + ); + } + ); + } + ); +} +let currentLanguage = null; export function getCurrentLanguage() { return currentLanguage; } @@ -149,7 +229,7 @@ export function sendVerificationEmail() { showBackgroundLoader(); let cu = firebase.auth().currentUser; cu.sendEmailVerification() - .then((e) => { + .then(() => { hideBackgroundLoader(); showNotification("Email sent to " + cu.email, 4000); }) @@ -204,39 +284,6 @@ export function mean(array) { } } -export function showNotification(text, time) { - let noti = $(".notification"); - noti.text(text); - noti.css("top", `-${noti.outerHeight()}px`); - noti.stop(true, false).animate( - { - top: "1rem", - }, - 250, - "swing", - () => { - noti.stop(true, false).animate( - { - opacity: 1, - }, - time, - () => { - noti.stop(true, false).animate( - { - top: `-${noti.outerHeight()}px`, - }, - 250, - "swing", - () => { - noti.text(""); - } - ); - } - ); - } - ); -} - export function getReleasesFromGitHub() { $.getJSON( "https://api.github.com/repos/Miodec/monkeytype/releases", @@ -291,53 +338,6 @@ export function kogasa(cov) { ); } -function hexToHSL(H) { - // Convert hex to RGB first - let r = 0, - g = 0, - b = 0; - if (H.length == 4) { - r = "0x" + H[1] + H[1]; - g = "0x" + H[2] + H[2]; - b = "0x" + H[3] + H[3]; - } else if (H.length == 7) { - r = "0x" + H[1] + H[2]; - g = "0x" + H[3] + H[4]; - b = "0x" + H[5] + H[6]; - } - // Then to HSL - r /= 255; - g /= 255; - b /= 255; - let cmin = Math.min(r, g, b), - cmax = Math.max(r, g, b), - delta = cmax - cmin, - h = 0, - s = 0, - l = 0; - - if (delta == 0) h = 0; - else if (cmax == r) h = ((g - b) / delta) % 6; - else if (cmax == g) h = (b - r) / delta + 2; - else h = (r - g) / delta + 4; - - h = Math.round(h * 60); - - if (h < 0) h += 360; - - l = (cmax + cmin) / 2; - s = delta == 0 ? 0 : delta / (1 - Math.abs(2 * l - 1)); - s = +(s * 100).toFixed(1); - l = +(l * 100).toFixed(1); - - return { - hue: h, - sat: s, - lgt: l, - string: "hsl(" + h + "," + s + "%," + l + "%)", - }; -} - export function roundTo2(num) { return Math.round((num + Number.EPSILON) * 100) / 100; }