class Blog { constructor() { this.object = { body: document.getElementsByTagName('body')[0], section: document.getElementById('main'), blogButtonList: document.getElementsByClassName('bloglistbutton') } } Init() {this.#EventListener()} #EventListener() { for (let i = 0; i < this.object.blogButtonList.length; i++) { this.object.blogButtonList[i].addEventListener('click', () => { new Loading().Start() new Menu().HideIcon() this.#GetBlog(this.object.blogButtonList[i].value) }) } } #GetUrl() { if (window.location.href.endsWith('/')) { return `${window.location.href}item` } else { return `${window.location.href}/item` } } async #GetBlog(x) { const object = { url: this.#GetUrl(), value: x } await fetch(object.url, { method: 'post', body: JSON.stringify(object), headers: new Headers({ 'Content-Type': 'application/json' }) }) .then(res => res.json()) .then(output => { const object = output.html new Promise(res => { const script = document.createElement('script') script.src = `${window.location.origin}/js/blogitem.js` this.object.body.appendChild(script) script.onload = res }).then(output => { new BlogItem().Init(object) }) }) } } new Blog().Init()