Skip to content

Instantly share code, notes, and snippets.

@ticky
Created April 15, 2014 06:06
Show Gist options
  • Select an option

  • Save ticky/10706172 to your computer and use it in GitHub Desktop.

Select an option

Save ticky/10706172 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name ID Linker
// @namespace http://geoffstokes.net/
// @include *
// ==/UserScript==
(function () {
// TODO: Search up the DOM tree for the nearest ID.
Array.prototype.slice.call(document.querySelectorAll('[id]')).forEach(function (element) {
element.addEventListener('click', function (event) {
if (event.button === 1 && event.altKey) {
window.location.hash = "#" + element.id;
event.preventDefault();
event.stopPropagation();
}
});
});
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment