Skip to content

Instantly share code, notes, and snippets.

@mushtat
Last active August 29, 2015 14:23
Show Gist options
  • Save mushtat/dc0f8923e99d304d2777 to your computer and use it in GitHub Desktop.
Save mushtat/dc0f8923e99d304d2777 to your computer and use it in GitHub Desktop.
Detect all window properties that was added after script run
'use strict';
// ES6 Object.assign
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
if (!Object.assign) {
Object.defineProperty(Object, 'assign', {
enumerable: false,
configurable: true,
writable: true,
value: function(target) {
if (target === undefined || target === null) {
throw new TypeError('Cannot convert first argument to object');
}
var to = Object(target);
for (var i = 1; i < arguments.length; i++) {
var nextSource = arguments[i];
if (nextSource === undefined || nextSource === null) {
continue;
}
nextSource = Object(nextSource);
var keysArray = Object.keys(Object(nextSource));
for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) {
var nextKey = keysArray[nextIndex];
var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
if (desc !== undefined && desc.enumerable) {
to[nextKey] = nextSource[nextKey];
}
}
}
return to;
}
});
}
(function(){
var Detector = function(/*obj*/target){
this.target = target;
this.states = {
before : Object.assign({}, target),
after : {}
};
this.result = [];
};
Detector.prototype = {
check : function(){
this.result = [];
this.states.after = Object.assign({}, this.target);
for (var i in this.states.after) {
if (!this.states.before[i]) {
this.result.push(i);
}
}
return this.result;
}
};
window.detector = new Detector(window);
}());
// run window.detector.check() when you need to see changes in window object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment