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, 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 } } diff --git a/src/js/sites/GitHub/api.js b/src/js/sites/GitHub/api.js index b9be161..a26bd34 100644 --- a/src/js/sites/GitHub/api.js +++ b/src/js/sites/GitHub/api.js @@ -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 => ( ` ` )).join('\n\n'); - + return getMarkdownPreview(markdown).then(res => { const $res = $(res); return Array.from($res.filter('p')).map(p => { 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; 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 `