Google search
This commit is contained in:
@@ -252,7 +252,13 @@ class BrowserViewController: UIViewController, WKNavigationDelegate,
|
||||
// MARK: UITextField Delegate
|
||||
|
||||
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
|
||||
if let text = textField.text, var url = URL(string: text) {
|
||||
if let text = textField.text?.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) {
|
||||
|
||||
// Dumb rules for stuff that "looks like" a URL
|
||||
if !text.contains(" "),
|
||||
text.components(separatedBy: ".").count > 1,
|
||||
var url = URL(string: text)
|
||||
{
|
||||
if url.scheme == nil {
|
||||
let urlString = "https://\(text)"
|
||||
if let fixedURL = URL(string: urlString) {
|
||||
@@ -261,9 +267,15 @@ class BrowserViewController: UIViewController, WKNavigationDelegate,
|
||||
}
|
||||
|
||||
tab.beginLoadingURL(url)
|
||||
} else {
|
||||
// Assume google search
|
||||
let queryString = text.replacingOccurrences(of: " ", with: "+")
|
||||
let searchURL = URL(string: "https://google.com/search?q=\(queryString)&gbv=1")! // gbv=1: no JS
|
||||
tab.beginLoadingURL(searchURL)
|
||||
}
|
||||
|
||||
textField.resignFirstResponder()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user