Browse Source

Add link to latest release in readme (#395)

master
Jonas Gierer 7 years ago
committed by GitHub
parent
commit
be756e68dd
  1. 14
      extension/content.css
  2. 39
      extension/content.js
  3. 1
      extension/manifest.json
  4. 2
      extension/vendor/to-semver.js
  5. 2
      readme.md

14
extension/content.css

@ -190,22 +190,30 @@ a .commit-ref:hover span {
}
/* style for edit README button */
#readme.blob #refined-github-readme-edit-link {
#readme.blob #refined-github-readme-buttons {
display: none;
}
#refined-github-readme-edit-link {
#refined-github-readme-buttons {
position: absolute;
top: 10px;
right: 10px;
}
#refined-github-readme-buttons a {
opacity: 0.2;
transition: opacity 250ms;
text-decoration: none;
}
#refined-github-readme-edit-link:hover {
#refined-github-readme-buttons a:hover {
opacity: 1;
}
#refined-github-readme-buttons a:not(:first-child) {
margin-left: 5px;
}
/* style for delete fork link */
.post-merge-message {
min-height: 85px;

39
extension/content.js

@ -1,4 +1,4 @@
/* globals utils, gitHubInjection, pageDetect, icons, diffFileHeader, addReactionParticipants, addFileCopyButton, addGistCopyButton, enableCopyOnY, showRealNames, markUnread, linkifyURLsInCode, addUploadBtn, filePathCopyBtnListner, elementReady */
/* globals utils, toSemver, gitHubInjection, pageDetect, icons, diffFileHeader, addReactionParticipants, addFileCopyButton, addGistCopyButton, enableCopyOnY, showRealNames, markUnread, linkifyURLsInCode, addUploadBtn, filePathCopyBtnListner, elementReady */
'use strict';
const {ownerName, repoName} = pageDetect.getOwnerAndRepo();
@ -165,24 +165,45 @@ function infinitelyMore() {
}
}
function addReadmeEditButton() {
function addReadmeButtons() {
const readmeContainer = utils.select('#readme');
if (!readmeContainer) {
return;
}
let releaseButtonHtml = '';
const releases = [];
$('.branch-select-menu .select-menu-list[data-tab-filter="tags"] .select-menu-item').each((index, element) => {
releases.push({
name: element.getAttribute('data-name'),
link: element.getAttribute('href')
});
});
const releaseNamesSorted = toSemver(releases.map(release => release.name), {clean: false});
if (releaseNamesSorted.length > 0) {
const latestRelease = releases.find(release => release.name === releaseNamesSorted[0]);
if (latestRelease) {
releaseButtonHtml = `
<a href="${latestRelease.link}#readme" class="tooltipped tooltipped-nw" aria-label="View this file at the latest version (${latestRelease.name})">${icons.tag}</a>
`;
}
}
const readmeName = utils.select('#readme > h3').textContent.trim();
const path = $('.js-repo-root ~ .js-path-segment, .final-path').get().map(el => el.textContent).join('/');
const selectMenuButton = utils.select('.file-navigation .select-menu.float-left button.select-menu-button');
const currentBranch = selectMenuButton.getAttribute('title') || selectMenuButton.querySelector('span').textContent;
const editHref = `/${repoUrl}/edit/${currentBranch}/${path ? `${path}/` : ''}${readmeName}`;
const editButtonHtml = `<div id="refined-github-readme-edit-link">
<a href="${editHref}">
${icons.edit}
</a>
</div>`;
const editButtonHtml = `
<a href="${editHref}" class="tooltipped tooltipped-nw" aria-label="Edit this file">${icons.edit}</a>
`;
$(editButtonHtml).appendTo(readmeContainer);
$(`
<div id="refined-github-readme-buttons">
${releaseButtonHtml}
${editButtonHtml}
</div>
`).appendTo(readmeContainer);
}
function addDeleteForkLink() {
@ -538,7 +559,7 @@ function init() {
}
if (pageDetect.isRepoRoot() || pageDetect.isRepoTree()) {
addReadmeEditButton();
addReadmeButtons();
}
if (pageDetect.isPRList() || pageDetect.isIssueList()) {

1
extension/manifest.json

@ -41,6 +41,7 @@
"vendor/jquery.slim.min.js",
"vendor/element-ready.js",
"vendor/gh-injection.js",
"vendor/to-semver.js",
"vendor/webext-dynamic-content-scripts.js",
"util.js",
"page-detect.js",

2
extension/vendor/to-semver.js

File diff suppressed because one or more lines are too long

2
readme.md

@ -19,7 +19,7 @@ Our hope is that GitHub will notice and implement some of these much needed impr
- [Adds a 'Releases' tab to repos](https://cloud.githubusercontent.com/assets/170270/13136797/16d3f0ea-d64f-11e5-8a45-d771c903038f.png) *(<kbd>g</kbd><kbd>r</kbd> hotkey)*
- [Adds a 'Compare' tab to repos](screenshot-compare-tab.png)
- [Adds user avatars to Reactions](screenshot-reactions.png)
- [Adds a quick edit button to the readme](https://cloud.githubusercontent.com/assets/170270/13379292/61cd4c42-de54-11e5-8829-f4b82ba8c2bc.png)
- [Adds a quick edit button and a link to the latest release to the readme](https://cloud.githubusercontent.com/assets/4331946/25596611/4afa98ae-2eca-11e7-9dbf-72a9e7ffe82d.jpg)
- [Shows current filename in the sticky pull request header](https://cloud.githubusercontent.com/assets/170270/14153322/97a8e902-f6e1-11e5-8331-19e284e3e6fa.png)
- [Shows user's full name in comments](https://cloud.githubusercontent.com/assets/170270/16172068/0a67b98c-3580-11e6-92f0-6fc930ee17d1.png)
- [Improves readability of tab indented code](https://cloud.githubusercontent.com/assets/170270/14170088/d3be931e-f755-11e5-8edf-c5f864336382.png)

Loading…
Cancel
Save