twitter-image-new-tab-redirect-original

2023.08.17.13

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name        twitter-image-new-tab-redirect-original
// @description 2023.08.17.13
// @namespace   https://danor.app/
// @version     2.2.0
// @author      DanoR
// @grant       none
// @run-at      document-start
// @match       *://pbs.twimg.com/media/*
// ==/UserScript==



(async () => {
	if(/name=/.test(location.href) && !/name=orig/.test(location.href)) {
		let href = location.href.replace(/name=\w+/, 'name=orig');

		if(/format=webp/.test(location.href)) {
			for(const format of ['webp', 'png', 'jpg', 'bmp', 'gif']) {
				const { status } = await fetch(
					href.replace(/format=\w+/, `format=${format}`),
					{ method: 'HEAD' },
				);

				if(status == 200) {
					href = href.replace(/format=\w+/, `format=${format}`);

					break;
				}
			}
		}

		location.href = href;
	}
})();