-
-
Save mosbth/7b44224d138f3c5eb5c1 to your computer and use it in GitHub Desktop.
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
javascript: | |
var highlightedText = window.getSelection().toString(); | |
highlightedText = highlightedText.replace("?","."); | |
highlightedText = highlightedText.replace("!","."); | |
highlightedText = highlightedText.replace(/\.\.*/g,"."); | |
var sentances = highlightedText.split("."); | |
var sentanceCount = (highlightedText.match(/\.\s/g) != null) ? highlightedText.match(/\.\s/g).length : 0; | |
sentanceCount += (highlightedText.slice(-1) == ".") ? 1:0; | |
var wordCount = highlightedText.split(" ").length; | |
var avgWordsPerSentance = (wordCount/sentanceCount).toFixed(2); | |
var commasCount = highlightedText.split(",").length; | |
var avgCommasPerSentance = (commasCount/sentanceCount).toFixed(2); | |
console.log("\n\n\n\n\n\n"); | |
var analysis = "ANALYZED TEXT!\n"; | |
analysis += "Sentances: "+sentanceCount+"\n"; | |
analysis += "Words: "+wordCount+"\n"; | |
analysis += "Avg words/sentance: "+avgWordsPerSentance+"\n"; | |
analysis += "commasCount: "+commasCount+"\n"; | |
analysis += "Avg commas/sentance: "+avgCommasPerSentance+"\n"; | |
console.log(analysis); alert(analysis); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment