给网页上选中的文本添加临时注释的JS代码
// Select some text in the current page and click the button to 
// add a comment; i.e. an editable textarea.
// The comment is only temporary but a screenshot could be taken.
// My site: andrew.dx.am
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;})();
// Here' the expanded code as well:
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;
}
)();



