-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #254 from mkobayashime/slack-no-autofocus
Use more general logic and support the new UI
- Loading branch information
Showing
3 changed files
with
22 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,15 @@ | ||
const waitForChannelNameWrapper = async (): Promise<Element> => | ||
new Promise((resolve) => { | ||
const timeout = window.setTimeout(() => { | ||
throw new Error("Timeout: Getting channel name wrapper"); | ||
}, 30000); | ||
void (async () => { | ||
let curTitle = ""; | ||
|
||
const interval = window.setInterval(() => { | ||
const channelNameWrapper = document.querySelector( | ||
".p-workspace__primary_view" | ||
); | ||
new MutationObserver(() => { | ||
if (document.title === curTitle) return; | ||
|
||
if (channelNameWrapper) { | ||
resolve(channelNameWrapper); | ||
curTitle = document.title; | ||
|
||
window.clearInterval(interval); | ||
window.clearTimeout(timeout); | ||
} | ||
}, 200); | ||
if (!(document.activeElement instanceof HTMLElement)) return; | ||
document.activeElement.blur(); | ||
}).observe(document.head, { | ||
subtree: true, | ||
childList: true, | ||
}); | ||
|
||
(async function () { | ||
const channelNameWrapper = await waitForChannelNameWrapper(); | ||
|
||
new MutationObserver((e) => { | ||
const oldAriaLabel = e[0].oldValue; | ||
|
||
if (!(e[0].target instanceof HTMLElement)) return; | ||
const currentAriaLabel = e[0].target.ariaLabel; | ||
|
||
if (!oldAriaLabel || !currentAriaLabel) return; | ||
|
||
if (oldAriaLabel !== currentAriaLabel) { | ||
if (!(document.activeElement instanceof HTMLElement)) return; | ||
document.activeElement.blur(); | ||
} | ||
}).observe(channelNameWrapper, { attributeOldValue: true }); | ||
})(); |