Skip to content
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ GitHub Enterprise is also supported by [authorizing your own domain in the optio
- Copy canonical link to file when [the <kbd>y</kbd> hotkey](https://help.github.com/articles/getting-permanent-links-to-files/) is used
- Supports indenting with the tab key in textareas like the comment box (<kbd>Shift</kbd> <kbd>Tab</kbd> for original behavior)
- [Uses the pull request title as commit title when merging with 'Squash and merge'](https://github.com/sindresorhus/refined-github/issues/276)
- [Replaces linked gists in issue and pull request comments with an embedded version of the gist file](https://user-images.githubusercontent.com/6978877/33911900-c62ee968-df8b-11e7-8685-506ffafc60b4.PNG)

### More actions

Expand Down
2 changes: 2 additions & 0 deletions source/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import focusConfirmationButtons from './features/focus-confirmation-buttons';
import addKeyboardShortcutsToCommentFields from './features/add-keyboard-shortcuts-to-comment-fields';
import addConfirmationToCommentCancellation from './features/add-confirmation-to-comment-cancellation';
import addCILink from './features/add-ci-link';
import embedGistInline from './features/embed-gist-inline';
import expandCollapseOutdatedComments from './features/expand-collapse-outdated-comments';

import * as pageDetect from './libs/page-detect';
Expand Down Expand Up @@ -161,6 +162,7 @@ function ajaxedPagesHandler() {
if (pageDetect.isPR() || pageDetect.isIssue()) {
safely(linkifyIssuesInTitles);
safely(addUploadBtn);
safely(embedGistInline);

observeEl('.new-discussion-timeline', () => {
safely(addOPLabels);
Expand Down
28 changes: 28 additions & 0 deletions source/features/embed-gist-inline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {h} from 'dom-chef';
import select from 'select-dom';

const isGist = link =>
!link.pathname.includes('.') && // Exclude links to embed files
(
link.hostname.startsWith('gist.') ||
link.pathname.startsWith('gist/')
);

const createGistElement = gistData => (
<div>
<link rel="stylesheet" href={gistData.stylesheet} />
<div dangerouslySetInnerHTML={{__html: gistData.div}} />
</div>
);

async function embedGist(link) {
const response = await fetch(`${link.href}.json`);
const gistData = await response.json();
const gistEl = createGistElement(gistData);
link.parentNode.attachShadow({mode: 'open'}).append(gistEl);
}
export default () => {
select.all('.js-comment-body p a:only-child')
.filter(isGist)
.forEach(embedGist);
};