aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts
diff options
context:
space:
mode:
Diffstat (limited to 'content_scripts')
-rw-r--r--content_scripts/mode.coffee16
1 files changed, 16 insertions, 0 deletions
diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee
index f411d29b..8041f462 100644
--- a/content_scripts/mode.coffee
+++ b/content_scripts/mode.coffee
@@ -76,5 +76,21 @@ class Mode
func()
mode.exit()
+# A SingletonMode is a Mode of which there may be at most one instance of the same name (@singleton) active at
+# any one time. New instances cancel previous instances on startup.
+class SingletonMode extends Mode
+ constructor: (@singleton, options) ->
+ @cancel @singleton
+ super options
+
+ @instances: {}
+
+ cancel: (instance) ->
+ SingletonMode[instance].exit() if SingletonMode[instance]
+
+ exit: ->
+ delete SingletonMode[@instance]
+ super()
+
root = exports ? window
root.Mode = Mode