summaryrefslogtreecommitdiff
path: root/source/features/clean-repo-filelist-actions.tsx
blob: 1c47242ca5cd1cf0b8442f29e240a3387fb55981 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import React from 'dom-chef';
import {$, elementExists} from 'select-dom';
import * as pageDetect from 'github-url-detection';
import {CodeIcon, PlusIcon, SearchIcon} from '@primer/octicons-react';

import observe from '../helpers/selector-observer.js';
import {assertNodeContent, wrap} from '../helpers/dom-utils.js';
import features from '../feature-manager.js';

/** Add tooltip on a wrapper to avoid breaking dropdown functionality */
function addTooltipToSummary(childElement: Element, tooltip: string): void {
	wrap(
		childElement.closest('details')!,
		<div className="tooltipped tooltipped-ne" aria-label={tooltip}/>,
	);
}

function cleanFilelistActions(searchButton: Element): void {
	searchButton.classList.add('tooltipped', 'tooltipped-ne');
	searchButton.setAttribute('aria-label', 'Go to file');

	// Replace "Go to file" with  icon
	searchButton.firstChild!.replaceWith(<SearchIcon/>);

	// This button doesn't appear on `isSingleFile`
	const addFileDropdown = searchButton.nextElementSibling!.querySelector('.dropdown-caret');
	if (addFileDropdown) {
		addFileDropdown.parentElement!.classList.replace('d-md-flex', 'd-md-block');

		// Replace label with icon
		assertNodeContent(addFileDropdown.previousSibling, 'Add file')
			.replaceWith(<PlusIcon/>);

		addTooltipToSummary(addFileDropdown, 'Add file');
	}

	if (!pageDetect.isRepoRoot()) {
		return;
	}

	const codeDropdownButton = $('get-repo summary')!;
	addTooltipToSummary(codeDropdownButton, 'Clone, open or download');

	const label = $('.Button-label', codeDropdownButton)!;
	if (!elementExists('.octicon-code', codeDropdownButton)) {
		// The icon is missing for users without Codespaces https://github.com/refined-github/refined-github/pull/5074#issuecomment-983251719
		label.before(<span className="Button-visual Button-leadingVisual"><CodeIcon/></span>);
	}

	label.remove();
}

function init(signal: AbortSignal): void {
	// `.btn` selects the desktop version
	observe('.btn[data-hotkey="t"]', cleanFilelistActions, {signal});
}

void features.add(import.meta.url, {
	include: [
		pageDetect.isRepoTree,
		pageDetect.isSingleFile,
	],
	exclude: [
		pageDetect.isRepoFile404,
	],
	init,
});

/*

Test URLs
https://github.com/refined-github/sandbox
https://github.com/refined-github/sandbox/tree/branch/with/slashes

*/
g-template'>nate/new-blog-template Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/packages/create-astro (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2023-01-12[ci] release (beta) (#5792)create-astro@2.0.0-beta.0astro@2.0.0-beta.2@astrojs/webapi@2.0.0-beta.0@astrojs/vue@2.0.0-beta.1@astrojs/vercel@3.0.0-beta.1@astrojs/telemetry@2.0.0-beta.0@astrojs/tailwind@3.0.0-beta.1@astrojs/svelte@2.0.0-beta.1@astrojs/solid-js@2.0.0-beta.0@astrojs/react@2.0.0-beta.0@astrojs/prism@2.0.0-beta.0@astrojs/preact@2.0.0-beta.0@astrojs/partytown@1.0.3-beta.0@astrojs/node@5.0.0-beta.1@astrojs/netlify@2.0.0-beta.2@astrojs/mdx@1.0.0-beta.2@astrojs/markdown-remark@2.0.0-beta.2@astrojs/lit@1.0.2-beta.0@astrojs/image@1.0.0-beta.2@astrojs/deno@4.0.0-beta.2@astrojs/cloudflare@6.0.0-beta.1Gravatar Fred K. Bot 2-1/+7
2023-01-12 Add `.astro/` to `.gitignore` in example projects (#5841)Gravatar Chris Swithinbank 24-98/+46
2023-01-12chore: update changeset for `_astro` directory (#5843)Gravatar Nate Moore 1-2/+2
2023-01-12fix: pass flags to dev (#5840)Gravatar Sam Chen 3-1/+9
2023-01-12chore: update changelogs, add changeset for `_astro` directory (#5842)Gravatar Nate Moore 5-18/+10
2023-01-12[ci] formatGravatar natemoo-re 1-1/+1
2023-01-12fix(core): handle encoded characters when matching routes (#5836)Gravatar Nate Moore 8-2/+85
2023-01-12Handle compiler breaking change (#5803)Gravatar Bjorn Lu 12-328/+109
2023-01-12fix shiki css class replace logic in md and mdx integrations (#5837)Gravatar Giuseppe La Torre 3-3/+9
2023-01-11[ci] formatGravatar matthewp 2-2/+2
2023-01-11Simplify HMR handling (#5811)Gravatar Bjorn Lu 8-108/+46
2023-01-11[Content collections] Remove experimental flag (#5825)Gravatar Ben Holmes 27-103/+58
2023-01-11[Content collections] Improve content config handling (#5824)Gravatar Ben Holmes 5-58/+78
2023-01-11Run sync as part of `astro check` (#5823)Gravatar Chris Swithinbank 3-2/+13
2023-01-11[ci] update lockfile (#5815)Gravatar Fred K. Bot 1-257/+256
2023-01-11Fix order-of-execution bug when generating pages (#5822)Gravatar Nate Moore 2-2/+7
2023-01-11Fix `Code.astro` shiki css class replace logic (#5829)Gravatar Giuseppe La Torre 2-1/+6