Browse Source

Add Edit(Pencil) link for readmes not in the root

master
Andrew Levine 9 years ago
committed by Sindre Sorhus
parent
commit
fb58ab591c
  1. 9
      extension/content.js
  2. 3
      extension/page-detect.js

9
extension/content.js

@ -211,9 +211,14 @@ function addBlameParentLinks() {
function addReadmeEditButton() {
const readmeContainer = $('#readme');
if (!readmeContainer.length) {
return;
}
const readmeName = $('#readme > h3').text().trim();
const path = $('.js-repo-root ~ .js-path-segment, .final-path').map((idx, el) => $(el).text()).get().join('/');
const currentBranch = $('.file-navigation .select-menu.left button.select-menu-button').attr('title');
const editHref = `/${repoUrl}/edit/${currentBranch}/${readmeName}`;
const editHref = `/${repoUrl}/edit/${currentBranch}/${path ? `${path}/` : ''}${readmeName}`;
const editButtonHtml = `<div id="refined-github-readme-edit-link">
<a href="${editHref}">
<svg class="octicon octicon-pencil" height="16" version="1.1" viewBox="0 0 14 16" width="14"><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"></path></svg>
@ -384,7 +389,7 @@ document.addEventListener('DOMContentLoaded', () => {
addBlameParentLinks();
}
if (pageDetect.isRepoRoot()) {
if (pageDetect.isRepoRoot() || pageDetect.isRepoTree()) {
addReadmeEditButton();
}

3
extension/page-detect.js

@ -11,6 +11,8 @@ window.pageDetect = (() => {
const isRepoRoot = () => isRepo() && /^(\/?$|\/tree\/)/.test(getRepoPath()) && $('.repository-meta-content').length > 0;
const isRepoTree = () => isRepo() && /\/tree\//.test(getRepoPath());
const isIssueList = () => isRepo() && /^\/issues\/?$/.test(getRepoPath());
const isIssue = () => isRepo() && /^\/issues\/\d+/.test(getRepoPath());
@ -38,6 +40,7 @@ window.pageDetect = (() => {
isDashboard,
isRepo,
isRepoRoot,
isRepoTree,
isIssueList,
isIssue,
isPRList,

Loading…
Cancel
Save