Skip to content

Instantly share code, notes, and snippets.

@agibsonsw
Created January 8, 2016 22:13
Show Gist options
  • Save agibsonsw/5a4702c0b697c6f4bb66 to your computer and use it in GitHub Desktop.
Save agibsonsw/5a4702c0b697c6f4bb66 to your computer and use it in GitHub Desktop.
Bookmarklet to add a comment box at selection
javascript: (function() {
var d = document;
var wrap = d.createElement('span');
wrap.style.position = 'relative';
wrap.className = 'wrap';
var cmt = d.createElement('textarea');
cmt.style.backgroundColor = 'yellow';
cmt.style.top = '1.5em';
cmt.style.position = 'absolute';
cmt.style.zIndex = '99';
cmt.className = 'cmt';
cmt.style.height = '4em';
cmt.style.width = '170px';
if (window.getSelection) {
var sel = window.getSelection();
if (sel.rangeCount) {
var rng = sel.getRangeAt(0).cloneRange();
rng.surroundContents(wrap);
sel.removeAllRanges();
sel.addRange(rng);
wrap.insertBefore(cmt, wrap.firstChild);
cmt.thetext = rng;
cmt.focus();
}
}
return false;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment