Google Sheets Suppress F1 Key Preventing Help-Popup

Interception of F1 keypress on Google Sheets and replaces default behavior with nothing.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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
// @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();
  }

});