I came to the realisation that I get mad whenever I accidently paste formatted text and that I am too lazy to use CTRL + SHIFT + V, so I wrote a tiny Google Chrome extension that removes formatting and markup information from text that you copy to your clipboard: Plain Text Copy And Paste
I recently have to do a lot of copy and paste work from websites to OpenOffice Calc and I lose my mind whenever the table cells contain styling that I did not mean to paste. Again, I am too lazy to use CTRL + SHIFT + V to “paste special” without formatting - especially since OpenOffice shows another selection dialogue (rant: Why on earth show a selection dialogue if there is only one item to choose from?!).
The source code of this extension can be found on GitHub: klovadis / Plain-Text-Copy-And-Paste.
How this extension works
Here’s the technical explanation on how the extension works: After the initialisation of the document the script.js file gets injected into each and every page that you visit. See the manifest.json file, lines 5 through 12. Also note that the script file is executed in its own scope, as explained here, that’s why the injection does not take place in an anonymous function.
When the script is run, it adds an event listener to the body that listens for the “keydown” event, thus when a keyboard key is pressed. If CTRL + C is pressed, the magic happens: A hidden textarea is created and selected, which holds the plain text version of the currently selected text. After about 100ms the textarea is being hidden again.
After executing the event listener function, Chrome proceeds to do what it is supposed to do, when CTRL + C is pressed: Copying the selected text to the clipboard. However, we changed the selection before this could happen. So by selecting text in a textarea, we got rid of any style information