Greasy Fork is available in English.

flibusta.is качать с названием в клипборде

2/11/2023, 9:38:17 PM

// ==UserScript==
// @name        flibusta.is качать с названием в клипборде
// @namespace   Violentmonkey Scripts
// @match       http://flibusta.is/a/*
// @grant       GM_setClipboard
// @version     1.0
// @author      -
// @description 2/11/2023, 9:38:17 PM
// ==/UserScript==

let extMap = {
    'fb2': '.fb2.zip',
    'epub': '.epub',
    'mobi': '.mobi',
    'download': ''
};

let author = document.querySelector('h1.title').innerText;

let books = {};

Array.from(document.querySelectorAll('a[href]')).forEach(a => {
    let href = a.getAttribute("href");
    let match = href.match(/^\/b\/(\d+)$/);

    if (match) {
        books[match[1]] = a.innerText.trim();
        return;
    }

    match = href.match(/^\/b\/(\d+)\/(fb2|epub|mobi|download)$/);

    if (match) {
        let id = match[1];
        let type = match[2];
        
        if (books[id]) {
            let title = books[id];

            let filename = author + ". " + title + extMap[type];

            a.addEventListener('click', () => GM_setClipboard(filename));
        }
    }
});