
<html>
<head>
      <title>Online Text Editor</title>
      <link rel="icon" type="image/x-icon" href="logo.png">

    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=2.0, user-scalable=yes">
    <script defer data-domain="tools.badheshchauhan.com"  src="https://getanalyzr.vercel.app/tracking-script.js"></script>

  <style>
   .tool-header {
    font-size: 24px;
    font-weight: bold;
    margin-bottom: 20px;
    text-shadow: 2px 2px 10px green;

      }
 #editor {
    width: 100%;
    height: 400px;
    border: 4px solid black;
    border-radius: 25px;
  }
    .button {
        background-color: #4CAF50;
        color: white;
        padding: 12px 10px;
        margin: 10px 0;
        border: none;
        cursor: pointer;
        width: 100%;
        border-radius: 30px;
        font-size: 15px;
       text-shadow: 2px 2px 5px red;


  }
</style>
</head>
<body>
    <div class="tool-container"><br />
      <center><div class="tool-header">Online Text Editor</div></center><br />
<textarea id="editor"></textarea>
<br>
<button class="button" onclick="calculateWordCount()">Calculate Word Count</button>
<button class="button" class="button" onclick="calculateCharacterCount()">Calculate Character Count</button>
<button class="button" onclick="convertToLowercase()">Convert to Lowercase</button>
<button class="button" onclick="convertToUppercase()">Convert to Uppercase</button>
<button class="button" onclick="capitalizeFirstLetter()">Capitalize First Letter of Each Word</button>
<button class="button" onclick="caseConverter()">Case Converter</button>
<button class="button" onclick="copyText()">Copy</button>
<button class="button" onclick="saveAsText()">Save as Text</button>

<p>The word count is: <span id="wordCount"></span></p>
<p>The character count is: <span id="characterCount"></span></p>

<script>
var editor = document.getElementById("editor");

// Function to calculate the word count
function calculateWordCount() {
  var text = editor.value;
  var wordArray = text.split(" ");
  var wordCount = wordArray.length;
  document.getElementById("wordCount").innerHTML = wordCount;
}

// Function to calculate the character count
function calculateCharacterCount() {
  var text = editor.value;
  var characterCount = text.length;
  document.getElementById("characterCount").innerHTML = characterCount;
}

// Function to convert text to lowercase
function convertToLowercase() {
  editor.value = editor.value.toLowerCase();
}

// Function to convert text to uppercase
function convertToUppercase() {
  editor.value = editor.value.toUpperCase();
}
function caseConverter() {
  var text = editor.value;
  var caseConvertedText = text.split("").map(char => char === char.toUpperCase() ? char.toLowerCase() : char.toUpperCase()).join("");
  editor.value = caseConvertedText;
}
// Function to capitalize the first letter of each word
function capitalizeFirstLetter() {
  editor.value = editor.value.toLowerCase().split(" ").map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
}

// Function to copy the text
function copyText() {
  editor.select();
  document.execCommand("copy");
  alert("Text copied to clipboard!");
}

// Function to save the text as a .txt file
function saveAsText() {
  var text = editor.value;
  var file = new Blob([text], {type: "text/plain"});
  var a = document.createElement("a");
  a.href = URL.createObjectURL(file);
  a.download = "text.txt";
  a.click();
}

// Saving the content on the local storage
editor.addEventListener("keyup", function(){
  localStorage.setItem("content", editor.value);
});

// Retrieving the content from the local storage
editor.value = localStorage.getItem("content");
</script>

</body>
</html>

