Skip to content

Instantly share code, notes, and snippets.

@f-steff
Last active January 2, 2025 23:25
Show Gist options
  • 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 to intercept F1 on Google Sheets, so that the annoying Help popup can be suppressed.

Suppress the Google Sheets Help popup when F1 is pressed.

Did you ever by accident press F1, when you really wanted to press F2 to edit a cell, just to have your entire flow destroyed by the annoying help popup that can't just be dismissed with a flick of your hands, and require you to spend time finding the right browser tab to be able to continue work?

I did, once too many!

The result, this script. The perfect solusion to a stupid problem!

// ==UserScript==
// @name Google Sheets Suppress F1 Key Preventing Help-Popup
// @namespace https://gist.github.com/f-steff
// @version 1.1
// @description Interception of F1 keypress on Google Sheets and replaces default behavior with nothing.
// @author Flemming Steffensen
// @license MIT
// @match http://docs.google.com/spreadsheets/*
// @match https://docs.google.com/spreadsheets/*
// @include http://docs.google.com/spreadsheets/*
// @include https://docs.google.com/spreadsheets/*
// @grant none
// @homepageURL https://gist.github.com/f-steff/83be141ea8ce81a526e1b76a8be4a9bc
// @updateURL https://gist.githubusercontent.com/f-steff/83be141ea8ce81a526e1b76a8be4a9bc/raw/GoogleSheetsDisableF1.user.js
// @downloadURL https://gist.githubusercontent.com/f-steff/83be141ea8ce81a526e1b76a8be4a9bc/raw/GoogleSheetsDisableF1.user.js
// @run-at document-start
// ==/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();
}
});
0.1 Initial version
1.0 Added auto-update and publish ability. No code change.
1.1 Changed script @name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment