Skip to content

Commit

Permalink
feat: change approach and drop subdomain checker
Browse files Browse the repository at this point in the history
  • Loading branch information
piraces committed Oct 12, 2023
1 parent 37739f3 commit a6efc31
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 126 deletions.
32 changes: 7 additions & 25 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,14 @@ <h2 id="goal"><a href="#goal">#</a>Goal</h2>
</p>
</section>
<section class="topic">
<h2 id="subdomains"><a href="#subdomains">#</a>Subdomains</h2>
<h1 class="title"><a href="https://freedns.afraid.org/subdomain/edit.php">Click here to get your own subdomain!</a></h1>
</section>
<section class="topic">
<h2 id="subdomains"><a href="#subdomains">#</a>Current stats</h2>
<section class="nes-container with-title bottom-margin">

<h2 class="title">Check for available subdomains:</h2>
<div class="nes-field is-inline centered">
<input type="url" id="name_field" [ngClass]="getActualClass()" [(ngModel)]="subdomain"
(keydown)="changeInput()" (ngModelChange)="domainAvailable = false" (keyup.enter)="checkAvailability()" required>
<label for="name_field">.developer.li</label>
</div>
<div *ngIf="domainAvailableChecked == false">
<p style="color: red">{{subdomain}}.developer.li is not available</p>
</div>
<div *ngIf="domainAvailableChecked == true">
<p style="color: green">{{subdomain}}.developer.li is available!</p>
</div>
<div class="centered top-margin bottom-margin" *ngIf="checkingAvailability">
<progress class="nes-progress" [value]="progress" max="100"></progress>
</div>
<div class="centered top-margin bottom-margin" *ngIf="!domainAvailable">
<button type="button" [disabled]="checkingAvailability" [ngClass]="{'is-disabled': checkingAvailability}" class="nes-btn is-primary" (click)="checkAvailability()">Check availability</button>
</div>
<div class="centered top-margin bottom-margin" *ngIf="domainAvailable">
<button type="button" class="nes-btn is-success"
onclick="location.href='https://freedns.afraid.org/'">Hurray! Reserve subdomain</button>
</div>
<p [hidden]="subdomainCount === 0">{{subdomainCount}} subdomains registered and counting!</p>
<h2 [hidden]="subdomainCount === 0">
{{subdomainCount}} subdomains registered and counting! <i class="nes-icon trophy is-medium"></i>
</h2>
<p>Powered by FreeDNS: <a target="_blank" href="https://freedns.afraid.org/">freedns.afraid.org</a></p>
<p>Check out more available domains in their <a target="_blank"
href="https://freedns.afraid.org/domain/registry/">registry!</a></p>
Expand Down
73 changes: 0 additions & 73 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Component, Inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { DOCUMENT } from '@angular/common';
import { IPLookup } from '../interfaces/IPLookup';
import { LookupError } from 'src/interfaces/Error';

@Component({
selector: 'app-root',
Expand All @@ -11,17 +9,8 @@ import { LookupError } from 'src/interfaces/Error';
})

export class AppComponent {
domainAvailable = false;
domainAvailableChecked = undefined;
checkingAvailability = false;
progress = 0;
progressBarInterval: any;
subdomain: any;
baseDomain = '.developer.li';
basePrefix = 'https://json.geoiplookup.io/';
liberaPayUrl = 'https://liberapay.com/piraces';
registrySearchUrl = `https://api.allorigins.win/get?charset=ISO-8859-1&url=${encodeURIComponent('https://freedns.afraid.org/domain/registry/?sort=5&q=developer.li&submit=SEARCH')}`;
notOwned = 'Dosarrest';
actualYear = new Date().getFullYear();
subdomainCount = 0;

Expand All @@ -32,43 +21,14 @@ export class AppComponent {
this.getSubdomainsNumber();
}

public changeInput() {
this.domainAvailable = false;
this.domainAvailableChecked = undefined;
}

public supportMe() {
this.document.location.href = this.liberaPayUrl;
}

public getActualClass() {
if (typeof this.domainAvailableChecked === 'undefined') {
return 'nes-input';
} else if (this.domainAvailableChecked) {
return ['nes-input', 'is-success'];
} else if (!this.domainAvailableChecked) {
return ['nes-input', 'is-error'];
}
}

public startProgressBar() {
this.progressBarInterval = setInterval(() => {
if (this.progress >= 100) {
this.progress = 0;
} else {
this.progress += 10;
}
}, 200);
}

public stopProgressBar() {
clearInterval(this.progressBarInterval);
}

public getSubdomainsNumber() {
this.http.get(this.registrySearchUrl, {responseType: 'text'}).subscribe(
(data) => {
debugger;
if (data) {
const matches = data.match(/\([0-9]+\shosts\sin\suse\)/g);
if (matches && matches.length > 0) {
Expand All @@ -86,37 +46,4 @@ export class AppComponent {
}
);
}

public checkAvailability() {
if (this.subdomain && this.subdomain.length > 0) {
this.checkingAvailability = true;
this.startProgressBar();
this.http
.get(this.basePrefix + this.subdomain + this.baseDomain)
.subscribe(
(data) => {
let errorResponse = data as LookupError;
const response = data as IPLookup;

if (errorResponse && errorResponse.error && !errorResponse.success) {
this.domainAvailable = true;
this.domainAvailableChecked = true;
} else if (response && response.isp && !response.isp.toLowerCase().includes(this.notOwned.toLowerCase())) {
this.domainAvailable = false;
this.domainAvailableChecked = false;
} else {
this.domainAvailable = true;
this.domainAvailableChecked = true;
}
this.checkingAvailability = false;
this.stopProgressBar();
},
(_) => {
this.domainAvailable = false;
this.domainAvailableChecked = false;
this.checkingAvailability = false;
this.stopProgressBar();
});
}
}
}
1 change: 0 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { HttpClientModule } from '@angular/common/http';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { IPLookup } from '../interfaces/IPLookup';

@NgModule({
declarations: [
Expand Down
4 changes: 0 additions & 4 deletions src/interfaces/Error.ts

This file was deleted.

23 changes: 0 additions & 23 deletions src/interfaces/IPLookup.ts

This file was deleted.

0 comments on commit a6efc31

Please sign in to comment.