right click + scroll up/down == left/right

useful for any site with galleries, hold right click and scroll to cycle images

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

// ==UserScript==
// @name        right click + scroll up/down == left/right
// @match       https://twitter.com/*
// @version     0.1
// @author      f-carraro
// @description useful for any site with galleries, hold right click and scroll to cycle images
// @namespace https://greasyfork.org/users/699847
// ==/UserScript==

var hold = false;
var didsomething = false;

window.addEventListener("mousedown", ({button}) => {
    if (button === 2) { // right click
        hold = true;
    }
});

window.addEventListener("mouseup", ({button}) => {
    if (button === 2) {
        hold = false;
    }
});

window.addEventListener("wheel", e=>{
    if (hold){
        e.preventDefault;
        if (e.deltaY < 0){
            sendKey(37); 
        } else {
            sendKey(39);  
        }
        didsomething = true;
    }
});

window.addEventListener('contextmenu', e=>{
    if (didsomething){
        e.preventDefault();
    }
    didsomething=false;
});

function sendKey(code){
    const ke = new KeyboardEvent("keydown", {bubbles: true, cancelable: true, keyCode: code});
    document.dispatchEvent(ke);
}