Skip to content

Commit

Permalink
Code Style.
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitbatra1 committed May 26, 2020
1 parent c0d4b25 commit ea75be3
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions Safari Reverse Image Search Extension/SafariExtensionHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ class SafariExtensionHandler: SFSafariExtensionHandler {

// show menu option if image is selected and image is not embedded
if (userInfo!["isImage"] as! String == "IMG"){
let x = userInfo!["url"] as! String

if (!x.contains("data:image")){
if (!(userInfo!["url"] as! String).contains("data:image")){
validationHandler(false, nil)
}
else{
Expand All @@ -37,6 +36,15 @@ class SafariExtensionHandler: SFSafariExtensionHandler {

}

func openTab(newTabURL: URL){
// This grabs the active window.
SFSafariApplication.getActiveWindow { (activeWindow) in
// Request a new tab on the active window, with the URL we want.
activeWindow?.openTab(with: newTabURL, makeActiveIfPossible: true, completionHandler: {_ in
})
}
}

override func contextMenuItemSelected(withCommand command: String, in page: SFSafariPage, userInfo: [String : Any]? = nil) {

// Handling when context menu option is selected.
Expand All @@ -49,16 +57,11 @@ class SafariExtensionHandler: SFSafariExtensionHandler {
imageLink = imageLink.addingPercentEncoding(withAllowedCharacters: .alphanumerics)!

imageSearch += imageLink
let myUrl = URL(string: imageSearch)!

let myURL = URL(string: imageSearch)!

//open the search results in a new tab
openTab(newTabURL: myURL)

// This grabs the active window.
SFSafariApplication.getActiveWindow { (activeWindow) in

// Request a new tab on the active window, with the URL we want.
activeWindow?.openTab(with: myUrl, makeActiveIfPossible: true, completionHandler: {_ in
})
}
}
if (command == "TinEye"){

Expand All @@ -69,16 +72,11 @@ class SafariExtensionHandler: SFSafariExtensionHandler {
imageLink = imageLink.addingPercentEncoding(withAllowedCharacters: .alphanumerics)!

imageSearch += imageLink
let myUrl = URL(string: imageSearch)!
let myURL = URL(string: imageSearch)!

//open the search results in a new tab
openTab(newTabURL: myURL)


// This grabs the active window.
SFSafariApplication.getActiveWindow { (activeWindow) in

// Request a new tab on the active window, with the URL we want.
activeWindow?.openTab(with: myUrl, makeActiveIfPossible: true, completionHandler: {_ in
})
}
}

}
Expand Down

0 comments on commit ea75be3

Please sign in to comment.