Eliminate line brakes, time stamps, remaining extra commas!

Paste the code below into the 'Clipboard Transformer Function (JavaScript):' input box and assign it to any trigger or gesture of your choice. I created this specifically to take a YouTube transcript and format it into a nice, legible and concise format!!!!

async (clipboardContentString) => {

  let line = '';
  let line2= '';
  let line3 = '';
  let lines = clipboardContentString.split("\n"); //multiLines contains your text
  for (var i = 0; i < lines.length; i++) {
    if (lines[i].startsWith(" ")) {
      line += " " + lines[i].trim();
    } else {
      line += ", " + lines[i].trim();

    }
    let reg = /, , /g;
    line = line.replace(/[0-9]/g, "")
    line2 = line.replace(reg, ", ")
    line = line.replace(/:/g, "");
  }
  
  line3 = line2.substring(1).trim();
 
  return line3
}

Tip: the /:/g, (/[0-9]|:/g, and /, , /g are what is known as REGEX, regular expressions. To modify the code and remove other characters or symbols, I would use the first example, /:/g, which removes colons (:). You can modify the code to remove, say underscores, by changing that code to /_/g.

2 Likes