Created
June 14, 2023 07:46
-
-
Save meisterx2020/7f368e6752877f9c66c8e47d2378ef26 to your computer and use it in GitHub Desktop.
Text Converter for Teachable .VTT file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data:text/html,<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>Text Converter</title> <style>textarea{width: 400px; height: 200px;}</style> <script>function processLines(lines){var timestampFound=false; var filteredLines=[]; var previousLineEnds=[".", "?", "!"]; for (var i=0; i < lines.length; i++){var line=lines[i]; if (line.indexOf("-->") !==-1){timestampFound=true;}if (timestampFound){filteredLines.push(line);}}var processedLines=[]; for (var i=0; i < filteredLines.length; i++){var line=filteredLines[i].trim(); if (line.length <=4){continue;}if (line===""){continue;}if (line.indexOf("-->") !==-1){if (processedLines.length > 0 && !previousLineEnds.some(function(lineEnd){return processedLines[processedLines.length - 1].indexOf(lineEnd) !==-1;})){continue;}}processedLines.push(line);}var finalLines=[]; for (var i=0; i < processedLines.length; i++){var line=processedLines[i]; if (line.indexOf("-->") !==-1){line +="\n";}if (line.endsWith(".") || line.endsWith("?") || line.endsWith("!")){line +="\n\n";}if (line[line.length - 1] !=="\n"){line +=" ";}finalLines.push(line);}return finalLines;}function convertText(){var input=document.getElementById("input").value; var lines=input.split("\n"); var processedLines=processLines(lines); var output=processedLines.join(""); var result=document.getElementById("result"); result.innerText=output;}</script> </head> <body> <h1>Text Converter</h1> <textarea id="input" placeholder="Paste your text here"></textarea> <br><button onclick="convertText()">Submit</button> <h2>Result</h2> <div id="result"></div></body></html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment