eto.ia.samgmail.com / Vimeo Download

// ==UserScript==
// @name         Vimeo Download
// @namespace    http://tampermonkey.net/
// @version      0.12
// @license MIT
// @description  Add Vimeo download button
// @author       Bagdaulet
// @include      *//vimeo.com/*
// @include      *//player.vimeo.com/video/*
// @run-at       document-end
// @grant        none
// ==/UserScript==

const downloadIcon = '<img src="data:image/svg+xml;utf8;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pgo8IS0tIEdlbmVyYXRvcjogQWRvYmUgSWxsdXN0cmF0b3IgMTYuMC4wLCBTVkcgRXhwb3J0IFBsdWctSW4gLiBTVkcgVmVyc2lvbjogNi4wMCBCdWlsZCAwKSAgLS0+CjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+CjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiBpZD0iQ2FwYV8xIiB4PSIwcHgiIHk9IjBweCIgd2lkdGg9IjE2cHgiIGhlaWdodD0iMTZweCIgdmlld0JveD0iMCAwIDQ3NS4wNzggNDc1LjA3NyIgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDAgNDc1LjA3OCA0NzUuMDc3OyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+CjxnPgoJPGc+CgkJPHBhdGggZD0iTTQ2Ny4wODMsMzE4LjYyN2MtNS4zMjQtNS4zMjgtMTEuOC03Ljk5NC0xOS40MS03Ljk5NEgzMTUuMTk1bC0zOC44MjgsMzguODI3Yy0xMS4wNCwxMC42NTctMjMuOTgyLDE1Ljk4OC0zOC44MjgsMTUuOTg4ICAgIGMtMTQuODQzLDAt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go8L2c+CjxnPgo8L2c+CjxnPgo8L2c+Cjwvc3ZnPgo=" />';

function parse() {
    const regex = /(?:(?:\"width\"\:1280).+\"(https:\/\/vod-progressive\.akamaized\.net.+\.mp4)\".+\"quality\":\"720p\")/ig;
    const regexFallback = /(?:(?:\"width\"\:960).+\"(https:\/\/vod-progressive\.akamaized\.net.+\.mp4)\".+\"quality\":\"540p\")/ig;
    const body = document.body.innerHTML;

    let partsRaw = body.matchAll(regex);

    let parts = [...partsRaw];

    if (parts.length === 0) {
        partsRaw = body.matchAll(regexFallback);
        parts = [...partsRaw];
    }

    if (parts.length) {
        const url = parts[0][1];
        if (url) {
            return url;
        }
    }
    return null;
}

function createButton(link) {
    var button = document.createElement( 'button' );
    button.setAttribute( 'class', "button download" );
    button.setAttribute( 'type', "button" );
    button.setAttribute( 'aria-label', "Download" );
    button.setAttribute( 'style', 'display: inline-block; font-size: 1.75em; margin: -0.10em 0 0 0.5em; color: #fff' );

    const a = document.createElement('a');
    a.setAttribute('href', link);
    a.setAttribute('download', 'true');
    a.innerHTML = downloadIcon;

    button.appendChild( a );

    document.querySelector('#player .vp-controls .play-bar').appendChild(button);
}

(function() {
    'use strict';

    window.addEventListener('load', function() {
        const link = parse();

        if(link) {
            createButton(link);
        }
    })

})();