-
Notifications
You must be signed in to change notification settings - Fork 1
feat(unskim): strip tracking params from extracted destination URL #421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| javascript:'use%20strict'%3B(()=%3E%7Blet%20e=new%20URL(document.location.href)%3Bif('safari-resource:%2FErrorPage.html'===e.href)%7Bconst%20t=document.querySelector('p.error-message')%3F.textContent%3F.match(%2FSafari%20can't%20open%20the%20page%20%22(https%3F:%5B%5E%22%5D%2B)%22%2F)%3F.%5B1%5D%3Bt%26%26(e=new%20URL(t))%7Dif(13%3Ee.search.length)return%3Bconst%20t=new%20URLSearchParams(e.search)%2Cr=%5B'url'%2C'destination'%2C'redirect'%2C'target'%2C'goto'%2C'u'%2C'dest'%2C'link'%2C'out'%5D.filter(e=%3Et.has(e)).map(e=%3E%7Bconst%20r=t.get(e)%3Breturn%20r%3FdecodeURIComponent(r):''%7D).find(e=%3Ee.match(%2F%5Ehttps%3F:%2F))%3Br%26%26window.location.replace(new%20URL(r))%7D)()%3Bvoid'2.0.2' | ||
| javascript:'use%20strict'%3B(()=%3E%7Blet%20e=new%20URL(document.location.href)%3Bif('safari-resource:%2FErrorPage.html'===e.href)%7Bconst%20t=document.querySelector('p.error-message')%3F.textContent%3F.match(%2FSafari%20can't%20open%20the%20page%20%22(https%3F:%5B%5E%22%5D%2B)%22%2F)%3F.%5B1%5D%3Bt%26%26(e=new%20URL(t))%7Dif(13%3Ee.search.length)return%3Bconst%20t=new%20URLSearchParams(e.search)%2Cr=%5B'url'%2C'destination'%2C'redirect'%2C'target'%2C'goto'%2C'u'%2C'dest'%2C'link'%2C'out'%5D.filter(e=%3Et.has(e)).map(e=%3E%7Bconst%20r=t.get(e)%3Breturn%20r%3FdecodeURIComponent(r):''%7D).find(e=%3Ee.match(%2F%5Ehttps%3F:%2F))%3Bif(r)%7Bconst%20e=new%20URL(r)%3Bif(e.searchParams.size%3E0)%7Bconst%20t=new%20URLSearchParams(e.search)%3Bfor(const%20e%20of%5B...t.keys()%5D)%7Bconst%20r=e.toLowerCase()%3B(r.startsWith('utm%5F')%7C%7Cr.startsWith('fb%5F')%7C%7C%5B'fbclid'%2C'gclid'%2C'msclkid'%2C'ref'%2C'referrer'%2C'ttclid'%2C'twclid'%5D.includes(r))%26%26t.delete(e)%7De.search=t.toString()%7Dwindow.location.replace(e)%7D%7D)()%3Bvoid'2.1.0' |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -35,9 +35,21 @@ | |||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||
| .find((url: string) => url.match(/^https?:/)); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| // navigate to new URL if found | ||||||||||||||||||||||||||||||||||||||||||||
| // navigate to new URL if found, after stripping common tracking params | ||||||||||||||||||||||||||||||||||||||||||||
| if (urlCandidate) { | ||||||||||||||||||||||||||||||||||||||||||||
| window.location.replace(new URL(urlCandidate)); | ||||||||||||||||||||||||||||||||||||||||||||
| const targetUrl: URL = new URL(urlCandidate); | ||||||||||||||||||||||||||||||||||||||||||||
| if (targetUrl.searchParams.size > 0) { | ||||||||||||||||||||||||||||||||||||||||||||
| const targetParams: URLSearchParams = new URLSearchParams(targetUrl.search); | ||||||||||||||||||||||||||||||||||||||||||||
| for (const key of [...targetParams.keys()]) { | ||||||||||||||||||||||||||||||||||||||||||||
| const k: string = key.toLowerCase(); | ||||||||||||||||||||||||||||||||||||||||||||
| if (k.startsWith('utm_') || k.startsWith('fb_') || | ||||||||||||||||||||||||||||||||||||||||||||
| ['fbclid', 'gclid', 'msclkid', 'ref', 'referrer', 'ttclid', 'twclid'].includes(k)) { | ||||||||||||||||||||||||||||||||||||||||||||
| targetParams.delete(key); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| targetUrl.search = targetParams.toString(); | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+42
to
+50
|
||||||||||||||||||||||||||||||||||||||||||||
| const targetParams: URLSearchParams = new URLSearchParams(targetUrl.search); | |
| for (const key of [...targetParams.keys()]) { | |
| const k: string = key.toLowerCase(); | |
| if (k.startsWith('utm_') || k.startsWith('fb_') || | |
| ['fbclid', 'gclid', 'msclkid', 'ref', 'referrer', 'ttclid', 'twclid'].includes(k)) { | |
| targetParams.delete(key); | |
| } | |
| } | |
| targetUrl.search = targetParams.toString(); | |
| let removedTrackingParam = false; | |
| for (const key of [...targetUrl.searchParams.keys()]) { | |
| const k: string = key.toLowerCase(); | |
| if (k.startsWith('utm_') || k.startsWith('fb_') || | |
| ['fbclid', 'gclid', 'msclkid', 'ref', 'referrer', 'ttclid', 'twclid'].includes(k)) { | |
| targetUrl.searchParams.delete(key); | |
| removedTrackingParam = true; | |
| } | |
| } | |
| if (!removedTrackingParam) { | |
| // Preserve the original query-string serialization when nothing was removed. | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bookmarklets.jsonbumps unskim to 2.1.0, but README.md still references unskim v2.0.2 (including the embedded bookmarklet/setup links). If the README is expected to reflect current bookmarklet versions/code, re-run the README generation step (e.g.,npm run build:readme/npm run deploy) and include the resulting README updates in this PR.