2014-05-04 08:44:18 +02:00
|
|
|
|
module.exports = function(el) {
|
|
|
|
|
|
// console.log("going to execute script", el)
|
|
|
|
|
|
|
|
|
|
|
|
var code = (el.text || el.textContent || el.innerHTML || "")
|
2017-09-18 14:13:39 +02:00
|
|
|
|
var parent = el.parentNode || document.querySelector("head") || document.documentElement
|
2014-05-04 08:44:18 +02:00
|
|
|
|
var script = document.createElement("script")
|
|
|
|
|
|
|
|
|
|
|
|
if (code.match("document.write")) {
|
|
|
|
|
|
if (console && console.log) {
|
|
|
|
|
|
console.log("Script contains document.write. Can’t be executed correctly. Code skipped ", el)
|
|
|
|
|
|
}
|
|
|
|
|
|
return false
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
script.type = "text/javascript"
|
|
|
|
|
|
try {
|
|
|
|
|
|
script.appendChild(document.createTextNode(code))
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (e) {
|
|
|
|
|
|
// old IEs have funky script nodes
|
|
|
|
|
|
script.text = code
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// execute
|
2017-09-18 14:13:39 +02:00
|
|
|
|
parent.appendChild(script);
|
|
|
|
|
|
// avoid pollution only in head or body tags
|
|
|
|
|
|
if (["head","body"].indexOf(parent.tagName.toLowerCase()) > 0) {
|
|
|
|
|
|
parent.removeChild(script)
|
|
|
|
|
|
}
|
2014-05-04 08:44:18 +02:00
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
}
|