1
0
Fork 0
This repository has been archived on 2024-06-28. You can view files and clone it, but cannot push or open issues or pull requests.
matomo-injector/lib/run.js
2014-07-26 09:07:57 +02:00

36 lines
1,008 B
JavaScript

(function() {
function injectScript(src, where) {
var elm = document.createElement('script');
elm.src = src;
document[where || 'head'].appendChild(elm);
}
var customjs = localStorage['customjs'];
if( customjs ) {
customjs = JSON.parse(customjs);
if( customjs.config.enable ) {
// Predefined include
if( customjs.config.include ) {
injectScript('https://ajax.googleapis.com/ajax/libs' + customjs.config.include);
}
// Extra include
var extra = (customjs.config.extra || '').split(';');
extra.forEach(function(line) {
if( line.substr(0, 1) !== '#' ) {
injectScript(line);
}
});
// Script
if( customjs.source ) {
setTimeout(function() {
injectScript(customjs.source, 'body');
}, 250);
}
}
}
})();