Post

WP Cursor Hijack Fix

WP Cursor Hijack Fix

A wordpress plugin in my company’s website was getting on my nerves so I decided to take matters into my own hands.

I’m not from the IT department, but I do have experience from my golden days when I was a kid. I reverse-engineered the problem and fixed it (only for myself)

The Diagnosis

I opened DevTools, a drag library hooks mousemove at window or document. What’s the problem you might ask, well the problem is whenever I wanna highlight certain texts, the screen gets dragged with my cursor!

The Fix

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// ==UserScript==
// @name         Screen Drag Fix
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Blocks drag libraries from hijacking mouse and touch movement
// @author       hafiz
// @match        https://your-site.com/*
// @grant        none
// ==/UserScript==

(function() {
  'use strict';
  const block = e => { e.stopImmediatePropagation(); };
(function() {
  'use strict';
  const block = e => { e.stopImmediatePropagation(); };
  ['mousemove', 'touchmove', 'pointermove'].forEach(ev => {
    window.addEventListener(ev, block, true);
  });
})();

Change match to whatever site you wanna apply the fix to. Not sure if it works on any page but it worked on mine.

Conclusion?

The plugin didn’t need to be fixed BY YOU. That’d be a pain in the ass for you to understand! You just need to understand a little bit of javascript

This post is licensed under CC BY 4.0 by the author.

Trending Tags