Move MutationObserver shim

Since it will be used only for older Safari versions, move it to Safari
related code, so it doesn't pollute the content scripts.
This commit is contained in:
Deathamns 2014-11-11 17:14:54 +01:00
parent 36ad23a1db
commit 8f0b3cf592
2 changed files with 15 additions and 16 deletions

View File

@ -30,7 +30,7 @@
if (vAPI.safari) {
if (!/^https?:/.test(location.protocol)) {
throw "uBlock> contentscript-end.js > Skipping page: " + location.protocol + location.host;
throw "uBlock> contentscript-end.js > Skipping " + location.protocol;
}
}
@ -418,21 +418,6 @@ var messager = vAPI.messaging.channel('contentscript-end.js');
return;
}
if (!window.MutationObserver) {
window.MutationObserver = window.WebKitMutationObserver || window.MozMutationObserver;
// dummy shim for older browsers
if (!window.MutationObserver) {
window.MutationObserver = function(handler) {
this.observe = function(target) {
target.addEventListener('DOMNodeInserted', function(e) {
handler([{addedNodes: [e.target]}]);
}, true);
};
}
}
}
var ignoreTags = {
'link': true,
'LINK': true,

View File

@ -197,6 +197,20 @@ if (self.chrome) {
return;
}
window.MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
if (!window.MutationObserver) {
// dummy, minimalistic shim for older versions (<6)
// only supports node insertions, but currently we don't use it for anything else
window.MutationObserver = function(handler) {
this.observe = function(target) {
target.addEventListener('DOMNodeInserted', function(e) {
handler([{addedNodes: [e.target]}]);
}, true);
};
}
}
var beforeLoadEvent = document.createEvent('Event');
beforeLoadEvent.initEvent('beforeload');