Auto Focus Username Field

Attempts to locate the username input box and change focus to it, will briefly change the background color of the field green when it activates.

当前为 2014-08-24 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Auto Focus Username Field
  3. // @namespace ClintPriest.com
  4. // @description Attempts to locate the username input box and change focus to it, will briefly change the background color of the field green when it activates.
  5. // @include http://*
  6. // @include https://*
  7. // @version 1
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. var names = new Set([ 'username','login_name','user','login' ]);
  12.  
  13. function findFocus(e) {
  14. console.log('load %o', e);
  15. for(var x of names.values()) {
  16. var elem = document.querySelector('INPUT[name*=' + x + ']');
  17. if(elem) {
  18. elem.origbackgroundColor= elem.style.backgroundColor;
  19. elem.style.backgroundColor = '#A0FFA0';
  20. elem.focus();
  21. elem.selectionStart = 0;
  22. elem.selectionEnd = 999;
  23.  
  24. setTimeout(function() {
  25. elem.style.backgroundColor = elem.origbackgroundColor;
  26. delete elem.origbackgroundColor;
  27. }, 2000);
  28. break;
  29. }
  30. }
  31. window.removeEventListener('DOMContentLoaded', findFocus);
  32. };
  33.  
  34. window.addEventListener('DOMContentLoaded', findFocus);