miketheman / AWS Console Filter Focus Keyboard shortcut

// ==UserScript==
// @name         AWS Console Filter Focus Keyboard shortcut
// @namespace    https://tampermonkey.net/
// @version      0.1
// @description  Focus filters with keyboard (not sitewide search)
// @author       miketheman@gmail.com
// @match        https://*.aws.amazon.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

// These are super manual, and not awesome, but kinda sorta work.
const selectors = {
  '/cloudformation/home': 'input[type="search"][placeholder="Filter by stack name"]',
  // ec2 is kinda busted right now, JS won't even fire, since it's in an iframe.  '/ec2/home': 'input[type="text"][placeholder="Find Instance by attribute or tag (case-sensitive)"]',
  '/ecs/v2/clusters': 'input[type="search"][placeholder="Search clusters"]',
  '/rds/home': 'input[type="search"][placeholder="Filter by databases"]',
  '/route53/v2/hostedzones': 'input[type="text"][placeholder="Filter records by property or value"]'
};

(function () {
  'use strict';

  window.addEventListener('keydown', function (e) {
    if (e.key === '/' && !document.activeElement.closest('input')) {
      e.preventDefault();

      const pathname = window.location.pathname;
      console.log(pathname);

      const selector = selectors[pathname];
      console.log(selector);

      if (selector) {
        const input = document.querySelector(selector);
        if (input) {
          input.focus();
        }
      }
      else {
        console.log(`No matching selector found for URL: ${pathname}`);
      }
    }
  });
})();