Created
September 7, 2019 12:14
-
-
Save GHolk/4a2edcf9cf3f956ec7eb7d7823348b6c to your computer and use it in GitHub Desktop.
make mouse scroll flip page in hackmd slide mode.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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