[ALL] Block Right & Middle Mouse Button Click Hijacking

Block mouse button click hijacking.

  1. // ==UserScript==
  2. // @name [ALL] Block Right & Middle Mouse Button Click Hijacking
  3. // @author
  4. // @description Block mouse button click hijacking.
  5. // @downloadURL
  6. // @grant
  7. // @homepageURL https://bitbucket.org/INSMODSCUM/userscripts-scripts/src
  8. // @icon
  9. // @include http*://*
  10. // @namespace insmodscum
  11. // @require
  12. // @run-at document-start
  13. // @updateURL
  14. // @version 1.0
  15. // ==/UserScript==
  16.  
  17. // block right click
  18.  
  19. unsafeWindow.document.oncontextmenu = null;
  20. unsafeWindow.document.oncontextmenu = false;
  21. document.body.removeAttribute ("oncontextmenu");
  22.  
  23. // block middle mouse
  24. // source: https://greasyfork.org/en/scripts/12434-prevent-middle-click-hijacking/code
  25.  
  26. function handler(e){
  27. if(e.button == 1 || (e.button === 0 && e.ctrlKey)){
  28. e.stopPropagation();
  29. }
  30. }
  31.  
  32. addEventListener('click', handler, true);
  33. addEventListener('mousedown', handler, true);
  34. addEventListener('mouseup', handler, true);