From fc46c8b8a9418da117183774ccb8298f63cc3be8 Mon Sep 17 00:00:00 2001
From: teramako
Date: Mon, 11 Feb 2013 21:59:29 +0900
Subject: add sanitizeScript and remove unused createHTMLDocument
---
lookupDictionary.js | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
(limited to 'lookupDictionary.js')
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`
@@ -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]*?]*)?>[ \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
--
cgit v1.2.3