import './edit-files-faster.css'; import React from 'dom-chef'; import select from 'select-dom'; import PencilIcon from 'octicon/pencil.svg'; import * as pageDetect from 'github-url-detection'; import {wrap} from '../helpers/dom-utils'; import features from '.'; import GitHubURL from '../github-helpers/github-url'; import {isPermalink} from '../github-helpers'; import getDefaultBranch from '../github-helpers/get-default-branch'; import onFileListUpdate from '../github-events/on-file-list-update'; async function init(): Promise { const isPermalink_ = await isPermalink(); for (const fileIcon of select.all('.js-navigation-container .octicon-file')) { const fileLink = fileIcon.closest('.js-navigation-item')!.querySelector('.js-navigation-open')!; const url = new GitHubURL(fileLink.href).assign({ route: 'edit' }); if (isPermalink_) { // eslint-disable-next-line no-await-in-loop url.branch = await getDefaultBranch(); // Permalinks can't be edited } wrap(fileIcon, ); fileIcon.after(); } } void features.add(__filebasename, { include: [ pageDetect.isRepoTree ], additionalListeners: [ onFileListUpdate ], init });