EHentai Torrent Rename

Remove "{EHT PERSONALIZED TORRENT - DO NOT REDISTRIBUTE}" prefix for EHentai torrent downloading.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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         EHentai Torrent Rename
// @namespace    https://github.com/Cirn09
// @version      0.2
// @description  Remove "{EHT PERSONALIZED TORRENT - DO NOT REDISTRIBUTE}" prefix for EHentai torrent downloading.
// @author       Cirn09
// @match        https://exhentai.org/gallerytorrents.php*
// @match        https://e-hentai.org/gallerytorrents.php*
// @icon         https://e-hentai.org/favicon.ico
// @grant        none
// @license      GPLv3
// ==/UserScript==

(function () {
    'use strict';
    const start = "document.location='";
    const end = "'; return false";

    let downloadLinks = document.querySelectorAll('a');
    for (let a of downloadLinks) {
        if ('onclick' in a.attributes) {
            let onclick = a.attributes['onclick'].nodeValue;
            if (!onclick.startsWith(start)) { return; }
            a.href = onclick.slice(start.length, onclick.indexOf(end));
            a.attributes.removeNamedItem('onclick');
            a.onclick = (function (event) {
                let url = this.href;
                let filename = a.innerText.trim() + '.torrent';

                fetch(url)
                    .then(function (response) {
                        if (response.ok) {
                            return response.blob();
                        }
                        throw new Error('Network response was not ok.');
                    })
                    .then(function (blob) {
                        var downloadLink = document.createElement('a');
                        downloadLink.href = URL.createObjectURL(blob);
                        downloadLink.download = filename;
                        document.body.appendChild(downloadLink);
                        downloadLink.click();
                        document.body.removeChild(downloadLink);
                    })
                    .catch(function (error) {
                        console.log('Error:', error);
                    });

                return false;

            });
        }
    }
})();