From 7926821c48ad512b0c9bd2420216a36fe2237e4f Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Mon, 14 Dec 2020 22:56:38 -0500 Subject: Rename SimpleDOMParser to NativeSimpleDOMParser (#1113) --- ext/bg/background.html | 2 +- ext/bg/js/audio-downloader.js | 6 ++--- ext/bg/js/native-simple-dom-parser.js | 46 +++++++++++++++++++++++++++++++++++ ext/bg/js/simple-dom-parser.js | 46 ----------------------------------- 4 files changed, 50 insertions(+), 50 deletions(-) create mode 100644 ext/bg/js/native-simple-dom-parser.js delete mode 100644 ext/bg/js/simple-dom-parser.js diff --git a/ext/bg/background.html b/ext/bg/background.html index f42a411d..e139514d 100644 --- a/ext/bg/background.html +++ b/ext/bg/background.html @@ -39,7 +39,7 @@ - + diff --git a/ext/bg/js/audio-downloader.js b/ext/bg/js/audio-downloader.js index 77cd7294..ddddfe18 100644 --- a/ext/bg/js/audio-downloader.js +++ b/ext/bg/js/audio-downloader.js @@ -16,7 +16,7 @@ */ /* global - * SimpleDOMParser + * NativeSimpleDOMParser */ class AudioDownloader { @@ -109,7 +109,7 @@ class AudioDownloader { }); const responseText = await response.text(); - const dom = new SimpleDOMParser(responseText); + const dom = new NativeSimpleDOMParser(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 SimpleDOMParser(responseText); + const dom = new NativeSimpleDOMParser(responseText); try { const audio = dom.getElementById(`audio_${expression}:${reading}`); if (audio !== null) { diff --git a/ext/bg/js/native-simple-dom-parser.js b/ext/bg/js/native-simple-dom-parser.js new file mode 100644 index 00000000..2aa4134d --- /dev/null +++ b/ext/bg/js/native-simple-dom-parser.js @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2020 Yomichan Authors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +class NativeSimpleDOMParser { + constructor(content) { + this._document = new DOMParser().parseFromString(content, 'text/html'); + } + + getElementById(id, root=null) { + return (root || this._document).querySelector(`[id='${id}']`); + } + + getElementByTagName(tagName, root=null) { + return (root || this._document).querySelector(tagName); + } + + getElementsByTagName(tagName, root=null) { + return [...(root || this._document).querySelectorAll(tagName)]; + } + + getElementsByClassName(className, root=null) { + return [...(root || this._document).querySelectorAll(`.${className}`)]; + } + + getAttribute(element, attribute) { + return element.hasAttribute(attribute) ? element.getAttribute(attribute) : null; + } + + getTextContent(element) { + return element.textContent; + } +} diff --git a/ext/bg/js/simple-dom-parser.js b/ext/bg/js/simple-dom-parser.js deleted file mode 100644 index 258b1f76..00000000 --- a/ext/bg/js/simple-dom-parser.js +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2020 Yomichan Authors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -class SimpleDOMParser { - constructor(content) { - this._document = new DOMParser().parseFromString(content, 'text/html'); - } - - getElementById(id, root=null) { - return (root || this._document).querySelector(`[id='${id}']`); - } - - getElementByTagName(tagName, root=null) { - return (root || this._document).querySelector(tagName); - } - - getElementsByTagName(tagName, root=null) { - return [...(root || this._document).querySelectorAll(tagName)]; - } - - getElementsByClassName(className, root=null) { - return [...(root || this._document).querySelectorAll(`.${className}`)]; - } - - getAttribute(element, attribute) { - return element.hasAttribute(attribute) ? element.getAttribute(attribute) : null; - } - - getTextContent(element) { - return element.textContent; - } -} -- cgit v1.2.3