Created
May 17, 2023 05:40
-
-
Save karim23657/a28440fd687387bb72e263e176bc1da8 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<style> | |
</style> | |
</head> | |
<body> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Word Frequency Analyzer</title> | |
<style> | |
body { | |
font-family: Arial, sans-serif; | |
margin: 0; | |
padding: 0; | |
} | |
header { | |
background-color: #333; | |
color: #fff; | |
padding: 1rem; | |
text-align: center; | |
} | |
h1 { | |
margin: 0; | |
} | |
main { | |
display: flex; | |
flex-direction: column; | |
align-items: center; | |
justify-content: center; | |
height: calc(100vh - 3rem); | |
} | |
textarea { | |
width: 80%; | |
height: 10rem; | |
resize: none; | |
padding: 0.5rem; | |
border-radius: 0.25rem; | |
border: 1px solid #ccc; | |
margin-bottom: 1rem; | |
} | |
button { | |
background-color: #4CAF50; | |
color: #fff; | |
border: none; | |
padding: 0.5rem 1rem; | |
border-radius: 0.25rem; | |
cursor: pointer; | |
} | |
button:hover { | |
background-color: #3e8e41; | |
} | |
</style> | |
</head> | |
<body> | |
<header> | |
<h1>Word Frequency Analyzer</h1> | |
</header> | |
<main> | |
<textarea id="text" placeholder="Enter text">سامانهٔ فرهنگ املایی حاصل کوشش چندهزارساعته دغدغهمندان این وادی است. خزانهٔ واژگان این سامانه شامل دههاهزار واژه است و آمادهسازی هرکدام و تطبیق قواعد دستورخط بر آنها و تکمیل اطلاعات ضروری این خزانهٔ واژگان زمانبر است. زبان هم که پدیدهای زنده است و مدام تازه میشود و رشد میکند. تاکنون اینان در توسعۀ این سامانه همکاری کردهاند:</textarea> | |
<button onclick="analyze()">Analyze</button> | |
<a id="download" href="#" download="results.json" style="display: none;">Download Results</a> | |
</main> | |
<script src="script.js"></script> | |
</body> | |
</html> | |
<script> | |
function analyze() { | |
// Get the text from the textarea | |
const text = document.getElementById('text').value; | |
// Remove any punctuation and convert to lowercase | |
const cleanText = text | |
// Split the text into an array of words | |
const words = cleanText.split(/\s+/); | |
// Create an object to store the frequency of each word | |
const frequency = {}; | |
// Count the frequency of each word | |
for (let i = 0; i < words.length; i++) { | |
if (!frequency[words[i]]) { | |
frequency[words[i]] = 1; | |
} else { | |
frequency[words[i]]++; | |
} | |
} | |
// Convert the frequency object to a JSON string | |
const jsonString = JSON.stringify(frequency); | |
// Set the href attribute of the download link to the JSON string | |
const downloadLink = document.getElementById('download'); | |
downloadLink.href = 'data:text/json;charset=utf-8,' + encodeURIComponent(jsonString); | |
// Show the download link | |
downloadLink.style.display = ''; | |
} | |
</script></body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment