(function () {
var addedScriptElemObserver = new MutationObserver(function(records, observer) {
for (var record of records) {
for (var addedNode of record.addedNodes) {
if(addedNode.nodeType === 1 && addedNode.nodeName == 'SCRIPT') {
var elemIdsToRemove = ['hs-script-loader'];
var elemId = addedNode.getAttribute('id');
var shouldRemoveElem = false;
if(elemId && elemIdsToRemove.indexOf(elemId) >= 0) {
shouldRemoveElem = true;
}
if(shouldRemoveElem) {
var observedTargetElemName = record.target.nodeName;
console.log(`Found "${elemId}" element being added to "${observedTargetElemName}"! Removing the element.`);
addedNode.remove();
// Firefox has this additional event which prevents scripts from being executed
const beforeScriptExecuteListener = function (event) {
event.preventDefault();
addedNode.removeEventListener('beforescriptexecute', beforeScriptExecuteListener);
}
addedNode.addEventListener('beforescriptexecute', beforeScriptExecuteListener);
}
}
}
}
});
var bodyElem = document.querySelector('html > body');
if(bodyElem) {
console.debug('Watching the "body" element for "script" elements added...');
addedScriptElemObserver.observe(bodyElem, { childList: true });
}
var headElem = document.querySelector('html > head');
if(headElem) {
console.debug('Watching the "head" element for "script" elements added...');
addedScriptElemObserver.observe(headElem, { childList: true });
}
})();