Compare commits

...
5 Commits
Author SHA1 Message Date
klemek e956731642 feat: save ignored tlds in cookies
Lint / TypeScript (push) Successful in 4m31s
Lint / Oxlint (push) Successful in 4m31s
Lint / ESLint (push) Successful in 4m32s
Deploy / Build (push) Successful in 5m16s
Deploy / Deploy to Stapler (push) Successful in 5m24s
2026-06-26 14:47:20 +02:00
klemek e883073ea7 fix: tld-list link with correct extension
Lint / Oxlint (push) Successful in 3m57s
Deploy / Build (push) Successful in 4m14s
Lint / TypeScript (push) Successful in 3m57s
Lint / ESLint (push) Successful in 4m7s
Deploy / Deploy to Stapler (push) Successful in 6m5s
2026-06-26 14:28:22 +02:00
klemek e5ab509c29 feat: whois timeout
Lint / Oxlint (push) Successful in 50s
Lint / ESLint (push) Successful in 58s
Lint / TypeScript (push) Successful in 58s
Deploy / Build (push) Successful in 1m4s
Deploy / Deploy to Stapler (push) Successful in 7m9s
2026-06-26 14:16:33 +02:00
klemek e40a082c2a performances: async loading
Lint / Oxlint (push) Successful in 52s
Lint / TypeScript (push) Successful in 55s
Lint / ESLint (push) Successful in 59s
Deploy / Build (push) Successful in 1m3s
Deploy / Deploy to Stapler (push) Successful in 6m4s
2026-06-26 11:53:44 +02:00
klemek c41bdbec06 fix: factory ext
Lint / Oxlint (push) Successful in 7m41s
Lint / TypeScript (push) Successful in 7m41s
Deploy / Build (push) Successful in 8m6s
Lint / ESLint (push) Successful in 8m5s
Deploy / Deploy to Stapler (push) Successful in 3m58s
2026-06-26 11:06:51 +02:00
9 changed files with 128 additions and 101 deletions
+15 -30
View File
@@ -1,15 +1,20 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, onMounted, onBeforeMount } from "vue"; import { ref, onMounted, defineAsyncComponent, onBeforeMount } from "vue";
import PageRandom from "@/components/PageRandom.vue"; const PageRandom = defineAsyncComponent(() => import("@/components/PageRandom.vue"));
import PageInput from "@/components/PageInput.vue"; const PageInput = defineAsyncComponent(() => import("@/components/PageInput.vue"));
const PageHistory = defineAsyncComponent(() => import("./components/PageHistory.vue"));
import { DomainFactory } from "@/lib/factory"; import { DomainFactory } from "@/lib/factory";
import PageHistory from "./components/PageHistory.vue"; import { getCookie, IGNORED_TLDS_COOKIE } from "@/lib/cookies";
const visible = ref<boolean>(false); const visible = ref<boolean>(false);
const factory = ref<DomainFactory>(new DomainFactory()); const factory = ref<DomainFactory>(new DomainFactory());
onBeforeMount(() => { onBeforeMount(() => {
factory.value.init(); factory.value.ignoreTlds(
...getCookie(IGNORED_TLDS_COOKIE)
.split(".")
.filter((tld: string) => tld.length),
);
}); });
onMounted(() => { onMounted(() => {
@@ -22,37 +27,17 @@ onMounted(() => {
<template> <template>
<div :style="{ display: visible ? 'inherit' : 'none' }"> <div :style="{ display: visible ? 'inherit' : 'none' }">
<div class="tabs tabs-xs tabs-bottom w-xl max-w-svw shrink-0"> <div class="tabs tabs-xs tabs-bottom w-xl max-w-svw shrink-0">
<input <input type="radio" name="app_tabs" class="tab" :aria-label="$t('tab.random')" checked />
type="radio" <div class="tab-content bg-base-100 border-base-300 shadow-2xl p-6 overflow-hidden">
name="app_tabs"
class="tab"
:aria-label="$t('tab.random')"
checked
/>
<div
class="tab-content bg-base-100 border-base-300 shadow-2xl p-6 overflow-hidden"
>
<PageRandom :factory="factory" /> <PageRandom :factory="factory" />
</div> </div>
<input <input type="radio" name="app_tabs" class="tab" :aria-label="$t('tab.input')" />
type="radio" <div class="tab-content bg-base-100 border-base-300 shadow-2xl p-6 overflow-hidden">
name="app_tabs"
class="tab"
:aria-label="$t('tab.input')"
/>
<div
class="tab-content bg-base-100 border-base-300 shadow-2xl p-6 overflow-hidden"
>
<PageInput :factory="factory" /> <PageInput :factory="factory" />
</div> </div>
<input <input type="radio" name="app_tabs" class="tab" :aria-label="$t('tab.history')" />
type="radio"
name="app_tabs"
class="tab"
:aria-label="$t('tab.history')"
/>
<div <div
class="tab-content bg-base-100 border-base-300 shadow-2xl p-6 overflow-x-hidden overflow-y-scroll max-h-96" class="tab-content bg-base-100 border-base-300 shadow-2xl p-6 overflow-x-hidden overflow-y-scroll max-h-96"
> >
+2 -1
View File
@@ -1,6 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import type { DomainFactory } from "@/lib/factory"; import type { DomainFactory } from "@/lib/factory";
import CoolDomain from "./CoolDomain.vue"; import { defineAsyncComponent } from "vue";
const CoolDomain = defineAsyncComponent(() => import("./CoolDomain.vue"));
defineProps<{ factory: DomainFactory }>(); defineProps<{ factory: DomainFactory }>();
</script> </script>
+3 -3
View File
@@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref } from "vue"; import { defineAsyncComponent, ref } from "vue";
import type { DomainFactory } from "@/lib/factory"; import type { DomainFactory } from "@/lib/factory";
import CoolDomain from "./CoolDomain.vue"; const CoolDomain = defineAsyncComponent(() => import("./CoolDomain.vue"));
import type { Domain } from "@/types"; import type { Domain } from "@/types";
import { isDomainAvailable } from "@/lib/whois"; import { isDomainAvailable } from "@/lib/whois";
@@ -62,7 +62,7 @@ function newDomain() {
<span v-else-if="domain.available" <span v-else-if="domain.available"
>&nbsp;{{ $t("seems") }} >&nbsp;{{ $t("seems") }}
<a <a
:href="`https://tld-list.com/${$i18n.locale}/tld/${domain.name?.split('.')[1]}`" :href="`https://tld-list.com/${$i18n.locale}/tld/${domain.tld}`"
target="_blank" target="_blank"
class="underline" class="underline"
>{{ $t("available") }}</a >{{ $t("available") }}</a
+10 -8
View File
@@ -1,10 +1,11 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, onBeforeMount, watch } from "vue"; import { ref, onBeforeMount, watch, defineAsyncComponent } from "vue";
import { isDomainAvailable } from "@/lib/whois"; import { isDomainAvailable } from "@/lib/whois";
import type { DomainFactory } from "@/lib/factory"; import type { DomainFactory } from "@/lib/factory";
import CoolDomain from "./CoolDomain.vue"; const CoolDomain = defineAsyncComponent(() => import("./CoolDomain.vue"));
import type { Domain } from "@/types"; import type { Domain } from "@/types";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { IGNORED_TLDS_COOKIE, setCookie } from "@/lib/cookies";
enum State { enum State {
Loading, Loading,
@@ -60,9 +61,10 @@ function checkAvailability() {
} }
} }
function removeExt() { function removeTld() {
if (domain.value) { if (domain.value) {
props.factory.removeExt(domain.value.extension); props.factory.ignoreTlds(domain.value.tld);
setCookie(IGNORED_TLDS_COOKIE, props.factory.ignoredTldList.join(","));
newDomain(); newDomain();
} }
} }
@@ -108,7 +110,7 @@ watch(i18n.locale, newDomain);
<div v-else-if="state === State.Ready && domain?.available" class="py-6"> <div v-else-if="state === State.Ready && domain?.available" class="py-6">
{{ $t("this_domain") }} {{ $t("seems") }} {{ $t("this_domain") }} {{ $t("seems") }}
<a <a
:href="`https://tld-list.com/${$i18n.locale}/tld/${domain.name?.split('.')[1]}`" :href="`https://tld-list.com/${$i18n.locale}/tld/${domain.tld}`"
target="_blank" target="_blank"
class="underline" class="underline"
>{{ $t("available") }}</a >{{ $t("available") }}</a
@@ -129,10 +131,10 @@ watch(i18n.locale, newDomain);
{{ $t("button.new_domain") }} {{ $t("button.new_domain") }}
</button> </button>
<br /> <br />
<p v-if="domain && state === State.Ready"> <p v-if="domain">
<small <small
><a class="underline" href="#" @click.prevent="removeExt">{{ ><a class="underline" href="#" @click.prevent="removeTld">{{
$t("page_random.dont_suggest", { ext: `.${domain.extension}` }) $t("page_random.dont_suggest", { ext: `.${domain.tld}` })
}}</a></small }}</a></small
> >
</p> </p>
+20
View File
@@ -0,0 +1,20 @@
export function setCookie(name: string, value: string, days = 400) {
const date = new Date();
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
const expires = `expires=${date.toUTCString()}`;
document.cookie = `${name}=${value}; path=/; ${expires}`;
}
export function getCookie(name: string, defaultValue = ""): string {
const prefix = `${name}=`;
const decodedCookie = decodeURIComponent(document.cookie);
const cookies = decodedCookie.split(";");
for (const cookie of cookies) {
if (cookie.trim().startsWith(prefix)) {
return cookie.trim().substring(prefix.length, cookie.length);
}
}
return defaultValue;
}
export const IGNORED_TLDS_COOKIE = "ignored_tlds";
+68 -41
View File
@@ -1,22 +1,31 @@
import rawTldList from "@/data/tld.txt?raw"; const rawTldList = () => import("@/data/tld.txt?raw");
import englishWords from "@/data/english.txt?raw"; const englishWords = () => import("@/data/english.txt?raw");
import frenchWords from "@/data/french.txt?raw"; const frenchWords = () => import("@/data/french.txt?raw");
import { randomElement, shuffled } from "./random"; import { randomElement, shuffled } from "./random";
import type { Domain } from "@/types"; import type { Domain } from "@/types";
const TLD_LIST: string[] = rawTldList.trim().split("\n");
export class DomainFactory { export class DomainFactory {
error: string | null = null; error: string | null = null;
words: Record<string, string[]> = {}; words: Record<string, string[]> = {};
generated: string[] = []; generated: string[] = [];
history: Domain[] = []; history: Domain[] = [];
tldList: string[] = []; tldList: string[] = [];
ignoredTldList: string[] = [];
init() { async init(lang: string | null = null) {
this.words.fr = this.initWords(frenchWords); if (lang && !this.words[lang]) {
this.words.en = this.initWords(englishWords); switch (lang) {
this.tldList = TLD_LIST; case "en":
this.words.en = this.initWords((await englishWords()).default);
break;
case "fr":
this.words.fr = this.initWords((await frenchWords()).default);
break;
}
}
if (this.tldList.length == 0) {
this.tldList = (await rawTldList()).default.trim().split("\n");
}
} }
escapeWord(word: string): string { escapeWord(word: string): string {
@@ -50,6 +59,9 @@ export class DomainFactory {
randomDomain(word: string): string | null { randomDomain(word: string): string | null {
for (const tld of shuffled(this.tldList.slice())) { for (const tld of shuffled(this.tldList.slice())) {
if (this.ignoredTld(tld)) {
continue;
}
const tldEscaped: string = tld.replace(".", ""); const tldEscaped: string = tld.replace(".", "");
if (word.endsWith(tldEscaped) && word.length > tldEscaped.length + 2) { if (word.endsWith(tldEscaped) && word.length > tldEscaped.length + 2) {
const domain = `${word.substring(0, word.length - tldEscaped.length)}.${tld}`; const domain = `${word.substring(0, word.length - tldEscaped.length)}.${tld}`;
@@ -64,55 +76,70 @@ export class DomainFactory {
next(lang: string): Promise<Domain> { next(lang: string): Promise<Domain> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let k = 10000; this.init(lang)
while (k > 0) { .then(() => {
k--; let k = 10000;
const word = this.randomWord(lang); while (k > 0) {
const domain = this.randomDomain(word); k--;
if (domain) { const word = this.randomWord(lang);
const output = this.newDomain(domain); const domain = this.randomDomain(word);
this.history.push(output); if (domain) {
resolve(output); const output = this.newDomain(domain);
return; this.history.push(output);
} resolve(output);
} return;
this.error = "Could not generate a valid domain"; }
reject(new Error(this.error)); }
this.error = "Could not generate a valid domain";
reject(new Error(this.error));
})
.catch(reject);
}); });
} }
removeExt(ext: string): void { ignoreTlds(...tlds: string[]): void {
this.tldList = this.tldList.filter((tld: string) => tld !== ext && !tld.endsWith(ext)); this.ignoredTldList.push(...tlds);
} }
newDomain(domain: string): Domain { newDomain(domain: string): Domain {
return { return {
name: domain, name: domain,
extension: domain.split(".", 1)[1] ?? "", tld: domain.split(".").slice(1).join("."),
searching: false, searching: false,
available: true, available: true,
}; };
} }
ignoredTld(tld: string): boolean {
return this.ignoredTldList.some((ignoredTld: string) => tld.endsWith(ignoredTld));
}
allFromWord(word: string): Promise<Domain[]> { allFromWord(word: string): Promise<Domain[]> {
const escapedWord = this.escapeWord(word.replace(/ /gm, "-")); const escapedWord = this.escapeWord(word.replace(/ /gm, "-"));
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const domains = []; this.init()
for (const tld of shuffled(this.tldList.slice())) { .then(() => {
const tldEscaped: string = tld.replace(".", ""); const domains = [];
if (escapedWord.endsWith(tldEscaped) && escapedWord.length >= tldEscaped.length + 2) { for (const tld of shuffled(this.tldList.slice())) {
const domain = `${escapedWord.substring(0, escapedWord.length - tldEscaped.length)}.${tld}`; if (this.ignoredTld(tld)) {
if (!domain.includes("-.")) { continue;
const output = this.newDomain(domain); }
this.history.push(output); const tldEscaped: string = tld.replace(".", "");
domains.push(output); if (escapedWord.endsWith(tldEscaped) && escapedWord.length >= tldEscaped.length + 2) {
const domain = `${escapedWord.substring(0, escapedWord.length - tldEscaped.length)}.${tld}`;
if (!domain.includes("-.")) {
const output = this.newDomain(domain);
this.history.push(output);
domains.push(output);
}
}
} }
} if (domains.length) {
} resolve(domains);
if (domains.length) { }
resolve(domains); reject(new Error("Could not generate a valid domain"));
} })
reject(new Error("Could not generate a valid domain")); .catch(reject);
}); });
} }
} }
+5 -13
View File
@@ -1,10 +1,4 @@
import type { import type { WhoIsResponse, WhoIsData, WhoIsEvent, WhoIsIpAddresses, Domain } from "@/types";
WhoIsResponse,
WhoIsData,
WhoIsEvent,
WhoIsIpAddresses,
Domain,
} from "@/types";
function checkEvents(events: WhoIsEvent[]): boolean { function checkEvents(events: WhoIsEvent[]): boolean {
for (const event of events) { for (const event of events) {
@@ -21,18 +15,16 @@ function checkIpAddresses(ipAddresses: WhoIsIpAddresses): boolean {
function checkWhoIsData(data: WhoIsData): boolean { function checkWhoIsData(data: WhoIsData): boolean {
return ( return (
checkEvents(data.events) && checkEvents(data.events) && checkIpAddresses(data.ipAddresses) && data.nameservers.length === 0
checkIpAddresses(data.ipAddresses) &&
data.nameservers.length === 0
); );
} }
export async function isDomainAvailable(domain: Domain): Promise<boolean> { export async function isDomainAvailable(domain: Domain): Promise<boolean> {
domain.searching = true; domain.searching = true;
try { try {
const response = await fetch( const response = await fetch(`https://whois.klemek.fr/api/lookup/${domain.name}`, {
`https://whois.klemek.fr/api/lookup/${domain.name}`, signal: AbortSignal.timeout(5000),
); });
const content: WhoIsResponse = await response.json(); const content: WhoIsResponse = await response.json();
domain.available = checkWhoIsData(content.data); domain.available = checkWhoIsData(content.data);
} catch { } catch {
+4 -4
View File
@@ -1,8 +1,8 @@
import { createApp } from "vue"; import { createApp, defineAsyncComponent } from "vue";
import { createI18n } from "vue-i18n"; import { createI18n } from "vue-i18n";
import App from "./App.vue"; const App = defineAsyncComponent(() => import("./App.vue"));
import en from "./i18n/en.json"; const en = await import("./i18n/en.json");
import fr from "./i18n/fr.json"; const fr = await import("./i18n/fr.json");
function getLang() { function getLang() {
return document.location.hash === "#french" ? "fr" : "en"; return document.location.hash === "#french" ? "fr" : "en";
+1 -1
View File
@@ -34,7 +34,7 @@ export interface WhoIsEntity {
export interface Domain { export interface Domain {
name: string; name: string;
extension: string; tld: string;
available: boolean; available: boolean;
searching: boolean; searching: boolean;
} }