random string generator

generates a random string

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(У мене вже є менеджер скриптів, дайте мені встановити його!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         random string generator
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  generates a random string
// @license MIT
// @author       joshclark756
// @include http://*/*
// @include https://*/*
// @grant        none
// ==/UserScript==

function getRandomString(length) {
  const charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
  let randomString = '';
  for (let i = 0; i < length; i++) {
    const randomIndex = Math.floor(Math.random() * charset.length);
    randomString += charset[randomIndex];
  }
  return randomString;
}

function detectSelectedInput() {
  return document.activeElement;
}

document.addEventListener('keydown', function(event) {
  if (event.key === 'Insert') {
    const selectedInput = detectSelectedInput();
    if (selectedInput) {
      const randomString = getRandomString(10); // Change the length as needed
      selectedInput.value = randomString;
    }
  }
});