Create function to create a new DOM parser (#1114)
This commit is contained in:
parent
7926821c48
commit
26dd0270d9
@ -109,7 +109,7 @@ class AudioDownloader {
|
||||
});
|
||||
const responseText = await response.text();
|
||||
|
||||
const dom = new NativeSimpleDOMParser(responseText);
|
||||
const dom = this._createSimpleDOMParser(responseText);
|
||||
for (const row of dom.getElementsByClassName('dc-result-row')) {
|
||||
try {
|
||||
const audio = dom.getElementByTagName('audio', row);
|
||||
@ -149,7 +149,7 @@ class AudioDownloader {
|
||||
});
|
||||
const responseText = await response.text();
|
||||
|
||||
const dom = new NativeSimpleDOMParser(responseText);
|
||||
const dom = this._createSimpleDOMParser(responseText);
|
||||
try {
|
||||
const audio = dom.getElementById(`audio_${expression}:${reading}`);
|
||||
if (audio !== null) {
|
||||
@ -237,4 +237,12 @@ class AudioDownloader {
|
||||
_arrayBufferToBase64(arrayBuffer) {
|
||||
return btoa(String.fromCharCode(...new Uint8Array(arrayBuffer)));
|
||||
}
|
||||
|
||||
_createSimpleDOMParser(content) {
|
||||
if (NativeSimpleDOMParser.isSupported()) {
|
||||
return new NativeSimpleDOMParser(content);
|
||||
} else {
|
||||
throw new Error('DOM parsing not supported');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -43,4 +43,8 @@ class NativeSimpleDOMParser {
|
||||
getTextContent(element) {
|
||||
return element.textContent;
|
||||
}
|
||||
|
||||
static isSupported() {
|
||||
return typeof DOMParser !== 'undefined';
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user