Twitter Media Puller

spits out potential media for single twitter posts.

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        Twitter Media Puller
// @namespace   https://greasyfork.org/en/users/306263-one-hit
// @description spits out potential media for single twitter posts.
// @include     https://twitter.com*/status/*
// @version     1.0.0
// ==/UserScript==

try {

    let twitterId = document.location.href.split('/').pop().split('?').shift();

    let twitterRegex = new RegExp(twitterId+'\.json$', 'i');

    (function(open) {
        XMLHttpRequest.prototype.open = function() {
            this.addEventListener("readystatechange", function() {
                if(this.readyState === 4){
                    if(this.responseURL.match(twitterRegex)){
                        let video_data = JSON.parse(this.responseText);
                        console.log(video_data);
                        if(video_data.track && video_data.track.playbackUrl){
                            console.log('source found');
                            console.log(video_data.track.playbackUrl);
                        }
                    }
                }
            }, false);
            open.apply(this, arguments);
        };
    })(XMLHttpRequest.prototype.open);

} catch (err) {
    alert(err.toString());
}