Skip to content

Commit bfc74ef

Browse files
committed
Fix broken menu bar items after facebook.com/messages migration
Update DOM selectors to use aria-label attributes instead of fragile auto-generated class names that changed with the migration: - Insert GIF: [aria-label="Choose a GIF"] - Insert Sticker: [aria-label="Choose a sticker"] - Insert Emoji: [aria-label="Choose an emoji"] - Attach Files: [aria-label="Attach a file up to 25 MB"] - Find Conversation: [aria-label="Search Messenger"] (was selecting Facebook search) - Search in Conversation: Simplified to click [aria-label="Search"] directly Fixes issues introduced in commit 5d4e29c
1 parent 9ac0a1b commit bfc74ef

1 file changed

Lines changed: 15 additions & 13 deletions

File tree

source/browser.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -156,42 +156,44 @@ ipc.answerMain('log-out', async () => {
156156
});
157157

158158
ipc.answerMain('find', () => {
159-
document.querySelector<HTMLElement>('[type="search"]')!.focus();
159+
document.querySelector<HTMLElement>('[aria-label="Search Messenger"]')!.focus();
160160
});
161161

162162
async function openSearchInConversation() {
163-
const mainView = document.querySelector('.x9f619.x1ja2u2z.x78zum5.x1n2onr6.x1r8uery.x1iyjqo2.xs83m0k.xeuugli.x1qughib.x1qjc9v5.xozqiw3.x1q0g3np.xexx8yu.x85a59c')!;
164-
const rightSidebarIsClosed = Boolean(mainView.querySelector<HTMLElement>(':scope > div:only-child'));
163+
const chatInfoButton = document.querySelector<HTMLElement>('[aria-label="Conversation information"]');
164+
const isPanelExpanded = chatInfoButton?.getAttribute('aria-expanded') === 'true';
165165

166-
if (rightSidebarIsClosed) {
166+
// Expand the right panel if it's collapsed
167+
if (!isPanelExpanded) {
167168
document.querySelector<HTMLElement>(selectors.rightSidebarMenu)?.click();
169+
// Wait for panel to expand and search button to appear
170+
await new Promise(resolve => {
171+
setTimeout(resolve, 300);
172+
});
168173
}
169174

170-
await elementReady(selectors.rightSidebarButtons, {stopOnDomReady: false});
171-
const buttonList = document.querySelectorAll<HTMLElement>(selectors.rightSidebarButtons);
172-
173-
// Search in conversation is the last button
174-
buttonList[buttonList.length - 1].click();
175+
// Click the Search button in the right panel
176+
document.querySelector<HTMLElement>('[aria-label="Search"]')?.click();
175177
}
176178

177179
ipc.answerMain('search', () => {
178180
openSearchInConversation();
179181
});
180182

181183
ipc.answerMain('insert-gif', () => {
182-
document.querySelector<HTMLElement>('.x1n2onr6.x1iyjqo2.xw2csxc > div:nth-child(3) > span > div')!.click();
184+
document.querySelector<HTMLElement>('[aria-label="Choose a GIF"]')!.click();
183185
});
184186

185187
ipc.answerMain('insert-emoji', async () => {
186-
document.querySelector<HTMLElement>('.x1n2onr6.x1iyjqo2.xw2csxc > div:nth-child(5) > span > div')!.click();
188+
document.querySelector<HTMLElement>('[aria-label="Choose an emoji"]')!.click();
187189
});
188190

189191
ipc.answerMain('insert-sticker', () => {
190-
document.querySelector<HTMLElement>('.x1n2onr6.x1iyjqo2.xw2csxc > div:nth-child(2) > span > div')!.click();
192+
document.querySelector<HTMLElement>('[aria-label="Choose a sticker"]')!.click();
191193
});
192194

193195
ipc.answerMain('attach-files', () => {
194-
document.querySelector<HTMLElement>('.x1n2onr6.x1iyjqo2.xw2csxc > div:nth-child(1) > span > div')!.click();
196+
document.querySelector<HTMLElement>('[aria-label="Attach a file up to 25 MB"]')!.click();
195197
});
196198

197199
ipc.answerMain('focus-text-input', () => {

0 commit comments

Comments
 (0)