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

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

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

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