Initialize DOMParser only once

This commit is contained in:
Jimmy Cai 2022-01-18 20:08:02 +00:00 committed by GitHub
parent d256daeb0a
commit 0c0b207667

View File

@ -210,9 +210,9 @@ class Search {
/// Not fetched yet /// Not fetched yet
const jsonURL = this.form.dataset.json; const jsonURL = this.form.dataset.json;
this.data = await fetch(jsonURL).then(res => res.json()); this.data = await fetch(jsonURL).then(res => res.json());
const parser = new DOMParser();
for (const item of this.data) { for (const item of this.data) {
const parser = new DOMParser();
item.content = parser.parseFromString(item.content, 'text/html').body.innerText; item.content = parser.parseFromString(item.content, 'text/html').body.innerText;
} }
} }