evan-king / drag-scroll

Fork of the Grab n' Drag legacy extension for Firefox/Palemoon
0 stars 0 forks source link

Right-click menus not always suppressed #2

Open evan-king opened 7 years ago

evan-king commented 7 years ago

Occurring in Pale Moon Version: 27.4.1 (64-bit) on Windows 10. Appears to only occur on drag clicks that begin and end outside content areas (away from text/images) but not limited to any discernable high-level DOM scopes.

evan-king commented 6 years ago

This greasemonkey script provides a passable workaround, as work on drag-scroll is unlikely to begin any time soon.

// ==UserScript==
// @name        DragCompanion
// @namespace   Honoredsoft
// @description Cover for Grab 'n Drag's failure to suppress context menu
// @version     1
// @grant       none
// ==/UserScript==

const RCLICK = 2, MAX_DELTA = 9;

let x = 0, y = 0, delta = 0;

document.addEventListener('mousedown', function(event) {
    if(event.button !== RCLICK) return;
    x = event.screenX;
    y = event.screenY;
}, false);

document.addEventListener('contextmenu', function(event) {
    delta = Math.abs(x - event.screenX) + Math.abs(y - event.screenY);
    if(delta > MAX_DELTA) event.preventDefault();
}, true);

Drag operations that end very near their start will still pop up the menu, but this happens so rarely in practice I deem it better not to add a mousemove listener to address it.