Files
Romhack-Plaza---WordPress-P…/ts/admin/widgets/rhpz-url/class-rhpz-url.ts

50 lines
1.2 KiB
TypeScript
Raw Normal View History

2026-01-11 19:39:55 +01:00
declare const _romhackplaza_rhpz_url: any;
export class RhpzUrl {
container: HTMLElement;
form_field_url: HTMLInputElement|null;
form: HTMLElement|null;
output: HTMLElement|null;
constructor( selector: any ){
this.form_field_url = null;
this.form = null;
this.output = null;
this.container = document.querySelector( selector );
if ( !this.container )
return;
this.form_field_url = this.container.querySelector( '#FormUrl' );
this.form = this.container;
this.output = this.container.querySelector( '#Create-A-RHPZ-Url-Response' );
this.events();
}
events() {
this.form!.onsubmit = ( event ) => this.submit_request( event );
}
async submit_request( e: Event ){
e.preventDefault();
let url = this.form_field_url!.value;
url = url.replace("https://", "");
url = url.replace("http://", "");
const xhr = new XMLHttpRequest();
xhr.open( 'GET', _romhackplaza_rhpz_url.create_url + url, true );
xhr.onload = () => {
this.output!.innerHTML = '<a href="' + xhr.responseText + '" target="_blank">' + xhr.responseText + '</a>';
}
xhr.send();
}
}