Amazon Tag Remove (All)

Elimina la variable tag de los vínculos hacia Amazon

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name           Amazon Tag Remove (All)
// @namespace      Tag remove for links of Amazon
// @description    Elimina la variable tag de los vínculos hacia Amazon
// @include        *
// @author         WeSo
// @version        20160310
// @run-at         document-end

// ==/UserScript==


// Amazon sites
var sites = Array(
      "amazon.com",
      "amazon.es",
      "amazon.co.uk",
      "amazon.de",
      "amazon.it",
      "amazon.fr",
      "amazon.ca",
      "amazon.cn",
      "amazon.co.jp",
      "goo.gl"
    );

function delTag (text) {
  var tmp = unescape(text);
  tmp = tmp.replace(/&/gi,"&");

  // &...&
  var pattern = "&tag=[a-zA-Z0-9.-]*-[0-9]{1,2}&";
  var exp = new RegExp(pattern, "g");
  tmp = tmp.replace(exp,"&");

  // &...
  pattern = "&tag=[a-zA-Z0-9.-]*-[0-9]{1,2}";
  exp = new RegExp(pattern, "g");
  tmp = tmp.replace(exp,"");

  // ?...&
  pattern = "\\?tag=[a-zA-Z0-9.-]*-[0-9]{1,2}&";
  exp = new RegExp(pattern, "g");
  tmp = tmp.replace(exp,"?");

  // ?...
  pattern = "\\?tag=[a-zA-Z0-9.-]*-[0-9]{1,2}";
  exp = new RegExp(pattern, "g");
  tmp = tmp.replace(exp,"");


  return tmp;
}

function clearText (text,site) {
  var tmp = unescape(text);
  tmp = tmp.replace(/&/gi,"&");
  var result;

  // Filtro 1
  var pattern = "http(s?)://[w]{0,3}.?"+site+"/(.*)/dp/B([A-Z0-9]{9})/?.*";
  var exp = new RegExp(pattern, "gi");
  if (result = exp.exec(tmp))
    tmp = "http"+result[1]+"://www."+site+"/dp/B"+result[3]+"/"+result[2]+"/";

  // Filtro 2
  pattern = "http(s?)://[w]{0,3}.?"+site+"/(.*)/dp/([A-Z0-9]{9,10})/?.*";
  exp = new RegExp(pattern, "gi");
  if (result = exp.exec(tmp))
    tmp = "http"+result[1]+"://www."+site+"/dp/B"+result[3]+"/"+result[2]+"/";

  // Filtro 3
  pattern = "http(s?)://[w]{0,3}.?"+site+"/gp/product/([A-Z0-9]{9,10}).*";
  exp = new RegExp(pattern, "gi");
  if (result = exp.exec(tmp))
    tmp = "http"+result[1]+"://www."+site+"/gp/product/"+result[2]+"/";

  // Filtro 5 (link.php)
  pattern = "http(s?)://[w]{0,3}.?.*?/link\.php\?url\=(.*)";
  exp = new RegExp(pattern, "gi");
  if (result = exp.exec(tmp))
    tmp = result[2];

  // Filtro 6 (limpiar por delante)
  pattern = ".*http(s?)://[w]{0,3}.?"+site+"/(.*)";
  exp = new RegExp(pattern, "gi");
  if (result = exp.exec(tmp))
    tmp = "http"+result[1]+"://www."+site+"/"+result[2];

  return tmp;
}

for (var n = 0; n < sites.length; n++) {
    var links = document.evaluate("//a[contains(@href, '"+sites[n]+"')]", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
    for (var i = 0; i < links.snapshotLength; i++)
    {
        var link = links.snapshotItem(i);
        link.href = clearText(decodeURIComponent(link.href),sites[n]);
        link.href = delTag(link.href);
    }
}