Echo JS 0.11.0

<~>
tracker1 1192 days ago. link 1 point
With help from https://stackoverflow.com/a/43438960

    window.addEventListener('DOMContentLoaded', (event) => {
      document.documentElement.addEventListener('paste', e => {
        if (e.target.nodeName.toLowerCase() === 'input') {
          e.preventDefault();
          var text;
          var clp = (e.originalEvent || e).clipboardData;
          if (clp === undefined || clp === null) {
            text = window.clipboardData.getData("text") || "";
            if (text !== "") {
              text = text.replace(/[\t\r\n\s]+/g, " ");
              document.selection.createRange().pasteHTML(text);
            }
          } else {
            text = clp.getData('text/plain') || " ";
            if (text !== "") {
              text = text.replace(/[\t\r\n\s]+/g, " ");
              document.execCommand('insertText', false, text);
            }
          }
        }
      });
    });

Note, the regex I'm calling out \t as well as \r\s and \s ... \s is any whitespace, and probably all you want/need adjust ast desired.

Replies