From aa77a7896da735b68b74c62f1726d35e8a6b1774 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Thu, 5 Sep 2019 18:30:39 -0400 Subject: Group all two-column settings together --- ext/bg/settings.html | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'ext/bg/settings.html') diff --git a/ext/bg/settings.html b/ext/bg/settings.html index 85b7ee5f..6c649251 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -107,6 +107,16 @@ +
+ + +
+ +
+ + +
+
@@ -129,16 +139,6 @@
-
- - -
- -
- - -
-
-- cgit v1.2.3 From 2e87cd72bc87ebbb5eb25dd8e967f31ab14ca444 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Thu, 5 Sep 2019 18:39:28 -0400 Subject: Use consistent styling for all two-column settings --- ext/bg/settings.html | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'ext/bg/settings.html') diff --git a/ext/bg/settings.html b/ext/bg/settings.html index 6c649251..ccd749b9 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -140,26 +140,41 @@
-
-
-
+
+ + +
+
+ + +
-
-
-
+
+ + +
+
+ + +
-
-
-
+
+ + +
+
+ + +
-- cgit v1.2.3 From fb8cb3db43c38e5a984cf4a45b5b9def311cf0a0 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Thu, 5 Sep 2019 18:45:42 -0400 Subject: Collapse two-column options on smaller screens --- ext/bg/settings.html | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'ext/bg/settings.html') diff --git a/ext/bg/settings.html b/ext/bg/settings.html index ccd749b9..093a3c26 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -49,6 +49,16 @@ [data-browser=firefox-mobile] [data-show-for-browser~=firefox-mobile] { display: initial; } + + @media screen and (max-width: 740px) { + .col-xs-6 { + float: none; + width: 100%; + } + .col-xs-6+.col-xs-6 { + margin-top: 15px; + } + } -- cgit v1.2.3 From dbfbf9d12dd4a5be16fa31cecf53c5eb300d8978 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Thu, 5 Sep 2019 18:53:12 -0400 Subject: Use non-bold text for label information Units, etc. --- ext/bg/settings.html | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'ext/bg/settings.html') diff --git a/ext/bg/settings.html b/ext/bg/settings.html index 093a3c26..76078274 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -30,6 +30,10 @@ padding-bottom: 1em; } + .label-light { + font-weight: normal; + } + #custom-popup-css { width: 100%; min-height: 34px; @@ -118,7 +122,7 @@
- +
@@ -152,11 +156,11 @@
- +
- +
@@ -165,11 +169,11 @@
- +
- +
@@ -178,11 +182,11 @@
- +
- +
@@ -230,12 +234,12 @@
- +
- +
@@ -351,12 +355,12 @@
- +
- +
@@ -374,7 +378,7 @@
- +
-- cgit v1.2.3 From bc7759d94c4d4bbe2480e5328a4c3488ff29e493 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Thu, 5 Sep 2019 20:57:10 -0400 Subject: Add some parameters to field-templates textarea --- ext/bg/settings.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/bg/settings.html') diff --git a/ext/bg/settings.html b/ext/bg/settings.html index 76078274..ddda8303 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -442,7 +442,7 @@ their Anki cards. If you encounter problems with your changes you can always reset to default template settings.

- +
-- cgit v1.2.3 From cab39e89c93a9b1826dce5d6555c213fa722c82e Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 7 Sep 2019 20:04:43 -0400 Subject: Create section for Popup Content Scanning Options --- ext/bg/settings.html | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'ext/bg/settings.html') diff --git a/ext/bg/settings.html b/ext/bg/settings.html index ddda8303..8c368474 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -221,14 +221,6 @@ -
- -
- -
- -
-
@@ -252,9 +244,26 @@ + -
- + -- cgit v1.2.3 From 71b700cd22f5a57a07cd2f9a6afa823793f5f95e Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Tue, 10 Sep 2019 20:49:17 -0400 Subject: Add checkbox for options.general.enable --- ext/bg/js/settings.js | 2 ++ ext/bg/settings.html | 4 ++++ 2 files changed, 6 insertions(+) (limited to 'ext/bg/settings.html') diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js index 06dba538..f2f08b6e 100644 --- a/ext/bg/js/settings.js +++ b/ext/bg/js/settings.js @@ -23,6 +23,7 @@ function getOptionsContext() { } async function formRead(options) { + options.general.enable = $('#enable').prop('checked'); options.general.showGuide = $('#show-usage-guide').prop('checked'); options.general.compactTags = $('#compact-tags').prop('checked'); options.general.compactGlossaries = $('#compact-glossaries').prop('checked'); @@ -87,6 +88,7 @@ async function formRead(options) { } async function formWrite(options) { + $('#enable').prop('checked', options.general.enable); $('#show-usage-guide').prop('checked', options.general.showGuide); $('#compact-tags').prop('checked', options.general.compactTags); $('#compact-glossaries').prop('checked', options.general.compactGlossaries); diff --git a/ext/bg/settings.html b/ext/bg/settings.html index 8c368474..577e1a1f 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -70,6 +70,10 @@

General Options

+
+ +
+
-- cgit v1.2.3 From ba1875c56a89edcd896184ab6b9734ce36f70e15 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 14 Sep 2019 19:59:45 -0400 Subject: Add rel="noopener" to all anchors with target="_blank" --- ext/bg/guide.html | 2 +- ext/bg/settings.html | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'ext/bg/settings.html') diff --git a/ext/bg/guide.html b/ext/bg/guide.html index 6f98d264..7ec1d8d9 100644 --- a/ext/bg/guide.html +++ b/ext/bg/guide.html @@ -15,7 +15,7 @@

Read the steps below to get up and running with Yomichan. For complete documentation, - visit the official homepage. + visit the official homepage.

    diff --git a/ext/bg/settings.html b/ext/bg/settings.html index 577e1a1f..62539972 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -307,7 +307,7 @@

    Select a dictionary to import for use below. Please visit the Yomichan homepage to - download free dictionaries + download free dictionaries for use with this extension and to learn about importing proprietary EPWING dictionaries.

    @@ -333,7 +333,7 @@
    On Firefox and Firefox for Android, the storage information feature may be hidden behind a browser flag. - If you would like to enable this flag, open about:config and search for the + If you would like to enable this flag, open about:config and search for the dom.storageManager.enabled option. If this option has a value of false, toggling it to true may allow storage information to be calculated.
    @@ -355,9 +355,9 @@

    - Yomichan supports automatic flashcard creation for Anki, a free application + Yomichan supports automatic flashcard creation for Anki, a free application designed to help you remember. This feature requires installation of the - AnkiConnect plugin. + AnkiConnect plugin.

    @@ -473,14 +473,14 @@ countless hours that I have devoted to this extension.

    - +


 
             
         
-- cgit v1.2.3 From f8aa926f8a554edc4fe963d8a9efddf67662d3da Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 14 Sep 2019 20:01:51 -0400 Subject: Upgrade website URLs to https --- README.md | 24 ++++++++++++------------ ext/bg/settings.html | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) (limited to 'ext/bg/settings.html') diff --git a/README.md b/README.md index 5671e5de..40576a5a 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ Import](https://foosoft.net/projects/yomichan-import) page to learn how to conve Please be aware that the non-English dictionaries contain fewer entries than their English counterparts. Even if your primary language is not English, you may consider also importing the English version for better coverage. -* **[JMdict](http://www.edrdg.org/enamdict/enamdict_doc.html)** (Japanese vocabulary) +* **[JMdict](https://www.edrdg.org/enamdict/enamdict_doc.html)** (Japanese vocabulary) * [jmdict\_dutch.zip](https://foosoft.net/projects/yomichan/dl/dict/jmdict_dutch.zip) * [jmdict\_english.zip](https://foosoft.net/projects/yomichan/dl/dict/jmdict_english.zip) * [jmdict\_french.zip](https://foosoft.net/projects/yomichan/dl/dict/jmdict_french.zip) @@ -71,7 +71,7 @@ primary language is not English, you may consider also importing the English ver * [jmdict\_slovenian.zip](https://foosoft.net/projects/yomichan/dl/dict/jmdict_slovenian.zip) * [jmdict\_spanish.zip](https://foosoft.net/projects/yomichan/dl/dict/jmdict_spanish.zip) * [jmdict\_swedish.zip](https://foosoft.net/projects/yomichan/dl/dict/jmdict_swedish.zip) -* **[JMnedict](http://www.edrdg.org/enamdict/enamdict_doc.html)** (Japanese names) +* **[JMnedict](https://www.edrdg.org/enamdict/enamdict_doc.html)** (Japanese names) * [jmnedict.zip](https://foosoft.net/projects/yomichan/dl/dict/jmnedict.zip) * **[KireiCake](https://kireicake.com/rikaicakes/)** (Japanese slang) * [kireicake.zip](https://foosoft.net/projects/yomichan/dl/dict/kireicake.zip) @@ -127,7 +127,7 @@ Import](https://foosoft.net/projects/yomichan-import). Please see the project pa ## Anki Integration ## -Yomichan features automatic flashcard creation for [Anki](http://ankisrs.net/), a free application designed to help you +Yomichan features automatic flashcard creation for [Anki](https://apps.ankiweb.net/), a free application designed to help you retain knowledge. This feature requires the prior installation of an Anki plugin called [AnkiConnect](https://foosoft.net/projects/anki-connect). Please see the respective project page for more information about how to set up this software. @@ -135,7 +135,7 @@ Please see the respective project page for more information about how to set up Before flashcards can be automatically created, you must configure the templates used to create term and/or Kanji notes. If you are unfamiliar with Anki deck and model management, this would be a good time to reference the [Anki -Manual](http://ankisrs.net/docs/manual.html). In short, you must specify what information should be included in the +Manual](https://apps.ankiweb.net/docs/manual.html). In short, you must specify what information should be included in the flashcards that Yomichan creates through AnkiConnect. Flashcard fields can be configured with the following steps: @@ -145,7 +145,7 @@ Flashcard fields can be configured with the following steps: 3. Select the type of template to configure by clicking on either the *Terms* or *Kanji* tabs. 4. Select the Anki deck and model to use for new creating new flashcards of this type. 5. Fill the model fields with markers corresponding to the information you wish to include (several can be used at - once). Advanced users can also configure the actual [Handlebars](http://handlebarsjs.com/) templates used to create + once). Advanced users can also configure the actual [Handlebars](https://handlebarsjs.com/) templates used to create the flashcard contents (this is strictly optional). #### Markers for Term Cards #### @@ -243,7 +243,7 @@ following basic guidelines when creating pull requests: ### Templates ### -Yomichan uses [Handlebars](http://handlebarsjs.com/) templates for user interface generation. The source templates are +Yomichan uses [Handlebars](https://handlebarsjs.com/) templates for user interface generation. The source templates are found in the `tmpl` directory and the compiled version is stored in the `ext/bg/js/templates.js` file. If you modify the source templates, you will need to also recompile them. If you are developing on Linux or Mac OS X, you can use the included `build_tmpl.sh` and `build_tmpl_auto.sh` shell scripts to do this for you @@ -255,13 +255,13 @@ tmpl/*.html -f ext/bg/js/templates.js` from the project's base directory to comp Yomichan uses several third-party libraries to function. Below are links to homepages and snapshots of the exact versions packaged. -* Bootstrap Toggle: [homepage](http://www.bootstraptoggle.com/) - [snapshot](https://github.com/minhur/bootstrap-toggle/archive/b76c094.zip) -* Bootstrap: [homepage](http://getbootstrap.com/) - [snapshot](https://github.com/twbs/bootstrap/releases/download/v3.3.7/bootstrap-3.3.7-dist.zip) -* Dexie: [homepage](http://dexie.org/) - [snapshot](https://github.com/dfahlander/Dexie.js/archive/v2.0.0-beta.10.zip) -* Handlebars: [homepage](http://handlebarsjs.com/) - [snapshot](http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars.min-714a4c4.js) +* Bootstrap Toggle: [homepage](https://www.bootstraptoggle.com/) - [snapshot](https://github.com/minhur/bootstrap-toggle/archive/b76c094.zip) +* Bootstrap: [homepage](https://getbootstrap.com/) - [snapshot](https://github.com/twbs/bootstrap/releases/download/v3.3.7/bootstrap-3.3.7-dist.zip) +* Dexie: [homepage](https://dexie.org/) - [snapshot](https://github.com/dfahlander/Dexie.js/archive/v2.0.0-beta.10.zip) +* Handlebars: [homepage](https://handlebarsjs.com/) - [snapshot](http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars.min-714a4c4.js) * JQuery: [homepage](https://blog.jquery.com/) - [snapshot](https://code.jquery.com/jquery-3.2.1.min.js) -* JSZip: [homepage](http://stuk.github.io/jszip/) - [snapshot](https://raw.githubusercontent.com/Stuk/jszip/de7f52fbcba485737bef7923a83f0fad92d9f5bc/dist/jszip.min.js) -* WanaKana: [homepage](http://wanakana.com/) - [snapshot](https://raw.githubusercontent.com/WaniKani/WanaKana/7c4a052/gh-pages/assets/js/wanakana.min.js) +* JSZip: [homepage](https://stuk.github.io/jszip/) - [snapshot](https://raw.githubusercontent.com/Stuk/jszip/de7f52fbcba485737bef7923a83f0fad92d9f5bc/dist/jszip.min.js) +* WanaKana: [homepage](https://wanakana.com/) - [snapshot](https://raw.githubusercontent.com/WaniKani/WanaKana/7c4a052/gh-pages/assets/js/wanakana.min.js) ## Frequently Asked Questions ## diff --git a/ext/bg/settings.html b/ext/bg/settings.html index 62539972..7df47980 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -355,7 +355,7 @@

- Yomichan supports automatic flashcard creation for Anki, a free application + Yomichan supports automatic flashcard creation for Anki, a free application designed to help you remember. This feature requires installation of the AnkiConnect plugin.

@@ -450,7 +450,7 @@

- Fields are formatted using the Handlebars.js template rendering + Fields are formatted using the Handlebars.js template rendering engine. Advanced users can modify these templates for ultimate control of what information gets included in their Anki cards. If you encounter problems with your changes you can always reset to default template settings. -- cgit v1.2.3 From 6c571bf8284c44bf01fe20c267fe72cce235b90d Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 8 Sep 2019 13:16:05 -0400 Subject: Add UI for profiles --- ext/bg/js/api.js | 6 +- ext/bg/js/settings-profiles.js | 201 +++++++++++++++++++++++++++++++++++++++++ ext/bg/js/settings.js | 11 +-- ext/bg/settings.html | 53 +++++++++++ 4 files changed, 260 insertions(+), 11 deletions(-) create mode 100644 ext/bg/js/settings-profiles.js (limited to 'ext/bg/settings.html') diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js index 81772d08..f32b984f 100644 --- a/ext/bg/js/api.js +++ b/ext/bg/js/api.js @@ -21,9 +21,13 @@ function apiOptionsGet(optionsContext) { return utilBackend().getOptions(optionsContext); } +function apiOptionsGetFull() { + return utilBackend().getFullOptions(); +} + async function apiOptionsSave(source) { const backend = utilBackend(); - const options = await backend.getFullOptions(); + const options = await apiOptionsGetFull(); await optionsSave(options); backend.onOptionsUpdated(source); } diff --git a/ext/bg/js/settings-profiles.js b/ext/bg/js/settings-profiles.js new file mode 100644 index 00000000..dca452d2 --- /dev/null +++ b/ext/bg/js/settings-profiles.js @@ -0,0 +1,201 @@ +/* + * 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 . + */ + +let currentProfileIndex = 0; + +function getOptionsContext() { + return { + index: currentProfileIndex + }; +} + + +async function profileOptionsSetup() { + const optionsFull = await apiOptionsGetFull(); + currentProfileIndex = optionsFull.profileCurrent; + + profileOptionsSetupEventListeners(); + await profileOptionsUpdateTarget(optionsFull); +} + +function profileOptionsSetupEventListeners() { + $('#profile-target').change(utilAsync(onTargetProfileChanged)); + $('#profile-name').change(onProfileNameChanged); + $('#profile-add').click(utilAsync(onProfileAdd)); + $('#profile-remove').click(utilAsync(onProfileRemove)); + $('#profile-remove-confirm').click(utilAsync(onProfileRemoveConfirm)); + $('.profile-form').find('input, select, textarea').not('.profile-form-manual').change(utilAsync(onProfileOptionsChanged)); +} + +function tryGetIntegerValue(selector, min, max) { + const value = parseInt($(selector).val(), 10); + return ( + typeof value === 'number' && + Number.isFinite(value) && + Math.floor(value) === value && + value >= min && + value < max + ) ? value : null; +} + +async function profileFormRead(optionsFull) { + const profile = optionsFull.profiles[currentProfileIndex]; + + // Current profile + const index = tryGetIntegerValue('#profile-active', 0, optionsFull.profiles.length); + if (index !== null) { + optionsFull.profileCurrent = index; + } + + // Profile name + profile.name = $('#profile-name').val(); +} + +async function profileFormWrite(optionsFull) { + const profile = optionsFull.profiles[currentProfileIndex]; + + profileOptionsPopulateSelect($('#profile-active'), optionsFull.profiles, optionsFull.profileCurrent); + profileOptionsPopulateSelect($('#profile-target'), optionsFull.profiles, currentProfileIndex); + $('#profile-remove').prop('disabled', optionsFull.profiles.length <= 1); + + $('#profile-name').val(profile.name); +} + +function profileOptionsPopulateSelect(select, profiles, currentValue) { + select.empty(); + + for (let i = 0; i < profiles.length; ++i) { + const profile = profiles[i]; + select.append($(``)); + } + + select.val(`${currentValue}`); +} + +async function profileOptionsUpdateTarget(optionsFull) { + profileFormWrite(optionsFull); + + const optionsContext = getOptionsContext(); + const options = await apiOptionsGet(optionsContext); + await formWrite(options); +} + +function profileOptionsCreateCopyName(name, profiles, maxUniqueAttempts) { + let space, index, prefix, suffix; + const match = /^([\w\W]*\(Copy)((\s+)(\d+))?(\)\s*)$/.exec(name); + if (match === null) { + prefix = `${name} (Copy`; + space = ''; + index = ''; + suffix = ')'; + } else { + prefix = match[1]; + suffix = match[5]; + if (typeof match[2] === 'string') { + space = match[3]; + index = parseInt(match[4], 10) + 1; + } else { + space = ' '; + index = 2; + } + } + + let i = 0; + while (true) { + const newName = `${prefix}${space}${index}${suffix}`; + if (i++ >= maxUniqueAttempts || profiles.findIndex(profile => profile.name === newName) < 0) { + return newName; + } + if (typeof index !== 'number') { + index = 2; + space = ' '; + } else { + ++index; + } + } +} + +async function onProfileOptionsChanged(e) { + if (!e.originalEvent && !e.isTrigger) { + return; + } + + const optionsFull = await apiOptionsGetFull(); + await profileFormRead(optionsFull); + await apiOptionsSave(); +} + +async function onTargetProfileChanged() { + const optionsFull = await apiOptionsGetFull(); + const index = tryGetIntegerValue('#profile-target', 0, optionsFull.profiles.length); + if (index === null || currentProfileIndex === index) { + return; + } + + currentProfileIndex = index; + + await profileOptionsUpdateTarget(optionsFull); +} + +async function onProfileAdd() { + const optionsFull = await apiOptionsGetFull(); + const profile = utilIsolate(optionsFull.profiles[currentProfileIndex]); + profile.name = profileOptionsCreateCopyName(profile.name, optionsFull.profiles, 100); + optionsFull.profiles.push(profile); + currentProfileIndex = optionsFull.profiles.length - 1; + await profileOptionsUpdateTarget(optionsFull); + await apiOptionsSave(); +} + +async function onProfileRemove() { + const optionsFull = await apiOptionsGetFull(); + if (optionsFull.profiles.length <= 1) { + return; + } + + const profile = optionsFull.profiles[currentProfileIndex]; + + $('#profile-remove-modal-profile-name').text(profile.name); + $('#profile-remove-modal').modal('show'); +} + +async function onProfileRemoveConfirm() { + $('#profile-remove-modal').modal('hide'); + + const optionsFull = await apiOptionsGetFull(); + if (optionsFull.profiles.length <= 1) { + return; + } + + optionsFull.profiles.splice(currentProfileIndex, 1); + + if (currentProfileIndex >= optionsFull.profiles.length) { + --currentProfileIndex; + } + + if (optionsFull.profileCurrent >= optionsFull.profiles.length) { + optionsFull.profileCurrent = optionsFull.profiles.length - 1; + } + + await profileOptionsUpdateTarget(optionsFull); + await apiOptionsSave(); +} + +function onProfileNameChanged() { + $('#profile-active, #profile-target').find(`[value="${currentProfileIndex}"]`).text(this.value); +} diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js index 88929c49..b6434843 100644 --- a/ext/bg/js/settings.js +++ b/ext/bg/js/settings.js @@ -16,12 +16,6 @@ * along with this program. If not, see . */ -function getOptionsContext() { - return { - depth: 0 - }; -} - async function formRead(options) { options.general.enable = $('#enable').prop('checked'); options.general.showGuide = $('#show-usage-guide').prop('checked'); @@ -239,11 +233,8 @@ async function onFormOptionsChanged(e) { } async function onReady() { - const optionsContext = getOptionsContext(); - const options = await apiOptionsGet(optionsContext); - formSetupEventListeners(); - await formWrite(options); + await profileOptionsSetup(); storageInfoInitialize(); diff --git a/ext/bg/settings.html b/ext/bg/settings.html index 7df47980..1a1bc2ed 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -67,6 +67,58 @@

+
+

Profiles

+ +

+ Profiles allow you to create multiple configurations and quickly switch between them. +

+ +
+ + +
+ +
+ +
+
+ + + + +
+ +
+ +
+
+
+ +
+ + +
+ + +
+

General Options

@@ -498,6 +550,7 @@ + -- cgit v1.2.3 From 1f77506f43607c6d3c9c87fbf82b993d87039526 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Tue, 10 Sep 2019 21:20:03 -0400 Subject: Implement profile copy --- ext/bg/js/settings-profiles.js | 39 ++++++++++++++++++++++++++++++++++++--- ext/bg/settings.html | 19 +++++++++++++++++++ 2 files changed, 55 insertions(+), 3 deletions(-) (limited to 'ext/bg/settings.html') diff --git a/ext/bg/js/settings-profiles.js b/ext/bg/js/settings-profiles.js index dca452d2..fa06203e 100644 --- a/ext/bg/js/settings-profiles.js +++ b/ext/bg/js/settings-profiles.js @@ -39,6 +39,8 @@ function profileOptionsSetupEventListeners() { $('#profile-add').click(utilAsync(onProfileAdd)); $('#profile-remove').click(utilAsync(onProfileRemove)); $('#profile-remove-confirm').click(utilAsync(onProfileRemoveConfirm)); + $('#profile-copy').click(utilAsync(onProfileCopy)); + $('#profile-copy-confirm').click(utilAsync(onProfileCopyConfirm)); $('.profile-form').find('input, select, textarea').not('.profile-form-manual').change(utilAsync(onProfileOptionsChanged)); } @@ -69,17 +71,22 @@ async function profileFormRead(optionsFull) { async function profileFormWrite(optionsFull) { const profile = optionsFull.profiles[currentProfileIndex]; - profileOptionsPopulateSelect($('#profile-active'), optionsFull.profiles, optionsFull.profileCurrent); - profileOptionsPopulateSelect($('#profile-target'), optionsFull.profiles, currentProfileIndex); + profileOptionsPopulateSelect($('#profile-active'), optionsFull.profiles, optionsFull.profileCurrent, null); + profileOptionsPopulateSelect($('#profile-target'), optionsFull.profiles, currentProfileIndex, null); $('#profile-remove').prop('disabled', optionsFull.profiles.length <= 1); + $('#profile-copy').prop('disabled', optionsFull.profiles.length <= 1); $('#profile-name').val(profile.name); } -function profileOptionsPopulateSelect(select, profiles, currentValue) { +function profileOptionsPopulateSelect(select, profiles, currentValue, ignoreIndices) { select.empty(); + for (let i = 0; i < profiles.length; ++i) { + if (ignoreIndices !== null && ignoreIndices.indexOf(i) >= 0) { + continue; + } const profile = profiles[i]; select.append($(``)); } @@ -199,3 +206,29 @@ async function onProfileRemoveConfirm() { function onProfileNameChanged() { $('#profile-active, #profile-target').find(`[value="${currentProfileIndex}"]`).text(this.value); } + +async function onProfileCopy() { + const optionsFull = await apiOptionsGetFull(); + if (optionsFull.profiles.length <= 1) { + return; + } + + profileOptionsPopulateSelect($('#profile-copy-source'), optionsFull.profiles, currentProfileIndex === 0 ? 1 : 0, [currentProfileIndex]); + $('#profile-copy-modal').modal('show'); +} + +async function onProfileCopyConfirm() { + $('#profile-copy-modal').modal('hide'); + + const optionsFull = await apiOptionsGetFull(); + const index = tryGetIntegerValue('#profile-copy-source', 0, optionsFull.profiles.length); + if (index === null || index === currentProfileIndex) { + return; + } + + const profile = utilIsolate(optionsFull.profiles[index].options); + optionsFull.profiles[currentProfileIndex].options = profile; + + await profileOptionsUpdateTarget(optionsFull); + await settingsSaveOptions(); +} diff --git a/ext/bg/settings.html b/ext/bg/settings.html index 1a1bc2ed..c0489894 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -100,6 +100,25 @@
+ +