aboutsummaryrefslogtreecommitdiffstats
path: root/background_scripts/main.coffee
diff options
context:
space:
mode:
Diffstat (limited to 'background_scripts/main.coffee')
-rw-r--r--background_scripts/main.coffee21
1 files changed, 21 insertions, 0 deletions
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee
index 4c1b9ae7..c1c8dfc8 100644
--- a/background_scripts/main.coffee
+++ b/background_scripts/main.coffee
@@ -339,6 +339,25 @@ updateOpenTabs = (tab) ->
setBrowserActionIcon = (tabId,path) ->
chrome.browserAction.setIcon({ tabId: tabId, path: path })
+chrome.browserAction.setBadgeBackgroundColor
+ # This is Vimium blue (from the icon).
+ # color: [102, 176, 226, 255]
+ # This is a slightly darker blue. It makes the badge more striking in the corner of the eye, and the symbol
+ # easier to read.
+ color: [82, 156, 206, 255]
+
+setBadge = do ->
+ current = null
+ timer = null
+ updateBadge = (badge) -> -> chrome.browserAction.setBadgeText text: badge
+ (request) ->
+ badge = request.badge
+ if badge? and badge != current
+ current = badge
+ clearTimeout timer if timer
+ # We wait a few moments. This avoids badge flicker when there are rapid changes.
+ timer = setTimeout updateBadge(badge), 50
+
# Updates the browserAction icon to indicate whether Vimium is enabled or disabled on the current page.
# Also propagates new enabled/disabled/passkeys state to active window, if necessary.
# This lets you disable Vimium on a page without needing to reload.
@@ -367,6 +386,7 @@ root.updateActiveState = updateActiveState = (tabId) ->
else
# We didn't get a response from the front end, so Vimium isn't running.
setBrowserActionIcon(tabId,disabledIcon)
+ setBadge {badge: ""}
handleUpdateScrollPosition = (request, sender) ->
updateScrollPosition(sender.tab, request.scrollX, request.scrollY)
@@ -633,6 +653,7 @@ sendRequestHandlers =
refreshCompleter: refreshCompleter
createMark: Marks.create.bind(Marks)
gotoMark: Marks.goto.bind(Marks)
+ setBadge: setBadge
# Convenience function for development use.
window.runTests = -> open(chrome.runtime.getURL('tests/dom_tests/dom_tests.html'))