]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blob - app/src/main/java/com/stoutner/privacybrowser/helpers/SanitizeUrlHelper.kt
Update the file name when the URL changes in SaveDialog. https://redmine.stoutner...
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / helpers / SanitizeUrlHelper.kt
1 /*
2  * Copyright 2022 Soren Stoutner <soren@stoutner.com>.
3  *
4  * This file is part of Privacy Browser Android <https://www.stoutner.com/privacy-browser-android>.
5  *
6  * Privacy Browser Android is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Privacy Browser Android is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Privacy Browser Android.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 package com.stoutner.privacybrowser.helpers
21
22 private val trackingQueriesList = listOf(
23     "__hsfp=",             // HubSpot.
24     "__hssc=",             // HubSpot.
25     "__hstc=",             // HubSpot.
26     "__s=",                // Drip.com.
27     "_hsenc=",             // HubSpot.
28     "_openstat=",          // Yandex.
29     "dclid=",              // DoubleClick ID.
30     "fbadid=",             // FaceBook Ad ID.
31     "fbclid=",             // FaceBook Click ID.
32     "gclid=",              // Google Click ID.
33     "hsCtaTracking=",      // HubSpot.
34     "igshid=",             // Instagram.
35     "mc_eid=",             // MailChimp Email ID.
36     "?mkt_tok=",           // Adobe Marketo.
37     "ml_subscriber=",      // MailerLite.
38     "ml_subscriber_hash=", // MailerLite.
39     "msclkid=",            // Microsoft Click ID.
40     "oly_anon_id=",        // Omeda Anonymous ID.
41     "oly_enc_id=",         // Omeda ID.
42     "rb_clickid=",         // Unknown tracker.
43     "s_cid=",              // Adobe Site Catalyst.
44     "utm_",                // Google Analytics.
45     "vero_conv=",          // Vero.
46     "vero_id=",            // Vero ID.
47     "wickedid=",           // Wicked Reports ID.
48     "yclid="               // Yandex Click ID.
49 )
50
51 object SanitizeUrlHelper {
52     @JvmStatic
53     fun sanitizeTrackingQueries(inputUrl: String): String {
54         // Make a copy of the input URL so that it can be modified.
55         var url = inputUrl
56
57         // Remove each tracking query from the URL.
58         trackingQueriesList.forEach {
59             if (url.contains("?$it")) {  // Check for an initial query
60                 // Remove the first query and anything after it.
61                 url = url.substring(0, url.indexOf("?$it"))
62             }
63             else if (url.contains("&$it")) {  // Check for a subsequent query.
64                 // Remove the query and anything after it.
65                 url = url.substring(0, url.indexOf("&$it"))
66             }
67         }
68
69         // Return the sanitized URL.
70         return url
71     }
72
73     @JvmStatic
74     fun sanitizeAmpRedirects(inputUrl: String): String {
75         // Make a copy of the input URL so that it can be modified.
76         var url = inputUrl
77
78         // Remove Twitter `amp=1`.
79         if (url.contains("?amp"))
80             url = url.substring(0, url.indexOf("?amp"))
81         else if (url.contains("&amp"))
82             url = url.substring(0, url.indexOf("&amp"))
83
84         // Return the sanitized URL.
85         return url
86     }
87 }