Google search
This commit is contained in:
@@ -252,7 +252,13 @@ class BrowserViewController: UIViewController, WKNavigationDelegate,
|
|||||||
// MARK: UITextField Delegate
|
// MARK: UITextField Delegate
|
||||||
|
|
||||||
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
|
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 {
|
if url.scheme == nil {
|
||||||
let urlString = "https://\(text)"
|
let urlString = "https://\(text)"
|
||||||
if let fixedURL = URL(string: urlString) {
|
if let fixedURL = URL(string: urlString) {
|
||||||
@@ -261,9 +267,15 @@ class BrowserViewController: UIViewController, WKNavigationDelegate,
|
|||||||
}
|
}
|
||||||
|
|
||||||
tab.beginLoadingURL(url)
|
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()
|
textField.resignFirstResponder()
|
||||||
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user