From 7400bb2ae61a5395ac61884f7e2acb909a68b588 Mon Sep 17 00:00:00 2001 From: camiska <159632556+camiska@users.noreply.github.com> Date: Mon, 15 Apr 2024 22:41:35 +0200 Subject: [PATCH] Update script.js --- script.js | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/script.js b/script.js index 005500c..c3fb8a9 100644 --- a/script.js +++ b/script.js @@ -1,16 +1,10 @@ -function analyzeText() { +document.getElementById('analyzeButton').addEventListener('click', function() { const inputText = document.getElementById('inputText').value; const outputArea = document.getElementById('outputText'); - const keywords = ["ethics", "ethic", "ethical", "moral", "morally", "ethically", "ethik", "ethisch", "moralisch", "dilemma"]; + const keywords = ["ethics", "ethic", "ethical", "moral", "morally", "ethically", "ethik", "ethisch", "moral", "moralisch", "dilemma"]; + const regex = new RegExp(keywords.join('|'), 'i'); // Case insensitive search const lines = inputText.split('\n'); - const results = []; - - lines.forEach(line => { - const lineLower = line.toLowerCase(); - if (keywords.some(keyword => lineLower.includes(keyword))) { - results.push(line); - } - }); + const results = lines.filter(line => regex.test(line)); outputArea.value = results.join('\n\n'); -} +});