Altium viewer - disable number hotkeys

Suppress some number keys in online altium viewer, to prevent accidentally switching between e.g. schematic and PCB views.

  1. // ==UserScript==
  2. // @name Altium viewer - disable number hotkeys
  3. // @namespace http://www.stderr.nl/
  4. // @version 2024-09-03
  5. // @description Suppress some number keys in online altium viewer, to prevent accidentally switching between e.g. schematic and PCB views.
  6. // @author Matthijs Kooijman <matthijs@stdin.nl>
  7. // @license The MIT license; http://opensource.org/licenses/MIT
  8. // @match https://cdn.365.altium.com/microfrontends/viewer/*
  9. // @grant none
  10. // @run-at document-start
  11. // ==/UserScript==
  12.  
  13. // Number keys can be used to switch between schematic, PCB and 3D views. When running Firefox
  14. // on Gnome, switching between virtual desktops with super-1/2/3 seems to deliver the keyup event
  15. // for that to the website, causing altium viewer to switch modes. This might be a gnome-shell bug,
  16. // but this script eats up those keyup events to work around this.
  17.  
  18. // This script matches the URL of the viewer iframe in the altium webpage, since that is where the key events
  19. // are handled (and if the iframe is focused, the outer document never sees the events).
  20.  
  21. // Approach is based on https://stackoverflow.com/a/19785922/740048
  22.  
  23. (function() {
  24. 'use strict';
  25. var keys = ['1', '2', '3'];
  26. document.addEventListener('keyup', function(e) {
  27. // console.log("KEY EVT", e);
  28. if (keys.indexOf(e.key) != -1) {
  29. console.log("CANCELING EVT", e);
  30. e.cancelBubble = true;
  31. e.stopImmediatePropagation();
  32. }
  33. return false;
  34. }, {capture: true});
  35. })();