Various fixes

This commit is contained in:
Ilya Laktyushin
2024-07-26 00:06:19 +02:00
parent aa5ad8e194
commit 332408acb7
5 changed files with 226 additions and 73 deletions

View File

@@ -182,6 +182,11 @@ final class BrowserWebContent: UIView, BrowserContent, WKNavigationDelegate, WKU
configuration.mediaPlaybackRequiresUserAction = false
}
let contentController = WKUserContentController()
let videoScript = WKUserScript(source: videoSource, injectionTime: .atDocumentStart, forMainFrameOnly: false)
contentController.addUserScript(videoScript)
configuration.userContentController = contentController
self.webView = WebView(frame: CGRect(), configuration: configuration)
self.webView.allowsLinkPreview = true
@@ -601,7 +606,7 @@ final class BrowserWebContent: UIView, BrowserContent, WKNavigationDelegate, WKU
if download {
decisionHandler(.download, preferences)
} else {
decisionHandler(.cancel, preferences)
// decisionHandler(.cancel, preferences)
}
})
} else {
@@ -1147,6 +1152,48 @@ let setupFontFunctions = """
})();
"""
private let videoSource = """
function disableWebkitEnterFullscreen(videoElement) {
if (videoElement && videoElement.webkitEnterFullscreen) {
Object.defineProperty(videoElement, 'webkitEnterFullscreen', {
value: undefined
});
}
}
function disableFullscreenOnExistingVideos() {
document.querySelectorAll('video').forEach(disableWebkitEnterFullscreen);
}
function handleMutations(mutations) {
mutations.forEach((mutation) => {
if (mutation.addedNodes && mutation.addedNodes.length > 0) {
mutation.addedNodes.forEach((newNode) => {
if (newNode.tagName === 'VIDEO') {
disableWebkitEnterFullscreen(newNode);
}
if (newNode.querySelectorAll) {
newNode.querySelectorAll('video').forEach(disableWebkitEnterFullscreen);
}
});
}
});
}
disableFullscreenOnExistingVideos();
const observer = new MutationObserver(handleMutations);
observer.observe(document.body, {
childList: true,
subtree: true
});
function disconnectObserver() {
observer.disconnect();
}
"""
@available(iOS 16.0, *)
final class BrowserSearchOptions: UITextSearchOptions {
override var wordMatchMethod: UITextSearchOptions.WordMatchMethod {