mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-26 13:29:31 -04:00
commit
This commit is contained in:
parent
e4697d8bb1
commit
2ce3b75e62
@ -11,6 +11,12 @@ import JavaScriptCore
|
||||
|
||||
class JS {
|
||||
|
||||
class func inject(webView: UIWebView) {
|
||||
guard let url = Bundle.main.url(forResource: "injection", withExtension: "js"),
|
||||
let jString = try? String(contentsOf: url) else {return}
|
||||
webView.stringByEvaluatingJavaScript(from: jString)
|
||||
}
|
||||
|
||||
class func preventDefaultLongTap(webView: UIWebView) {
|
||||
let jString = "document.body.style.webkitTouchCallout='none';"
|
||||
webView.context.evaluateScript(jString)
|
||||
|
@ -28,6 +28,7 @@ extension MainController: UIWebViewDelegate, SFSafariViewControllerDelegate {
|
||||
}
|
||||
|
||||
func webViewDidFinishLoad(_ webView: UIWebView) {
|
||||
JS.inject(webView: webView)
|
||||
JS.preventDefaultLongTap(webView: webView)
|
||||
URLResponseCache.shared.stop()
|
||||
|
||||
@ -157,8 +158,10 @@ extension MainController: ButtonDelegates {
|
||||
func didLongPressBookmarkButton() {
|
||||
showBookmarkHUD()
|
||||
|
||||
// guard let url
|
||||
// let article = Article.fetch(url: <#T##URL#>, context: <#T##NSManagedObjectContext#>)
|
||||
guard let url = webView.request?.url,
|
||||
let article = Article.fetch(url: url, context: AppDelegate.persistentContainer.viewContext) else {return}
|
||||
article.title = JS.getTitle(from: webView)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@
|
||||
</dict>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.8.3396</string>
|
||||
<string>1.8.3401</string>
|
||||
<key>ITSAppUsesNonExemptEncryption</key>
|
||||
<false/>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
|
@ -21,7 +21,7 @@
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.8.3396</string>
|
||||
<string>1.8.3401</string>
|
||||
<key>NSExtension</key>
|
||||
<dict>
|
||||
<key>NSExtensionMainStoryboard</key>
|
||||
|
@ -1,19 +1,2 @@
|
||||
function getSnippet() {
|
||||
var element = document.getElementById('mw-content-text');
|
||||
if (element) {
|
||||
var children = element.children;
|
||||
for (i = 0; i < children.length; i++) {
|
||||
var child = children[i];
|
||||
if (child.tagName == 'P') {
|
||||
var text = child.textContent || child.innerText || "";
|
||||
if (text.replace(/\s/g, '').length) {
|
||||
var regex = /\[[0-9|a-z|A-Z| ]*\]/g;
|
||||
text = text.replace(regex, "");
|
||||
return text;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
getSnippet();
|
||||
|
@ -136,3 +136,22 @@ function startCallBack() {
|
||||
function stopCallBack() {
|
||||
window.onscroll = undefined;
|
||||
}
|
||||
|
||||
function getSnippet() {
|
||||
var element = document.getElementById('mw-content-text');
|
||||
if (element) {
|
||||
var children = element.children;
|
||||
for (i = 0; i < children.length; i++) {
|
||||
var child = children[i];
|
||||
if (child.tagName == 'P') {
|
||||
var text = child.textContent || child.innerText || "";
|
||||
if (text.replace(/\s/g, '').length) {
|
||||
var regex = /\[[0-9|a-z|A-Z| ]*\]/g;
|
||||
text = text.replace(regex, "");
|
||||
return text;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user