From 077f3d91d36fac605c31aa07e26b30b60d20fd1c Mon Sep 17 00:00:00 2001 From: marsn3 Date: Sun, 24 Dec 2023 17:04:30 +0000 Subject: [PATCH] Add src/vxtwitter.user.js --- src/vxtwitter.user.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/vxtwitter.user.js diff --git a/src/vxtwitter.user.js b/src/vxtwitter.user.js new file mode 100644 index 0000000..06b5f96 --- /dev/null +++ b/src/vxtwitter.user.js @@ -0,0 +1,28 @@ +// ==UserScript== +// @name Convert Twitter/X to FXTwitter +// @namespace http://tampermonkey.net/ +// @version 0.1 +// @description Convert copied twitter.com and x.com links to vxtwitter.com +// @author You +// @match *://twitter.com/* +// @match *://x.com/* +// @grant none +// ==/UserScript== + +(function() { + 'use strict'; + + document.addEventListener('copy', function(e) { + let text = window.getSelection().toString(); + const regex = /https?:\/\/(twitter\.com|x\.com)\/[a-zA-Z0-9_\-\/]+/g; + + if (regex.test(text)) { + text = text.replace(regex, function(match) { + return match.replace(/(twitter\.com|x\.com)/, 'vxtwitter.com'); + }); + text = text.split('?') + e.clipboardData.setData('text/plain', text[0]); + e.preventDefault(); + } + }); +})(); \ No newline at end of file