twitter-image-new-tab-redirect-original

2023.08.17.13

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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;
	}
})();