isCapsLockEnabled.js

This script causes an alert message to pop up if the user types a character and caps lock is enabled.

  1. // ==UserScript==
  2. // @name isCapsLockEnabled.js
  3. // @namespace https://bitbucket.org/azuelsdorf16
  4. // @version 1.0.0
  5. // @date 23 February 2015
  6. // @description This script causes an alert message to pop up if the user types a character and caps lock is enabled.
  7. // @author Andrew Zuelsdorf
  8. // @include https://*
  9. // @include http://*
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. //For use with Chrome Developer Tools debuggin
  14. debugger;
  15.  
  16. function isAlpha(character) {
  17. if (character >= String.fromCharCode(0x41) &&
  18. character <= String.fromCharCode(0x5A)) {
  19. return true;
  20. }
  21. else if (character >= String.fromCharCode(0x61) &&
  22. character <= String.fromCharCode(0x7A)) {
  23. return true;
  24. }
  25. else if (character >= String.fromCharCode(0xC0) &&
  26. character <= String.fromCharCode(0x2B8)) {
  27. return true;
  28. }
  29. else if (character >= String.fromCharCode(0x363) &&
  30. character <= String.fromCharCode(0x1FFF)) {
  31. return true;
  32. }
  33. else {
  34. return false;
  35. }
  36. }
  37.  
  38. var continuePopupMessages = true;
  39.  
  40. document.onkeypress = function(e) {
  41. if (continuePopupMessages) {
  42. e = e || window.event;
  43. var s = String.fromCharCode(e.keyCode || e.which);
  44. if ((s.toUpperCase() === s && !e.shiftKey) || (e.shiftKey && s.toLowerCase() === s)) {
  45. if (isAlpha(s)) {
  46. continuePopupMessages = (true === confirm("Caps lock is on! Press \"Cancel\" to stop receiving this message on this page. Press \"OK\" otherwise"));
  47. }
  48. }
  49. }
  50. };