├── .gitignore ├── Makefile ├── manifest.yaml ├── manifest.json ├── test_urls.md ├── README.md └── background.js /.gitignore: -------------------------------------------------------------------------------- 1 | link_cleaner.zip 2 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: manifest.json background.js 2 | apack link_cleaner.zip *.js *.json 3 | 4 | manifest.json: manifest.yaml 5 | remarshal -if yaml -of json --indent-json $< > $@ 6 | 7 | -------------------------------------------------------------------------------- /manifest.yaml: -------------------------------------------------------------------------------- 1 | manifest_version: 2 2 | name: Link Cleaner 3 | author: Erwan Ameil 4 | homepage_url: https://github.com/idlewan/link_cleaner 5 | version: '1.5' 6 | 7 | description: > 8 | Clean URLs that are about to be visited: 9 | - removes utm_* parameters 10 | - on item pages of aliexpress and amazon, removes tracking parameters 11 | - skip redirect pages of facebook, steam and reddit (directly go to the url 12 | being redirected to, and never hit their outgoing redirect tracking) 13 | 14 | You can now visit and bookmark clean links instead of the long, 15 | tracking-enabled ones! 16 | 17 | background: 18 | scripts: 19 | - background.js 20 | 21 | permissions: 22 | - '' 23 | - webRequest 24 | - webRequestBlocking 25 | -------------------------------------------------------------------------------- /manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "author": "Erwan Ameil", 3 | "background": { 4 | "scripts": [ 5 | "background.js" 6 | ] 7 | }, 8 | "description": "Clean URLs that are about to be visited: - removes utm_* parameters - on item pages of aliexpress and amazon, removes tracking parameters - skip redirect pages of facebook, steam and reddit (directly go to the url being redirected to, and never hit their outgoing redirect tracking)\nYou can now visit and bookmark clean links instead of the long, tracking-enabled ones!\n", 9 | "homepage_url": "https://github.com/idlewan/link_cleaner", 10 | "manifest_version": 2, 11 | "name": "Link Cleaner", 12 | "permissions": [ 13 | "", 14 | "webRequest", 15 | "webRequestBlocking" 16 | ], 17 | "version": "1.5" 18 | } 19 | -------------------------------------------------------------------------------- /test_urls.md: -------------------------------------------------------------------------------- 1 | http://meyerweb.com/eric/thoughts/2017/03/07/welcome-to-the-grid/?utm_source=frontendfocus&utm_medium=email 2 | 3 | https://www.amazon.com/AmazonBasics-Type-C-USB-Male-Cable/dp/B01GGKYQ02/ref=sr_1_1?s=amazonbasics&srs=10112675011&ie=UTF8&qid=1489067885&sr=8-1&keywords=usb-c 4 | 5 | https://www.amazon.co.uk/Crazepony-UK-Camera-Vacuum-Plastic-Crazepony/dp/B06XPCXCSH?SubscriptionId=AKIAILSHYYTFIVPWUY6Q&tag=duckduckgo-ffab-uk-21&linkCode=xm2&camp=2025&creative=165953&creativeASIN=B06XPCXCSH 6 | 7 | https://l.facebook.com/l.php?u=https%3A%2F%2Fwww.fsf.org%2Fcampaigns%2F&h=ATP1kf98S0FxqErjoW8VmdSllIp4veuH2_m1jl69sEEeLzUXbkNXrVnzRMp65r5vf21LJGTgJwR2b66m97zYJoXx951n-pr4ruS1osMvT2c9ITsplpPU37RlSqJsSgba&s=1 8 | 9 | https://out.reddit.com/t3_5pq7qd?url=https%3A%2F%2Finternethealthreport.org%2Fv01%2F&token=AQAAZV6JWHBBnIcVjV1wvxVg5gKyCQQSdUhGIvuEUmdPZhxhm8kH&app_name=reddit.com 10 | 11 | https://steamcommunity.com/linkfilter/?url=https://getfedora.org/ 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Link Cleaner 2 | 3 | --- 4 | This repository is currently unmaintained at the moment. There's an active fork (Link Cleaner+) that's accepting pull requests here https://github.com/apiraino/link_cleaner/ if you have PRs or feedback on issues. 5 | --- 6 | 7 | Find and install this extension on the [Mozilla Add-ons website]( 8 | https://addons.mozilla.org/en-US/firefox/addon/link-cleaner/). 9 | 10 | Browser extension to clean URLs that are about to be visited: 11 | - removes utm_* parameters 12 | - on item pages of aliexpress and amazon, removes tracking parameters 13 | - skip redirect pages of facebook, steam and reddit (directly go to the url 14 | being redirected to, and never hit their outgoing redirect tracking) 15 | 16 | You can now visit and bookmark clean links instead of the long, 17 | tracking-enabled ones! 18 | 19 | # Examples: 20 | - utm_* removal: 21 | http://meyerweb.com/eric/thoughts/2017/03/07/welcome-to-the-grid/?utm_source=frontendfocus&utm_medium=email 22 | is changed to: 23 | http://meyerweb.com/eric/thoughts/2017/03/07/welcome-to-the-grid/ 24 | - amazon item url: 25 | https://www.amazon.com/AmazonBasics-Type-C-USB-Male-Cable/dp/B01GGKYQ02/ref=sr_1_1?s=amazonbasics&srs=10112675011&ie=UTF8&qid=1489067885&sr=8-1&keywords=usb-c 26 | is changed to: 27 | https://www.amazon.com/AmazonBasics-Type-C-USB-Male-Cable/dp/B01GGKYQ02/ 28 | - facebook redirect: 29 | https://l.facebook.com/l.php?u=https%3A%2F%2Fwww.fsf.org%2Fcampaigns%2F&h=ATP1kf98S0FxqErjoW8VmdSllIp4veuH2_m1jl69sEEeLzUXbkNXrVnzRMp65r5vf21LJGTgJwR2b66m97zYJoXx951n-pr4ruS1osMvT2c9ITsplpPU37RlSqJsSgba&s=1 30 | is changed to 31 | https://www.fsf.org/campaigns/ 32 | - reddit redirect: 33 | https://out.reddit.com/t3_5pq7qd?url=https%3A%2F%2Finternethealthreport.org%2Fv01%2F&token=AQAAZV6JWHBBnIcVjV1wvxVg5gKyCQQSdUhGIvuEUmdPZhxhm8kH&app_name=reddit.com 34 | is changed to: 35 | https://internethealthreport.org/v01/ 36 | - steam redirect 37 | https://steamcommunity.com/linkfilter/?url=https://getfedora.org/ 38 | is changed to: 39 | https://getfedora.org/ 40 | 41 | # Comparison to other add-ons 42 | Unlike other legacy add-ons like CleanLinks, Link Cleaner doesn't inject 43 | JavaScript into pages to change links. 44 | Instead, it listens to main url requests and changes them (if needed to remove 45 | redirects or tracking. 46 | 47 | That means it's doing less unneeded work and consumes less resources 48 | (memory and CPU). 49 | 50 | # License 51 | Released under the GPLv3 license 52 | -------------------------------------------------------------------------------- /background.js: -------------------------------------------------------------------------------- 1 | // Filter out utm_* query parameters 2 | function clean_utm(requestDetails) { 3 | var url = new URL(requestDetails.url) 4 | //console.log("cleanURL utm_*", url.href); 5 | 6 | if (url.search.length > 0) { 7 | var params = url.searchParams; 8 | var new_params = new URLSearchParams(params); 9 | var needs_redirect = false; 10 | for (let p of params.keys()) { 11 | if (p.startsWith("utm_")) { 12 | needs_redirect = true; 13 | new_params.delete(p); 14 | } 15 | } 16 | if (needs_redirect) { 17 | var new_url = new URL(url); 18 | new_url.search = new_params.toString(); 19 | /*console.info("Removing utm_* params from url: ", 20 | requestDetails.url, " and redirection to: ", 21 | new_url.href);*/ 22 | return { 23 | redirectUrl: new_url.href 24 | } 25 | } 26 | } 27 | 28 | 29 | return { 30 | } 31 | } 32 | 33 | browser.webRequest.onBeforeRequest.addListener( 34 | clean_utm, 35 | {urls: [""], 36 | types:["main_frame"]}, 37 | ["blocking"] 38 | ); 39 | 40 | 41 | function clean_amazon(requestDetails) { 42 | var url = requestDetails.url; 43 | let slash_d_index = url.indexOf("/d"); 44 | let slash_ref_index = url.indexOf("/ref=", slash_d_index + 2); 45 | if (slash_ref_index > 0 && url.length > slash_ref_index + 1) { 46 | var new_url = url.substring(0, slash_ref_index + 1); 47 | if (new_url != url) { // try to avoid infinite redirect loops that might arise 48 | //console.info("Redirecting from: ", url, " to:", new_url); 49 | return {redirectUrl: new_url}; 50 | } 51 | } else { 52 | url = new URL(url); 53 | if (url.search.length > 0) { 54 | url.search = ""; 55 | //console.info("Clean url to:", url.href); 56 | return {redirectUrl: url.href}; 57 | } 58 | } 59 | } 60 | 61 | browser.webRequest.onBeforeRequest.addListener( 62 | clean_amazon, 63 | {urls: [ 64 | "*://*.amazon.com/d/*", 65 | "*://*.amazon.ca/d/*", 66 | "*://*.amazon.co.jp/d/*", 67 | "*://*.amazon.co.uk/d/*", 68 | "*://*.amazon.cn/d/*", 69 | "*://*.amazon.de/d/*", 70 | "*://*.amazon.fr/d/*", 71 | "*://*.amazon.in/d/*", 72 | "*://*.amazon.it/d/*", 73 | "*://*.amazon.com.mx/d/*", 74 | "*://*.amazon.com.au/d/*", 75 | "*://*.amazon.com.br/d/*", 76 | 77 | "*://*.amazon.com/dp/*", 78 | "*://*.amazon.ca/dp/*", 79 | "*://*.amazon.co.jp/dp/*", 80 | "*://*.amazon.co.uk/dp/*", 81 | "*://*.amazon.cn/dp/*", 82 | "*://*.amazon.de/dp/*", 83 | "*://*.amazon.fr/dp/*", 84 | "*://*.amazon.in/dp/*", 85 | "*://*.amazon.it/dp/*", 86 | "*://*.amazon.com.mx/dp/*", 87 | "*://*.amazon.com.au/dp/*", 88 | "*://*.amazon.com.br/dp/*", 89 | 90 | "*://*.amazon.com/gp/aw/d/*", 91 | "*://*.amazon.ca/gp/aw/d/*", 92 | "*://*.amazon.co.jp/gp/aw/d/*", 93 | "*://*.amazon.co.uk/gp/aw/d/*", 94 | "*://*.amazon.cn/gp/aw/d/*", 95 | "*://*.amazon.de/gp/aw/d/*", 96 | "*://*.amazon.fr/gp/aw/d/*", 97 | "*://*.amazon.in/gp/aw/d/*", 98 | "*://*.amazon.it/gp/aw/d/*", 99 | "*://*.amazon.com.mx/gp/aw/d/*", 100 | "*://*.amazon.com.au/gp/aw/d/*", 101 | "*://*.amazon.com.br/gp/aw/d/*", 102 | 103 | 104 | "*://*.amazon.com/*/dp/*", 105 | "*://*.amazon.ca/*/dp/*", 106 | "*://*.amazon.co.jp/*/dp/*", 107 | "*://*.amazon.co.uk/*/dp/*", 108 | "*://*.amazon.cn/*/dp/*", 109 | "*://*.amazon.de/*/dp/*", 110 | "*://*.amazon.fr/*/dp/*", 111 | "*://*.amazon.in/*/dp/*", 112 | "*://*.amazon.it/*/dp/*", 113 | "*://*.amazon.com.mx/*/dp/*", 114 | "*://*.amazon.com.au/*/dp/*", 115 | "*://*.amazon.com.br/*/dp/*", 116 | 117 | "*://*.amazon.com/gp/product/*", 118 | "*://*.amazon.ca/gp/product/*", 119 | "*://*.amazon.co.jp/gp/product/*", 120 | "*://*.amazon.co.uk/gp/product/*", 121 | "*://*.amazon.cn/gp/product/*", 122 | "*://*.amazon.de/gp/product/*", 123 | "*://*.amazon.fr/gp/product/*", 124 | "*://*.amazon.in/gp/product/*", 125 | "*://*.amazon.it/gp/product/*", 126 | "*://*.amazon.com.mx/gp/product/*", 127 | "*://*.amazon.com.au/gp/product/*", 128 | "*://*.amazon.com.br/gp/product/*", 129 | ], types: ["main_frame"]}, 130 | ["blocking"] 131 | ); 132 | 133 | 134 | function remove_searchparams(requestDetails) { 135 | var url = new URL(requestDetails.url) 136 | if (url.search.length > 0) { 137 | url.search = ""; 138 | //console.info("Clean url to:", url.href); 139 | return {redirectUrl: url.href}; 140 | } 141 | } 142 | browser.webRequest.onBeforeRequest.addListener( 143 | remove_searchparams, 144 | { 145 | urls: [ 146 | "*://*.aliexpress.com/item/*.html*", 147 | "*://*.aliexpress.com/store/product/*.html*", 148 | ], types: ["main_frame"] 149 | }, ["blocking"] 150 | ); 151 | 152 | function build_redirect_to_query_param(query_param_name){ 153 | const redirect_to_get_param = function(requestDetails){ 154 | const search_params = new URLSearchParams(new URL(requestDetails.url).search); 155 | const real_url_from_param = search_params.get(query_param_name); 156 | if (real_url_from_param){ 157 | // console.log('Redirecting to ' + real_url_from_param); 158 | return {redirectUrl: real_url_from_param}; 159 | } 160 | } 161 | return redirect_to_get_param; 162 | } 163 | 164 | const urls_to_param_mappers = [ 165 | { 166 | urls: ["*://l.facebook.com/*"], 167 | param_name: 'u' 168 | }, 169 | { 170 | urls: ["*://out.reddit.com/*"] 171 | }, 172 | { 173 | urls: ["*://steamcommunity.com/linkfilter/*"] 174 | } 175 | ]; 176 | 177 | urls_to_param_mappers.forEach(function(listenerConfig) { 178 | const param_name = listenerConfig.param_name ? listenerConfig.param_name : 'url'; 179 | // console.log('Mapping ' + listenerConfig.urls + ' to param name ' + param_name); 180 | browser.webRequest.onBeforeRequest.addListener( 181 | build_redirect_to_query_param(param_name), { 182 | urls: listenerConfig.urls, 183 | types: ["main_frame"] 184 | }, ["blocking"] 185 | ); 186 | }); 187 | --------------------------------------------------------------------------------