From f823d5c4b2e8c1c11a4e0ba5c22f33cd836113c9 Mon Sep 17 00:00:00 2001 From: mic Date: Fri, 14 Feb 2025 22:20:36 +0100 Subject: [PATCH] warning spam threshold too low added. see #231 --- _locales/en/messages.json | 8 ++++++++ pages/spamfilter/mzta-spamfilter.css | 8 ++++++++ pages/spamfilter/mzta-spamfilter.html | 2 +- pages/spamfilter/mzta-spamfilter.js | 18 ++++++++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 15f4f918..ea758ff0 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -1098,5 +1098,13 @@ "prefs_OptionText_spamfilter_threshold_Info": { "message": "If the value returned by the AI is above this threshold, the email will be moved to the spam folder.", "description": "" + }, + "spam_threshold_too_low": { + "message": "The spam threshold is too low! You will likely mark too much mails as spam!", + "description": "" + }, + "spam_threshold_zero": { + "message": "The spam threshold is zero! You will mark all mails as spam!", + "description": "" } } \ No newline at end of file diff --git a/pages/spamfilter/mzta-spamfilter.css b/pages/spamfilter/mzta-spamfilter.css index 4e4a769a..6a9bacc0 100644 --- a/pages/spamfilter/mzta-spamfilter.css +++ b/pages/spamfilter/mzta-spamfilter.css @@ -91,6 +91,14 @@ table#miczPrefs tr:last-child td { color: red; } +#spam_threshold_too_low{ + display: none; + color:red; + font-weight: bold; + font-size: 1.1em; + margin-left: 10px; +} + @media (prefers-color-scheme: dark) { body { diff --git a/pages/spamfilter/mzta-spamfilter.html b/pages/spamfilter/mzta-spamfilter.html index 1791e1b5..4fafb0c9 100644 --- a/pages/spamfilter/mzta-spamfilter.html +++ b/pages/spamfilter/mzta-spamfilter.html @@ -17,7 +17,7 @@ __MSG_prefs_OptionText_spamfilter_threshold__ diff --git a/pages/spamfilter/mzta-spamfilter.js b/pages/spamfilter/mzta-spamfilter.js index 54fca13f..bec1afdb 100644 --- a/pages/spamfilter/mzta-spamfilter.js +++ b/pages/spamfilter/mzta-spamfilter.js @@ -34,6 +34,9 @@ document.addEventListener('DOMContentLoaded', async () => { element.addEventListener("change", saveOptions); }); + document.getElementById("spamfilter_threshold").addEventListener("input", check_spamfilter_threshold); + check_spamfilter_threshold({target: document.getElementById("spamfilter_threshold")}); + let spamfilter_textarea = document.getElementById('spamfilter_prompt_text'); let spamfilter_save_btn = document.getElementById('btn_save_prompt'); let spamfilter_reset_btn = document.getElementById('btn_reset_prompt'); @@ -77,6 +80,21 @@ document.addEventListener('DOMContentLoaded', async () => { }); +function check_spamfilter_threshold(event) { + let spam_threshold_too_low = document.getElementById("spam_threshold_too_low"); + if(event.target.value < 50){ + spam_threshold_too_low.style.display = "inline"; + if(event.target.value == 0){ + spam_threshold_too_low.textContent = browser.i18n.getMessage('spam_threshold_zero'); + spam_threshold_too_low.style.fontSize = "1.5em"; + }else{ + spam_threshold_too_low.textContent = browser.i18n.getMessage('spam_threshold_too_low'); + spam_threshold_too_low.style.fontSize = "1.1em"; + } + }else{ + spam_threshold_too_low.style.display = "none"; + } +} // Methods to manage options, derived from: /options/mzta-options.js