This commit is contained in:
Brent Simmons
2023-11-22 17:27:23 -08:00
7 changed files with 60 additions and 30 deletions

View File

@@ -96,6 +96,18 @@ protocol DetailWebViewControllerDelegate: AnyObject {
userContentController.add(self, name: MessageName.windowDidScroll)
userContentController.add(self, name: MessageName.mouseDidEnter)
userContentController.add(self, name: MessageName.mouseDidExit)
let baseURL = ArticleRenderer.page.baseURL
let appScriptsWorld = WKContentWorld.world(name: "NetNewsWire")
for fileName in ["main.js", "main_mac.js", "newsfoot.js"] {
userContentController.addUserScript(
.init(source: try! String(contentsOf: baseURL.appending(path: fileName,
directoryHint: .notDirectory)),
injectionTime: .atDocumentStart,
forMainFrameOnly: true,
in: appScriptsWorld))
}
configuration.userContentController = userContentController
webView = DetailWebView(frame: NSRect.zero, configuration: configuration)
@@ -326,7 +338,7 @@ private extension DetailWebViewController {
]
let html = try! MacroProcessor.renderedText(withTemplate: ArticleRenderer.page.html, substitutions: substitutions)
webView.loadHTMLString(html, baseURL: ArticleRenderer.page.baseURL)
webView.loadHTMLString(html, baseURL: URL(string: rendering.baseURL))
}
func scrollInfo() async -> ScrollInfo? {

View File

@@ -4,14 +4,6 @@
<style>
[[style]]
</style>
<script src="main.js"></script>
<script src="main_mac.js"></script>
<script src="newsfoot.js" async="async"></script>
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function(event) {
processPage();
})
</script>
<base href="[[baseURL]]">
</head>
<body>

View File

@@ -14,19 +14,31 @@ import Foundation
// Since the Toolbar intercepts right clicks we need to stop it from doing that here
// so that the ArticleExtractorButton can receive right click events.
if event.isRightClick,
let frameView = contentView?.superview,
let view = frameView.hitTest(frameView.convert(event.locationInWindow, from: nil)),
type(of: view).description() == "NSToolbarView" {
if #available(macOS 14.0, *) {
if event.isRightClick,
let frameView = contentView?.superview,
let view = frameView.hitTest(frameView.convert(event.locationInWindow, from: nil)),
let articleExtractorButton = view as? ArticleExtractorButton {
for subview in view.subviews {
for subsubview in subview.subviews {
let candidateView = subsubview.hitTest(subsubview.convert(event.locationInWindow, from: nil))
if candidateView is ArticleExtractorButton {
candidateView?.rightMouseDown(with: event)
return
articleExtractorButton.rightMouseDown(with: event)
return
}
} else {
if event.isRightClick,
let frameView = contentView?.superview,
let view = frameView.hitTest(frameView.convert(event.locationInWindow, from: nil)),
type(of: view).description() == "NSToolbarView" {
for subview in view.subviews {
for subsubview in subview.subviews {
let candidateView = subsubview.hitTest(subsubview.convert(event.locationInWindow, from: nil))
if candidateView is ArticleExtractorButton {
candidateView?.rightMouseDown(with: event)
return
}
}
}
}
}

View File

@@ -168,3 +168,8 @@ function processPage() {
removeWpSmiley()
postRenderProcessing();
}
document.addEventListener("DOMContentLoaded", function(event) {
window.scrollTo(0, [[windowScrollY]]);
processPage();
})

View File

@@ -263,6 +263,10 @@ figure {
margin-top: 1em;
}
figure > * + * {
margin-top: 0.5em;
}
figcaption {
font-size: 14px;
line-height: 1.3em;

View File

@@ -529,6 +529,20 @@ private extension WebViewController {
}
configuration.setURLSchemeHandler(articleIconSchemeHandler, forURLScheme: ArticleRenderer.imageIconScheme)
let userContentController = WKUserContentController()
let baseURL = ArticleRenderer.page.baseURL
let appScriptsWorld = WKContentWorld.world(name: "NetNewsWire")
for fileName in ["main.js", "main_ios.js", "newsfoot.js"] {
userContentController.addUserScript(
.init(source: try! String(contentsOf: baseURL.appending(path: fileName,
directoryHint: .notDirectory)),
injectionTime: .atDocumentStart,
forMainFrameOnly: true,
in: appScriptsWorld))
}
configuration.userContentController = userContentController
let webView = WKWebView(frame: self.view.bounds, configuration: configuration)
webView.isOpaque = false;
webView.backgroundColor = .clear;
@@ -591,8 +605,8 @@ private extension WebViewController {
]
let html = try! MacroProcessor.renderedText(withTemplate: ArticleRenderer.page.html, substitutions: substitutions)
webView.loadHTMLString(html, baseURL: ArticleRenderer.page.baseURL)
webView.loadHTMLString(html, baseURL: URL(string: rendering.baseURL))
}
func finalScrollPosition(scrollingUp: Bool) -> CGFloat {

View File

@@ -5,15 +5,6 @@
<style>
[[style]]
</style>
<script src="main.js"></script>
<script src="main_ios.js"></script>
<script src="newsfoot.js" async="async"></script>
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function(event) {
window.scrollTo(0, [[windowScrollY]]);
processPage();
})
</script>
<base href="[[baseURL]]">
</head>
<body>