X to vxtwitter URL Copier with Hotkey

Copies URL and replaces x.com with vxtwitter.com when hotkey is pressed

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         X to vxtwitter URL Copier with Hotkey
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Copies URL and replaces x.com with vxtwitter.com when hotkey is pressed
// @author       rkk1995
// @match        https://x.com/*
// @grant        none
// @run-at       document-start
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to copy modified URL to clipboard
    async function copyModifiedURL() {
        // Parse the current URL
        let url = new URL(window.location.href);

        // Check if the host is x.com and replace it with vxtwitter.com
        if (url.host === 'x.com') {
            url.host = 'vxtwitter.com';
            let modifiedURL = url.href;

            await navigator.clipboard.writeText(modifiedURL);
        }
    }

    // Add a keydown event listener to the document
    document.addEventListener('keydown', (event) => {
        // Check if the hotkey (Ctrl+C) is pressed
        if (event.ctrlKey && event.code === 'KeyC') {
            copyModifiedURL();
        }
    });
})();