commit 4d385d0d8bacee8b15645e23e2e5fa285e11fae8 Author: chase Date: Mon Aug 25 15:18:35 2025 -0400 Initial commit diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..34591c9 --- /dev/null +++ b/flake.nix @@ -0,0 +1,18 @@ +{ + description = "yt-share-cleaner - remove tracking from YouTube share URLs"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + }; + + outputs = { self, nixpkgs }: let + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + in { + devShells.${system}.default = pkgs.mkShell { + nativeBuildInputs = with pkgs; [ + web-ext + ]; + }; + }; +} diff --git a/icons/yt-share-cleaner-128.png b/icons/yt-share-cleaner-128.png new file mode 100644 index 0000000..d637c4e Binary files /dev/null and b/icons/yt-share-cleaner-128.png differ diff --git a/icons/yt-share-cleaner-16.png b/icons/yt-share-cleaner-16.png new file mode 100644 index 0000000..f7cd1fd Binary files /dev/null and b/icons/yt-share-cleaner-16.png differ diff --git a/icons/yt-share-cleaner-256.png b/icons/yt-share-cleaner-256.png new file mode 100644 index 0000000..76fd119 Binary files /dev/null and b/icons/yt-share-cleaner-256.png differ diff --git a/icons/yt-share-cleaner-32.png b/icons/yt-share-cleaner-32.png new file mode 100644 index 0000000..c2f7409 Binary files /dev/null and b/icons/yt-share-cleaner-32.png differ diff --git a/icons/yt-share-cleaner-64.png b/icons/yt-share-cleaner-64.png new file mode 100644 index 0000000..7ace763 Binary files /dev/null and b/icons/yt-share-cleaner-64.png differ diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..b4feebd --- /dev/null +++ b/manifest.json @@ -0,0 +1,28 @@ +{ + "manifest_version": 3, + "name": "yt-share-cleaner", + "version": "0.0.1", + + "description": "Cleans tracking from share URLs on YouTube", + + "icons": { + "16": "icons/yt-share-cleaner-16.png", + "32": "icons/yt-share-cleaner-32.png", + "64": "icons/yt-share-cleaner-64.png", + "128": "icons/yt-share-cleaner-128.png", + "256": "icons/yt-share-cleaner-256.png" + }, + + "permissions": [ + "activeTab", + "clipboardRead", + "clipboardWrite" + ], + + "content_scripts": [ + { + "js": ["yt-share-cleaner.js"], + "matches": ["*://*.youtube.com/*"] + } + ] +} diff --git a/yt-share-cleaner.js b/yt-share-cleaner.js new file mode 100644 index 0000000..23a4105 --- /dev/null +++ b/yt-share-cleaner.js @@ -0,0 +1,44 @@ +(function() { + // 'use strict'; + function isShareLink(url) { + // test if input is a share link, return True or False + const regex = /https:\/\/youtu\.be\/[A-Za-z0-9\_-]+\?si=.+/i; + const isShareLink = regex.test(url); + return(isShareLink) + } + + function cleanUrl(url){ + // clean tracker from URL if it is a share link + if (isShareLink(url)) { + // replace tracker portion with empty string + const cleanedUrl = url.replace(/\?si=[^&]+&?/, ""); + return(cleanedUrl) + } + // return original url if it is not a share link + console.log("Not a share link, clipboard contents unmodified.") + return(url) + } + + function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + + async function onMouseUp() { + // wait half a second after clicking before reading clipboard + await sleep(500); + + let clipText = await navigator.clipboard.readText(); + let newText = cleanUrl(clipText); + + if (clipText !== newText) { + const newClip = await navigator.clipboard.writeText(newText); + console.log("Modified clipboard with cleaned share link: %o", newText); + clipText = undefined; + newText = undefined; + } + clipText = undefined; + newText = undefined; + } + + document.addEventListener('mouseup', onMouseUp, false); +})();