Skip to content

Instantly share code, notes, and snippets.

@ashmind
Last active December 10, 2015 16:38
Show Gist options
  • Save ashmind/4461836 to your computer and use it in GitHub Desktop.
Save ashmind/4461836 to your computer and use it in GitHub Desktop.
Just a small fun thing — if used as a bookmarklet (crunched with http://ted.mielczarek.org/code/mozilla/bookmarklet.html), creates a circular hole in the current page that you can use to peek at html code beneath. Chrome/Safari only.
var init = function($) {
$("<style type='text/css'></style>").text('.cx { background: #f5f2f0; color: black; }' +
' .cx .tag { color: #999; }' +
' .cx .tag .title, .cx .css .attribute { color: #905; }' +
' .cx .tag .attribute, .cx .string, .cx .css .tag, .cx .css .class { color: #690; }' +
' .cx .tag .value, .cx .keyword { color: #07a; }' +
' .cx { font-family: Consolas, Courier New; position: absolute; z-index: 50000; left: 0; top: 0; right: 0; white-space: pre; }')
.appendTo($('head'));
var source = $('<code></code>').text(document.documentElement.outerHTML)
.addClass('cx')
.hide()
.appendTo($('body'));
var centerX = 0;
var centerY = 0;
var radius = 100;
var updateMask = function() {
source[0].style.webkitMask = 'url(\'data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="' + 2*radius + '" height="' + 2*radius + '"><circle cx="50%" cy="50%" r="' + radius + '" fill="red" /></svg>\') no-repeat ' + (centerX - radius) + 'px ' + (centerY - radius) + 'px';
};
updateMask();
source.show();
$(document).mousemove(function(e) {
centerX = e.pageX;
centerY = e.pageY;
updateMask();
});
$(document).mousewheel(function(e, delta) {
e.preventDefault();
radius += delta * 3;
updateMask();
});
hljs.highlightBlock(source[0]);
};
var require = function(condition, url, callback) {
if (condition) {
callback();
return;
}
var done = false;
var script = document.createElement("script");
script.src = url;
script.onload = script.onreadystatechange = function() {
if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
done = true;
callback();
}
};
document.getElementsByTagName("head")[0].appendChild(script);
};
require(window.jQuery !== undefined, '//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js', function() {
require(window.jQuery.fn.mousewheel !== undefined, '//cdnjs.cloudflare.com/ajax/libs/jquery-mousewheel/3.0.6/jquery.mousewheel.min.js', function() {
require(window.hljs !== undefined, '//cdnjs.cloudflare.com/ajax/libs/highlight.js/7.3/highlight.min.js', function() {
init(window.jQuery);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment