Fix screenshot quality option

Change-Id: Ie5b4735fc8cf019daa6e582376489915e2e20bfd
diff --git a/src/js/options.js b/src/js/options.js
index abb2efc..f56bc7a 100644
--- a/src/js/options.js
+++ b/src/js/options.js
@@ -27,27 +27,28 @@
   initScreenCaptureQuality();

 }

 

-function save() {

+function save(callback) {

+  var screenshotQuality = $('lossy').checked ? 'jpeg' : '' ||

+      $('lossless').checked ? 'png' : '';

   chrome.storage.local.set({

-    'screenshootQuality': 

-      $('lossy').checked ? 'jpeg' : '' ||

-      $('lossless').checked ? 'png' : '',

+    screenshotQuality,

+  }, _ => {

+    callback(true);

   });

-

-  return true;

 }

 

 function saveAndClose() {

-  if (save())

+  save(_ => {

     chrome.tabs.getSelected(null, function(tab) {

       chrome.tabs.remove(tab.id);

     });

+  });

 }

 

 function initScreenCaptureQuality() {

   chrome.storage.local.get('screenshotQuality', value => {

-    $('lossy').checked = value == 'jpeg';

-    $('lossless').checked = value == 'png';

+    $('lossy').checked = value['screenshotQuality'] == 'jpeg';

+    $('lossless').checked = value['screenshotQuality'] == 'png';

   });

 }

 

diff --git a/src/js/showimage.js b/src/js/showimage.js
index 6e6d8ad..e9aea79 100644
--- a/src/js/showimage.js
+++ b/src/js/showimage.js
@@ -504,12 +504,12 @@
 
   save: function() {
     photoshop.draw();
-    chrome.storage.local.get('screenshotQuality', formatParam => {
-      var formatParam = formatParam || 'png';
+    chrome.storage.local.get('screenshotQuality', options => {
+      var formatParam = options['screenshotQuality'] || 'png';
       var dataUrl;
       var isJpeg = formatParam == 'jpeg';
       $('canvas').toBlob(function(blob) {
-        saveAs(blob, chrome.extension.getBackgroundPage().screenshot.screenshotName+".png");
+        saveAs(blob, chrome.extension.getBackgroundPage().screenshot.screenshotName + (isJpeg ? ".jpeg" : ".png"));
       }, 'image/' + (isJpeg ? 'jpeg' : 'png'), (isJpeg ? 0.5 : null));
       photoshop.finish();
     });