This commit is contained in:
Chris Li 2016-10-17 16:36:45 -04:00
parent 9bd8c3e462
commit c1a40805ad
5 changed files with 16 additions and 11 deletions

View File

@ -1,5 +1,5 @@
// //
// JSInjection.swift // JS.swift
// Kiwix // Kiwix
// //
// Created by Chris Li on 9/9/16. // Created by Chris Li on 9/9/16.
@ -9,13 +9,12 @@
import UIKit import UIKit
import JavaScriptCore import JavaScriptCore
class JSInjection { class JS {
class func inject(webView: UIWebView) { class func inject(webView: UIWebView) {
let context = webView.valueForKeyPath("documentView.webView.mainFrame.javaScriptContext") as? JSContext
let path = NSBundle.mainBundle().pathForResource("injection", ofType: "js") let path = NSBundle.mainBundle().pathForResource("injection", ofType: "js")
let jString = try? String(contentsOfFile: path!) let jString = try? String(contentsOfFile: path!)
context?.evaluateScript(jString!) webView.context.evaluateScript(jString!)
} }
class func adjustFontSizeIfNeeded(webView: UIWebView) { class func adjustFontSizeIfNeeded(webView: UIWebView) {
@ -48,3 +47,9 @@ class JSInjection {
return snippet == "null" ? nil : snippet return snippet == "null" ? nil : snippet
} }
} }
extension UIWebView {
var context: JSContext {
return valueForKeyPath("documentView.webView.mainFrame.javaScriptContext") as! JSContext
}
}

View File

@ -158,7 +158,7 @@ class MainController: UIViewController {
func configureTableOfContents() { func configureTableOfContents() {
guard isShowingTableOfContents else {return} guard isShowingTableOfContents else {return}
tableOfContentsController?.headings = JSInjection.getTableOfContents(webView) tableOfContentsController?.headings = JS.getTableOfContents(webView)
} }
func configureUserActivity() { func configureUserActivity() {

View File

@ -44,15 +44,15 @@ extension MainController: UIWebViewDelegate, SFSafariViewControllerDelegate, LPT
// Create article object // Create article object
guard let url = webView.request?.URL, guard let url = webView.request?.URL,
let article = Article.addOrUpdate(url: url, context: NSManagedObjectContext.mainQueueContext) else {return} let article = Article.addOrUpdate(url: url, context: NSManagedObjectContext.mainQueueContext) else {return}
article.title = JSInjection.getTitle(from: webView) article.title = JS.getTitle(from: webView)
article.thumbImagePath = URLResponseCache.shared.firstImage()?.path article.thumbImagePath = URLResponseCache.shared.firstImage()?.path
self.article = article self.article = article
// UI Updates // UI Updates
configureNavigationButtonTint() configureNavigationButtonTint()
configureTableOfContents() configureTableOfContents()
JSInjection.adjustFontSizeIfNeeded(webView) JS.adjustFontSizeIfNeeded(webView)
JSInjection.inject(webView) JS.inject(webView)
} }
func webView(webView: UIWebView, didFailLoadWithError error: NSError) { func webView(webView: UIWebView, didFailLoadWithError error: NSError) {
@ -83,7 +83,7 @@ extension MainController: UIWebViewDelegate, SFSafariViewControllerDelegate, LPT
article.isBookmarked = !article.isBookmarked article.isBookmarked = !article.isBookmarked
if article.isBookmarked {article.bookmarkDate = NSDate()} if article.isBookmarked {article.bookmarkDate = NSDate()}
if article.snippet == nil {article.snippet = JSInjection.getSnippet(webView)} if article.snippet == nil {article.snippet = JS.getSnippet(webView)}
// let cloudKitUpdateOperation = BookmarkCloudKitOperation(article: article) // let cloudKitUpdateOperation = BookmarkCloudKitOperation(article: article)
// GlobalQueue.shared.addOperation(cloudKitUpdateOperation) // GlobalQueue.shared.addOperation(cloudKitUpdateOperation)

View File

@ -49,7 +49,7 @@
</dict> </dict>
</array> </array>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>1.8.1783</string> <string>1.8.1787</string>
<key>ITSAppUsesNonExemptEncryption</key> <key>ITSAppUsesNonExemptEncryption</key>
<false/> <false/>
<key>LSRequiresIPhoneOS</key> <key>LSRequiresIPhoneOS</key>

View File

@ -21,7 +21,7 @@
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>1.8.1783</string> <string>1.8.1787</string>
<key>NSExtension</key> <key>NSExtension</key>
<dict> <dict>
<key>NSExtensionMainStoryboard</key> <key>NSExtensionMainStoryboard</key>