diff options
| author | Stephen Blott | 2016-10-17 11:28:37 +0100 |
|---|---|---|
| committer | Stephen Blott | 2016-12-11 15:28:56 +0000 |
| commit | d142f4c4c75eceb92184c0773f4d7b376870accf (patch) | |
| tree | 0deea35ad427a8db50acaea8416137a07aefff8a /background_scripts | |
| parent | b4eb7140f5cf4f567c83f7af952b09e8bc80918d (diff) | |
| download | vimium-d142f4c4c75eceb92184c0773f4d7b376870accf.tar.bz2 | |
Extend createTab to open specific pages.
Example:
map a createTab http://edition.cnn.com/ http://www.bbc.co.uk/news
which creates two new tabs, but preloaded with these specific URLs.
`2a` creates four new tabs, two copies of each.
Limitation:
- We cannot control the order of the tabs, so we might get CNN then BBC,
or BBC then CNN. This happens because command options are stored in
an object, and we cannot control the order of the keys.
Also, with:
map a createTab http://www.bbc.co.uk/news http://www.bbc.co.uk/news
we only get one new tab (same reason as above).
Diffstat (limited to 'background_scripts')
| -rw-r--r-- | background_scripts/main.coffee | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 8f99cf3e..14d93101 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -146,14 +146,30 @@ mkRepeatCommand = (command) -> (request) -> # mapped in commands.coffee. BackgroundCommands = createTab: mkRepeatCommand (request, callback) -> - request.url ?= do -> - url = Settings.get "newTabUrl" - if url == "pages/blank.html" - # "pages/blank.html" does not work in incognito mode, so fall back to "chrome://newtab" instead. - if request.tab.incognito then "chrome://newtab" else chrome.runtime.getURL newTabUrl + request.urls ?= + if request.url + # If the request contains a URL, then use it. + [request.url] else - url - TabOperations.openUrlInNewTab request, (tab) -> callback extend request, {tab, tabId: tab.id} + # Otherwise, if we have a registryEntry containing URLs, then use them. + urlList = (opt for own opt of request.registryEntry?.options ? {} when Utils.isUrl opt) + if 0 < urlList.length + urlList + else + # Otherwise, just create a new tab. + url = Settings.get "newTabUrl" + if url == "pages/blank.html" + # "pages/blank.html" does not work in incognito mode, so fall back to "chrome://newtab" instead. + [if request.tab.incognito then "chrome://newtab" else chrome.runtime.getURL newTabUrl] + else + [url] + urls = request.urls[..] + do openNextUrl = (request) -> + if 0 < urls.length + TabOperations.openUrlInNewTab (extend request, {url: urls.pop()}), (tab) -> + openNextUrl extend request, {tab, tabId: tab.id} + else + callback request duplicateTab: mkRepeatCommand (request, callback) -> chrome.tabs.duplicate request.tabId, (tab) -> callback extend request, {tab, tabId: tab.id} moveTabToNewWindow: ({count, tab}) -> |
