diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2018-06-17 20:21:39 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2018-06-17 21:55:25 +0900 |
commit | 48e4bccf0d24bb6ce53c4ecea567ed7750fe8949 (patch) | |
tree | 7c16a68489f2894564da18ae059ba492db88907a /src/background/shared/zooms.js | |
parent | 88238005ab64f957d9def8c18473d8210b280de9 (diff) |
Use async/await on background
Diffstat (limited to 'src/background/shared/zooms.js')
-rw-r--r-- | src/background/shared/zooms.js | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/src/background/shared/zooms.js b/src/background/shared/zooms.js index e3e2aa6..17b28fa 100644 --- a/src/background/shared/zooms.js +++ b/src/background/shared/zooms.js @@ -9,26 +9,20 @@ const ZOOM_SETTINGS = [ 1.10, 1.25, 1.50, 1.75, 2.00, 2.50, 3.00 ]; -const zoomIn = (tabId = undefined) => { - return browser.tabs.getZoom(tabId).then((factor) => { - for (let f of ZOOM_SETTINGS) { - if (f > factor) { - browser.tabs.setZoom(tabId, f); - break; - } - } - }); +const zoomIn = async(tabId = undefined) => { + let current = await browser.tabs.getZoom(tabId); + let factor = ZOOM_SETTINGS.find(f => f > current); + if (factor) { + return browser.tabs.setZoom(tabId, factor); + } }; -const zoomOut = (tabId = undefined) => { - return browser.tabs.getZoom(tabId).then((factor) => { - for (let f of [].concat(ZOOM_SETTINGS).reverse()) { - if (f < factor) { - browser.tabs.setZoom(tabId, f); - break; - } - } - }); +const zoomOut = async(tabId = undefined) => { + let current = await browser.tabs.getZoom(tabId); + let factor = [].concat(ZOOM_SETTINGS).reverse().find(f => f < current); + if (factor) { + return browser.tabs.setZoom(tabId, factor); + } }; const neutral = (tabId = undefined) => { |