Rule34 Image Opener

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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