Skip to content

Instantly share code, notes, and snippets.

@tamsky
Last active August 12, 2021 01:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tamsky/5e96b0cf253b85a3e4b56924dc834115 to your computer and use it in GitHub Desktop.
Save tamsky/5e96b0cf253b85a3e4b56924dc834115 to your computer and use it in GitHub Desktop.
don't make me click on the password prompt....c'mon, it's the required field, and the only field.
// ==UserScript==
// @name Speed up AWS login
// @namespace http://tampermonkey.net/
// @version 0.1
// @include https://us-east-1.signin.aws/platform/login?*
// @grant none
// @run-at document-end
// ==/UserScript==
(function() {
'use strict';
var myfocuser = function () {
document.getElementById("awsui-input-1").focus();
// console.log("we got hit!");
};
waitForKeyElements("#awsui-input-1", myfocuser );
})();
// via: https://github.com/CoeJoder/waitForKeyElements.js/blob/master/waitForKeyElements.js
/**
* A utility function for userscripts that detects and handles AJAXed content.
*
* @example
* waitForKeyElements("div.comments", (element) => {
* element.innerHTML = "This text inserted by waitForKeyElements().";
* });
*
* waitForKeyElements(() => {
* const iframe = document.querySelector('iframe');
* if (iframe) {
* const iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
* return iframeDoc.querySelectorAll("div.comments");
* }
* return null;
* }, callbackFunc);
*
* @param {(string|function)} selectorOrFunction - The selector string or function.
* @param {function} callback - The callback function; takes a single DOM element as parameter.
* If returns true, element will be processed again on subsequent iterations.
* @param {boolean} [waitOnce=true] - Whether to stop after the first elements are found.
* @param {number} [interval=300] - The time (ms) to wait between iterations.
* @param {number} [maxIntervals=-1] - The max number of intervals to run (negative number for unlimited).
*/
function waitForKeyElements(selectorOrFunction, callback, waitOnce, interval, maxIntervals) {
if (typeof waitOnce === "undefined") {
waitOnce = true;
}
if (typeof interval === "undefined") {
interval = 300;
}
if (typeof maxIntervals === "undefined") {
maxIntervals = -1;
}
var targetNodes = (typeof selectorOrFunction === "function")
? selectorOrFunction()
: document.querySelectorAll(selectorOrFunction);
var targetsFound = targetNodes && targetNodes.length > 0;
if (targetsFound) {
targetNodes.forEach(function(targetNode) {
var attrAlreadyFound = "data-userscript-alreadyFound";
var alreadyFound = targetNode.getAttribute(attrAlreadyFound) || false;
if (!alreadyFound) {
var cancelFound = callback(targetNode);
if (cancelFound) {
targetsFound = false;
}
else {
targetNode.setAttribute(attrAlreadyFound, true);
}
}
});
}
if (maxIntervals !== 0 && !(targetsFound && waitOnce)) {
maxIntervals -= 1;
setTimeout(function() {
waitForKeyElements(selectorOrFunction, callback, waitOnce, interval, maxIntervals);
}, interval);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment