Skip to content

Commit

Permalink
Merge pull request #34 from jhonatasrm/fixes-issue-with-notifications
Browse files Browse the repository at this point in the history
Fixes notifications issue after first status change at preferences page 
Minor fixes
  • Loading branch information
jhonatasrm authored Aug 5, 2019
2 parents f2d5299 + a3ff8f5 commit cf14d62
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
7 changes: 5 additions & 2 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ let savedQuestions = browser.storage.local.get('questions');
savedQuestions.then(loaded);
var requestAPI = "";
var numberOfQuestionsOpened = 0;

// stored values
var frequencySeekNewQuestions = localStorage.getItem("frequencySeekNewQuestions");
var locale = localStorage.getItem("chooseLanguage");
var showNotifications = localStorage.getItem("showNotifications");

// set the preferences settings
if (typeof frequencySeekNewQuestions === 'undefined' || frequencySeekNewQuestions === null){
Expand Down Expand Up @@ -276,10 +279,10 @@ request.onload = function() {
savedQuestions = newQuestionList.concat(savedQuestions);
browser.storage.local.set({'questions':savedQuestions});

if (localStorage.getItem("showNotifications") && newQuestionList.length > 0) {
if (showNotifications === 'true' && newQuestionList.length > 0) {
showNotification(newQuestionList);
}

toggleScreen();
questionCount();
load.style.display = 'none';
Expand Down
12 changes: 6 additions & 6 deletions src/js/language.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
let textElements = document.querySelectorAll('[data-manifest]');
for (let element of textElements) {
element.textContent = Manifest[element.dataset.manifest];
}
for (let element of textElements) {
element.textContent = Manifest[element.dataset.manifest];
}

textElements = document.querySelectorAll('[data-i18n]');
for (let element of textElements) {
element.textContent = browser.i18n.getMessage(element.dataset.i18n);
}
for (let element of textElements) {
element.textContent = browser.i18n.getMessage(element.dataset.i18n);
}
18 changes: 12 additions & 6 deletions src/js/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ version.textContent = browser.runtime.getManifest().name + " (v"+ browser.runtim
// }
//$('input[name="showNewQuestions"]').on('change', function(){
// localStorage.setItem('showNewQuestions', $(this).val());
// backgroundPage.request.onload();// });
// backgroundPage.location.reload(); });
//});

// language questions
Expand All @@ -31,7 +31,7 @@ $(document).ready(function(){

$('select[name="chooseLanguage"]').on('change', function(){
localStorage.setItem('chooseLanguage', $(this).val());
backgroundPage.request.onload();
backgroundPage.location.reload();
});
});

Expand All @@ -48,20 +48,26 @@ $(document).ready(function(){

$('input[name="frequencySeekNewQuestions"]').on('change', function(){
localStorage.setItem('frequencySeekNewQuestions', $(this).val());
backgroundPage.request.onload();
backgroundPage.location.reload();
});
});

// show or hide browser notifications
$(document).ready(function(){
var checkbox = document.getElementById("showNotifications");
var val = localStorage.getItem('showNotifications');
if (val) {
if (val){
checkbox.checked = val;
} else {
}else{
checkbox.checked = false;
}
//
$('#showNotifications').on('change', function(){
localStorage.setItem('showNotifications', $(this).val());
if(checkbox.checked == true){
localStorage.setItem('showNotifications', true);
}else{
localStorage.setItem('showNotifications', false);
}
backgroundPage.location.reload();
});
});

0 comments on commit cf14d62

Please sign in to comment.