Greasy Fork

来自缓存

Greasy Fork is available in English.

复制网址自动打开新标签页

复制内容中包含网址时自动在新标签打开该网址

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         复制网址自动打开新标签页
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  复制内容中包含网址时自动在新标签打开该网址
// @source        https://github.com/Phinsin666/Copying-a-URL-automatically-opens-a-new-tab
// @author       Phinsin666T
// @match        *://*/*
// @grant        none
// ==/UserScript==


(function () {
    'use strict';

    let lastClipboardText = '';

    document.addEventListener('keydown', async (e) => {
        if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'c') {
            // 延迟一点读取剪贴板
            setTimeout(async () => {
                try {
                    const text = await navigator.clipboard.readText();
                    if (!text || text === lastClipboardText) return;

                    lastClipboardText = text;

                    const urlRegex = /(https?:\/\/[^\s]+)/g;
                    const matches = text.match(urlRegex);
                    if (matches && matches.length > 0) {
                        const url = matches[0];
                        window.open(url, '_blank');
                    }
                } catch (err) {
                    console.warn('无法读取剪贴板内容:', err);
                }
            }, 100);
        }
    });
})();