Simplify the if structure

remark: Customize a function to avoid "Line exceeds maximum allowed length"
This commit is contained in:
YFdyh000 2019-01-22 01:43:56 +08:00 committed by sn-o-w
parent 815e162640
commit 93d1d89fb2

View File

@ -25,18 +25,15 @@ class ChromeTabs
tabs.forEach (tab) =>
@_dirtyTabs[tab.id] = tab.id
@onUpdated tab.id, {}, tab if tab.active
if chrome.action.setPopup?
chrome.action.setTitle({title: action.title})
else
chrome.action.setTitle({title: action.shortTitle})
title = if @_canSetPopup() then action.title else action.shortTitle
chrome.action.setTitle({title: title})
@setIcon(action.icon)
onUpdated: (tabId, changeInfo, tab) ->
if @_dirtyTabs.hasOwnProperty(tab.id)
delete @_dirtyTabs[tab.id]
else if not changeInfo.url?
if changeInfo.status? and changeInfo.status != 'loading'
return
else if not changeInfo.url? and changeInfo.status == "complete"
return
@processTab(tab, changeInfo)
processTab: (tab, changeInfo) ->
@ -58,10 +55,8 @@ class ChromeTabs
@clearIcon tab.id
return
@setIcon(action.icon, tab.id)
if chrome.action.setPopup?
chrome.action.setTitle({title: action.title, tabId: tab.id})
else
chrome.action.setTitle({title: action.shortTitle, tabId: tab.id})
title = if @_canSetPopup() then action.title else action.shortTitle
return chrome.action.setTitle({title: title, tabId: tab.id})
).catch((e) ->
console.log('error:', e)
)
@ -77,17 +72,15 @@ class ChromeTabs
setIcon: (icon, tabId) ->
return unless icon?
if tabId?
params = {
imageData: icon
tabId: tabId
}
else
params = {
imageData: icon
}
params = {
imageData: icon
}
params.tabId = tabId if tabId?
@_chromeSetIcon(params)
_canSetPopup: ->
chrome.action.setPopup?
_chromeSetIcon: (params) ->
try
chrome.action.setIcon?(params, @ignoreError)