Books download

Added download button for audio book

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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         Books download
// @namespace    http://tampermonkey.net/
// @version      2024-05-28
// @description  Added download button for audio book
// @author       Dead4W
// @match        https://knigavuhe.info/*
// @license      MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const downloadButton = document.createElement("a");
    downloadButton.innerText = "Download mp3"
    downloadButton.style = "color: black;cursor: pointer; margin: 3px; display: block";

    function init() {
        const videoElem = document.querySelector("#player video");

        if (!videoElem) {
            setTimeout(init, 100);
            return;
        }

        downloadButton.onclick = () => {downloadUrl(videoElem.src)};
        document.querySelector("#oframeplayer").appendChild(downloadButton);
    }

    function downloadUrl(url) {
        const options = {
            headers: {
                Referer: location.origin,
            }
        };

        downloadButton.style = "color: black;cursor: progress; margin: 3px; display: block";

        fetch(url, options)
            .then( res => res.blob() )
            .then( blob => {
                var file = window.URL.createObjectURL(blob);
                window.open(file, '_blank');
                downloadButton.style = "color: black;cursor: pointer; margin: 3px; display: block";
            });
    }

    $(document).ready(function() {
        init();
    });
})();