Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion shells/chrome/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const apiKey = 'dc6zaTOxFJmzC'; // Public API key
// on github.com
function giphySearch(searchTerm) {
const encodedSearch = encodeURIComponent(searchTerm);
const uri = `${apiBase}/gifs/search?q=${encodedSearch}&api_key=${apiKey}`;
const uri = `${apiBase}/gifs/search?q=${encodedSearch}&api_key=${apiKey}&limit=8`;
return fetch(uri).then(res => res.json()).then(res => {
return res.data.map(image => ({
uri: image.images.original.url,
Expand Down
2 changes: 1 addition & 1 deletion shells/chrome/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
],
"background": {
"scripts": ["background.js"],
"peristent": false
"persistent": false

@DrewML DrewML Feb 3, 2017 •

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha! Can't believe I missed that 😆. Nice catch

}
}
20 changes: 10 additions & 10 deletions src/js/sites/GitHub/api.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { getAuthenticityToken, getPreviewUri } from './page';

function getMarkdownPreview(text) {
// Upgrade jQuery deferred to an ES6 Promise
return Promise.resolve($.ajax({
return fetch('https://api.github.com/markdown', {
method: 'POST',
url: getPreviewUri(),
data: {
authenticity_token: getAuthenticityToken(),
headers: {
"Content-Type" : "application/json",
"Accept": "application/vnd.github.v3+json",
},
body : JSON.stringify({
mode: 'markdown',
text
}
}));
}),
}).then(res => res.text())
}

export function bypassCSPForImages(images = []) {
const markdown = images.map(image => (
`![${image.name}](${image.uri}) ![downsized](${image.downsizedUri})`
)).join('\n\n');

return getMarkdownPreview(markdown).then(res => {
const $res = $(res);
return Array.from($res.filter('p')).map(p => {
Expand Down
9 changes: 0 additions & 9 deletions src/js/sites/GitHub/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@ export function onGiphyBtnClick(cb) {
));
}

export function getAuthenticityToken() {
return $('input[name="authenticity_token"]').val();
}

export function getPreviewUri() {
return $('.js-previewable-comment-form')
.attr('data-preview-url');
}

export function insertTextAtCursor(textarea, text) {
const pos = textarea.selectionStart;
const currentVal = textarea.value;
Expand Down
2 changes: 1 addition & 1 deletion src/js/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default {
updateImageList(images = []) {
const imageDOM = images.map(image => {
return `<li>
<img src="${image.downsizedUri}" title="${image.name}" data-full-uri="${image.uri}>"
<img src="${image.downsizedUri}" title="${image.name}" data-full-uri="${image.uri}" />
</li>`;
}).join('');

Expand Down