Skip to content

Instantly share code, notes, and snippets.

@michaelb958
Last active August 29, 2015 13:56
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 michaelb958/8927839 to your computer and use it in GitHub Desktop.
Save michaelb958/8927839 to your computer and use it in GitHub Desktop.
"On your keyboard, idiot!" - To quote SE user Macha on the <kbd> tag (http://meta.stackoverflow.com/posts/comments/3247): 'Now all they need is an onclick handler to make them look like you are pressing them. Then an alert box pops up and says "On your keyboard, idiot!".' Well, here you go.
// ==UserScript==
// @name On your keyboard, idiot!
// @description For those who just keep clicking <kbd>s.
// @namespace michaelb958
// @author michaelb958
// @license MIT (http://opensource.org/licenses/MIT)
// @include *://*.stackexchange.com/*
// @include *://*.stackoverflow.com/*
// @include *://*.serverfault.com/*
// @include *://*.superuser.com/*
// @include *://*.stackapps.com/*
// @include *://*.askubuntu.com/*
// @include *://*.mathoverflow.net/*
// ==/UserScript==
function with_jQuery(f) {
var s = document.createElement("script");
s.type = "text/javascript";
s.textContent = "(" + f.toString() + ")(jQuery)";
s.setAttribute('data-with-jquery', '');
document.head.appendChild(s);
};
with_jQuery(function($) {
$('<style type="text/css">')
.text('kbd:hover { border-style: outset; } kbd:active { border-style: inset; }')
.appendTo(document.head);
$(document).on('click', '*:not(a) > kbd:not(:has(a))', function() {
alert("On your keyboard, idiot!");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment