Twitch Clip Downloader

adds a download link to twitch clips

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Twitch Clip Downloader
// @namespace    cdl
// @version      0.2
// @description  adds a download link to twitch clips
// @author       cc114
// @match        http*://clips.twitch.tv/*
// @exclude      http*://clips.twitch.tv/create
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    var link;
    var fail = 0;
    function geturl() {
        console.log('[CDL] searching');
        link = document.querySelector(".video-ref > video").getAttribute("src");
        if (link == null || link == undefined || link == "") {
            console.log('[CDL] waiting');
            if (fail < 5) {
                fail++;
                setTimeout(geturl, 500);
            }
        } else {
            console.log('[CDL] found link: ' + link);
            var div = document.createElement ('div');
            div.innerHTML = '<a href="' + link + '">Download</a>';
            var button = document.querySelectorAll('[data-test-selector="clips-watch-full-button"]')[0];
            button.insertAdjacentElement("afterend",div)
        }
    }
    window.addEventListener('load', () => {
        geturl();
    });
})();