diff --git a/html/content.js b/html/content.js index cbc29b2..2d88c4e 100644 --- a/html/content.js +++ b/html/content.js @@ -71,3 +71,15 @@ function setNightmode(nightmode) { if(nightmode) document.body.className = "nightmode"; else document.body.className = ""; } + +document.onkeydown = checkKey; + +function checkKey(e) { + e = e || window.event; + if (e.keyCode == '37') { + window.location.href = "feedthemonkey:previous"; + } + else if (e.keyCode == '39') { + window.location.href = "feedthemonkey:next"; + } +} diff --git a/qml/Content.qml b/qml/Content.qml index b00764a..086dbef 100644 --- a/qml/Content.qml +++ b/qml/Content.qml @@ -85,9 +85,14 @@ Item { webView.runJavaScript("if(typeof setNightmode == \"function\") setNightmode(" + (content.nightmode ? "true" : "false") + ")") } - onNavigationRequested: { - if (request.navigationType != WebEngineView.LinkClickedNavigation) { + if (request.url == "feedthemonkey:previous") { + request.action = WebEngineView.IgnoreRequest; + app.showPreviousPost(); + } else if (request.url == "feedthemonkey:next") { + request.action = WebEngineView.IgnoreRequest; + app.showNextPost(); + } else if (request.navigationType != WebEngineView.LinkClickedNavigation) { request.action = WebEngineView.AcceptRequest; } else { request.action = WebEngineView.IgnoreRequest; diff --git a/qml/main.qml b/qml/main.qml index e08f3d9..7746367 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -114,6 +114,14 @@ ApplicationWindow { return forEscapingHTML.getText(0, forEscapingHTML.length) } + function showNextPost() { + sidebar.next() + } + + function showPreviousPost() { + sidebar.previous() + } + function keyPressed(event) { switch (event.key) { case Qt.Key_Right: