Larvata / twitter full size image

// ==UserScript==
// @name         twitter full size image
// @namespace    https://github.com/larvata
// @version      0.4
// @description  always get the hi-res image from twitter
// @author       Larvata
// @match        https://pbs.twimg.com/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';
    if(location.href.includes('=orig')) return;

    if (location.href.endsWith('.jpg')) {
        location.href = location.href.split('.jpg')[0] + '?format=jpg&name=orig';
        return;
    }

    const ret = location.href.replace( /([^\/]*\?format=\S+&name=)(\S+)$/, (a,b) => b+'orig');
    if (ret !== location.href) {
       location.href = ret;
    }
})();