i've been using copyq scripts and redirector to get rid of tracking parameters in instagram and twitter urls especially from the coli but I decided to go to get to the root of the problem as best as I could and try to modify the urls directly in the embeds. I used a LLM to create a userscript that removes everything after "?" in the urls. it isn't site specific but you can replace
update: added reddit.com and tiktok.com
not making it site specific right now to see if it breaks anything websurfing,
AI generated explanation
claude-3-haiku
Bookmarklet:
- The bookmarklet is a small piece of JavaScript code that you can save as a bookmark in your web browser.
- When you click on the bookmarklet, it will automatically find all the links on the current web page that start with "https://twitter.com/" or "Instagram".
- For each of those links, the bookmarklet will remove the part of the link that contains the tracking parameters (the stuff after the "?" in the URL).
- This allows you to copy the clean, tracking-free links from the page.
Userscript:
- The userscript is a small program that runs automatically in your web browser whenever you visit a web page.
- The userscript is designed to work with browser extensions like Tampermonkey or Greasemonkey, which allow you to install and run custom scripts.
- When the userscript runs, it will automatically find all the links on the page that start with "https://twitter.com/" or "Instagram".
- For each of those links, the userscript will remove the part of the link that contains the tracking parameters.
- The userscript will also continue to monitor the page for any changes, and will automatically remove the tracking parameters from any new links that are added to the page.
In both cases, the goal is to make it easier for you to copy and share the links from embedded tweets and Instagram posts without the extra tracking information that the social media platforms sometimes add to the URLs.
update #3:
since I left it to work on any site, i realized the old code broke reddit search url parameter so made updated the userscript to have an exclude option that ignores "/search/" in the url when it match's the domain.
Changelog:
**Version 0.1 (Initial Code):**
- The initial code provided removes tracking parameters from links in embedded tweets, Instagram posts, Reddit, and TikTok.
- The script runs on page load and also observes the DOM for AJAX content updates, running the cleanup function whenever new content is added.
**Version 0.8 (Final Code):**
- Added a list of included domains (e.g., twitter.com, instagram.com, reddit.com, tiktok.com) to specify which links should be cleaned.
- Added a list of URL patterns to exclude from being cleaned, using regular expressions.
- Improved the exclusion logic to check if the domain is included and the URL doesn't match any of the excluded patterns.
- Added comments to explain how to add new exclusion patterns using regular expressions.
Layman's Summary:
This userscript is designed to clean up links in various social media and content platforms, such as Twitter, Instagram, Reddit, and TikTok. It removes any tracking parameters (e.g., `?utm_source=...`) from the links, making them more readable and less cluttered.
The script runs automatically when the page loads and also monitors the page for any AJAX-based content updates, cleaning up the links as new content is added.
The script is highly customizable, allowing you to specify which domains should be included (e.g., twitter.com, reddit.com) and which URL patterns should be excluded from the cleaning process (e.g., URLs containing "/search/?q="). This makes it easy to tailor the script to your specific needs and preferences.
Overall, this userscript helps to improve the user experience by removing unnecessary tracking parameters from links, making them more clean and readable.
// @match *://*/*
with // @match https://www.thecoli.com/*
if you only want it to work on this site. you can easily modify the script to also work on urls other than twitter or instagram too.
Code:
// ==UserScript==
// @name Remove Tracking Parameters from Twitter and Instagram Links
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Removes tracking parameters from links in embedded tweets and Instagram posts
// @author Your Name
// @match *://*/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
function cleanLinks() {
var links = document.querySelectorAll('a[href^="https://twitter.com/"], a[href^="https://instagram.com/"]');
for (var i = 0; i < links.length; i++) {
var link = links[i];
var url = new URL(link.href);
url.search = '';
link.href = url.toString();
}
}
// Run the script on page load
window.addEventListener('load', cleanLinks);
// Run the script on AJAX content updates
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.type === 'childList') {
cleanLinks();
}
});
});
observer.observe(document.body, { childList: true, subtree: true });
})();
not making it site specific right now to see if it breaks anything websurfing,
Code:
// ==UserScript==
// @name Remove Tracking Parameters from Tweets, Instagram Posts, Reddit, and TikTok Links
// @namespace http://tampermonkey.net/
// @version 0.3
// @description Removes tracking parameters from links in embedded tweets, Instagram posts, Reddit, and TikTok
// @author Your Name
// @match *://*/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
function cleanLinks() {
var links = document.querySelectorAll('a[href^="https://twitter.com/"], a[href^="https://instagram.com/"], a[href^="https://www.instagram.com/"], a[href^="https://www.reddit.com/"], a[href^="https://www.tiktok.com/"]');
for (var i = 0; i < links.length; i++) {
var link = links[i];
var url = new URL(link.href);
url.search = '';
link.href = url.toString();
}
}
// Run the script on page load
window.addEventListener('load', cleanLinks);
// Run the script on AJAX content updates
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.type === 'childList') {
cleanLinks();
}
});
});
observer.observe(document.body, { childList: true, subtree: true });
})();
AI generated explanation
claude-3-haiku
Bookmarklet:
- The bookmarklet is a small piece of JavaScript code that you can save as a bookmark in your web browser.
- When you click on the bookmarklet, it will automatically find all the links on the current web page that start with "https://twitter.com/" or "Instagram".
- For each of those links, the bookmarklet will remove the part of the link that contains the tracking parameters (the stuff after the "?" in the URL).
- This allows you to copy the clean, tracking-free links from the page.
Userscript:
- The userscript is a small program that runs automatically in your web browser whenever you visit a web page.
- The userscript is designed to work with browser extensions like Tampermonkey or Greasemonkey, which allow you to install and run custom scripts.
- When the userscript runs, it will automatically find all the links on the page that start with "https://twitter.com/" or "Instagram".
- For each of those links, the userscript will remove the part of the link that contains the tracking parameters.
- The userscript will also continue to monitor the page for any changes, and will automatically remove the tracking parameters from any new links that are added to the page.
In both cases, the goal is to make it easier for you to copy and share the links from embedded tweets and Instagram posts without the extra tracking information that the social media platforms sometimes add to the URLs.
update #3:
since I left it to work on any site, i realized the old code broke reddit search url parameter so made updated the userscript to have an exclude option that ignores "/search/" in the url when it match's the domain.
Code:
// ==UserScript==
// @name Remove Tracking Parameters from Tweets, Instagram Posts, Reddit, and TikTok Links
// @namespace http://tampermonkey.net/
// @version 0.8
// @description Removes tracking parameters from links in embedded tweets, Instagram posts, Reddit, and TikTok
// @author Your Name
// @match *://*/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// List of domains to include
const includedDomains = [
'twitter.com',
'instagram.com',
'www.instagram.com',
'reddit.com',
'www.reddit.com',
'tiktok.com',
'www.tiktok.com'
];
// List of URL patterns to exclude
// To add a new exclusion pattern, use a regular expression
// Example: /\/search\/\?q=/ will exclude URLs containing "/search/?q="
// Example: /\/some-other-pattern/ will exclude URLs containing "/some-other-pattern"
const excludedPatterns = [
/\/search\/\?q=/,
/cdninstagram.com/,
/\/search\?/,
/\?limit=/,
/out.reddit.com/,
/\/some-other-pattern/
];
function cleanLinks() {
var links = document.querySelectorAll('a[href]');
for (var i = 0; i < links.length; i++) {
var link = links[i];
var url = new URL(link.href);
// Check if the domain is included and the URL doesn't match any excluded patterns
if (includedDomains.some(domain => url.hostname.endsWith(domain)) && !excludedPatterns.some(pattern => pattern.test(url.href))) {
url.search = '';
link.href = url.toString();
}
}
}
// Run the script on page load
window.addEventListener('load', cleanLinks);
// Run the script on AJAX content updates
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.type === 'childList') {
cleanLinks();
}
});
});
observer.observe(document.body, { childList: true, subtree: true });
})();
Changelog:
**Version 0.1 (Initial Code):**
- The initial code provided removes tracking parameters from links in embedded tweets, Instagram posts, Reddit, and TikTok.
- The script runs on page load and also observes the DOM for AJAX content updates, running the cleanup function whenever new content is added.
**Version 0.8 (Final Code):**
- Added a list of included domains (e.g., twitter.com, instagram.com, reddit.com, tiktok.com) to specify which links should be cleaned.
- Added a list of URL patterns to exclude from being cleaned, using regular expressions.
- Improved the exclusion logic to check if the domain is included and the URL doesn't match any of the excluded patterns.
- Added comments to explain how to add new exclusion patterns using regular expressions.
Layman's Summary:
This userscript is designed to clean up links in various social media and content platforms, such as Twitter, Instagram, Reddit, and TikTok. It removes any tracking parameters (e.g., `?utm_source=...`) from the links, making them more readable and less cluttered.
The script runs automatically when the page loads and also monitors the page for any AJAX-based content updates, cleaning up the links as new content is added.
The script is highly customizable, allowing you to specify which domains should be included (e.g., twitter.com, reddit.com) and which URL patterns should be excluded from the cleaning process (e.g., URLs containing "/search/?q="). This makes it easy to tailor the script to your specific needs and preferences.
Overall, this userscript helps to improve the user experience by removing unnecessary tracking parameters from links, making them more clean and readable.
Last edited: