tool.user.js

tool.user

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.gf.qytechs.cn/scripts/525123/1528092/tooluserjs.js

  1. function getRandomNum(min, max) {
  2. if (min >= max) {
  3. throw new Error("Min must be less than max");
  4. }
  5. min = Math.ceil(min);
  6. max = Math.floor(max);
  7. return Math.floor(Math.random() * (max - min + 1)) + min;
  8. }
  9.  
  10. /**
  11. * 模拟用户输入填充input元素
  12. * @param {HTMLInputElement} inputElement - 输入框元素
  13. * @param {string|number} value - 要填充的值
  14. */
  15. function fillFormInput(inputElement, value) {
  16. let index = 0;
  17. value = value.toString();
  18. inputElement.value = "";
  19.  
  20. // 使用文档片段减少DOM操作
  21. const docFragment = document.createDocumentFragment();
  22. const intervalId = setInterval(() => {
  23. if (index < value.length) {
  24. docFragment.textContent += value[index];
  25. inputElement.value = docFragment.textContent;
  26. const inputEvent = new Event("input", { bubbles: true });
  27. inputElement.dispatchEvent(inputEvent);
  28. index++;
  29. } else {
  30. clearInterval(intervalId);
  31. }
  32. }, 100);
  33. }
  34.  
  35. function getRandomCharFrom(str) {
  36. const randomIndex = Math.floor(Math.random() * str.length);
  37. return str.charAt(randomIndex);
  38. }
  39.  
  40. const leftKeyboardChars = "1234567890qwertyuiop[]asdfghjkl;'zxcvbnm,./";
  41.  
  42. function getRandomLeftKeyboardChar() {
  43. return getRandomCharFrom(leftKeyboardChars);
  44. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址