Skip to content

Instantly share code, notes, and snippets.

@ccarterc
Forked from topliceanu/description.markdown
Created January 3, 2014 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ccarterc/8242828 to your computer and use it in GitHub Desktop.
Save ccarterc/8242828 to your computer and use it in GitHub Desktop.

This bookmarklet can be used to keep track of global variables attached to window.

It displays the user-defined global variables by comparing all properties attached on current window to all standard properties extracted from an empty iframe.

To install, create a new bookmark in your bookmark bar and copy-paste the contents of listGlobals.bookmarklet

(function(){var a;a=function(a){var b,c,d,e,f,g,h;f=a.document.createElement("iframe");f.src="about:blank";f.style.display="none";a.document.body.appendChild(f);h=f.contentWindow||f.contentWindow;g=function(){var a;a=[];for(c in h){a.push(c)}return a}();b=function(){var b;b=[];for(d in a){b.push(d)}return b}();return e=function(){var d,e,f;f=[];for(d=0,e=b.length;d<e;d++){c=b[d];if(g.indexOf(c)===-1&&a[c]!=null){f.push(c)}}return f}().sort()};alert(a(this))})()
javascript:(function(){var a;a=function(a){var b,c,d,e,f,g,h;f=a.document.createElement("iframe");f.src="about:blank";f.style.display="none";a.document.body.appendChild(f);h=f.contentWindow||f.contentWindow;g=function(){var a;a=[];for(c in h){a.push(c)}return a}();b=function(){var b;b=[];for(d in a){b.push(d)}return b}();return e=function(){var d,e,f;f=[];for(d=0,e=b.length;d<e;d++){c=b[d];if(g.indexOf(c)===-1&&a[c]!=null){f.push(c)}}return f}().sort()};alert(a(this))})();
listGlobals = (win) ->
iframe = win.document.createElement 'iframe'
iframe.src = 'about:blank'
iframe.style.display = 'none'
win.document.body.appendChild iframe
iframeWin = iframe.contentWindow || iframe.contentWindow
iframeGlobals = (g for g of iframeWin)
allGlobals = (global for global of win)
globals = (g for g in allGlobals when iframeGlobals.indexOf(g) is -1 and win[g]?)
.sort()
alert listGlobals this
(function () {
var listGlobals;
listGlobals = function(win) {
var allGlobals, g, global, globals, iframe, iframeGlobals, iframeWin;
iframe = win.document.createElement('iframe');
iframe.src = 'about:blank';
iframe.style.display = 'none';
win.document.body.appendChild(iframe);
iframeWin = iframe.contentWindow || iframe.contentWindow;
iframeGlobals = (function() {
var _results;
_results = [];
for (g in iframeWin) {
_results.push(g);
}
return _results;
})();
allGlobals = (function() {
var _results;
_results = [];
for (global in win) {
_results.push(global);
}
return _results;
})();
return globals = ((function() {
var _i, _len, _results;
_results = [];
for (_i = 0, _len = allGlobals.length; _i < _len; _i++) {
g = allGlobals[_i];
if (iframeGlobals.indexOf(g) === -1 && (win[g] != null)) {
_results.push(g);
}
}
return _results;
})()).sort();
};
alert(listGlobals(this));
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment