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
//
// Created by Chris Li on 9/9/16.
@ -9,13 +9,12 @@
import UIKit
import JavaScriptCore
class JSInjection {
class JS {
class func inject(webView: UIWebView) {
let context = webView.valueForKeyPath("documentView.webView.mainFrame.javaScriptContext") as? JSContext
let path = NSBundle.mainBundle().pathForResource("injection", ofType: "js")
let jString = try? String(contentsOfFile: path!)
context?.evaluateScript(jString!)
webView.context.evaluateScript(jString!)
}
class func adjustFontSizeIfNeeded(webView: UIWebView) {
@ -48,3 +47,9 @@ class JSInjection {
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() {
guard isShowingTableOfContents else {return}
tableOfContentsController?.headings = JSInjection.getTableOfContents(webView)
tableOfContentsController?.headings = JS.getTableOfContents(webView)
}
func configureUserActivity() {

View File

@ -44,15 +44,15 @@ extension MainController: UIWebViewDelegate, SFSafariViewControllerDelegate, LPT
// Create article object
guard let url = webView.request?.URL,
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
self.article = article
// UI Updates
configureNavigationButtonTint()
configureTableOfContents()
JSInjection.adjustFontSizeIfNeeded(webView)
JSInjection.inject(webView)
JS.adjustFontSizeIfNeeded(webView)
JS.inject(webView)
}
func webView(webView: UIWebView, didFailLoadWithError error: NSError) {
@ -83,7 +83,7 @@ extension MainController: UIWebViewDelegate, SFSafariViewControllerDelegate, LPT
article.isBookmarked = !article.isBookmarked
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)
// GlobalQueue.shared.addOperation(cloudKitUpdateOperation)

View File

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

View File

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