[JavaScript] 给网页上选中的文本添加临时注释的JS代码 →→→→→进入此内容的聊天室

来自 , 2019-06-10, 写在 JavaScript, 查看 111 次.
URL http://www.code666.cn/view/09eb27de
  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

回复 "给网页上选中的文本添加临时注释的JS代码"

这儿你可以回复上面这条便签

captcha