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

37 lines
1,008 B
JavaScript
Raw Normal View History

(function() {
2014-05-12 11:22:21 +02:00
function injectScript(src, where) {
var elm = document.createElement('script');
elm.src = src;
document[where || 'head'].appendChild(elm);
2014-05-07 13:56:35 +02:00
}
2014-05-12 11:22:21 +02:00
var customjs = localStorage['customjs'];
if( customjs ) {
2014-07-26 08:22:51 +02:00
customjs = JSON.parse(customjs);
2014-05-12 11:22:21 +02:00
if( customjs.config.enable ) {
// Predefined include
if( customjs.config.include ) {
injectScript('https://ajax.googleapis.com/ajax/libs' + customjs.config.include);
}
// Extra include
2014-05-12 11:22:21 +02:00
var extra = (customjs.config.extra || '').split(';');
extra.forEach(function(line) {
if( line.substr(0, 1) !== '#' ) {
injectScript(line);
}
});
// Script
2014-07-26 08:22:51 +02:00
if( customjs.source ) {
2014-05-12 11:22:21 +02:00
setTimeout(function() {
injectScript(customjs.source, 'body');
}, 250);
}
2014-05-07 13:56:35 +02:00
}
}
2014-05-12 11:22:21 +02:00
})();