OrangesSuck

Disable Focus on Window Load

Jul 4th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name           Disable Focus on Window Load
  3. // @namespace      http://userscripts.org/
  4. // @description    Stop stealing focus and hotkeys
  5. // @include        *://www.change.org/*
  6. // @include        *://answers.yahoo.com/*
  7. // @include        *://alternativeto.net/*
  8. // @include        *://www.facebook.com/*
  9. // @include        *://*.deviantart.com/*
  10. // @include        *://*.yahoo.com/*
  11. // @include        *://www.google.*
  12. // @include        *://*thefreedictionary.com/*
  13. // @include        *://github.com/*
  14. // @include        *://imgur.com/*
  15. // @include        *://www.merriam-webster.com/*
  16. // @run-at         document-end
  17.  
  18. // ==/UserScript==
  19.  
  20. function disableFocus(evt) {
  21.     if (evt.target.nodeName == "#document") {
  22.         var input_elements = document.getElementsByTagName('input');
  23.         for (var i = 0; i < input_elements.length; i++) {
  24.             input_elements[i].blur();
  25.         }
  26.     }
  27. }
  28.  
  29. if(document.URL.indexOf("www.google") >= 0)
  30. {   document.addEventListener('keydown', function(e) {
  31.         if (document.activeElement.nodeName != 'INPUT' && !e.ctrlKey && !e.altkey) {
  32.             e.cancelBubble = true;
  33.             e.stopImmediatePropagation();
  34.             return false;
  35.             }
  36.         return true;
  37.         }, true);
  38. }
  39. else if(document.URL.indexOf("imgur") >= 0)
  40. {   document.addEventListener('keydown', function(e) {
  41.         if (e.keyCode == 37 || e.keyCode == 39) { //disable left and right arrow keys
  42.             e.cancelBubble = true;
  43.             e.stopImmediatePropagation();
  44.             return false;
  45.             }
  46.         return true;
  47.         }, true);
  48.     document.addEventListener('scroll', function(e) {
  49.             e.cancelBubble = true;
  50.             e.stopImmediatePropagation();
  51.             return false;
  52.             }, true);  
  53. }
  54. else
  55.     window.addEventListener('load', disableFocus, true);
Add Comment
Please, Sign In to add comment