@@ -14,6 +14,20 @@ const padding = {
14
14
bottom : 3 ,
15
15
left : 0 ,
16
16
} ;
17
+
18
+ const translationDict = {
19
+ en : { markRead : 'Mark as read' ,
20
+ chats : 'Chats' ,
21
+ } ,
22
+ el : { markRead : 'Τα έχω διαβάσει' ,
23
+ chats : 'Συνομιλίες' ,
24
+ } ,
25
+ } ;
26
+
27
+ let translatedStrings = {
28
+ markRead : "" ,
29
+ chats : "" ,
30
+ }
17
31
18
32
function drawIcon ( size : number , img ?: HTMLImageElement ) : HTMLCanvasElement {
19
33
const canvas = document . createElement ( 'canvas' ) ;
@@ -131,7 +145,7 @@ async function createConversationNewDesign(element: HTMLElement): Promise<Conver
131
145
*/
132
146
133
147
conversation . selected = Boolean ( element . querySelector ( '[role=row] [role=link] > div:only-child' ) ) ;
134
- conversation . unread = Boolean ( element . querySelector ( ' [aria-label="Mark as Read"]' ) ) ;
148
+ conversation . unread = Boolean ( element . querySelector ( ` [aria-label="${ translatedStrings . markRead } "]` ) ) ;
135
149
136
150
const unparsedLabel = element . querySelector < HTMLElement > ( '.a8c37x1j.ni8dbmo4.stjgntxs.l9j0dhe7 > span > span' ) ! ;
137
151
conversation . label = await getLabel ( unparsedLabel ) ;
@@ -154,7 +168,14 @@ async function createConversationList(): Promise<Conversation[]> {
154
168
return [ ] ;
155
169
}
156
170
157
- const elements : HTMLElement [ ] = [ ...list . children ] as HTMLElement [ ] ;
171
+ const convList = list . querySelector ( 'div[class=x1n2onr6]' ) ;
172
+
173
+ if ( ! convList ) {
174
+ console . error ( 'No conversations found' ) ;
175
+ return [ ] ;
176
+ }
177
+
178
+ const elements : HTMLElement [ ] = [ ...convList . children ] as HTMLElement [ ] ;
158
179
159
180
// Remove last element from childer list
160
181
elements . splice ( - 1 , 1 ) ;
@@ -213,9 +234,17 @@ function countUnread(mutationsList: MutationRecord[]): void {
213
234
}
214
235
}
215
236
216
- window . addEventListener ( 'load' , async ( ) => {
217
- const sidebar = await elementReady ( '[role=navigation]' , { stopOnDomReady : false } ) ;
237
+ function transDictLookUp ( ) {
238
+ let locale = document . documentElement . lang ;
239
+ let currDict = translationDict [ locale as keyof typeof translationDict ] ;
218
240
241
+ translatedStrings . chats = currDict [ 'chats' ] ;
242
+ translatedStrings . markRead = currDict [ 'markRead' ] ;
243
+ }
244
+
245
+ window . addEventListener ( 'load' , async ( ) => {
246
+ transDictLookUp ( ) ;
247
+ const sidebar = await elementReady ( `[aria-label=${ translatedStrings . chats } ]` , { stopOnDomReady : false } ) ;
219
248
if ( sidebar ) {
220
249
const conversationListObserver = new MutationObserver ( async ( ) => sendConversationList ( ) ) ;
221
250
const conversationCountObserver = new MutationObserver ( countUnread ) ;
0 commit comments