diff options
author | teramako | 2013-02-11 21:59:29 +0900 |
---|---|---|
committer | teramako | 2013-02-11 21:59:29 +0900 |
commit | fc46c8b8a9418da117183774ccb8298f63cc3be8 (patch) | |
tree | f69e6c34ab88c4a3c13f70528cf20f5571a1181f /lookupDictionary.js | |
parent | aa354ab95bd6a31e218264e224aa7e9838cfc983 (diff) | |
download | vimperator-plugins-fc46c8b8a9418da117183774ccb8298f63cc3be8.tar.bz2 |
add sanitizeScript and remove unused createHTMLDocument
Diffstat (limited to 'lookupDictionary.js')
-rw-r--r-- | lookupDictionary.js | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/lookupDictionary.js b/lookupDictionary.js index 4ca4e39..67b8cef 100644 --- a/lookupDictionary.js +++ b/lookupDictionary.js @@ -170,6 +170,7 @@ SITE_DEFINITION.forEach(function (dictionary) { liberator.echoerr('Nothing to show...'); return; } + result = sanitizeScript(result); var xs = new XMLSerializer(); liberator.echo(xml`<div style="white-space:normal;"> <base href=${util.escapeHTML(url)}/> @@ -227,16 +228,15 @@ function getHTML(url, callback, charset) { xhr.send(null); } /** - * @param {String} str - * @return {DOMDocument} + * sanitize script element + * @param {Element} element + * @return {Element} */ -function createHTMLDocument(str) { - str = str.replace(/^[\s\S]*?<html(?:[ \t\r\n][^>]*)?>[ \t\n\r]*|[ \t\n\r]*<\/html[ \t\r\n]*>[\S\s]*$/ig,'').replace(/[\r\n]+/g,' '); - var htmlFragment = content.document.implementation.createDocument(null,'html',null); - var range = content.document.createRange(); - range.setStartAfter(window.content.document.body); - htmlFragment.documentElement.appendChild(htmlFragment.importNode(range.createContextualFragment(str),true)); - return htmlFragment; +function sanitizeScript (element) { + for (let node of element.querySelectorAll("script")){ + node.parentNode.removeChild(node); + } + return element; } /** * @param {String} xpath XPath Expression |