|
// ==UserScript== |
|
// @name YouTube Share Link Cleaner |
|
// @namespace http://tampermonkey.net/ |
|
// @version 0.0.1 |
|
// @description Cleaner YouTube share links to remove tracking parameters |
|
// @author ChatGPT |
|
// @match https://www.youtube.com/* |
|
// @grant none |
|
// ==/UserScript== |
|
|
|
(function() { |
|
'use strict'; |
|
|
|
// Function to extract video ID and time from the URL |
|
function extractVideoInfo(url) { |
|
const videoIdMatch = url.match(/\/([a-zA-Z0-9_-]{11})/); |
|
const timeMatch = url.match(/&t=(\d+)/); |
|
const videoId = videoIdMatch ? videoIdMatch[1] : ''; |
|
const time = timeMatch ? '&t=' + timeMatch[1] : ''; |
|
return videoId + time; |
|
} |
|
|
|
// Override the copy-to-clipboard function |
|
function overrideCopyFunction() { |
|
const copyButton = document.getElementById('copy-button'); |
|
const originalCopyFunction = copyButton.onclick; |
|
|
|
copyButton.onclick = function() { |
|
const shareUrlInput = document.getElementById('share-url'); |
|
const originalUrl = shareUrlInput.value; |
|
|
|
// Extract video information and modify the URL |
|
const modifiedUrl = 'https://youtu.be/' + extractVideoInfo(originalUrl); |
|
|
|
// Copy the modified URL to the clipboard |
|
navigator.clipboard.writeText(modifiedUrl) |
|
.then(() => { |
|
console.log('Modified URL copied to clipboard:', modifiedUrl); |
|
}) |
|
.catch(error => { |
|
console.error('Error copying modified URL:', error); |
|
}); |
|
|
|
// Call the original copy function |
|
if (originalCopyFunction) { |
|
originalCopyFunction.apply(this, arguments); |
|
} |
|
}; |
|
} |
|
|
|
// Wait for the share button to be present and override the copy function |
|
function waitForShareButton() { |
|
const shareButton = document.getElementById('copy-button'); |
|
if (shareButton) { |
|
overrideCopyFunction(); |
|
} else { |
|
setTimeout(waitForShareButton, 500); |
|
} |
|
} |
|
|
|
// Initial setup |
|
waitForShareButton(); |
|
})(); |