diff --git a/README.md b/README.md index f6c68ef..8d531fe 100644 --- a/README.md +++ b/README.md @@ -177,6 +177,17 @@ In order to run this project you need: +
  • +
    +Word Counter +

    Word Counter App is a simple and efficient tool built using HTML, CSS, and JavaScript. This application provides users with an easy way to count words, characters, sentences, and paragraphs in a given text. Additionally, it offers features such as readability score and estimated reading time.

    + +
    +
  • +

    (back to top)

    diff --git a/Source-Code/WordCounter/index.html b/Source-Code/WordCounter/index.html new file mode 100644 index 0000000..7f4f4e0 --- /dev/null +++ b/Source-Code/WordCounter/index.html @@ -0,0 +1,34 @@ + + + + + + Word Counter + + + +
    +

    Word Counter

    + +
    +
    Characters: 0
    +
    Words: 0
    +
    +
    +
    Sentences: 0
    +
    Paragraphs: 0
    +
    +
    +
    Reading Time: 0
    +
    Show readability score.
    +
    +
    + Top keywords: + +
    +
    + + + + \ No newline at end of file diff --git a/Source-Code/WordCounter/script.js b/Source-Code/WordCounter/script.js new file mode 100644 index 0000000..5791ea4 --- /dev/null +++ b/Source-Code/WordCounter/script.js @@ -0,0 +1,785 @@ +/* eslint-disable */ +var input = document.querySelectorAll("textarea")[0], + characterCount = document.querySelector("#characterCount"), + wordCount = document.querySelector("#wordCount"), + sentenceCount = document.querySelector("#sentenceCount"), + paragraphCount = document.querySelector("#paragraphCount"), + readingTime = document.querySelector("#readingTime"), + readability = document.querySelector("#readability"), + keywordsDiv = document.querySelectorAll(".keywords")[0], + topKeywords = document.querySelector("#topKeywords"); + +// updating the displayed stats after every keypress +input.addEventListener("keyup", function () { + //keeping the console clean to make only the latest data visible + console.clear(); + + // character count + characterCount.innerHTML = input.value.length; + + // word count using a regex pattern to match words + var words = input.value.match(/\b[-?(\w+)?]+\b/gi); + wordCount.innerHTML = words ? words.length : 0; + + // sentence count using ./!/? as sentence separators + var sentences = input.value.split(/[.|!|?]+/g); + sentenceCount.innerHTML = sentences.length - 1; + + // paragraph count by splitting on newlines and filtering out empty lines + var paragraphs = input.value.replace(/\n$/gm, "").split(/\n/); + paragraphCount.innerHTML = paragraphs.filter( + (paragraph) => paragraph.trim().length > 0 + ).length; + + // reading time based on 275 words/minute + var seconds = Math.floor(((words ? words.length : 0) * 60) / 275); + if (seconds > 59) { + var minutes = Math.floor(seconds / 60); + seconds = seconds - minutes * 60; + readingTime.innerHTML = minutes + "m " + seconds + "s"; + } else { + readingTime.innerHTML = seconds + "s"; + } + + // calculating top keywords + if (words) { + // step-1: removing all the stop words + var nonStopWords = []; + var stopWords = [ + "a", + "able", + "about", + "above", + "abst", + "accordance", + "according", + "accordingly", + "across", + "act", + "actually", + "added", + "adj", + "affected", + "affecting", + "affects", + "after", + "afterwards", + "again", + "against", + "ah", + "all", + "almost", + "alone", + "along", + "already", + "also", + "although", + "always", + "am", + "among", + "amongst", + "an", + "and", + "announce", + "another", + "any", + "anybody", + "anyhow", + "anymore", + "anyone", + "anything", + "anyway", + "anyways", + "anywhere", + "apparently", + "approximately", + "are", + "aren", + "arent", + "arise", + "around", + "as", + "aside", + "ask", + "asking", + "at", + "auth", + "available", + "away", + "awfully", + "b", + "back", + "be", + "became", + "because", + "become", + "becomes", + "becoming", + "been", + "before", + "beforehand", + "begin", + "beginning", + "beginnings", + "begins", + "behind", + "being", + "believe", + "below", + "beside", + "besides", + "between", + "beyond", + "biol", + "both", + "brief", + "briefly", + "but", + "by", + "c", + "ca", + "came", + "can", + "cannot", + "can't", + "cause", + "causes", + "certain", + "certainly", + "co", + "com", + "come", + "comes", + "contain", + "containing", + "contains", + "could", + "couldnt", + "d", + "date", + "did", + "didn't", + "different", + "do", + "does", + "doesn't", + "doing", + "done", + "don't", + "down", + "downwards", + "due", + "during", + "e", + "each", + "ed", + "edu", + "effect", + "eg", + "eight", + "eighty", + "either", + "else", + "elsewhere", + "end", + "ending", + "enough", + "especially", + "et", + "et-al", + "etc", + "even", + "ever", + "every", + "everybody", + "everyone", + "everything", + "everywhere", + "ex", + "except", + "f", + "far", + "few", + "ff", + "fifth", + "first", + "five", + "fix", + "followed", + "following", + "follows", + "for", + "former", + "formerly", + "forth", + "found", + "four", + "from", + "further", + "furthermore", + "g", + "gave", + "get", + "gets", + "getting", + "give", + "given", + "gives", + "giving", + "go", + "goes", + "gone", + "got", + "gotten", + "h", + "had", + "happens", + "hardly", + "has", + "hasn't", + "have", + "haven't", + "having", + "he", + "hed", + "hence", + "her", + "here", + "hereafter", + "hereby", + "herein", + "heres", + "hereupon", + "hers", + "herself", + "hes", + "hi", + "hid", + "him", + "himself", + "his", + "hither", + "home", + "how", + "howbeit", + "however", + "hundred", + "i", + "id", + "ie", + "if", + "i'll", + "im", + "immediate", + "immediately", + "importance", + "important", + "in", + "inc", + "indeed", + "index", + "information", + "instead", + "into", + "invention", + "inward", + "is", + "isn't", + "it", + "itd", + "it'll", + "its", + "itself", + "i've", + "j", + "just", + "k", + "keep", + "keeps", + "kept", + "kg", + "km", + "know", + "known", + "knows", + "l", + "largely", + "last", + "lately", + "later", + "latter", + "latterly", + "least", + "less", + "lest", + "let", + "lets", + "like", + "liked", + "likely", + "line", + "little", + "'ll", + "look", + "looking", + "looks", + "ltd", + "m", + "made", + "mainly", + "make", + "makes", + "many", + "may", + "maybe", + "me", + "mean", + "means", + "meantime", + "meanwhile", + "merely", + "mg", + "might", + "million", + "miss", + "ml", + "more", + "moreover", + "most", + "mostly", + "mr", + "mrs", + "much", + "mug", + "must", + "my", + "myself", + "n", + "na", + "name", + "namely", + "nay", + "nd", + "near", + "nearly", + "necessarily", + "necessary", + "need", + "needs", + "neither", + "never", + "nevertheless", + "new", + "next", + "nine", + "ninety", + "no", + "nobody", + "non", + "none", + "nonetheless", + "noone", + "nor", + "normally", + "nos", + "not", + "noted", + "nothing", + "now", + "nowhere", + "o", + "obtain", + "obtained", + "obviously", + "of", + "off", + "often", + "oh", + "ok", + "okay", + "old", + "omitted", + "on", + "once", + "one", + "ones", + "only", + "onto", + "or", + "ord", + "other", + "others", + "otherwise", + "ought", + "our", + "ours", + "ourselves", + "out", + "outside", + "over", + "overall", + "owing", + "own", + "p", + "page", + "pages", + "part", + "particular", + "particularly", + "past", + "per", + "perhaps", + "placed", + "please", + "plus", + "poorly", + "possible", + "possibly", + "potentially", + "pp", + "predominantly", + "present", + "previously", + "primarily", + "probably", + "promptly", + "proud", + "provides", + "put", + "q", + "que", + "quickly", + "quite", + "qv", + "r", + "ran", + "rather", + "rd", + "re", + "readily", + "really", + "recent", + "recently", + "ref", + "refs", + "regarding", + "regardless", + "regards", + "related", + "relatively", + "research", + "respectively", + "resulted", + "resulting", + "results", + "right", + "run", + "s", + "said", + "same", + "saw", + "say", + "saying", + "says", + "sec", + "section", + "see", + "seeing", + "seem", + "seemed", + "seeming", + "seems", + "seen", + "self", + "selves", + "sent", + "seven", + "several", + "shall", + "she", + "shed", + "she'll", + "shes", + "should", + "shouldn't", + "show", + "showed", + "shown", + "showns", + "shows", + "significant", + "significantly", + "similar", + "similarly", + "since", + "six", + "slightly", + "so", + "some", + "somebody", + "somehow", + "someone", + "somethan", + "something", + "sometime", + "sometimes", + "somewhat", + "somewhere", + "soon", + "sorry", + "specifically", + "specified", + "specify", + "specifying", + "still", + "stop", + "strongly", + "sub", + "substantially", + "successfully", + "such", + "sufficiently", + "suggest", + "sup", + "sure", + "t", + "take", + "taken", + "taking", + "tell", + "tends", + "th", + "than", + "thank", + "thanks", + "thanx", + "that", + "that'll", + "thats", + "that've", + "the", + "their", + "theirs", + "them", + "themselves", + "then", + "thence", + "there", + "thereafter", + "thereby", + "thered", + "therefore", + "therein", + "there'll", + "thereof", + "therere", + "theres", + "thereto", + "thereupon", + "there've", + "these", + "they", + "theyd", + "they'll", + "theyre", + "they've", + "think", + "this", + "those", + "thou", + "though", + "thoughh", + "thousand", + "throug", + "through", + "throughout", + "thru", + "thus", + "til", + "tip", + "to", + "together", + "too", + "took", + "toward", + "towards", + "tried", + "tries", + "truly", + "try", + "trying", + "ts", + "twice", + "two", + "u", + "un", + "under", + "unfortunately", + "unless", + "unlike", + "unlikely", + "until", + "unto", + "up", + "upon", + "ups", + "us", + "use", + "used", + "useful", + "usefully", + "usefulness", + "uses", + "using", + "usually", + "v", + "value", + "various", + "'ve", + "very", + "via", + "viz", + "vol", + "vols", + "vs", + "w", + "want", + "wants", + "was", + "wasn't", + "way", + "we", + "wed", + "welcome", + "we'll", + "went", + "were", + "weren't", + "we've", + "what", + "whatever", + "what'll", + "whats", + "when", + "whence", + "whenever", + "where", + "whereafter", + "whereas", + "whereby", + "wherein", + "wheres", + "whereupon", + "wherever", + "whether", + "which", + "while", + "whim", + "whither", + "who", + "whod", + "whoever", + "whole", + "who'll", + "whom", + "whomever", + "whos", + "whose", + "why", + "widely", + "willing", + "wish", + "with", + "within", + "without", + "won't", + "words", + "world", + "would", + "wouldn't", + "www", + "x", + "y", + "yes", + "yet", + "you", + "youd", + "you'll", + "your", + "youre", + "yours", + "yourself", + "yourselves", + "you've", + "z", + "zero", + ]; + for (var i = 0; i < words.length; i++) { + if (stopWords.indexOf(words[i].toLowerCase()) === -1 && isNaN(words[i])) { + nonStopWords.push(words[i].toLowerCase()); + } + } + + // step-2: forming an object with keywords and their count + var keywords = {}; + for (var i = 0; i < nonStopWords.length; i++) { + keywords[nonStopWords[i]] = (keywords[nonStopWords[i]] || 0) + 1; + } + + // step-3: sorting the object by count + var sortedKeywords = Object.entries(keywords).sort((a, b) => b[1] - a[1]); + + // step-4: displaying top 4 keywords and their count + topKeywords.innerHTML = ""; + for (var i = 0; i < sortedKeywords.length && i < 4; i++) { + var li = document.createElement("li"); + li.innerHTML = + "" + sortedKeywords[i][0] + ": " + sortedKeywords[i][1]; + topKeywords.appendChild(li); + } + } + + // displaying top keywords only if there are words in the text area + keywordsDiv.style.display = words ? "block" : "none"; + + // calculating readability score + var syllables = countSyllables(input.value); + var readabilityScore = calculateFleschKincaid( + words ? words.length : 0, + sentences.length - 1, + syllables + ); + readability.innerHTML = convertReadabilityScore(readabilityScore); +}); + +// function to count syllables in a text +function countSyllables(text) { + var words = text.toLowerCase().split(/\s+/); + var syllableCount = 0; + words.forEach(function (word) { + word = word.replace(/(?:[^laeiouy]es|ed|[^laeiouy]e)$/, ""); + word = word.replace(/^y/, ""); + var syllables = word.match(/[aeiouy]{1,2}/g); + syllableCount += syllables ? syllables.length : 0; + }); + return syllableCount; +} + +// function to calculate Flesch-Kincaid readability score +function calculateFleschKincaid(words, sentences, syllables) { + var score = + 206.835 - 1.015 * (words / sentences) - 84.6 * (syllables / words); + return score; +} + +// function to convert readability score to human-readable format +function convertReadabilityScore(score) { + if (score <= 30) return "Readability: College graduate."; + if (score <= 50) return "Readability: College level."; + if (score <= 60) return "Readability: 10th - 12th grade."; + if (score <= 70) return "Readability: 8th - 9th grade."; + if (score <= 80) return "Readability: 7th grade."; + if (score <= 90) return "Readability: 6th grade."; + if (score <= 100) return "Readability: 5th grade."; + return "Not available."; +} diff --git a/Source-Code/WordCounter/style.css b/Source-Code/WordCounter/style.css new file mode 100644 index 0000000..b875a1c --- /dev/null +++ b/Source-Code/WordCounter/style.css @@ -0,0 +1,231 @@ +/* General Styles */ +body { + background-image: linear-gradient(#fec8d8, #ffdfd3); + line-height: 1; + width: 700px; + margin: 0 auto; + background-color: #fafafa; + font-family: 'Source Sans Pro', sans-serif; + color: #111; +} + +html { + box-sizing: border-box; + user-select: none; +} + +*, +*::before, +*::after { + box-sizing: inherit; +} + +/* Reset Styles */ +article, +aside, +details, +figcaption, +figure, +footer, +header, +hgroup, +menu, +nav, +section { + display: block; +} + +ol, +ul { + list-style: none; +} + +blockquote, +q { + quotes: none; +} + +blockquote::before, +blockquote::after, +q::before, +q::after { + content: none; +} + +table { + border-collapse: collapse; + border-spacing: 0; +} + +/* Typography */ +b { + font-weight: bold; +} + +/* Container */ +.container { + margin: 2% auto; + padding: 15px; + background-color: #fff; + box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.2); +} + +/* Headings */ +h1 { + font-size: 3rem; + font-weight: 900; + text-align: center; + margin: 1% 0 3%; +} + +/* Textarea */ +textarea { + width: 100%; + height: 250px; + padding: 10px; + border: 1px solid #d9d9d9; + outline: none; + font-size: 1rem; + resize: none; + line-height: 1.5rem; + transition: border-color 0.3s; +} + +textarea:hover { + border-color: #c0c0c0; +} + +textarea:focus { + border-color: #4d90fe; +} + +/* Output Row */ +.output.row { + width: 100%; + border: 1px solid #ddd; + font-size: 1.4rem; + margin: 1% 0; + background-color: #f9f9f9; + display: flex; + flex-wrap: wrap; +} + +.output.row div { + flex: 1 1 42%; + padding: 10px 15px; + margin: 1%; +} + +.output.row span { + font-weight: bold; + font-size: 1.5rem; +} + +/* Readability */ +#readability { + width: 52%; + font-weight: bold; + cursor: pointer; + transition: background-color 0.3s, color 0.3s; +} + +#readability:hover { + background-color: #4d90fe; + color: #fff; + border-radius: 2px; +} + +#readability:active { + background-color: #307af3; +} + +/* Keywords */ +.keywords { + display: none; + margin: 4% 0 0; + font-size: 2rem; + font-weight: 900; +} + +.keywords ul { + font-weight: 400; + border: 1px solid #ddd; + font-size: 1.4rem; + background-color: #f9f9f9; + margin: 2% 0; +} + +.keywords li { + display: inline-block; + width: 44%; + padding: 10px; + margin: 1%; +} + +/* Responsive Design */ +@media (max-width: 750px) { + body { + width: 600px; + } + + .output.row { + font-size: 1.2rem; + } + + .output.row span { + font-size: 1.3rem; + } + + .keywords ul { + font-size: 1.2rem; + } +} + +@media (max-width: 600px) { + body { + width: 95%; + } + + .output.row { + border: none; + background-color: #fff; + } + + .output.row div { + flex: 1 1 100%; + padding: 10px 15px; + margin: 2% auto; + border: 1px solid #ddd; + font-size: 1.8rem; + background-color: #f9f9f9; + } + + .output.row span { + font-size: 2rem; + } + + #readability { + width: 100%; + font-size: 1.6rem; + font-weight: 400; + } + + .keywords { + margin: 10% auto; + } + + .keywords ul { + font-weight: 400; + border: none; + font-size: 1.8rem; + background-color: #f9f9f9; + margin: 5% 0; + } + + .keywords li { + flex: 1 1 100%; + padding: 10px; + margin: 2% auto; + border: 1px solid #ddd; + } +}