Direct Links to Twitter Media Embeds

Generates a small link directly to the source of Twitter media embeds (Youtube, Twitch clips, etc.)

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         Direct Links to Twitter Media Embeds
// @namespace    http://bifrost.me
// @version      1.0
// @description  Generates a small link directly to the source of Twitter media embeds (Youtube, Twitch clips, etc.)
// @match        https://twitter.com/*
// @grant        none
// @require		 https://code.jquery.com/jquery-1.12.4.min.js
// ==/UserScript==

var documentHeight = '';

// Monitor the height of the window to detect when new tweets have been dynamically loaded
function heightWatcher() {
    if (documentHeight != document.body.scrollHeight) {
        addLinks();
    }
    documentHeight = document.body.scrollHeight;
    setTimeout(function(){heightWatcher();}, 3000);
};

function addLinks() {
    $('div.card-type-player').each(function() {
        if ($(this).attr('link-added')) {
            return;
        }
        const src = $(this).attr('data-card-url');
        $(this).before('<a href=\"' + src + '\">→</a>');
        $(this).attr('link-added', true)
    });
};

(function() {
    'use strict';

    heightWatcher();
})();