2
0
mirror of https://github.com/Y2Z/monolith synced 2024-11-05 06:01:10 +00:00
monolith/modules/js.js

28 lines
836 B
JavaScript
Raw Normal View History

2017-02-20 07:51:24 +00:00
'use strict';
var functions = require('../functions.js')
var retrieveFile = functions.retrieveFile
var dataURI = true // set to true to convert the src attribute to a dataURI link
module.exports = {
parser: function (window, absBasePath) {
var scripts = window.document.getElementsByTagName('script')
for (var i = 0, ilen = scripts.length; i < ilen; i++) {
if (scripts[i].getAttribute('src')) {
var data = retrieveFile(absBasePath, scripts[i].getAttribute('src').trim(), dataURI)
if (dataURI) {
scripts[i].setAttribute('src', "data:text/javascript;base64," + data)
} else {
scripts[i].removeAttribute('src')
scripts[i].innerHTML = data
}
}
}
}
}