Browse Source

Add file path copy button to PR diffs (#417)

master
Ashik Nesin 8 years ago
committed by Sindre Sorhus
parent
commit
59cf292062
  1. 8
      extension/content.css
  2. 3
      extension/content.js
  3. 38
      extension/copy-file-path.js
  4. 1
      extension/manifest.json
  5. 3
      readme.md

8
extension/content.css

@ -593,6 +593,14 @@ div.inline-comment-form .form-actions,
float: none;
}
/* "Copy file path" button in pull request diffs */
#rg-copy-filepath-btn,
#rg-copy-filepath-btn:focus,
#rg-copy-filepath-btn:active {
border: none;
background: transparent;
}
/* "Add a Project" button */
#refined-github-project-new-link {
margin-top: 5px;

3
extension/content.js

@ -1,4 +1,4 @@
/* globals utils, gitHubInjection, pageDetect, icons, diffFileHeader, addReactionParticipants, addFileCopyButton, addGistCopyButton, enableCopyOnY, showRealNames, markUnread, linkifyURLsInCode, addUploadBtn */
/* globals utils, gitHubInjection, pageDetect, icons, diffFileHeader, addReactionParticipants, addFileCopyButton, addGistCopyButton, enableCopyOnY, showRealNames, markUnread, linkifyURLsInCode, addUploadBtn, filePathCopyBtnListner */
'use strict';
const {ownerName, repoName} = pageDetect.getOwnerAndRepo();
@ -504,6 +504,7 @@ document.addEventListener('DOMContentLoaded', () => {
if (pageDetect.isPRFiles() || pageDetect.isPRCommit()) {
diffFileHeader.setup();
addDiffViewWithoutWhitespaceOption('pr');
filePathCopyBtnListner();
}
if (pageDetect.isSingleFile()) {

38
extension/copy-file-path.js

@ -0,0 +1,38 @@
/* globals utils addFilePathCopyBtn */
'use strict';
window.addFilePathCopyBtn = () => {
const $files = $('#files .file');
$files.each((i, el) => {
// Button already added
if ($(el).find('.copy-filepath-btn').length > 0) {
return;
}
const $fileUri = $(el).find('.file-header .file-info a');
const filePath = $fileUri.attr('title');
const copyButton = `
<button id="rg-copy-filepath-btn" class="btn-octicon tooltipped tooltipped-nw btn btn-sm copy-filepath-btn">
<svg aria-hidden="true" class="octicon octicon-clippy" height="16" version="1.1" viewBox="0 0 14 16" width="14" aria-label="Copy to clipboard">
<path fill-rule="evenodd" d="M2 13h4v1H2v-1zm5-6H2v1h5V7zm2 3V8l-3 3 3 3v-2h5v-2H9zM4.5 9H2v1h2.5V9zM2 12h2.5v-1H2v1zm9 1h1v2c-.02.28-.11.52-.3.7-.19.18-.42.28-.7.3H1c-.55 0-1-.45-1-1V4c0-.55.45-1 1-1h3c0-1.11.89-2 2-2 1.11 0 2 .89 2 2h3c.55 0 1 .45 1 1v5h-1V6H1v9h10v-2zM2 5h8c0-.55-.45-1-1-1H8c-.55 0-1-.45-1-1s-.45-1-1-1-1 .45-1 1-.45 1-1 1H3c-.55 0-1 .45-1 1z">
</path>
</svg>
</button>`;
$(copyButton)
.insertAfter($fileUri)
.mouseenter(e => {
$(e.currentTarget).attr('aria-label', 'Copy file path');
})
.on('click', e => {
e.preventDefault();
$(e.currentTarget).attr('aria-label', 'Copied!');
utils.copyToClipboard(filePath);
});
});
};
window.filePathCopyBtnListner = () => {
const $filesBucket = $('#files_bucket #files');
new MutationObserver(addFilePathCopyBtn).observe($filesBucket[0], {childList: true, subtree: true});
};

1
extension/manifest.json

@ -32,6 +32,7 @@
"icons.js",
"diffheader.js",
"reactions-avatars.js",
"copy-file-path.js",
"copy-file.js",
"copy-gist.js",
"copy-on-y.js",

3
readme.md

@ -28,7 +28,8 @@ Our hope is that GitHub will notice and implement some of these much needed impr
- [Adds option to view diffs without whitespace changes](https://cloud.githubusercontent.com/assets/170270/17603894/7b71a166-6013-11e6-81b8-22950ab8bce3.png) *(<kbd>d</kbd><kbd>w</kbd> hotkey)*
- [Adds links to patch and diff for each commit](https://cloud.githubusercontent.com/assets/737065/13605562/22faa79e-e516-11e5-80db-2da6aa7965ac.png)
- [Differentiates merge commits from regular commits](https://cloud.githubusercontent.com/assets/170270/14101222/2fe2c24a-f5bd-11e5-8b1f-4e589917d4c4.png)
- [Adds a `Copy` button to gist files](https://cloud.githubusercontent.com/assets/170270/21074840/5dc37578-bf03-11e6-9fd9-501d73edef87.png)
- [Adds `Copy` button to gist files](https://cloud.githubusercontent.com/assets/170270/21074840/5dc37578-bf03-11e6-9fd9-501d73edef87.png)
- [Adds `Copy` button for file paths to pull request diffs](https://cloud.githubusercontent.com/assets/4201088/26023064/18c9c77c-37d2-11e7-8926-b0a05a2706ae.png)
- [Adds labels to comments by the original poster](https://cloud.githubusercontent.com/assets/4331946/25075520/d62fbbd0-2316-11e7-921f-ab736dc3522e.png)
- [Adds navigation to milestone pages](https://cloud.githubusercontent.com/assets/170270/25217211/37b67aea-25d0-11e7-8482-bead2b04ee74.png)
- [Adds search filter for 'Everything commented by you'](https://cloud.githubusercontent.com/assets/940070/25518367/cb917d3e-2c36-11e7-8475-c4e6dbe0ed6c.png)

Loading…
Cancel
Save