Usually we copy the page above the code to the console debugging, sometimes it appears after the copied code to add a description of the information (author, copyright and other information), each need to delete to run, so today to see how to ensure that the code we pasted do not carry this information?
(function() {Document.addeventlistener (' Copy ', (e) = ={e.preventdefault (); E.stoppropagation (); Console.info (' Trigger Replication event '); /** Returns a Selection object that represents the text range selected by the user or the current position of the cursor Selection.getrangeat returns a Range object containing the contents of the current selection*/Let text= Window.getselection (). Getrangeat (0); Let node= document.createelement (' div '); //the Clonecontents method copies the contents of the range (range) to a DocumentFragment objectNode.appendchild (Window.getselection (). Getrangeat (0). Clonecontents ()); /** The Clipboardevent.clipboarddata property holds a DataTransfer object, which can be used to: describe what data can be placed into the clipboard by the cut and copy event handlers, usually by calling SE Tdata (format, data) method; Gets the data that is copied into the Clipboard by the paste event handler, usually by calling the GetData (format) method*/ if(e.clipboarddata) {E.clipboarddata.setdata ("Text/html", node.innerhtml); E.clipboarddata.setdata ("Text/plain", text); }Else if(window.clipboarddata) {returnWindow.clipboardData.setData ("Text", text); } })}());
JS to monitor copy and paste