Skip to content

Instantly share code, notes, and snippets.

@mathiasbynens
Last active June 3, 2023 08:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mathiasbynens/7083110 to your computer and use it in GitHub Desktop.
Save mathiasbynens/7083110 to your computer and use it in GitHub Desktop.
Quick and dirty user script that displays a Markdown-formatted link to the current code point detail page after double-clicking the title

Try it on the detail page for U+1F4A9 PILE OF POO, for example.

Screenshot after double-clicking the <h1>:

// ==UserScript==
// @name CodePoints.net: Double-click title to show Markdown-formatted link
// @author Mathias Bynens <http://mathiasbynens.be/>
// @match http://codepoints.net/U+*
// ==/UserScript==
(function(document) {
var h1 = document.querySelector('h1');
var text = h1.textContent;
var url = document.location;
var markdown = '[' + text + '](' + url + ')';
h1.addEventListener('dblclick', function() {
var element = document.createElement('code');
element.textContent = markdown;
h1.innerHTML = element.outerHTML;
var selection = window.getSelection();
var range = document.createRange();
range.selectNodeContents(h1);
selection.removeAllRanges();
selection.addRange(range);
});
}(document));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment