From 7686e56c00c724ad6f9e133134787e2cd083b062 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Fri, 27 Dec 2019 18:58:11 -0500 Subject: Move display templates into a single file --- ext/bg/js/api.js | 4 +++ ext/bg/js/backend.js | 8 +++++- ext/bg/js/request.js | 21 ++++++++------ ext/bg/search.html | 78 ---------------------------------------------------- 4 files changed, 23 insertions(+), 88 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js index 906aaa30..285b8016 100644 --- a/ext/bg/js/api.js +++ b/ext/bg/js/api.js @@ -25,6 +25,10 @@ function apiAudioGetUrl(definition, source, optionsContext) { return _apiInvoke('audioGetUrl', {definition, source, optionsContext}); } +function apiGetDisplayTemplatesHtml() { + return _apiInvoke('getDisplayTemplatesHtml'); +} + function _apiInvoke(action, params={}) { const data = {action, params}; return new Promise((resolve, reject) => { diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index 28b0201e..391d6243 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -522,6 +522,11 @@ class Backend { return result; } + async _onApiGetDisplayTemplatesHtml() { + const url = chrome.runtime.getURL('/mixed/display-templates.html'); + return await requestText(url, 'GET'); + } + // Command handlers async _onCommandSearch(params) { @@ -735,7 +740,8 @@ Backend._messageHandlers = new Map([ ['frameInformationGet', (self, ...args) => self._onApiFrameInformationGet(...args)], ['injectStylesheet', (self, ...args) => self._onApiInjectStylesheet(...args)], ['getEnvironmentInfo', (self, ...args) => self._onApiGetEnvironmentInfo(...args)], - ['clipboardGet', (self, ...args) => self._onApiClipboardGet(...args)] + ['clipboardGet', (self, ...args) => self._onApiClipboardGet(...args)], + ['getDisplayTemplatesHtml', (self, ...args) => self._onApiGetDisplayTemplatesHtml(...args)] ]); Backend._commandHandlers = new Map([ diff --git a/ext/bg/js/request.js b/ext/bg/js/request.js index b584c9a9..778f933b 100644 --- a/ext/bg/js/request.js +++ b/ext/bg/js/request.js @@ -17,10 +17,10 @@ */ -function requestJson(url, action, params) { +function requestText(url, action, params) { return new Promise((resolve, reject) => { const xhr = new XMLHttpRequest(); - xhr.overrideMimeType('application/json'); + xhr.overrideMimeType('text/plain'); xhr.addEventListener('load', () => resolve(xhr.responseText)); xhr.addEventListener('error', () => reject(new Error('Failed to connect'))); xhr.open(action, url); @@ -29,12 +29,15 @@ function requestJson(url, action, params) { } else { xhr.send(); } - }).then((responseText) => { - try { - return JSON.parse(responseText); - } - catch (e) { - return Promise.reject(new Error('Invalid response')); - } }); } + +async function requestJson(url, action, params) { + const responseText = await requestText(url, action, params); + try { + return JSON.parse(responseText); + } + catch (e) { + throw new Error('Invalid response'); + } +} diff --git a/ext/bg/search.html b/ext/bg/search.html index 819c8505..74afbb68 100644 --- a/ext/bg/search.html +++ b/ext/bg/search.html @@ -66,84 +66,6 @@ - - - - - - - - - - - - - - - - - -- cgit v1.2.3