Link Untracker

Remove tracking elements from links

Tính đến 11-01-2018. Xem phiên bản mới nhất.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

Bạn sẽ cần cài đặt một tiện ích mở rộng như Tampermonkey hoặc Violentmonkey để cài đặt kịch bản này.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        Link Untracker
// @namespace   IzzySoft
// @description Remove tracking elements from links
// @license     CC BY-NC-SA
// @include     *
// @exclude     *phpmyadmin*
// @version     5
// @grant       unsafeWindow
// ==/UserScript==

/* badp: we strip parameters starting with that. Some are taken from NetURL, see
   https://github.com/Smile4ever/firefoxaddons/tree/master/Neat%20URL-webext
   fb_: Facebook; ga_: Google; hmb_: HumbleBundle(?); utm_: Urchin Tracker; wt_: Webtrekk; WT.: Webtrends
*/
var badp = ['fb_','ga_','hmb_','utm_',
            'ei@google.','gws_rd@google.','sei@google.','ved@google.',
            'pd_rd_r@amazon.','pd_rd_w@amazon.','pd_rd_wg@amazon.','psc@amazon.',' _encoding@amazon.',
            'wt_','WT.','yclid','referrer'
           ];
var anch = '';
var replace_semicolon = true; /* some sites use ";" to separate URL params;
                                 URLSearchParams can't deal with that and messes up.
                                 If those sites don't work with "&", either set this
                                 to "false" or add that site on the exclude list
                               */

function getRealLinkFromGoogleUrl(a) { /* adapted from https://github.com/Rob--W/dont-track-me-google at 2018-01-03 */
    if ((a.hostname === location.hostname || a.hostname === 'www.google.com') &&
        /^\/(local_)?url$/.test(a.pathname)) {
        // Google Maps / Dito (/local_url?q=<url>)
        // Mobile (/url?q=<url>)
        var url = /[?&](?:q|url)=((?:https?|ftp)[%:][^&]+)/.exec(a.search);
        if (url) {
            return decodeURIComponent(url[1]);
        }
        // Help pages, e.g. safe browsing (/url?...&q=%2Fsupport%2Fanswer...)
        url = /[?&](?:q|url)=((?:%2[Ff]|\/)[^&]+)/.exec(a.search);
        if (url) {
            return a.origin + decodeURIComponent(url[1]);
        }
    }
    return a.href;
}

for(var i = 0; i < document.links.length; i++) {
  var elem = document.links[i];
  if (elem.search == '') continue;
  if (replace_semicolon) var purl = new URLSearchParams(elem.search.replace(new RegExp(';','g'),'&'));
  else var purl = new URLSearchParams(elem.search);
  for (let b of badp) { purl.delete(b); }
  if (elem.href.indexOf('#') > 0) anch = '#' + elem.href.split('#')[1];
  else anch = '';
  elem.href = elem.href.split('?')[0] + '?' + purl.toString() + anch;
  elem.href = getRealLinkFromGoogleUrl(elem);
}