From 3199e2bd52aefb41bc75e94c939d1d021ee5823e Mon Sep 17 00:00:00 2001 From: Yatharth Agarwal Date: Tue, 26 Nov 2019 23:01:00 -0800 Subject: [PATCH 1/4] Fix hiding conversations by changing CSS selectors --- source/browser.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/browser.ts b/source/browser.ts index 6a0647622..53df37891 100644 --- a/source/browser.ts +++ b/source/browser.ts @@ -51,7 +51,7 @@ async function withSettingsMenu(callback: () => Promise | void): Promise( - `.uiLayer:not(.hidden_elem) ._54nq._2i-c._558b._2n_z li:nth-child(${itemNumber}) a` + `.uiLayer:not(.hidden_elem) [role=menu] > li:nth-child(${itemNumber}) a` ); if (selector) { @@ -483,7 +483,7 @@ function setZoom(zoomFactor: number): void { async function withConversationMenu(callback: () => void): Promise { const menuButton = document.querySelector( - `${selectedConversationSelector} ._5blh._4-0h` + `${selectedConversationSelector} [aria-haspopup=true] [role=button]` ); if (menuButton) { From 84c825e86876fb85ee9a9748f11abf452a56b852 Mon Sep 17 00:00:00 2001 From: Yatharth Agarwal Date: Tue, 26 Nov 2019 23:24:30 -0800 Subject: [PATCH 2/4] Fix checking whether selected conversation is a group conversation --- source/browser.ts | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/source/browser.ts b/source/browser.ts index 53df37891..3c7f9ff30 100644 --- a/source/browser.ts +++ b/source/browser.ts @@ -9,6 +9,7 @@ import {createConversationList} from './browser/conversation-list'; const selectedConversationSelector = '._5l-3._1ht1._1ht2'; const preferencesSelector = '._10._4ebx.uiLayer._4-hy'; const messengerSoundsSelector = `${preferencesSelector} ._374d ._6bkz`; +const conversationMenuSelector = '.uiLayer:not(.hidden_elem) [role=menu]'; async function withMenu( menuButtonElement: HTMLElement, @@ -51,7 +52,7 @@ async function withSettingsMenu(callback: () => Promise | void): Promise( - `.uiLayer:not(.hidden_elem) [role=menu] > li:nth-child(${itemNumber}) a` + `${conversationMenuSelector} > li:nth-child(${itemNumber}) a` ); if (selector) { @@ -497,25 +498,32 @@ async function openMuteModal(): Promise { }); } -async function hideSelectedConversation(): Promise { - const groupConversationProfilePicture = document.querySelector( - `${selectedConversationSelector} ._55lu` +/* +This function assumes: + - There is a currently selected conversation. + - That conversation already has its conversation menu open. + +In other words, you should only use this function within a callback + that is provided to withConversationMenu() because withConversationMenu() + makes sure to have the conversation menu open before executing the + callback and closes the conversation menu afterward. +*/ +function isSelectedConversationGroup(): Boolean { + const separator = document.querySelector( + `${conversationMenuSelector} > li:nth-child(6)[role=separator]` ); - const isGroupConversation = Boolean(groupConversationProfilePicture); + return Boolean(separator); +} +async function hideSelectedConversation(): Promise { await withConversationMenu(() => { - selectMenuItem(isGroupConversation ? 4 : 3); + selectMenuItem(isSelectedConversationGroup() ? 4 : 3); }); } async function deleteSelectedConversation(): Promise { - const groupConversationProfilePicture = document.querySelector( - `${selectedConversationSelector} ._55lu` - ); - const isGroupConversation = Boolean(groupConversationProfilePicture); - await withConversationMenu(() => { - selectMenuItem(isGroupConversation ? 5 : 4); + selectMenuItem(isSelectedConversationGroup() ? 5 : 4); }); } From a012a148c0577d4bdad2e0098b6b131551bc7d4d Mon Sep 17 00:00:00 2001 From: Yatharth Agarwal Date: Tue, 26 Nov 2019 23:38:13 -0800 Subject: [PATCH 3/4] Adhere to lint rules by lowercasing Boolean in type annotation --- source/browser.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/browser.ts b/source/browser.ts index 3c7f9ff30..e004e40a7 100644 --- a/source/browser.ts +++ b/source/browser.ts @@ -508,7 +508,7 @@ In other words, you should only use this function within a callback makes sure to have the conversation menu open before executing the callback and closes the conversation menu afterward. */ -function isSelectedConversationGroup(): Boolean { +function isSelectedConversationGroup(): boolean { const separator = document.querySelector( `${conversationMenuSelector} > li:nth-child(6)[role=separator]` ); From 1b2bd1c83f478a0982e5904ea51f3a8188117be4 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Fri, 17 Jan 2020 00:15:56 +0700 Subject: [PATCH 4/4] Update browser.ts --- source/browser.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/source/browser.ts b/source/browser.ts index e004e40a7..45e4646ae 100644 --- a/source/browser.ts +++ b/source/browser.ts @@ -500,13 +500,10 @@ async function openMuteModal(): Promise { /* This function assumes: - - There is a currently selected conversation. - - That conversation already has its conversation menu open. +- There is a selected conversation. +- That the conversation already has its conversation menu open. -In other words, you should only use this function within a callback - that is provided to withConversationMenu() because withConversationMenu() - makes sure to have the conversation menu open before executing the - callback and closes the conversation menu afterward. +In other words, you should only use this function within a callback that is provided to `withConversationMenu()`, because `withConversationMenu()` makes sure to have the conversation menu open before executing the callback and closes the conversation menu afterwards. */ function isSelectedConversationGroup(): boolean { const separator = document.querySelector(