Last active
January 9, 2025 17:34
-
-
Save hjdarnel/e3c3e5c62b7aa27a5cbfddfcf34258cc to your computer and use it in GitHub Desktop.
Add site-wide hotkeys to Letterboxd
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 Letterboxd Site-wide Hotkeys | |
// @namespace hjdarnel | |
// @version 0.0.1 | |
// @description Press / anywhere on Letterboxd to search | |
// @author Henry Darnell https://github.com/hjdarnel | |
// @match https://letterboxd.com/* | |
// @downloadURL https://gist.github.com/hjdarnel/e3c3e5c62b7aa27a5cbfddfcf34258cc/raw/letterboxd-site-hotkeys.user.js | |
// @updateURL https://gist.github.com/hjdarnel/e3c3e5c62b7aa27a5cbfddfcf34258cc/raw/letterboxd-site-hotkeys.user.js | |
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== | |
// @grant none | |
// ==/UserScript== | |
'use strict'; | |
const sleep = (ms) => new Promise(res => setTimeout(res, ms)); | |
document.addEventListener('keyup', async (event) => { | |
const activeElement = document.activeElement; | |
if (activeElement.tagName === 'INPUT' || activeElement.tagName === 'TEXTAREA') { | |
if (event.code === 'Escape'){ | |
const cancelSearchEl = document.querySelector('li.js-nav-search-toggle a.nav-search-active') | |
if (cancelSearchEl) cancelSearchEl.click(); | |
} | |
return; | |
} | |
switch (event.code) { | |
case 'Slash': { | |
document.querySelector('li.navitem > a.replace').click(); | |
await sleep(100) | |
document.querySelector("#search-q").click(); | |
break; | |
} | |
}; | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment