Add src/vxtwitter.user.js

This commit is contained in:
marsn3 2023-12-24 17:04:30 +00:00
parent 95b11e1b0d
commit 077f3d91d3

28
src/vxtwitter.user.js Normal file
View file

@ -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();
}
});
})();