summaryrefslogtreecommitdiff
path: root/ext/bg/js/util.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-03-04 19:16:19 -0800
committerAlex Yatskov <alex@foosoft.net>2017-03-04 19:16:19 -0800
commitdb7e80dabfbaeec09c7cd30b4f36b3d68c6e52b6 (patch)
tree8072081db93083a212ac1da7addf617117f79e0d /ext/bg/js/util.js
parent30999c13d32e7f111db16814dc2cbb0f30825861 (diff)
wip
Diffstat (limited to 'ext/bg/js/util.js')
-rw-r--r--ext/bg/js/util.js35
1 files changed, 32 insertions, 3 deletions
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js
index c57f6ae1..d91415f7 100644
--- a/ext/bg/js/util.js
+++ b/ext/bg/js/util.js
@@ -23,7 +23,7 @@
function promiseCallback(promise, callback) {
return promise.then(result => {
- callback({result});
+ callback({result});
}).catch(error => {
/* eslint-disable */
console.log(error);
@@ -50,6 +50,22 @@ function instAnki() {
}
+/*
+ * Foreground
+ */
+
+function fgBroadcast(action, params) {
+ chrome.tabs.query({}, tabs => {
+ for (const tab of tabs) {
+ chrome.tabs.sendMessage(tab.id, {action, params}, () => null);
+ }
+ });
+}
+
+function fgOptionsSet(options) {
+ fgBroadcast('optionsSet', options);
+}
+
/*
* Options
@@ -188,6 +204,9 @@ function optionsSave(options) {
return new Promise((resolve, reject) => {
chrome.storage.sync.set(options, resolve);
+ }).then(() => {
+ instYomi().optionsSet(options);
+ fgOptionsSet(options);
});
}
@@ -468,7 +487,7 @@ function jsonLoadDb(indexUrl, indexLoaded, termsLoaded, kanjiLoaded) {
* Helpers
*/
-function helperKanjiLinks(options) {
+function handlebarsKanjiLinks(options) {
const isKanji = c => {
const code = c.charCodeAt(0);
return code >= 0x4e00 && code < 0x9fb0 || code >= 0x3400 && code < 0x4dc0;
@@ -486,6 +505,16 @@ function helperKanjiLinks(options) {
return result;
}
-function helperMultiLine(options) {
+function handlebarsMultiLine(options) {
return options.fn(this).split('\n').join('<br>');
}
+
+function handlebarsRegister() {
+ Handlebars.partials = Handlebars.templates;
+ Handlebars.registerHelper('kanjiLinks', handlebarsKanjiLinks);
+ Handlebars.registerHelper('multiLine', handlebarsMultiLine);
+}
+
+function handlebarsRender(template, data) {
+ return Handlebars.templates[template](data);
+}