Created
December 21, 2024 11:48
-
-
Save Steve-Mr/225223060230a2dcd6a0e57efeb97325 to your computer and use it in GitHub Desktop.
Replace 'twitter' to 'fxtwitter' when sharing links. Modified version of https://greasyfork.org/zh-CN/scripts/482406-twitter-to-vxtwitter.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Twitter to fxtwitter | |
| // @namespace http://tampermonkey.net/ | |
| // @version 2.0 | |
| // @description Replace `twitter` to `fxtwitter` when sharing links | |
| // @author Maary | |
| // @match https://twitter.com/* | |
| // @match https://mobile.twitter.com/* | |
| // @match https://tweetdeck.twitter.com/* | |
| // @match https://x.com/* | |
| // @match https://*.x.com/* | |
| // @icon https://www.google.com/s2/favicons?sz=64&domain=twitter.com | |
| // @grant none | |
| // @license MIT | |
| // ==/UserScript== | |
| (function() { | |
| 'use strict'; | |
| const convertUrl = (url) => { | |
| const regex = /^(https?:\/\/)?((?:www\.)?x\.com\/)([\w-]+\/status\/\d+)(\?.*)?$/; | |
| return url.replace(regex, 'https://fxtwitter.com/$3'); | |
| }; | |
| const copyTextToClipboard = async (text) => { | |
| try { | |
| await navigator.clipboard.writeText(text); | |
| console.log('URL converted and copied successfully:', text); | |
| } catch (err) { | |
| console.error('Failed to copy text: ', err); | |
| } | |
| }; | |
| document.addEventListener('copy', function(e) { | |
| const selectedText = window.getSelection().toString().trim(); | |
| if (selectedText.includes('x.com')) { | |
| e.preventDefault(); | |
| const convertedUrl = convertUrl(selectedText); | |
| copyTextToClipboard(convertedUrl); | |
| } | |
| }, true); | |
| })(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment