From ce51fe7eca2e893c8631c62ccb39ce3921ad1b6b Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Mon, 9 Dec 2019 22:45:28 -0500 Subject: Use a single api.js --- ext/bg/background.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/bg/background.html') diff --git a/ext/bg/background.html b/ext/bg/background.html index 5a6970c3..11838d14 100644 --- a/ext/bg/background.html +++ b/ext/bg/background.html @@ -20,10 +20,10 @@ + - -- cgit v1.2.3 From ec8b805e8f273756e3f9f559533b35576bca9ab6 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Fri, 20 Dec 2019 22:43:30 -0500 Subject: Fix missing API functions being used on the background page --- ext/bg/background.html | 2 +- ext/bg/js/api.js | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 ext/bg/js/api.js (limited to 'ext/bg/background.html') diff --git a/ext/bg/background.html b/ext/bg/background.html index 11838d14..fc0758cf 100644 --- a/ext/bg/background.html +++ b/ext/bg/background.html @@ -20,9 +20,9 @@ - + diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js new file mode 100644 index 00000000..d8200caf --- /dev/null +++ b/ext/bg/js/api.js @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2019 Alex Yatskov + * Author: Alex Yatskov + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +function apiTemplateRender(template, data, dynamic) { + return _apiInvoke('templateRender', {data, template, dynamic}); +} + +function apiAudioGetUrl(definition, source, optionsContext) { + return _apiInvoke('audioGetUrl', {definition, source, optionsContext}); +} + +function _apiInvoke(action, params={}) { + const data = {action, params}; + return new Promise((resolve, reject) => { + try { + const callback = (response) => { + if (response !== null && typeof response === 'object') { + if (typeof response.error !== 'undefined') { + reject(jsonToError(response.error)); + } else { + resolve(response.result); + } + } else { + const message = response === null ? 'Unexpected null response' : `Unexpected response of type ${typeof response}`; + reject(new Error(`${message} (${JSON.stringify(data)})`)); + } + }; + const backend = window.yomichan_backend; + backend.onMessage({action, params}, null, callback); + } catch (e) { + reject(e); + yomichan.triggerOrphaned(e); + } + }); +} -- cgit v1.2.3 From 11b94d5a82f520706b344fd70ffa9e502d18086c Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Thu, 12 Dec 2019 21:01:49 -0500 Subject: Make apiClipboardGet use plaintext Also clear the value before returning --- ext/bg/background.html | 2 +- ext/bg/js/backend.js | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'ext/bg/background.html') diff --git a/ext/bg/background.html b/ext/bg/background.html index fc0758cf..c45ef3cd 100644 --- a/ext/bg/background.html +++ b/ext/bg/background.html @@ -12,7 +12,7 @@ -
+ diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index 7b6498e1..ca03f94d 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -479,10 +479,12 @@ class Backend { async _onApiClipboardGet() { const clipboardPasteTarget = this.clipboardPasteTarget; - clipboardPasteTarget.innerText = ''; + clipboardPasteTarget.value = ''; clipboardPasteTarget.focus(); document.execCommand('paste'); - return clipboardPasteTarget.innerText; + const result = clipboardPasteTarget.value; + clipboardPasteTarget.value = ''; + return result; } // Command handlers -- cgit v1.2.3 From 8b89e99eff53cf9bc8907cff80d389f07ff726fb Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 15 Dec 2019 13:26:49 -0500 Subject: Remove contenteditable="true" from textarea --- ext/bg/background.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/bg/background.html') diff --git a/ext/bg/background.html b/ext/bg/background.html index c45ef3cd..4c6f8795 100644 --- a/ext/bg/background.html +++ b/ext/bg/background.html @@ -12,7 +12,7 @@ - + -- cgit v1.2.3 From 50e0fbbb662230a3a9f6e7354c229200bd1a03a2 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Thu, 28 Nov 2019 15:18:27 -0500 Subject: Use schema to validate options --- ext/bg/background.html | 1 + ext/bg/js/backend.js | 10 ++++++++++ 2 files changed, 11 insertions(+) (limited to 'ext/bg/background.html') diff --git a/ext/bg/background.html b/ext/bg/background.html index 4c6f8795..af87eddb 100644 --- a/ext/bg/background.html +++ b/ext/bg/background.html @@ -31,6 +31,7 @@ + diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index 1a874dc8..55841cd6 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -23,6 +23,7 @@ class Backend { this.anki = new AnkiNull(); this.mecab = new Mecab(); this.options = null; + this.optionsSchema = null; this.optionsContext = { depth: 0, url: window.location.href @@ -38,7 +39,16 @@ class Backend { async prepare() { await this.translator.prepare(); + + this.optionsSchema = await requestJson(chrome.runtime.getURL('/bg/data/options-schema.json'), 'GET'); this.options = await optionsLoad(); + try { + this.options = JsonSchema.getValidValueOrDefault(this.optionsSchema, this.options); + } catch (e) { + // This shouldn't happen, but catch errors just in case of bugs + logError(e); + } + this.onOptionsUpdated('background'); if (chrome.commands !== null && typeof chrome.commands === 'object') { -- cgit v1.2.3