Skip to content

Instantly share code, notes, and snippets.

@Yukaii
Created May 7, 2024 08:35
Show Gist options
  • Save Yukaii/7d90df30cca270eba186a3c5f715dca0 to your computer and use it in GitHub Desktop.
Save Yukaii/7d90df30cca270eba186a3c5f715dca0 to your computer and use it in GitHub Desktop.
additional keymapping for phanpy
// ==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