Books download

Added download button for audio book

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

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