X to vxtwitter URL Copier with Hotkey

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

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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();
        }
    });
})();