Skip to content

Persistent value: locale saved in browser storage - #12

Open
axtux wants to merge 1 commit into
callahad:masterfrom
axtux:master
Open

Persistent value: locale saved in browser storage#12
axtux wants to merge 1 commit into
callahad:masterfrom
axtux:master

Conversation

@axtux

@axtux axtux commented Dec 23, 2017

Copy link
Copy Markdown

Hello,

This resolves issue #10

Let me know if you want to merge it. If not, I will publish my own version on AMO.

Regards,
Axtux

@nevapadonak

Copy link
Copy Markdown

Hi Axtux,
Your fix works! (Firefox 115.3.0esr, GNU/Linux.)
But it misses one important feature. It doesn't update icon with language label after the browser restarting or when extension starts.

Please, see the patch:

diff --git a/background.js b/background.js
index f61c431..e1198bb 100644
--- a/background.js
+++ b/background.js
@@ -1,5 +1,10 @@
 let locale = "";
 
+var updateBadge = (text) => {
+  let label = /[^-,]*/.exec(text.trim())[0].toLowerCase();
+  chrome.browserAction.setBadgeText( { text: label });
+}
+
 chrome.webRequest.onBeforeSendHeaders.addListener(
   details => {
     if (locale) {
@@ -26,5 +31,6 @@ function getLocaleString() {
 browser.storage.sync.get('locale').then(data => {
     if(data['locale']) {
         setLocaleString(data['locale']);
+        updateBadge(data['locale']);
     }
 });
diff --git a/popup.js b/popup.js
index e16aacb..57f73e9 100644
--- a/popup.js
+++ b/popup.js
@@ -3,17 +3,12 @@
 
   let backgroundPage = chrome.extension.getBackgroundPage();
 
-  let updateBadge = (text) => {
-    let label = /[^-,]*/.exec(text.trim())[0].toLowerCase();
-    chrome.browserAction.setBadgeText( { text: label });
-  }
-
   input.value = backgroundPage.getLocaleString();
 
   input.select();
 
   input.addEventListener('input', e => {
-    updateBadge(e.target.value)
+    backgroundPage.updateBadge(e.target.value)
   });
 
   input.addEventListener('input', e => {

It works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants