Skip to content

Commit 51fdf49

Browse files
committed
Add a quick edit button for every file in the repo file browser.
Let's you quickly edit files without first having to open them. To use, you can either add the following additions to your own fork, or download my fork and load extension in Chrome.
1 parent b08966a commit 51fdf49

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

extension/content.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,29 @@ function infinitelyMore() {
133133
}
134134
}
135135

136+
function addEditButtons() {
137+
var dirListItems = $('tr.js-navigation-item');
138+
139+
dirListItems.each((index, element) => {
140+
// Add edit link to each list item.
141+
142+
var isFile = $(element).find('td.icon > svg.octicon-file-text').size() === 1;
143+
if (isFile) {
144+
var editHref = $(element).find('td.content > span > a').attr('href').replace('blob', 'edit');
145+
var editButtonHtml =
146+
`<td class="icon" style="padding-left:9px;">
147+
<a href="${editHref}">
148+
<svg aria-hidden="true" class="octicon octicon-pencil" height="16" role="img" version="1.1" viewBox="0 0 14 16" width="14">
149+
<path d="M0 12v3h3l8-8-3-3L0 12z m3 2H1V12h1v1h1v1z m10.3-9.3l-1.3 1.3-3-3 1.3-1.3c0.39-0.39 1.02-0.39 1.41 0l1.59 1.59c0.39 0.39 0.39 1.02 0 1.41z">
150+
</path>
151+
</svg>
152+
</a>
153+
</td>`;
154+
$(element).children('td.icon').replaceWith(editButtonHtml);
155+
}
156+
});
157+
}
158+
136159
document.addEventListener('DOMContentLoaded', () => {
137160
const username = getUsername();
138161

@@ -158,6 +181,8 @@ document.addEventListener('DOMContentLoaded', () => {
158181

159182
if (isRepo) {
160183
gitHubInjection(window, () => {
184+
const isRepoTree = window.location.href.split('/').length === 5 || window.location.href.split('/')[5] === 'tree';
185+
161186
addReleasesTab();
162187

163188
if (isPR()) {
@@ -166,6 +191,9 @@ document.addEventListener('DOMContentLoaded', () => {
166191
if (isPR() || isIssue()) {
167192
moveVotes();
168193
}
194+
if (isRepoTree) {
195+
addEditButtons();
196+
}
169197
});
170198
}
171199
});

screenshot-quick-edit.png

14.9 KB
Loading

0 commit comments

Comments
 (0)