summaryrefslogtreecommitdiff
path: root/source/libs/on-file-list-update.ts
blob: 13ad3d5b5bc80e1196db9882bc6f6f6607f5e23b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import select from 'select-dom';
import domLoaded from 'dom-loaded';

// Copied from https://github.com/sindresorhus/hide-files-on-github
export default async function (callback: VoidFunction): Promise<void> {
	await domLoaded;

	const observer = new MutationObserver(callback);
	const update = (): void => {
		callback();

		const ajaxFiles = select('include-fragment.file-wrap');
		if (ajaxFiles) {
			observer.observe(ajaxFiles.parentNode!, {
				childList: true
			});
		}
	};

	update();
	document.addEventListener('pjax:end', update);
}