文書チェックツール
テキストエリアに文書を入力してください。
<!DOCTYPE html>
<html>
<head>
<title>文書チェックツール</title>
<meta charset="utf-8">
</head>
<body>
<h1>文書チェックツール</h1>
<p>テキストエリアに文書を入力してください。</p>
<textarea id="inputArea" rows="10" cols="50"></textarea><br>
<button onclick="checkText()">チェック</button>
<br><br>
<div id="outputArea"></div>
<script>
function checkText() {
let input = document.getElementById("inputArea").value;
// 誤字脱字チェック
let output = input.replace(/\b(\w{8,})\b/gi, '$1😂'); // 8文字以上の単語に笑いの顔文字を挿入
output = output.replace(/you/gi, '👉$&👈'); // youを検出して、指さしているような絵文字で囲む
output = output.replace(/your/gi, '👉$&👈');
output = output.replace(/urs/gi, '👉$&👈'); // yourのスラング
output = output.replace(/(lose|loose)/gi, '🎲$&🎲'); // loseとlooseを区別するためにサイコロの絵文字で囲む
output = output.replace(/their/gi, '🏠$&🏠'); // theirを家の絵文字で囲む
output = output.replace(/there/gi, '📍$&📍'); // thereを場所の絵文字で囲む
output = output.replace(/they're/gi, '👫$&👫'); // they'reを2人の絵文字で囲む
output = output.replace(/(isn't|aren't|wasn't|weren't|hasn't|haven't|hadn't|doesn't|don't|didn't|won't|wouldn't|can't|cannot|could't|shouldn't)/gi, '🤔$&🤔'); // 否定形を検出して、考えている絵文字で囲む
output = output.replace(/(\.|!|\?) /g, '$&🤔 '); // 文末にピリオドや感嘆符、疑問符がある場合は考えている絵文字を追加
// 文法チェック
let sentences = output.split(/\. |\? |\! /g); // 文章をピリオド、感嘆符、疑問符で分割
for (let i=0; i<sentences.length; i++) {
let sentence = sentences[i].trim();
// 文法的に問題がある場合は強調する
if (sentence.toUpperCase() === sentence && sentence.length > 10) { // 大文字の単語が10文字以上連続する場合
output = output.replace(sentence, '<strong>' + sentence + '</strong>');
} else if (sentence.match(/(The|A|An) [a-zA-Z]+ (\<strong\>)?[a-zA-Z]+(\<\/strong\>)?/) && sentence.length > 20) { // 不定冠詞や定冠詞を正しく使っていない場合
output = output.replace(sentence, '<strong>' + sentence + '</strong>');
}
}
document.getElementById("outputArea").innerHTML = output;
}
</script>
</body>
</html>