There is a site where a custom function is triggered when copying, which adds additional text to the copied text, and also kills all the markup, merging all paragraphs into one continuous text, losing headlines, etc.

Is it possible to somehow prohibit the execution of a user-defined function for a copy event? Well, or after downloading the entire site, at least execute document.removeEventListener('copy', addLink);

From the developer's console, it will not work, because An earlier binding was made inside the anonymous jQuery function: $(function() { ... document.addEventListener('copy', addLink); ... function addLink() { .. } } .

I would be grateful for the hint.

1 answer 1

Paste the code into the developer console and everything will work:

 document.addEventListener('copy', e => e.stopPropagation(), true); 

Here the assignment of the handler to the capture stage is used . Handlers of this stage are called first, earlier than handlers of child elements or the stage of ascent. After an event is intercepted, its distribution is stopped using the stopPropagation () method, canceling the rest of the handlers.

This will work for all cases, unless the page itself has assigned a handler to the capture stage for the entire document.

For the lazy, I made an extension for Google Chrome, so far only for it, but it can be useful for such cases:

https://chrome.google.com/webstore/search/truecopy?hl=en

  • Try to write more detailed answers. Suppose what your code does in response - Grundy
  • it does exactly what I asked for, namely, it blocks the execution of a user function hung on a copy event. - Arsen Bespalov
  • Add an explanation directly to the answer. Desirable with an explanation of how this works - Grundy
  • 2
    @Qwertiy, because the code block says nothing :-) Answers only from the code are bad and in no way help to understand why this code worked - Grundy
  • one
    Under the link finds nothing - Grundy