From 0e8bbf43e5d33573deaada557cfb4d8142c15f38 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 27 Jul 2026 21:48:45 -0700 Subject: [PATCH] Make VoiceOver announce the article view feed icon as a Get Feed Info button. Fixes #4591. --- .../WebViewConfiguration.swift | 17 ++++++++++++++++- iOS/Resources/main_ios.js | 13 ++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Shared/Article Rendering/WebViewConfiguration.swift b/Shared/Article Rendering/WebViewConfiguration.swift index b2288652e..963ab4fd9 100644 --- a/Shared/Article Rendering/WebViewConfiguration.swift +++ b/Shared/Article Rendering/WebViewConfiguration.swift @@ -120,11 +120,26 @@ private extension WebViewConfiguration { let filenames = ["main", "main_mac", "newsfoot"] #endif - let scripts = filenames.map { filename in + var scripts = filenames.map { filename in let scriptURL = Bundle.main.url(forResource: filename, withExtension: ".js")! let scriptSource = try! String(contentsOf: scriptURL, encoding: .utf8) return WKUserScript(source: scriptSource, injectionTime: .atDocumentStart, forMainFrameOnly: true) } + +#if os(iOS) + scripts.insert(feedInfoLabelScript, at: 0) +#endif return scripts }() + +#if os(iOS) + // main_ios.js uses nnwGetFeedInfoLabel as the feed icon's accessibility label. + // The label is passed in from here because localized strings can't live in a static .js file. + // JSON encoding escapes the translation so it's a valid JavaScript string literal. + static let feedInfoLabelScript: WKUserScript = { + let label = NSLocalizedString("Get Feed Info", comment: "Get Feed Info") + let json = String(data: try! JSONSerialization.data(withJSONObject: label, options: .fragmentsAllowed), encoding: .utf8)! + return WKUserScript(source: "const nnwGetFeedInfoLabel = \(json);", injectionTime: .atDocumentStart, forMainFrameOnly: true) + }() +#endif } diff --git a/iOS/Resources/main_ios.js b/iOS/Resources/main_ios.js index bb880e594..37f7f31a8 100644 --- a/iOS/Resources/main_ios.js +++ b/iOS/Resources/main_ios.js @@ -133,7 +133,18 @@ function showClickedImage() { } function showFeedInspectorSetup() { - document.getElementById("nnwImageIcon").onclick = function(event) { + const imageIcon = document.getElementById("nnwImageIcon"); + if (!imageIcon) { + return; + } + + // Tell VoiceOver the icon is a button that opens the Feed Info sheet. + // + imageIcon.setAttribute("role", "button"); + imageIcon.setAttribute("tabindex", "0"); + imageIcon.setAttribute("aria-label", nnwGetFeedInfoLabel); + + imageIcon.onclick = function(event) { window.webkit.messageHandlers.showFeedInspector.postMessage(""); } }