Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Userscript to add a "term" parameter in the url to allow filtering of CloudFormation listings
// ==UserScript==
// @name CloudFormation Filter
// @namespace http://tampermonkey.net/
// @version 0.99a
// @description add filterability to the CloudFormation URL template via a "term" query parameter in the hash
// @author rektide
// @match https://console.aws.amazon.com/cloudformation/home*
// @grant none
// ==/UserScript==
(function() {
'use strict';
function changeEvent(){
var changeEvent = document.createEvent("HTMLEvents");
changeEvent.initEvent("change", true, false); // name, bubble, cancel
return changeEvent;
}
function initKeyboardEvent( type, bubbles, cancelable, view, ctrlKey, altKey, shiftKey, metaKey, keyCode, charCode){
// keycode comes out 0?!
//var kbEvent= new KeyboardEvent( type, {
// bubbles,
// cancelable,
// view,
// ctrlKey,
// altKey,
// shiftKey,
// metaKey,
// keyCode,
// charCode
//});
// keycode comes out 0?!
//var kbEvent= document.createEvent( "KeyboardEvent");
//kbEvent.initKeyboardEvent( type, bubbles, cancelable, view, ctrlKey, altKey, shiftKey, metaKey, keyCode, charCode);
// the old way. not a fan (versus the above ones) but it works.
var kbEvent = document.createEvent( "HTMLEvents");
kbEvent.initEvent( "keydown", true, true);
kbEvent.keyCode= 13;
kbEvent.charCode= 13;
kbEvent.which= 13;
// not being accepted from constructor?!
if(kbEvent.keyCode != keyCode){
console.log("WHAT THE HELL?!", kbEvent.keyCode);
}
return kbEvent;
}
function enterEvent(){
var enterDownKey= initKeyboardEvent( "keydown", true, true, window, false, false, false, false, 13, 0);
return enterEvent;
}
// focus on the search box
var search= document.getElementById( "stackNameFilter");
search.focus();
// fill in "term" filter
if( !window.location.hash) return;
var
searchParams= new URLSearchParams( window.location.hash),
term= searchParams.get( "term"),
change= changeEvent();
search.value= term;
search.dispatchEvent(changeEvent);
// pause then hit enter
var enter= enterEvent();
setTimeout( search.dispatchEvent.bind( search, enter), 200);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment