mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-10-06 13:40:16 +08:00
added islocalhost function to misc
This commit is contained in:
parent
e1c23538a7
commit
2b0ccbe44c
9 changed files with 21 additions and 18 deletions
|
@ -651,10 +651,7 @@ async function signUp(): Promise<void> {
|
|||
}
|
||||
|
||||
// Force user to use a capital letter, number, special character when setting up an account and changing password
|
||||
if (
|
||||
window.location.hostname !== "localhost" &&
|
||||
!Misc.isPasswordStrong(password)
|
||||
) {
|
||||
if (!Misc.isLocalhost() && !Misc.isPasswordStrong(password)) {
|
||||
Notifications.add(
|
||||
"Password must contain at least one capital letter, number, a special character and at least 8 characters long",
|
||||
0,
|
||||
|
|
|
@ -32,7 +32,7 @@ async function updateFavicon(size: number, curveSize: number): Promise<void> {
|
|||
let maincolor, bgcolor;
|
||||
bgcolor = await ThemeColors.get("bg");
|
||||
maincolor = await ThemeColors.get("main");
|
||||
if (window.location.hostname === "localhost") {
|
||||
if (Misc.isLocalhost()) {
|
||||
const swap = maincolor;
|
||||
maincolor = bgcolor;
|
||||
bgcolor = swap;
|
||||
|
|
|
@ -139,7 +139,7 @@ function updateFooter(lb: LbKey): void {
|
|||
}
|
||||
|
||||
if (
|
||||
window.location.hostname !== "localhost" &&
|
||||
!Misc.isLocalhost() &&
|
||||
(DB.getSnapshot()?.typingStats?.timeTyping ?? 0) < 7200
|
||||
) {
|
||||
$(`#leaderboardsWrapper table.${side} tfoot`).html(`
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import Ape from "../ape";
|
||||
import { secondsToString } from "../utils/misc";
|
||||
import { isLocalhost, secondsToString } from "../utils/misc";
|
||||
import * as Notifications from "./notifications";
|
||||
import format from "date-fns/format";
|
||||
import * as Alerts from "./alerts";
|
||||
|
@ -21,7 +21,7 @@ function setMemory(id: string): void {
|
|||
async function getLatest(): Promise<MonkeyTypes.PSA[] | null> {
|
||||
const response = await Ape.psas.get();
|
||||
if (response.status === 500) {
|
||||
if (window.location.hostname === "localhost") {
|
||||
if (isLocalhost()) {
|
||||
Notifications.addBanner(
|
||||
"Dev Info: Backend server not running",
|
||||
0,
|
||||
|
|
|
@ -3,7 +3,7 @@ import { FirebaseApp, initializeApp } from "firebase/app";
|
|||
import { getAuth, Auth as AuthType } from "firebase/auth";
|
||||
import { firebaseConfig } from "./constants/firebase-config"; // eslint-disable-line require-path-exists/exists
|
||||
import * as Notifications from "./elements/notifications";
|
||||
import { createErrorMessage } from "./utils/misc";
|
||||
import { createErrorMessage, isLocalhost } from "./utils/misc";
|
||||
|
||||
// Initialize Firebase
|
||||
export let app: FirebaseApp | undefined;
|
||||
|
@ -16,7 +16,7 @@ try {
|
|||
app = undefined;
|
||||
Auth = undefined;
|
||||
console.error("Authentication failed to initialize", e);
|
||||
if (window.location.hostname === "localhost") {
|
||||
if (isLocalhost()) {
|
||||
Notifications.addBanner(
|
||||
createErrorMessage(e, "Authentication uninitialized") +
|
||||
" Check your firebase-config.ts",
|
||||
|
|
|
@ -20,7 +20,7 @@ import {
|
|||
unlink,
|
||||
updatePassword,
|
||||
} from "firebase/auth";
|
||||
import { isElementVisible, isPasswordStrong } from "../utils/misc";
|
||||
import { isElementVisible, isLocalhost, isPasswordStrong } from "../utils/misc";
|
||||
import * as CustomTextState from "../states/custom-text-name";
|
||||
import * as Skeleton from "./skeleton";
|
||||
|
||||
|
@ -535,10 +535,7 @@ list["updatePassword"] = new SimplePopup(
|
|||
Notifications.add("New passwords don't match", 0);
|
||||
return;
|
||||
}
|
||||
if (
|
||||
window.location.hostname !== "localhost" &&
|
||||
!isPasswordStrong(newPass)
|
||||
) {
|
||||
if (!isLocalhost() && !isPasswordStrong(newPass)) {
|
||||
Notifications.add(
|
||||
"New password must contain at least one capital letter, number, a special character and at least 8 characters long",
|
||||
0,
|
||||
|
|
|
@ -15,7 +15,7 @@ import Konami from "konami";
|
|||
ManualRestart.set();
|
||||
UpdateConfig.loadFromLocalStorage();
|
||||
|
||||
if (window.location.hostname === "localhost") {
|
||||
if (Misc.isLocalhost()) {
|
||||
$("head title").text("localhost");
|
||||
$("#bottom .version .text").text("localhost");
|
||||
$("#bottom #versionGroup").removeClass("hidden");
|
||||
|
@ -82,7 +82,7 @@ if ("serviceWorker" in navigator) {
|
|||
window.addEventListener("load", () => {
|
||||
// disabling service workers on localhost - they dont really work well with local development
|
||||
// and cause issues with hot reloading
|
||||
if (window.location.hostname === "localhost") {
|
||||
if (Misc.isLocalhost()) {
|
||||
navigator.serviceWorker.getRegistrations().then(function (registrations) {
|
||||
for (const registration of registrations) {
|
||||
// if (registration.scope !== "https://monkeytype.com/")
|
||||
|
|
|
@ -7,6 +7,7 @@ import * as ConfigEvent from "./observables/config-event";
|
|||
import { debounce, throttle } from "throttle-debounce";
|
||||
import * as TestUI from "./test/test-ui";
|
||||
import { get as getActivePage } from "./states/active-page";
|
||||
import { isLocalhost } from "./utils/misc";
|
||||
|
||||
export function updateKeytips(): void {
|
||||
const modifierKey = window.navigator.userAgent.toLowerCase().includes("mac")
|
||||
|
@ -38,7 +39,7 @@ export function updateKeytips(): void {
|
|||
}
|
||||
}
|
||||
|
||||
if (window.location.hostname === "localhost") {
|
||||
if (isLocalhost()) {
|
||||
window.onerror = function (error): void {
|
||||
Notifications.add(error.toString(), -1);
|
||||
};
|
||||
|
|
|
@ -1374,3 +1374,11 @@ export function loadCSS(href: string, prepend = false): void {
|
|||
document.getElementsByTagName("head")[0].appendChild(link);
|
||||
}
|
||||
}
|
||||
|
||||
export function isLocalhost(): boolean {
|
||||
return (
|
||||
location.hostname === "localhost" ||
|
||||
location.hostname === "127.0.0.1" ||
|
||||
location.hostname === ""
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue