From c66d5e00f904095e42afc8ec9e5c7d7fae6ac500 Mon Sep 17 00:00:00 2001 From: Louis Lagrange Date: Wed, 1 Feb 2017 22:36:27 +0100 Subject: [PATCH 1/5] fix typo --- shells/chrome/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shells/chrome/manifest.json b/shells/chrome/manifest.json index ba58a00..0b5295f 100644 --- a/shells/chrome/manifest.json +++ b/shells/chrome/manifest.json @@ -17,6 +17,6 @@ ], "background": { "scripts": ["background.js"], - "peristent": false + "persistent": false } } From 499d829cd527af770d3ae8a0017532356d311743 Mon Sep 17 00:00:00 2001 From: Louis Lagrange Date: Wed, 1 Feb 2017 22:37:27 +0100 Subject: [PATCH 2/5] decrease nb of gifs (25 is way too much) Let's plan nfinite scroll ?? --- shells/chrome/background.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shells/chrome/background.js b/shells/chrome/background.js index 5aafaef..6fc46ca 100644 --- a/shells/chrome/background.js +++ b/shells/chrome/background.js @@ -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, From 4c9caeced3b6e8c138d6592f2820994c10c588e0 Mon Sep 17 00:00:00 2001 From: Louis Lagrange Date: Wed, 1 Feb 2017 22:38:22 +0100 Subject: [PATCH 3/5] fix bug when showing gif --- src/js/widget.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/widget.js b/src/js/widget.js index e1a2332..6664149 100644 --- a/src/js/widget.js +++ b/src/js/widget.js @@ -88,7 +88,7 @@ export default { updateImageList(images = []) { const imageDOM = images.map(image => { return `
  • -
  • `; }).join(''); From 0c48718eec42b0588a287c540a60db11246d1359 Mon Sep 17 00:00:00 2001 From: Louis Lagrange Date: Wed, 1 Feb 2017 22:39:05 +0100 Subject: [PATCH 4/5] make the extension work with the GitHub API v3 --- src/js/sites/GitHub/api.js | 36 ++++++++++++++++++------------------ src/js/sites/GitHub/page.js | 9 --------- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/src/js/sites/GitHub/api.js b/src/js/sites/GitHub/api.js index b9be161..9629cba 100644 --- a/src/js/sites/GitHub/api.js +++ b/src/js/sites/GitHub/api.js @@ -1,15 +1,15 @@ -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 = []) { @@ -18,14 +18,14 @@ export function bypassCSPForImages(images = []) { )).join('\n\n'); return getMarkdownPreview(markdown).then(res => { - const $res = $(res); - return Array.from($res.filter('p')).map(p => { - const imgs = $(p).find('img'); - return { - uri: imgs.get(0).src, - name: imgs.get(0).alt, - downsizedUri: imgs.get(1).src - }; - }); + const $res = $(res); + return Array.from($res.filter('p')).map(p => { + const imgs = $(p).find('img'); + return { + uri: imgs.get(0).src, + name: imgs.get(0).alt, + downsizedUri: imgs.get(1).src + }; + }); }); } diff --git a/src/js/sites/GitHub/page.js b/src/js/sites/GitHub/page.js index ac2c88b..b53302f 100644 --- a/src/js/sites/GitHub/page.js +++ b/src/js/sites/GitHub/page.js @@ -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; From 9616144c4429453c4e96d5cd61ccb10ff27fa0a8 Mon Sep 17 00:00:00 2001 From: Louis Lagrange Date: Fri, 3 Feb 2017 20:55:14 +0100 Subject: [PATCH 5/5] Fix indentation --- src/js/sites/GitHub/api.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/js/sites/GitHub/api.js b/src/js/sites/GitHub/api.js index 9629cba..a26bd34 100644 --- a/src/js/sites/GitHub/api.js +++ b/src/js/sites/GitHub/api.js @@ -16,16 +16,16 @@ 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 => { - const imgs = $(p).find('img'); - return { - uri: imgs.get(0).src, - name: imgs.get(0).alt, - downsizedUri: imgs.get(1).src - }; - }); + const $res = $(res); + return Array.from($res.filter('p')).map(p => { + const imgs = $(p).find('img'); + return { + uri: imgs.get(0).src, + name: imgs.get(0).alt, + downsizedUri: imgs.get(1).src + }; + }); }); }