Skip to content

Instantly share code, notes, and snippets.

@agoose77
Last active July 1, 2025 10:04
Show Gist options
  • Save agoose77/570b303d66d061779db1e19e7f458976 to your computer and use it in GitHub Desktop.
Save agoose77/570b303d66d061779db1e19e7f458976 to your computer and use it in GitHub Desktop.
Simple keyboard shortcuts for slides in MyST
// ==UserScript==
// @name MyST Slides
// @namespace http://tampermonkey.net/
// @version 2025-06-25
// @description Move between pages in MyST. Keys can be set in CSS via `--key-slide-next|prev` on the `:root` elem.
// @author Angus Hollands
// @match *://*/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=undefined.localhost
// @grant none
// ==/UserScript==
(function() {
'use strict';
const noModifiers = (evt) => !(evt.metaKey || evt.shiftKey || evt.ctrlKey || evt.altKey);
const style = window.getComputedStyle(document.documentElement);
const cssNextKey = style.getPropertyValue('--key-slide-next');
const cssPrevKey = style.getPropertyValue('--key-slide-prev');
const cssToggleKey = style.getPropertyValue('--key-slide-toggle');
const nextKey = cssNextKey ? cssNextKey : 'd';
const prevKey = cssPrevKey ? cssPrevKey : 'a';
const toggleKey = cssToggleKey ? cssToggleKey : 't';
window.addEventListener("keydown", (e) => {
if (event.key === prevKey && noModifiers(event)) {
const link = document.querySelector("main>:last-child>a:first-child");
if (link) link.click()
} else if (event.key === nextKey && noModifiers(event)) {
const link = document.querySelector("main>:last-child>a:last-child");
if (link) link.click()
} else if (event.key === toggleKey && noModifiers(event)) {
document.documentElement.classList.toggle("no-slide");
}
});
// main>:last-child
// Your code here...
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment