Rule34 Image Opener

Opens images in a new background tab when middle-clicked on rule34.xxx

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         Rule34 Image Opener
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Opens images in a new background tab when middle-clicked on rule34.xxx
// @author       MathaNoshto
// @match        https://rule34.xxx/*
// @grant        GM_openInTab
// ==/UserScript==

(function() {
    'use strict';

    // Function to handle middle mouse click on images
    function handleImageMiddleClick(event) {
        // Check if it's a middle mouse button click (button 1)
        if (event.button !== 1) return;

        const image = event.target;

        // Check if the clicked element is an image
        if (image.tagName === 'IMG') {
            // Prevent default middle-click behavior
            event.preventDefault();

            // Get the highest resolution image URL
            let imageUrl = '';

            // If it's a thumbnail, try to get the full image URL
            if (image.parentElement && image.parentElement.tagName === 'A') {
                imageUrl = image.parentElement.href;
            } else {
                // If it's already a full image, use its source
                imageUrl = image.src;
            }

            // Open the image in a new background tab using GM_openInTab
            if (imageUrl) {
                GM_openInTab(imageUrl, {
                    active: false,      // This ensures the tab opens in the background
                    insert: true,       // This opens the tab next to the current one
                    setParent: true     // This sets the current tab as the parent
                });
            }
        }
    }

    // Add mousedown event listener to the document
    document.addEventListener('mousedown', handleImageMiddleClick);

    // Log that the script is loaded
    console.log('Rule34 Image Opener script loaded!');
})();