Skip to content

Commit

Permalink
Disable dim-bots only when clicking on empty areas (refined-github#…
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante authored Sep 17, 2023
1 parent ca58484 commit 15e1ce7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions source/features/dim-bots.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import './dim-bots.css';
import select from 'select-dom';
import * as pageDetect from 'github-url-detection';
import delegate from 'delegate-it';
import delegate, {DelegateEvent} from 'delegate-it';

import features from '../feature-manager.js';
import preserveScroll from '../helpers/preserve-scroll.js';
Expand Down Expand Up @@ -35,8 +35,14 @@ const prSelectors = [

const dimBots = features.getIdentifiers(import.meta.url);

function undimBots(event: Event): void {
const resetScroll = preserveScroll(event.target as HTMLElement);
function undimBots(event: DelegateEvent): void {
const target = event.target as HTMLElement;
// Only undim when clicking on empty areas
if (target.closest('a, button, input, [tabindex]')) {
return;
}

const resetScroll = preserveScroll(target);
for (const bot of select.all(dimBots.selector)) {
bot.classList.add('rgh-interacted');
}
Expand All @@ -58,9 +64,6 @@ function init(signal: AbortSignal): void {

// Undim on mouse focus
delegate(dimBots.selector, 'click', undimBots, {signal});

// Undim on keyboard focus
document.documentElement.addEventListener('navigation:keydown', undimBots, {once: true, signal});
}

void features.add(import.meta.url, {
Expand Down
2 changes: 1 addition & 1 deletion source/features/hide-navigation-hover-highlight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const html = document.documentElement;

function init(): void {
html.setAttribute(attribute, '');
html.addEventListener('navigation:focus', () => {
html.addEventListener('navigation:keydown', () => {
html.removeAttribute(attribute);
}, {once: true});
}
Expand Down

0 comments on commit 15e1ce7

Please sign in to comment.