risu download

download risu.io file

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         risu download
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  download risu.io file
// @author       Charles
// @match        https://risu.io/*
// @icon         https://www.google.com/s2/favicons?domain=risu.io
// @run-at       document-start
// @grant        GM_download
// ==/UserScript==

(function () {
    'use strict';
    // Your code here...
    document.onreadystatechange = function () {
        if (document.readyState === "complete") {
            // Do something
            let button_bar = document.getElementsByClassName('input-group-append')[0];
            let submit_button = button_bar.getElementsByClassName('btn')[0];
            let download_button = submit_button.cloneNode(true);
            download_button.type = "button";
            download_button.textContent = "Download";
            download_button.style.marginLeft = '5px';
            button_bar.appendChild(download_button);
            let metas = document.getElementsByTagName("meta");
            let token;
            for (let i = 0; i < metas.length; i++) {
                if (metas[i].getAttribute('name') === 'csrf-token') {
                    let content = metas[i].getAttribute("content");
                    token = content;
                    break;
                }
            }
            download_button.onclick = async function () {
                let header = new Headers({
                    "Content-Type": "application/json;charset=utf-8",
                    "X-CSRF-Token": token,
                    "Accept": "application/json, text/plain, */*",
                });
                let send_obj = {password: document.getElementsByClassName("page-password")[0].value};
                console.log("send obj : " + send_obj);
                let result_json = await fetch(window.location.href + "/confirm.json", {
                    method: 'POST',
                    body: JSON.stringify(send_obj),
                    credentials: "same-origin",
                    headers: header,
                }).then(response => response.json()).then(response => response).catch(error => alert("error "));
                if (result_json.lock === false) {
                    alert("password error");
                }
                for (let i = 0; i < result_json.file_infos.length; i++) {
                    let content = result_json.file_infos[i];
                    let file_name = content.filename;
                    const url = content.file_path;
                    GM_download(url, file_name);
                }

            };
        }
    }
})();