Skip to content

Instantly share code, notes, and snippets.

@GHolk
Created September 7, 2019 12:14
Show Gist options
  • Save GHolk/4a2edcf9cf3f956ec7eb7d7823348b6c to your computer and use it in GitHub Desktop.
Save GHolk/4a2edcf9cf3f956ec7eb7d7823348b6c to your computer and use it in GitHub Desktop.
make mouse scroll flip page in hackmd slide mode.
// ==UserScript==
// @name hackmd scroll flip
// @namespace http://gholk.github.io/
// @version 6
// @description make mouse scroll flip page in hackmd slide mode.
// @match https://hackmd.io/*/*
// @grant none
// ==/UserScript==
if (document.querySelector('.reveal .slides')) {
const option = {}
option.pageup = {charCode:0,keyCode:33,altKey:false,ctrlKey:false,shiftKey:false,metaKey:false,repeat:false,isComposing:false,key:"PageUp",code:"PageUp",type:"keydown",composed:true}
option.pagedown = {charCode:0,keyCode:34,altKey:false,ctrlKey:false,shiftKey:false,metaKey:false,repeat:false,isComposing:false,key:"PageDown",code:"PageDown",type:"keydown",composed:true}
window.addEventListener(
'wheel',
function (scroll) {
scroll.preventDefault()
let keyOption
if (scroll.deltaY > 0) keyOption = option.pagedown
else keyOption = option.pageup
const key = new KeyboardEvent('keydown', keyOption)
document.dispatchEvent(key)
},
{passive: false}
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment