From cc659345a4512f282959933fc6f31f03e752684d Mon Sep 17 00:00:00 2001 From: Daniel Doblado Date: Fri, 13 Mar 2020 16:33:20 +0100 Subject: [PATCH 1/2] feat: Option to set a default schema URL --- src/manifest.json | 9 ++++-- src/options.html | 70 +++++++++++++++++++++++++++++++++++++++++++++++ src/options.js | 25 +++++++++++++++++ src/page.js | 12 ++++++-- 4 files changed, 111 insertions(+), 5 deletions(-) create mode 100644 src/options.html create mode 100644 src/options.js diff --git a/src/manifest.json b/src/manifest.json index 5cee852..b6a88e5 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -35,6 +35,11 @@ ], "permissions": [ - "activeTab" - ] + "activeTab", + "storage" + ], + "options_ui": { + "page": "options.html", + "open_in_tab": false + } } diff --git a/src/options.html b/src/options.html new file mode 100644 index 0000000..80dba1c --- /dev/null +++ b/src/options.html @@ -0,0 +1,70 @@ + + + + + + Options + + + + + +
+ +
+ + +
+ + +
+ + + + + \ No newline at end of file diff --git a/src/options.js b/src/options.js new file mode 100644 index 0000000..ffe0195 --- /dev/null +++ b/src/options.js @@ -0,0 +1,25 @@ +/* global chrome */ +const saveOptions = async (e) => { + e.preventDefault() + const { value } = document.getElementById('defaultSchema') + const saveBtn = document.getElementById('saveBtn') + await chrome.storage.local.set({ + defaultSchema: value + }) + + saveBtn.textContent = 'Options saved' + setTimeout(() => { + saveBtn.textContent = 'Save' + }, 750) +} + +const restoreOptions = () => { + chrome.storage.local.get({ + defaultSchema: '' + }, ({ defaultSchema }) => { + document.getElementById('defaultSchema').value = defaultSchema + }) +} + +document.addEventListener('DOMContentLoaded', restoreOptions) +document.getElementById('optionsForm').addEventListener('submit', saveOptions) diff --git a/src/page.js b/src/page.js index abccf30..6977c78 100644 --- a/src/page.js +++ b/src/page.js @@ -1,11 +1,17 @@ /* global chrome */ -var attach = () => { +var attach = async () => { const EDITOR_URL = 'https://test.skohub.io/editor/' - const SCHEMA_URL = 'https://raw.githubusercontent.com/literarymachine/oer-metadata-schemas/generic-OER/oer.json' + + const loadSavedOptions = new Promise((resolve, reject) => { + chrome.storage.local.get({ defaultSchema: null }, (options) => { + resolve(options) + }) + }) + const { defaultSchema } = await loadSavedOptions const url = new URL(EDITOR_URL) - url.searchParams.set('schema', SCHEMA_URL) + defaultSchema && url.searchParams.set('schema', defaultSchema) const getMetaTag = (attribute, value) => { return (document.querySelector(`meta[${attribute}="${value}"]`) && document.querySelector(`meta[${attribute}="${value}"]`).content) || null From ea0815e66350163d44a08886ba95695deabda809 Mon Sep 17 00:00:00 2001 From: Felix Ostrowski Date: Fri, 13 Mar 2020 17:02:38 +0100 Subject: [PATCH 2/2] Bump version --- package.json | 2 +- src/manifest.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 8864222..468f4c8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "skohub-extension", - "version": "0.0.3", + "version": "0.0.4", "description": "", "main": "index.js", "scripts": { diff --git a/src/manifest.json b/src/manifest.json index b6a88e5..6a72370 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "name": "__MSG_extensionName__", "short_name": "__MSG_extensionName__", - "version": "0.0.3", + "version": "0.0.4", "default_locale": "en", "description": "__MSG_extensionDescription__",