From fb58ab591cec0d380b8a793aa2fe135984f2667b Mon Sep 17 00:00:00 2001 From: Andrew Levine Date: Thu, 7 Apr 2016 02:43:10 -0500 Subject: [PATCH] Add Edit(Pencil) link for readmes not in the root --- extension/content.js | 9 +++++++-- extension/page-detect.js | 3 +++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/extension/content.js b/extension/content.js index 7baa6ad..404783c 100755 --- a/extension/content.js +++ b/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 = `