commit 1c858fad2e742ade11354f52a82dd5f13efcdaab Author: OverPoweredDev Date: Thu Jun 3 18:24:43 2021 +0530 minor bugfixes - JSON.stringify calls were making globalSettings a string instead of an Object - language pairs also needed to be updated on changing the source diff --git a/background/background.js b/background/background.js index 061c5d8..918eed0 100644 --- a/background/background.js +++ b/background/background.js @@ -1,6 +1,5 @@ window.browser = (function () { - return window.browser || - window.chrome; + return window.browser || window.chrome; })(); @@ -11,4 +10,5 @@ browser.runtime.onInstalled.addListener(function () { "documentUrlPatterns": [""], "contexts": ["page"] }); -}) \ No newline at end of file +}); + diff --git a/popup/popup.css b/popup/popup.css index e991f3b..d1de05d 100644 --- a/popup/popup.css +++ b/popup/popup.css @@ -213,7 +213,7 @@ tr, td, th { align-content: center; justify-content: flex-end; - margin-top: 0.5em; + margin-top: 0.3em; padding-right: 1em; } diff --git a/settings/settings.css b/settings/settings.css index dfd7586..14fba57 100644 --- a/settings/settings.css +++ b/settings/settings.css @@ -91,3 +91,32 @@ tr, td, th { .trash-icon { cursor: pointer; } + +.dropdown { + position: relative; + display: inline-block; +} + +.language-dropdown { + display: none; + position: absolute; + background-color: #f1f1f1; + min-width: 30em; + box-shadow: 0 0.2em 0.4em 0 rgba(0,0,0,0.2); + z-index: 1; +} + +.enabled-language { + color: black; + padding: 0.3em 0.4em; + text-decoration: none; + display: block; +} + +.disabled-language { + color: gray; + padding: 0.3em 0.4em; + text-decoration: none; + display: block; + cursor: pointer; +} \ No newline at end of file diff --git a/settings/settings.html b/settings/settings.html index 4fa18b8..0ea47b7 100644 --- a/settings/settings.html +++ b/settings/settings.html @@ -19,14 +19,20 @@
Default Language to Translate to -
- - +
diff --git a/settings/settings.js b/settings/settings.js index d0dbd15..bc763aa 100644 --- a/settings/settings.js +++ b/settings/settings.js @@ -1,24 +1,32 @@ globalSettings = getGlobalSettings(); +createDropdown(); -$("#update-button").click(async function () { - let languageList = await fetchLanguageList(getLangPairsEndpoint()); - let languagePairsJSON = JSON.stringify(createLanguagePairs(languageList)); - localStorage.setItem("apertium.langPairs", languagePairsJSON); +$("#default-target-language-button").click(function () { + let dropdown = $("#target-language-dropdown")[0]; + if(dropdown.style.display === "") { + dropdown.style.display ="block"; + } else { + dropdown.style.display =""; + } +}); - console.log(localStorage.getItem("apertium.langPairs")); +$("#update-button").click(async function () { + await updateLanguagePairs(); }); -$("#source-select").change(function () { +$("#source-select").change(async function () { let selectedSource = $("#source-select option:selected").text(); switch (selectedSource) { case "Apertium Release": globalSettings.ApertiumSource = "https://apertium.org/apy/"; - saveGlobalSettings(); + saveGlobalSettings(globalSettings); + await updateLanguagePairs(); break; case "Apertium Beta": globalSettings.ApertiumSource = "https://beta.apertium.org/apy/"; - saveGlobalSettings(); + saveGlobalSettings(globalSettings); + await updateLanguagePairs(); break; case "Local/Custom Source": alert("Option not available yet"); @@ -27,11 +35,11 @@ $("#source-select").change(function () { }); function getGlobalSettings() { - let settings = localStorage.getItem("apertium.settings") - + let settings = JSON.parse(localStorage.getItem("apertium.settings")); if (settings === null) { return { - ApertiumSource: "https://beta.apertium.org/apy/" + ApertiumSource: "https://beta.apertium.org/apy/", + DefaultLanguage: "eng" } } else { return settings; @@ -39,10 +47,19 @@ function getGlobalSettings() { } function saveGlobalSettings(settings) { - let settingsJSON = JSON.stringify(createLanguagePairs(settings)); + let settingsJSON = JSON.stringify(settings); localStorage.setItem("apertium.settings", settingsJSON); } +async function updateLanguagePairs() { + let languageList = await fetchLanguageList(getLangPairsEndpoint()); + let languagePairsJSON = JSON.stringify(createLanguagePairs(languageList)); + + localStorage.setItem("apertium.langPairs", languagePairsJSON); + + // console.log(localStorage.getItem("apertium.langPairs")); +} + function getLangPairsEndpoint() { return globalSettings.ApertiumSource + "listPairs"; } @@ -54,11 +71,25 @@ async function fetchLanguageList(listPairURL) { } function createLanguagePairs(languageList){ - let current = new Date() + let current = new Date(); return { last_updated: current.toLocaleString(), source: globalSettings.ApertiumSource, langPairs: languageList + }; +} + +function getTargetLanguages() { + let languageList = JSON.parse(localStorage.getItem("apertium.langPairs")).langPairs; + let list = []; + for (let i = 0; i < languageList.length; i++) { + list.push(languageList[i].targetLanguage); } + return [...new Set(list)]; +} + +function createDropdown() { + let list = getTargetLanguages(); + } \ No newline at end of file