Skip to content

Instantly share code, notes, and snippets.

@dieseltravis
Last active September 24, 2015 21:27
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 dieseltravis/811331 to your computer and use it in GitHub Desktop.
Save dieseltravis/811331 to your computer and use it in GitHub Desktop.
Unicode character html code
javascript:!function(n,t,e,o){e=t.prompt("char?",n.getSelection()),o=function(n,t,e){return t=n.charCodeAt(0),t>=55296&&56319>=t&&n.length>1&&(e=n.charCodeAt(1),e>=56320&&57343>=e)?1024*(t-55296)+e-56320+65536:t}(e),t.alert("HTML: &#"+o+"; \nURL: "+n.encodeURIComponent(e)+" \nUnicode: U+"+o.toString(16).toUpperCase())}(window,top)
// thx https://twitter.com/CodepointsNet/status/588685419262312448 !!
// see https://github.com/mathiasbynens/String.prototype.codePointAt/blob/master/codepointat.js#L30
(function (win, top, chr, code) {
chr = top.prompt("char?",win.getSelection());
code = (function (str, first, second) {
first = str.charCodeAt(0);
if (first >= 0xD800 && first <= 0xDBFF && str.length > 1) {
second = str.charCodeAt(1);
if (second >= 0xDC00 && second <= 0xDFFF) {
return (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
}
}
return first;
}(chr));
top.alert(
"HTML: &#"+code+"; \nURL: "+win.encodeURIComponent(chr)+" \nUnicode: U+"+code.toString(16).toUpperCase());
}(window, top));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment