Created
May 7, 2024 08:35
-
-
Save Yukaii/7d90df30cca270eba186a3c5f715dca0 to your computer and use it in GitHub Desktop.
additional keymapping for phanpy
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 Phanpy additional Keyboard Navigation | |
// @match https://phanpy.social/* | |
// @version 2024-05-07 | |
// @description additional keymapping for phanpy.social | |
// @author Yukai Huang | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=phanpy.social | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
let buffer = ''; | |
let timer; | |
function navigate(hash) { | |
window.location.hash = hash; | |
} | |
const shortcuts = { | |
'gh': () => navigate('/'), | |
'gn': () => navigate('/notifications') | |
}; | |
function handleKeypress(event) { | |
const key = event.key.toLowerCase(); | |
buffer += key; | |
if (timer) { | |
clearTimeout(timer); | |
} | |
timer = setTimeout(() => { | |
buffer = ''; | |
}, 2000); | |
Object.entries(shortcuts).forEach(([combo, action]) => { | |
if (combo === buffer) { | |
action(); | |
buffer = ''; | |
} | |
}); | |
} | |
document.addEventListener('keydown', handleKeypress); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment