@@ -79,15 +79,16 @@ document.addEventListener("DOMContentLoaded", async () => {
79
79
}
80
80
} ) ;
81
81
82
+
82
83
function displayEmailInfo ( ) {
83
84
const tableBody = document . getElementById ( "probabilities-table" ) ;
84
85
const tokenTablesContainer = document . getElementById ( "token-tables-container" ) ;
85
86
const toggleButton = document . getElementById ( "toggle-tokens-button" ) ;
86
- tokenTablesContainer . style . display = 'none' ; // Token-Tabellen anfangs ausblenden
87
+ tokenTablesContainer . style . display = 'none' ; // Initially hide token tables
88
+
87
89
let tagKeyToNameMap = { } ;
88
90
let tagNameToKeyMap = { } ;
89
-
90
- // Setze HTML-Übersetzungen mit der trans-Funktion
91
+ // Set translated texts using the trans function
91
92
document . getElementById ( 'email-info-title' ) . textContent = trans ( "emailinfo_title" ) ;
92
93
document . getElementById ( 'emailinfo_label_tag' ) . textContent = trans ( "emailinfo_label_tag" ) ;
93
94
document . getElementById ( 'emailinfo_label_probability' ) . textContent = trans ( "emailinfo_label_probability" ) ;
@@ -100,7 +101,7 @@ function displayEmailInfo() {
100
101
const probabilities = result . bayesInfoData || [ ] ;
101
102
const bayesData = result . bayesData || { } ;
102
103
103
- // Mapping von Tag-Key zu Tag-Name und umgekehrt erstellen
104
+ // Create mappings from Tag-Key to Tag-Name and vice versa
104
105
tags . forEach ( ( tag ) => {
105
106
tagKeyToNameMap [ tag . key ] = tag . tag ;
106
107
tagNameToKeyMap [ tag . tag ] = tag . key ;
@@ -109,56 +110,57 @@ function displayEmailInfo() {
109
110
probabilities . forEach ( ( item ) => {
110
111
const row = document . createElement ( "tr" ) ;
111
112
113
+ // Tag Cell
112
114
const tagCell = document . createElement ( "td" ) ;
113
115
tagCell . textContent = item . tag ;
114
116
row . appendChild ( tagCell ) ;
115
117
118
+ // Probability Cell
116
119
const probCell = document . createElement ( "td" ) ;
117
-
118
120
if ( ! bayesData [ item . tag ] ) {
119
121
probCell . textContent = "50%" ;
120
122
} else if ( ! bayesData [ item . tag ] . trainingCount ) {
121
123
probCell . textContent = "50%" ;
122
124
} else {
123
125
probCell . textContent = item . probability + "%" ;
124
126
}
125
-
126
127
row . appendChild ( probCell ) ;
127
128
128
- // Hinzufügen der Zelle für bekannte Tokens
129
+ // Known Tokens Percentage Cell (Unigrams / Bigrams)
129
130
const knownTokensCell = document . createElement ( "td" ) ;
130
- if ( item . knownTokenPercentage !== undefined ) {
131
- knownTokensCell . textContent = item . knownTokenPercentage + "%" ;
131
+ if ( item . knownUnigramsPercentage !== undefined && item . knownBigramsPercentage !== undefined ) {
132
+ knownTokensCell . textContent = ` ${ item . knownUnigramsPercentage } % / ${ item . knownBigramsPercentage } %` ;
132
133
} else {
133
- knownTokensCell . textContent = "0.00%" ; // Fallback, falls nicht definiert
134
+ knownTokensCell . textContent = "0.00% / 0.00% " ; // Fallback if percentages are not defined
134
135
}
135
136
row . appendChild ( knownTokensCell ) ;
136
137
137
138
tableBody . appendChild ( row ) ;
138
139
139
- // Verarbeitung der TokenContributions, um Top 5 positive und negative Tokens zu finden
140
+ // Process Token Contributions to find Top 5 Positive and Negative Tokens
140
141
const tokenContributions = item . tokenContributions || [ ] ;
141
142
142
- // Filtere die Tokens, die in der E-Mail vorhanden sind
143
+ // Filter tokens present in the email
143
144
const tokensInEmail = tokenContributions . filter ( tc => tc . isPresent ) ;
144
145
145
- // Top 5 positive Tokens (höchste positive Beiträge )
146
+ // Top 10 Positive Tokens (highest positive contributions )
146
147
const topPositiveTokens = tokensInEmail
147
148
. filter ( tc => tc . contribution > 0 )
148
149
. sort ( ( a , b ) => b . contribution - a . contribution )
149
- . slice ( 0 , 5 ) ;
150
+ . slice ( 0 , 10 ) ;
150
151
151
- // Top 5 negative Tokens (niedrigste negative Beiträge )
152
+ // Top 10 Negative Tokens (lowest negative contributions )
152
153
const topNegativeTokens = tokensInEmail
153
154
. filter ( tc => tc . contribution < 0 )
154
155
. sort ( ( a , b ) => a . contribution - b . contribution )
155
- . slice ( 0 , 5 ) ;
156
+ . slice ( 0 , 10 ) ;
156
157
157
- // Erstelle eine Tabelle für das aktuelle Schlagwort
158
+ // Create a table for the current tag
158
159
const tokenTable = document . createElement ( "table" ) ;
159
160
tokenTable . style . marginTop = "15px" ;
160
161
tokenTable . style . width = "100%" ;
161
162
163
+ // Table Header
162
164
const tokenTableHeader = document . createElement ( "thead" ) ;
163
165
const tokenTableHeaderRow = document . createElement ( "tr" ) ;
164
166
const tokenTableHeaderCell = document . createElement ( "th" ) ;
@@ -169,6 +171,7 @@ function displayEmailInfo() {
169
171
tokenTableHeader . appendChild ( tokenTableHeaderRow ) ;
170
172
tokenTable . appendChild ( tokenTableHeader ) ;
171
173
174
+ // Table Subheader
172
175
const tokenTableSubHeader = document . createElement ( "tr" ) ;
173
176
const tokenSubHeaderToken = document . createElement ( "th" ) ;
174
177
tokenSubHeaderToken . textContent = trans ( "emailinfo_token" ) ;
@@ -185,9 +188,10 @@ function displayEmailInfo() {
185
188
186
189
const tokenTableBody = document . createElement ( "tbody" ) ;
187
190
188
- // Füge die positiven Tokens hinzu
191
+ // Add Positive Tokens
189
192
topPositiveTokens . forEach ( tc => {
190
193
const tr = document . createElement ( "tr" ) ;
194
+
191
195
const tdToken = document . createElement ( "td" ) ;
192
196
tdToken . textContent = tc . token ;
193
197
tdToken . classList . add ( "positive-token" ) ;
@@ -197,15 +201,17 @@ function displayEmailInfo() {
197
201
198
202
const tdType = document . createElement ( "td" ) ;
199
203
tdType . textContent = trans ( "emailinfo_positive" ) ;
204
+
200
205
tr . appendChild ( tdToken ) ;
201
206
tr . appendChild ( tdContribution ) ;
202
207
tr . appendChild ( tdType ) ;
203
208
tokenTableBody . appendChild ( tr ) ;
204
209
} ) ;
205
210
206
- // Füge die negativen Tokens hinzu
211
+ // Add Negative Tokens
207
212
topNegativeTokens . forEach ( tc => {
208
213
const tr = document . createElement ( "tr" ) ;
214
+
209
215
const tdToken = document . createElement ( "td" ) ;
210
216
tdToken . textContent = tc . token ;
211
217
tdToken . classList . add ( "negative-token" ) ;
@@ -215,6 +221,7 @@ function displayEmailInfo() {
215
221
216
222
const tdType = document . createElement ( "td" ) ;
217
223
tdType . textContent = trans ( "emailinfo_negative" ) ;
224
+
218
225
tr . appendChild ( tdToken ) ;
219
226
tr . appendChild ( tdContribution ) ;
220
227
tr . appendChild ( tdType ) ;
@@ -225,31 +232,32 @@ function displayEmailInfo() {
225
232
tokenTablesContainer . appendChild ( tokenTable ) ;
226
233
} ) ;
227
234
228
- // Entferne bayesInfoData nach der Anzeige
235
+ // Remove bayesInfoData after display
229
236
messenger . storage . local . remove ( [ "bayesInfoData" ] ) ;
230
237
231
- // Fenstergröße nach dem Laden des Inhalts anpassen
238
+ // Adjust window size after loading content
232
239
adjustWindowSize ( ) ;
233
240
} ) . catch ( ( error ) => {
234
241
console . error ( "Error loading Bayes info data:" , error ) ;
235
242
} ) ;
236
243
237
- // Event Listener für den Toggle-Button hinzufügen
244
+ // Add Event Listener to the Toggle Button
238
245
if ( toggleButton ) {
239
246
toggleButton . addEventListener ( 'click' , ( ) => {
240
247
if ( tokenTablesContainer . style . display === 'none' || tokenTablesContainer . style . display === '' ) {
241
248
tokenTablesContainer . style . display = 'block' ;
242
- toggleButton . innerHTML = '▲' ; // Pfeil nach oben
249
+ toggleButton . innerHTML = '▲' ; // Up arrow
243
250
} else {
244
251
tokenTablesContainer . style . display = 'none' ;
245
- toggleButton . innerHTML = '▼' ; // Pfeil nach unten
252
+ toggleButton . innerHTML = '▼' ; // Down arrow
246
253
}
247
254
248
255
adjustWindowSize ( ) ;
249
256
} ) ;
250
257
}
251
258
}
252
259
260
+
253
261
function adjustWindowSize ( ) {
254
262
// Warten, bis der Inhalt gerendert wurde
255
263
setTimeout ( ( ) => {
0 commit comments