fixed reader updates

This commit is contained in:
cranci1 2025-07-14 11:03:27 +02:00
parent 2cc03e251c
commit b9eb5f2700

View file

@ -1255,9 +1255,25 @@ struct HTMLView: UIViewRepresentable {
}
let script = """
document.addEventListener('scroll', function() {
window.webkit.messageHandlers.scrollHandler.postMessage('scroll');
}, { passive: true });
(function() {
let lastUpdate = 0;
const throttleInterval = 16;
function updateProgress() {
const now = Date.now();
if (now - lastUpdate >= throttleInterval) {
window.webkit.messageHandlers.scrollHandler.postMessage('scroll');
lastUpdate = now;
}
requestAnimationFrame(updateProgress);
}
requestAnimationFrame(updateProgress);
document.addEventListener('scroll', function() {
requestAnimationFrame(updateProgress);
}, { passive: true });
})();
"""
let userScript = WKUserScript(source: script, injectionTime: .atDocumentEnd, forMainFrameOnly: true)