Skip to content

Commit

Permalink
Better default pattern in popup (https?://...).
Browse files Browse the repository at this point in the history
  • Loading branch information
smblott-github committed Nov 12, 2014
1 parent 7b9c101 commit 4a0f747
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions pages/popup.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ originalRule = undefined
originalPattern = undefined
originalPassKeys = undefined

generateDefaultPattern = (url) ->
if /^https?:\/\/./.test url
# The common use case is to disable Vimium at the domain level.
# Generate "https?://www.example.com/*" from "http://www.example.com/path/to/page.html".
"https?:/" + url.split("/",3)[1..].join("/") + "/*"
else if /^[a-z]{3,}:\/\/./.test url
# Anything else which seems to be a URL.
url.split("/",3).join("/") + "/*"
else
url + "*"

reset = (initialize=false) ->
document.getElementById("optionsLink").setAttribute "href", chrome.runtime.getURL("pages/options.html")
chrome.tabs.getSelected null, (tab) ->
Expand All @@ -13,11 +24,8 @@ reset = (initialize=false) ->
originalPattern = originalRule.pattern
originalPassKeys = originalRule.passKeys
else
# The common use case is to disable Vimium at the domain level.
# This regexp will match "http://www.example.com/" from "http://www.example.com/path/to/page.html".
domain = (tab.url.match(/[^\/]*\/\/[^\/]*\//) or tab.url) + "*"
originalRule = null
originalPattern = domain
originalPattern = generateDefaultPattern tab.url
originalPassKeys = ""
patternElement = document.getElementById("popupPattern")
passKeysElement = document.getElementById("popupPassKeys")
Expand Down

0 comments on commit 4a0f747

Please sign in to comment.