Hide Mouse Idle

Auto hide mouse pointer when idle

当前为 2020-01-07 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Hide Mouse Idle
  3. // @namespace iFantz7E.HideMouseIdle
  4. // @version 0.1
  5. // @description Auto hide mouse pointer when idle
  6. // @include *
  7. // @grant none
  8. // @license GPLv3
  9. // @copyright 2020, 7-elephant
  10. // ==/UserScript==
  11.  
  12. // License: GPLv3 - https://www.gnu.org/licenses/gpl-3.0.txt
  13.  
  14. // Since 8 Jan 2020
  15.  
  16. (function ()
  17. {
  18. "use strict";
  19. // jshint multistr:true
  20. function attachOnLoad(callback)
  21. {
  22. window.addEventListener("load", function (e)
  23. {
  24. callback();
  25. });
  26. }
  27.  
  28. function attachOnReady(callback)
  29. {
  30. document.addEventListener("DOMContentLoaded", function (e)
  31. {
  32. callback();
  33. });
  34. }
  35.  
  36. var isVisible = (function()
  37. {
  38. var stateKey;
  39. var eventKey;
  40. var keys =
  41. {
  42. hidden: "visibilitychange",
  43. webkitHidden: "webkitvisibilitychange",
  44. mozHidden: "mozvisibilitychange",
  45. msHidden: "msvisibilitychange"
  46. };
  47. for (stateKey in keys)
  48. {
  49. if (stateKey in document)
  50. {
  51. eventKey = keys[stateKey];
  52. break;
  53. }
  54. }
  55. return function(c)
  56. {
  57. if (c)
  58. {
  59. document.addEventListener(eventKey, c);
  60. }
  61. return !document[stateKey];
  62. }
  63. })();
  64.  
  65. function main()
  66. {
  67. var timingHideCursor = 5000; // 5 seconds
  68. var tmMouseMove = 0;
  69. document.body.addEventListener("mousemove", function(ev)
  70. {
  71. document.body.style.removeProperty("cursor");
  72. clearTimeout(tmMouseMove);
  73. tmMouseMove = setTimeout(function()
  74. {
  75. if (isVisible)
  76. {
  77. document.body.style.setProperty("cursor", "none");
  78. }
  79. }, timingHideCursor);
  80. });
  81. }
  82.  
  83. attachOnReady(main);
  84.  
  85. })();
  86.  
  87. // End