Skip to content

Instantly share code, notes, and snippets.

@gmammolo
Created December 13, 2024 14:27
Show Gist options
  • Save gmammolo/8528e393bc91c54717f21620b6979431 to your computer and use it in GitHub Desktop.
Save gmammolo/8528e393bc91c54717f21620b6979431 to your computer and use it in GitHub Desktop.
Custom Rule zhanghai/Untracker script: Instagram share reels untracker
/*
This script is a custom script for the Android app [Untracker](https://github.com/zhanghai/Untracker).
When sharing a reel from the Instagram app on Android, you get a link in the format `https://www.instagram.com/share/reel/...`.
This link contains a redirect to a direct link to the reel, but with a hidden tracker.
This script removes the tracker and returns the direct link to the reel.
*/
if ($.matches(url, 'www.instagram.com', '/share/reel/[^/]+/?')) {
let counter = 10;
while (counter > 0) {
response = $.fetch(url, { redirect: 'follow' });
for ([name, value] of response.headers) {
if (name.toLowerCase() === 'location') {
url = value;
continue;
}
}
if($.matches(url, 'www.instagram.com', '/reel/[^/]+/?')) {
break;
}
counter--;
}
url = url.replace(/\?.*$/, '');
return url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment