JS code to add temporary comments to the selected text on the web page

From , 4 Years ago, written in JavaScript, viewed 54 times.
URL https://pastebin.vip/view/c5df4f4e
  1. // Select some text in the current page and click the button to
  2. // add a comment; i.e. an editable textarea.
  3. // The comment is only temporary but a screenshot could be taken.
  4. // My site: andrew.dx.am
  5.  
  6. 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;})();
  7.  
  8. // Here' the expanded code as well:
  9. javascript:
  10. (function(){
  11.   var d=document;
  12.   var wrap=d.createElement('span');
  13.   wrap.style.position='relative';
  14.   wrap.className='wrap';
  15.   var cmt=d.createElement('textarea');
  16.   cmt.style.backgroundColor='yellow';
  17.   cmt.style.top='1.5em';
  18.   cmt.style.position='absolute';
  19.   cmt.style.zIndex='99';
  20.   cmt.className='cmt';
  21.   cmt.style.height='4em';
  22.   cmt.style.width='170px';
  23.   if(window.getSelection){
  24.     var sel=window.getSelection();
  25.     if(sel.rangeCount){
  26.       var rng=sel.getRangeAt(0).cloneRange();
  27.       rng.surroundContents(wrap);
  28.       sel.removeAllRanges();
  29.       sel.addRange(rng);
  30.       wrap.insertBefore(cmt,wrap.firstChild);
  31.       cmt.thetext=rng;
  32.       cmt.focus();
  33.     }
  34.   }
  35.   return false;
  36. }
  37. )();
  38. //javascript/5209

Reply to "JS code to add temporary comments to the selected text on the web page"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website