commit 4bf4f3cba65e13b8a104a627851ca291ed73aa06 Author: OverPoweredDev Date: Wed Jun 16 13:45:58 2021 +0530 implementing hover-enabled table previously only an html placeholder diff --git a/README.md b/README.md index 86371f7..ba8a93e 100644 --- a/README.md +++ b/README.md @@ -27,17 +27,7 @@ . ├── README.md ├── src -│   ├── assets -│   │   ├── apertium-logo.svg -│   │   ├── icons -│   │   │   ├── icon128.png -│   │   │   ├── icon16.png -│   │   │   ├── icon32.png -│   │   │   ├── icon512.png -│   │   │   └── icon64.png -│   │   ├── language.svg -│   │   ├── switch.svg -│   │   └── trash.svg +│   ├── assets/... │   ├── background │   │   ├── background.js │   │   ├── jquery.min.js @@ -53,8 +43,6 @@ │   └── settings │   └── settings.html/css/js └── tests - - ``` #### Background background.js contains all background scripts such as the right-click contextmenu option, the script to redirect the user to the settings page on being installed (TODO) and so on. storage.js is meant for all functions that deal with the two localStorage Objects, apertium.settings and apertium.langPairs. diff --git a/src/background/storage.js b/src/background/storage.js index f83aa6f..aa48ce0 100644 --- a/src/background/storage.js +++ b/src/background/storage.js @@ -1,3 +1,4 @@ +//GlobalSettings function getGlobalSettings() { let settings = JSON.parse(localStorage.getItem("apertium.settings")); if (settings === null) { @@ -19,6 +20,8 @@ function saveGlobalSettings(settings) { localStorage.setItem("apertium.settings", settingsJSON); } + +//Language Pairs function getLangPairs() { let langPairs = localStorage.getItem("apertium.langPairs"); @@ -31,6 +34,36 @@ function getLangPairs() { return JSON.parse(langPairs); } +async function fetchLanguageList(listPairURL) { + return fetch(listPairURL) + .then(response => response.json()) + .then(data => data.responseData); +} + +function createLanguagePairs(languageList){ + let current = new Date(); + + let langPairs = { + last_updated: current.toLocaleString(), + source: globalSettings.apertiumSource, + langPairs: languageList + }; + + let langPairsJSON = JSON.stringify(langPairs); + localStorage.setItem("apertium.langPairs", langPairsJSON); + return langPairs; +} + +async function updateLanguagePairs() { + let time = new Date().toLocaleString(); + let languageList = await fetchLanguageList(getLangPairsEndpoint()); + let languagePairsJSON = JSON.stringify(createLanguagePairs(languageList)); + + localStorage.setItem("apertium.langPairs", languagePairsJSON); + globalSettings.lastUpdated = time; + setLastUpdated(time); +} + function getLanguageCodeMap(){ return { "detect" : "Detect Language", @@ -182,16 +215,8 @@ function getLanguageCodeMap(){ } } -async function updateLanguagePairs() { - let time = new Date().toLocaleString(); - let languageList = await fetchLanguageList(getLangPairsEndpoint()); - let languagePairsJSON = JSON.stringify(createLanguagePairs(languageList)); - - localStorage.setItem("apertium.langPairs", languagePairsJSON); - globalSettings.lastUpdated = time; - setLastUpdated(time); -} +//API EndPoints function getLangPairsEndpoint() { return globalSettings.apertiumSource + "listPairs"; } @@ -200,26 +225,26 @@ function getTranslationEndpoint() { return globalSettings.apertiumSource + "translate"; } -async function fetchLanguageList(listPairURL) { - return fetch(listPairURL) - .then(response => response.json()) - .then(data => data.responseData); + +//TODO: Enabled Website List +function getEnabledWebsiteList(){ + return ["https://wikipedia.com", "https://www.youtube.com", "https://stackoverflow.com"]; } -function createLanguagePairs(languageList){ - let current = new Date(); +function saveEnabledWebsiteList() { - let langPairs = { - last_updated: current.toLocaleString(), - source: globalSettings.apertiumSource, - langPairs: languageList - }; +} + +function removeFromEnabledWebsiteList(url){ - let langPairsJSON = JSON.stringify(langPairs); - localStorage.setItem("apertium.langPairs", langPairsJSON); - return langPairs; } +function addToEnabledWebsiteList(url) { + +} + + +//Source/Target Language Lists function getSourceList() { let languageList = getLangPairs().langPairs; let list = []; diff --git a/src/popup/options.html b/src/popup/options.html index df0dfdc..4b6fe0e 100644 --- a/src/popup/options.html +++ b/src/popup/options.html @@ -52,32 +52,7 @@ - - - 1 - https://wikipedia.com - trash icon - - - 2 - https://stackoverflow.com/ - trash icon - - - 3 - https://www.w3schools.com/ - trash icon - - - 4 - https://www.youtube.com/ - trash icon - - - 5 - https://github.com/ - trash icon - + diff --git a/src/popup/options.js b/src/popup/options.js index 96e3d8f..e179291 100644 --- a/src/popup/options.js +++ b/src/popup/options.js @@ -27,11 +27,23 @@ $(".delete-website").on('click', function () { function init() { globalSettings = getGlobalSettings(); getLangPairs(); + updateEnabledTable($("#enabled-website-tbody")); createDropdown($("#target-language-dropdown")); setDefaultLanguage(globalSettings.defaultLanguage); } +function updateEnabledTable(parent) { + let list = getEnabledWebsiteList(); + + parent.empty(); + let rowIter = 1; + list.forEach((websiteURL) => { + parent.append("" + rowIter + "" + websiteURL + "trash icon"); + rowIter++; + }); +} + function setDefaultLanguage(defaultLanguage) { let codeMap = getLanguageCodeMap(); if (codeMap[defaultLanguage] === undefined) { @@ -42,9 +54,9 @@ function setDefaultLanguage(defaultLanguage) { } function createDropdown(parent) { - parent.empty(); let codeMap = getLanguageCodeMap(); let list = getTargetList(); + parent.empty(); list.forEach((languageCode) => { let languageName; if (codeMap[languageCode] === undefined) { diff --git a/src/settings/settings.html b/src/settings/settings.html index 22bd3ff..7cb28e1 100644 --- a/src/settings/settings.html +++ b/src/settings/settings.html @@ -59,32 +59,7 @@ - - - 1 - https://wikipedia.com - trash icon - - - 2 - https://stackoverflow.com/ - trash icon - - - 3 - https://www.w3schools.com/ - trash icon - - - 4 - https://www.youtube.com/ - trash icon - - - 5 - https://github.com/ - trash icon - + diff --git a/src/settings/settings.js b/src/settings/settings.js index 8268b6f..3ab1296 100644 --- a/src/settings/settings.js +++ b/src/settings/settings.js @@ -49,6 +49,7 @@ function init() { getLangPairs(); createDropdown($("#target-language-dropdown")); + updateEnabledTable($("#enabled-website-tbody")); setDefaultLanguage(globalSettings.defaultLanguage); setApertiumSource(globalSettings.apertiumSource); setLastUpdated(globalSettings.lastUpdated); @@ -105,4 +106,15 @@ function getSelectedLanguage(selector) { selector.removeClass("selected-language"); return text; +} + +function updateEnabledTable(parent) { + let list = getEnabledWebsiteList(); + + parent.empty(); + let rowIter = 1; + list.forEach((websiteURL) => { + parent.append("" + rowIter + "" + websiteURL + "trash icon"); + rowIter++; + }); } \ No newline at end of file