Twitter Middle Clicks

This script makes it possible to open a quoted tweet, a trend, a link in tweet input form, or an input complement into a new tab by middle click.

目前为 2019-11-26 提交的版本。查看 最新版本

// ==UserScript==
// @name        Twitter Middle Clicks
// @name:ja     Twitter 中クリック
// @description This script makes it possible to open a quoted tweet, a trend, a link in tweet input form, or an input complement into a new tab by middle click.
// @description:ja 引用されたツイート、トレンド、ツイート入力欄のリンク、入力補完を中クリックして新規タブで開けるようにします。
// @namespace   https://gf.qytechs.cn/users/137
// @version     1.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/*
// @license     MPL-2.0
// @contributionURL https://www.amazon.co.jp/registry/wishlist/E7PJ5C3K7AM2
// @compatible  Edge 最新安定版 / Latest stable (非推奨 / Deprecated)
// @compatible  Firefox
// @compatible  Opera
// @compatible  Chrome
// @grant       dummy
// @run-at      document-start
// @icon        data:image/svg+xml;charset=utf8,<svg id="Logo_FIXED" data-name="Logo %E2%80%94 FIXED" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 400"><defs><style>.cls-1{fill:none;}.cls-2{fill:%231da1f2;}</style></defs><title>Twitter_Logo_Blue</title><rect class="cls-1" width="400" height="400"/><path class="cls-2" d="M153.62,301.59c94.34,0,145.94-78.16,145.94-145.94,0-2.22,0-4.43-.15-6.63A104.36,104.36,0,0,0,325,122.47a102.38,102.38,0,0,1-29.46,8.07,51.47,51.47,0,0,0,22.55-28.37,102.79,102.79,0,0,1-32.57,12.45,51.34,51.34,0,0,0-87.41,46.78A145.62,145.62,0,0,1,92.4,107.81a51.33,51.33,0,0,0,15.88,68.47A50.91,50.91,0,0,1,85,169.86c0,.21,0,.43,0,.65a51.31,51.31,0,0,0,41.15,50.28,51.21,51.21,0,0,1-23.16.88,51.35,51.35,0,0,0,47.92,35.62,102.92,102.92,0,0,1-63.7,22A104.41,104.41,0,0,1,75,278.55a145.21,145.21,0,0,0,78.62,23"/></svg>
// @author      100の人
// @homepageURL https://gf.qytechs.cn/users/137
// ==/UserScript==

'use strict';

addEventListener('auxclick', function (event) {
	if (event.button !== 1 || event.detail !== 1 || event.target.closest('a')) {
		// 中クリックでない、ダブルクリック、またはリンクのクリックなら
		return;
	}
	
	if (event.target.dataset.text) {
		if (event.target.parentElement.parentElement.style.color !== 'rgb(27, 149, 224)') {
			return true;
		}

		// ツイート入力欄のリンク
		let url;
		const content = event.target.textContent;
		if (content.startsWith('@')) {
			url = '/' + content.replace('@', '');
		} else if (content.startsWith('#')) {
			// ハッシュタグ
			url = '/hashtag/' + encodeURIComponent(content.replace('#', ''));
		} else if (content.startsWith('$')) {
			// キャッシュタグ
			url = '/search?q=' + encodeURIComponent(content);
		} else {
			try {
				new URL(content);
			} catch (exception) {
				if (exception.name !== 'TypeError') {
					throw exception;
				}
				// ドメイン
				url = 'http://' + content;
			}

			if (!url) {
				// URL
				url = content;
			}
		}
		open(url);
		return;
	}
	
	const option = event.target.closest('[role="option"]');
	if (option) {
		// ツイート入力欄、または検索窓の入力補完
		let url;
		if (option.firstElementChild.dataset.testid === 'TypeaheadUser') {
			// ユーザー
			url = '/' + option.querySelector('[aria-haspopup] + div').textContent.replace('@', '');
		} else {
			const content = event.target.textContent;
			url = content.startsWith('#')
				? '/hashtag/' + encodeURIComponent(content.replace('#', '')) // ハッシュタグ
				: '/search?q=' + encodeURIComponent(content); // Twitterの検索窓では空白が「+」ではなく「%20」に置き換わる
		}
		open(url);
		return;
	}
	
	// Ctrl + 主クリック
	const init = {};
	for (const key in event) {
		init[key] = event[key];
	}
	init.button = 0;
	init.ctrlKey = true;
	if (!event.target.dispatchEvent(new MouseEvent('click', init))) {
		event.preventDefault();
		event.stopImmediatePropagation();
	}
}, true);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址