Rule34 Smash or Pass

Adds smash and pass buttons to rule34

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

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