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

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

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

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

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

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

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

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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);
}