fix: tld-list link with correct extension
This commit is contained in:
+3
-1
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, defineAsyncComponent } from "vue";
|
||||
import { ref, onMounted, defineAsyncComponent, onBeforeMount } from "vue";
|
||||
const PageRandom = defineAsyncComponent(() => import("@/components/PageRandom.vue"));
|
||||
const PageInput = defineAsyncComponent(() => import("@/components/PageInput.vue"));
|
||||
const PageHistory = defineAsyncComponent(() => import("./components/PageHistory.vue"));
|
||||
@@ -8,6 +8,8 @@ import { DomainFactory } from "@/lib/factory";
|
||||
const visible = ref<boolean>(false);
|
||||
const factory = ref<DomainFactory>(new DomainFactory());
|
||||
|
||||
onBeforeMount(() => {});
|
||||
|
||||
onMounted(() => {
|
||||
setTimeout(() => {
|
||||
visible.value = true;
|
||||
|
||||
@@ -62,7 +62,7 @@ function newDomain() {
|
||||
<span v-else-if="domain.available"
|
||||
> {{ $t("seems") }}
|
||||
<a
|
||||
:href="`https://tld-list.com/${$i18n.locale}/tld/${domain.name?.split('.')[1]}`"
|
||||
:href="`https://tld-list.com/${$i18n.locale}/tld/${domain.extension}`"
|
||||
target="_blank"
|
||||
class="underline"
|
||||
>{{ $t("available") }}</a
|
||||
|
||||
@@ -62,7 +62,7 @@ function checkAvailability() {
|
||||
|
||||
function removeExt() {
|
||||
if (domain.value) {
|
||||
props.factory.removeExt(domain.value.extension);
|
||||
props.factory.removeExtensions(domain.value.extension);
|
||||
newDomain();
|
||||
}
|
||||
}
|
||||
@@ -108,7 +108,7 @@ watch(i18n.locale, newDomain);
|
||||
<div v-else-if="state === State.Ready && domain?.available" class="py-6">
|
||||
{{ $t("this_domain") }} {{ $t("seems") }}
|
||||
<a
|
||||
:href="`https://tld-list.com/${$i18n.locale}/tld/${domain.name?.split('.')[1]}`"
|
||||
:href="`https://tld-list.com/${$i18n.locale}/tld/${domain.extension}`"
|
||||
target="_blank"
|
||||
class="underline"
|
||||
>{{ $t("available") }}</a
|
||||
|
||||
+13
-2
@@ -10,6 +10,7 @@ export class DomainFactory {
|
||||
generated: string[] = [];
|
||||
history: Domain[] = [];
|
||||
tldList: string[] = [];
|
||||
ignoredTldList: string[] = [];
|
||||
|
||||
async init(lang: string | null = null) {
|
||||
if (lang && !this.words[lang]) {
|
||||
@@ -58,6 +59,9 @@ export class DomainFactory {
|
||||
|
||||
randomDomain(word: string): string | null {
|
||||
for (const tld of shuffled(this.tldList.slice())) {
|
||||
if (this.ignoredTld(tld)) {
|
||||
continue;
|
||||
}
|
||||
const tldEscaped: string = tld.replace(".", "");
|
||||
if (word.endsWith(tldEscaped) && word.length > tldEscaped.length + 2) {
|
||||
const domain = `${word.substring(0, word.length - tldEscaped.length)}.${tld}`;
|
||||
@@ -93,8 +97,8 @@ export class DomainFactory {
|
||||
});
|
||||
}
|
||||
|
||||
removeExt(ext: string): void {
|
||||
this.tldList = this.tldList.filter((tld: string) => tld !== ext && !tld.endsWith(ext));
|
||||
removeExtensions(...extensions: string[]): void {
|
||||
this.ignoredTldList.push(...extensions);
|
||||
}
|
||||
|
||||
newDomain(domain: string): Domain {
|
||||
@@ -106,6 +110,10 @@ export class DomainFactory {
|
||||
};
|
||||
}
|
||||
|
||||
ignoredTld(tld: string): boolean {
|
||||
return this.ignoredTldList.some((ignoredTld: string) => tld.endsWith(ignoredTld));
|
||||
}
|
||||
|
||||
allFromWord(word: string): Promise<Domain[]> {
|
||||
const escapedWord = this.escapeWord(word.replace(/ /gm, "-"));
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -113,6 +121,9 @@ export class DomainFactory {
|
||||
.then(() => {
|
||||
const domains = [];
|
||||
for (const tld of shuffled(this.tldList.slice())) {
|
||||
if (this.ignoredTld(tld)) {
|
||||
continue;
|
||||
}
|
||||
const tldEscaped: string = tld.replace(".", "");
|
||||
if (escapedWord.endsWith(tldEscaped) && escapedWord.length >= tldEscaped.length + 2) {
|
||||
const domain = `${escapedWord.substring(0, escapedWord.length - tldEscaped.length)}.${tld}`;
|
||||
|
||||
Reference in New Issue
Block a user