Skip to content

Instantly share code, notes, and snippets.

@VladimirCores
Created September 29, 2019 13:09
Show Gist options
  • Select an option

  • Save VladimirCores/8e3ea60ae8c37c008181b4265d6ae991 to your computer and use it in GitHub Desktop.

Select an option

Save VladimirCores/8e3ea60ae8c37c008181b4265d6ae991 to your computer and use it in GitHub Desktop.
Remove breaks from text and copy to clipboard
function copyToClipboard(text) {
var dummy = document.createElement("textarea");
// to avoid breaking orgain page when copying more words
// cant copy when adding below this code
// dummy.style.display = 'none'
document.body.appendChild(dummy);
//Be careful if you use texarea. setAttribute('value', value), which works with "input" does not work with "textarea". – Eduard
dummy.value = text;
dummy.select();
document.execCommand("copy");
document.body.removeChild(dummy);
}
a = `
SOME_TEXT
`
a = a.replace(/(\r\n|\n|\r)/gm," ")
copyToClipboard(a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment