From 8791ed4e5e5f3418c26a1030f3920849090acc06 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Mon, 25 Sep 2017 22:15:56 +0900 Subject: [PATCH] add simple form --- manifest.json | 10 +++++++--- src/settings/index.js | 19 +++++++++++++++++++ src/settings/settings.html | 15 +++++++++++++++ src/settings/settings.scss | 7 +++++++ webpack.config.js | 6 ++++++ 5 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 src/settings/index.js create mode 100644 src/settings/settings.html create mode 100644 src/settings/settings.scss diff --git a/manifest.json b/manifest.json index dfb4ae9..7c60cdd 100644 --- a/manifest.json +++ b/manifest.json @@ -15,11 +15,15 @@ ] }, "permissions": [ + "history", "sessions", - "tabs", - "history" + "storage", + "tabs" ], "web_accessible_resources": [ "build/console.html" - ] + ], + "options_ui": { + "page": "build/settings.html" + } } diff --git a/src/settings/index.js b/src/settings/index.js new file mode 100644 index 0000000..f2bba32 --- /dev/null +++ b/src/settings/index.js @@ -0,0 +1,19 @@ +import './settings.scss'; + +let form = document.getElementById('vimvixen-settings-form'); + +form.addEventListener('submit', (e) => { + let value = { + json: e.target.elements['plain-json'].value + }; + e.preventDefault(); + browser.storage.local.set(value); +}); + +document.addEventListener('DOMContentLoaded', () => { + browser.storage.local.get().then((value) => { + if (value.json) { + form.elements['plain-json'].value = value.json; + } + }, console.error); +}); diff --git a/src/settings/settings.html b/src/settings/settings.html new file mode 100644 index 0000000..1719d6c --- /dev/null +++ b/src/settings/settings.html @@ -0,0 +1,15 @@ + + + + + + +
+ + + +
+ + + diff --git a/src/settings/settings.scss b/src/settings/settings.scss new file mode 100644 index 0000000..5a0f08c --- /dev/null +++ b/src/settings/settings.scss @@ -0,0 +1,7 @@ +.vimvixen-settings-form { + textarea[name=plain-json] { + font-family: monospace; + width: 100%; + resize: vertical; + } +} diff --git a/webpack.config.js b/webpack.config.js index ba08975..bf121d1 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -7,6 +7,7 @@ const dist = path.resolve(__dirname, 'build'); module.exports = { entry: { index: path.join(src, 'content'), + settings: path.join(src, 'settings'), background: path.join(src, 'background'), console: path.join(src, 'console', 'console.js') }, @@ -46,6 +47,11 @@ module.exports = { template: path.join(src, 'console', 'console.html'), filename: path.join(dist, 'console.html'), inject: false + }), + new HtmlWebpackPlugin({ + template: path.join(src, 'settings', 'settings.html'), + filename: path.join(dist, 'settings.html'), + inject: false }) ] };