Greasy Fork

Greasy Fork is available in English.

Twitter Original Image Link

Simple script that replace an image link with an original image URL if you click links on Tweet for navigating the image on new tab or copying the URL.

当前为 2022-07-18 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Twitter Original Image Link
// @name:ja     Twitter 原寸画像リンク
// @description Simple script that replace an image link with an original image URL if you click links on Tweet for navigating the image on new tab or copying the URL.
// @description:ja ツイート上の画像をクリックしたとき (新しいタブで開く・URLのコピー) に、画像のリンクを原寸画像のURLに置換する軽量スクリプトです。
// @namespace   http://greasyfork.icu/users/137
// @version     2.0.0
// @match       https://twitter.com/*
// @exclude     https://twitter.com/settings*
// @exclude     https://twitter.com/tos*
// @exclude     https://twitter.com/privacy*
// @exclude     https://twitter.com/jobs*
// @exclude     https://twitter.com/account/*
// @exclude     https://twitter.com/intent/*
// @exclude     https://twitter.com/i/cards/*
// @match       https://tweetdeck.twitter.com/*
// @license     MPL-2.0
// @contributionURL https://www.amazon.co.jp/registry/wishlist/E7PJ5C3K7AM2
// @compatible  Edge
// @compatible  Firefox Firefoxを推奨 / Firefox is recommended
// @compatible  Opera
// @compatible  Chrome
// @grant       dummy
// @run-at      document-start
// @icon        https://abs.twimg.com/favicons/twitter.ico
// @author      100の人
// @homepageURL http://greasyfork.icu/users/137
// ==/UserScript==

'use strict';

const tweetDeck = location.origin === 'https://tweetdeck.twitter.com';

function replaceImageLink(event)
{
	/** @type {HTMLElement} */
	const target = event.target;

	const localName = target.localName;
	if (tweetDeck ? localName !== 'a' || event.target.rel !== 'mediaPreview' : localName !== 'img') {
		return;
	}

	/** @type {HTMLAnchorElement} */
	const anchor = tweetDeck
		? target
		: event.target.closest('[href$="/photo/1"], [href$="/photo/2"], [href$="/photo/3"], [href$="/photo/4"]');
	if (!tweetDeck && (!anchor || !anchor.matches('article *'))) {
		return;
	}

	const url = new URL(tweetDeck ? /https:\/\/[^"]+/.exec(target.style.backgroundImage)[0] : event.target.src);
	url.searchParams.set('name', 'orig');
	anchor.href = url;
}

addEventListener('click', replaceImageLink, true);
addEventListener('auxclick', replaceImageLink, true);