Rule34 Smash or Pass

Adds smash and pass buttons to rule34

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @author	    Fiotux
// @namespace   https://greasyfork.org/en/users/1446209
// @license GNU General Public License v3.0
// @name         Rule34 Smash or Pass
// @version      1.2
// @description  Adds smash and pass buttons to rule34
// @match        https://rule34.xxx/index.php?page=post&s=view&id=*
// ==/UserScript==

(function() {
    'use strict';
    const img = document.querySelector('#image');
    const nextLink = document.querySelector('#next_search_link');

    function smash() {
        fetch(img.src)
            .then(response => response.blob())
            .then(blob => {
                const url = URL.createObjectURL(blob);
                const link = document.createElement('a');
                link.href = url;
                const fileName = img.src.split('/').pop();
                link.download = fileName;
                document.body.appendChild(link);
                link.click();
                document.body.removeChild(link);
                URL.revokeObjectURL(url);
         			 location.href = nextLink.href;
            });
      
    }

    function pass() {
        location.href = nextLink.href;
    }

    if (img && nextLink) {
        const container = document.createElement('div');
        container.style.margin = '1em';

        const smashBtn = document.createElement('button');
        smashBtn.textContent = 'Smash';
        smashBtn.onclick = smash;
        container.appendChild(smashBtn);

        const passBtn = document.createElement('button');
        passBtn.textContent = 'Pass';
        passBtn.onclick = pass;
        container.appendChild(passBtn);

        document.addEventListener('keydown', (event) => {
            if (event.key === '.') smash();
            else if (event.key === '/') pass();
        });

        document.getElementById('image').insertAdjacentElement('afterend', container);
    }
})();