New reddit: Prevent middle click scroll

Prevents the middle click scroll when middle clicking posts on the new reddit layout

  1. // ==UserScript==
  2. // @name New reddit: Prevent middle click scroll
  3. // @namespace https://greasyfork.org/users/649
  4. // @version 1.0.8
  5. // @description Prevents the middle click scroll when middle clicking posts on the new reddit layout
  6. // @author Adrien Pyke
  7. // @match *://*.reddit.com/*
  8. // @grant GM_openInTab
  9. // @require https://cdn.jsdelivr.net/gh/fuzetsu/userscripts@ec863aa92cea78a20431f92e80ac0e93262136df/wait-for-elements/wait-for-elements.js
  10. // ==/UserScript==
  11.  
  12. (() => {
  13. 'use strict';
  14.  
  15. const Util = {
  16. q(query, context = document) {
  17. return context.querySelector(query);
  18. },
  19. qq(query, context = document) {
  20. return Array.from(context.querySelectorAll(query));
  21. }
  22. };
  23.  
  24. const mousedown = e => {
  25. if (e.button === 1) return false;
  26. };
  27.  
  28. waitForElems({
  29. sel: '.Post',
  30. onmatch(post) {
  31. post.onmousedown = mousedown;
  32.  
  33. const links = Util.qq('a[data-click-id="comments"]', post);
  34. if (links.length) {
  35. const link = links[links.length - 1];
  36. if (link) {
  37. post.onclick = post.onauxclick = e => {
  38. if (
  39. e.button === 1 &&
  40. e.target.tagName !== 'A' &&
  41. e.target.parentNode.tagName !== 'A'
  42. ) {
  43. e.preventDefault();
  44. e.stopImmediatePropagation();
  45. GM_openInTab(link.href, true);
  46. }
  47. };
  48. }
  49. }
  50. }
  51. });
  52. })();