summaryrefslogtreecommitdiff
path: root/source/features/highlight-deleted-and-added-files-in-diffs.tsx
diff options
context:
space:
mode:
authorGravatar yakov116 <16872793+yakov116@users.noreply.github.com> 2020-08-19 21:52:22 -0400
committerGravatar GitHub <noreply@github.com> 2020-08-20 02:52:22 +0100
commit4248fcf8a430093077c5109e6e5f675c6a068045 (patch)
treee9009e6fd4fe7514e2a671262ba9d07dfbf07f95 /source/features/highlight-deleted-and-added-files-in-diffs.tsx
parent1fb0f872c8d8739f3e6108c633dce3d31b6e4dfd (diff)
downloadrefined-github-4248fcf8a430093077c5109e6e5f675c6a068045.tar.gz
refined-github-4248fcf8a430093077c5109e6e5f675c6a068045.tar.zst
refined-github-4248fcf8a430093077c5109e6e5f675c6a068045.zip
Lint (#3478)20.8.20
Diffstat (limited to 'source/features/highlight-deleted-and-added-files-in-diffs.tsx')
-rw-r--r--source/features/highlight-deleted-and-added-files-in-diffs.tsx19
1 files changed, 11 insertions, 8 deletions
diff --git a/source/features/highlight-deleted-and-added-files-in-diffs.tsx b/source/features/highlight-deleted-and-added-files-in-diffs.tsx
index dc3e5cac..36d8078a 100644
--- a/source/features/highlight-deleted-and-added-files-in-diffs.tsx
+++ b/source/features/highlight-deleted-and-added-files-in-diffs.tsx
@@ -1,19 +1,21 @@
import React from 'dom-chef';
import select from 'select-dom';
-import oneTime from 'onetime';
-import {observe} from 'selector-observer';
import elementReady from 'element-ready';
import * as pageDetect from 'github-url-detection';
+import {observe, Observer} from 'selector-observer';
import features from '.';
import {observeOneMutation} from '../helpers/simplified-element-observer';
+let observer: Observer;
+
async function loadDeferred(jumpList: Element): Promise<void> {
- const loadJumpList = (jumpList: Element) => jumpList.parentElement!.dispatchEvent(new MouseEvent('mouseover'));
- loadJumpList(jumpList);
- // The event listener might not have been attached yet, so we can try twice
- setTimeout(loadJumpList, 1000, jumpList);
+ // This event will trigger the loading, but if run too early, GitHub might not have attached the listener yet, so we try multiple times.
+ const retrier = setInterval(() => {
+ jumpList.parentElement!.dispatchEvent(new MouseEvent('mouseover'));
+ }, 100);
await observeOneMutation(jumpList);
+ clearInterval(retrier);
}
async function init(): Promise<void> {
@@ -25,7 +27,7 @@ async function init(): Promise<void> {
await loadDeferred(fileList!);
}
- observe('.file-info [href]:not(.rgh-pr-file-state)', {
+ observer = observe('.file-info [href]:not(.rgh-pr-file-state)', {
constructor: HTMLAnchorElement,
add(filename) {
filename.classList.add('rgh-pr-file-state');
@@ -65,6 +67,7 @@ void features.add({
pageDetect.isPRFile404,
pageDetect.isPRCommit404
],
- init: oneTime(init),
+ init,
+ deinit: () => observer.abort(),
waitForDomReady: false
});