forked from quoid/userscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSafariExtensionHandler.swift
More file actions
36 lines (29 loc) · 1.26 KB
/
Copy pathSafariExtensionHandler.swift
File metadata and controls
36 lines (29 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//
// SafariExtensionHandler.swift
// Userscripts Extension
//
// Created by Justin Wasack on 4/25/19.
// Copyright © 2019 Justin Wasack. All rights reserved.
//
import SafariServices
import WebKit
class SafariExtensionHandler: SFSafariExtensionHandler {
override func messageReceived(withName messageName: String, from page: SFSafariPage, userInfo: [String : Any]?) {
if messageName == "REQUEST_SAVED_CODE" {
if getSavedCode() != nil && UserDefaults.standard.bool(forKey: "toggleOff") != true {
let code = getSavedCode()!.addingPercentEncoding(withAllowedCharacters: .alphanumerics)!
page.dispatchMessageToScript(withName: "SEND_SAVED_CODE", userInfo: ["code": code])
}
}
}
override func toolbarItemClicked(in window: SFSafariWindow) {
// This method will be called when your toolbar item is clicked.
NSLog("The extension's toolbar item was clicked")
}
override func validateToolbarItem(in window: SFSafariWindow, validationHandler: @escaping ((Bool, String) -> Void)) {
validationHandler(true, "")
}
override func popoverViewController() -> SFSafariExtensionViewController {
return SafariExtensionViewController.shared
}
}