Skip to content

Instantly share code, notes, and snippets.

@f-steff
Created February 6, 2023 22:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save f-steff/83be141ea8ce81a526e1b76a8be4a9bc to your computer and use it in GitHub Desktop.
Save f-steff/83be141ea8ce81a526e1b76a8be4a9bc to your computer and use it in GitHub Desktop.
Userscript for Tampermonkey to intercept F1 on Google Sheets, so that the annoying Help popup can be suppressed.
// ==UserScript==
// @name F1 key interception on Google Sheets to suppress the Help
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Interception of F1 keypress on Google Sheets and replaces default behavior with nothing.
// @author Flemming Steffensen
// @match https://docs.google.com/spreadsheets/*
// @grant none
// ==/UserScript==
document.addEventListener("keydown", function(event) {
// For typical shortcuts
// Windows & Linux use the Control key == ctrlKey
// Mac uses the Command key == metaKey
// Other group keys are altKey and shiftKey
var isMac = navigator.platform.toUpperCase().indexOf('MAC')>=0;
var modifier = isMac ? event.metaKey : event.ctrlKey;
var debug = false
if(debug) {
if (!( (event.code === "ControlLeft") || (event.code === "ControlRight")
|| (event.code === "MetaLeft") || (event.code === "MetaRight")
|| (event.code === "AltLeft") || (event.code === "AltRight")
|| (event.code === "ShiftLeft") || (event.code === "ShiftRight")
)) {
alert("Key pressed Pressed: " + event.code + " (" + event.keyCode + ") on " + (isMac ? "Mac" : "nonMac ") + (modifier ? "with" : " without") + " modifier." )
}
}
// For some reason this triggers on F1, but not shift-F1, although event.code is F1 for both.
if (event.code === "F1") {
event.preventDefault();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment