Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Filter } from "@/types";
import { defaultSettings } from "@/const";
import { Filter, Settings } from "@/types";
import { type ClassValue, clsx } from "clsx";
import { isMatch } from "matcher";
import { twMerge } from "tailwind-merge";
Expand All @@ -21,6 +22,15 @@ export const textReplacement = (
return text;
};

export const isLocalhost = (hostname: string): boolean => {
return (
hostname === "localhost" ||
hostname === "127.0.0.1" ||
hostname === "[::1]" ||
hostname.endsWith(".localhost")
);
};

export const isEnabled = async (): Promise<boolean> => {
let res = true;

Expand All @@ -33,6 +43,15 @@ export const isEnabled = async (): Promise<boolean> => {
res = false;
}

// Check if localhost and if localhost is enabled
if (isLocalhost(url.hostname)) {
const settings = await storage.getItem<Settings>("local:settings");
const enableOnLocalhost = settings?.enableOnLocalhost ?? defaultSettings.enableOnLocalhost;
if (!enableOnLocalhost) {
res = false;
}
}

return res;
};

Expand Down