twitter-image-new-tab-redirect-original

2023.08.17.13

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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;
	}
})();