Skip to content

Persistent value: locale saved in browser storage #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

axtux
Copy link

@axtux axtux commented Dec 23, 2017

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

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