Reddit Remove Spy Linking

Remove Spy Linking on Reddit.com

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name        Reddit Remove Spy Linking
// @namespace   http://reddit.co.uk
// @description Remove Spy Linking on Reddit.com
// @include     https://*.reddit.com/*
// @include     https://reddit.com/*
// @include     http://reddit.com/*
// @include     http://*.reddit.com/*
// @version     1.0.1
// @grant       none
// ==/UserScript==

var a = document.getElementsByTagName("a");
for (var x=1; x<a.length; x++) {
  a[x].removeAttribute("data-outbound-url");
  a[x].removeAttribute("data-href-url");
  a[x].removeAttribute("data-outbound-expiration");
  a[x].removeAttribute("data-event-action");
  a[x].removeAttribute("rel");
  if (a[x].className.indexOf("comments")!=-1) {
    var nid = a[x].parentNode.parentNode.parentNode.parentNode.parentNode.getAttribute("data-fullname").split("_")[1];
    var sbr = a[x].parentNode.parentNode.parentNode.parentNode.parentNode.getAttribute("data-subreddit");
    var tid = a[x].parentNode.parentNode.parentNode.getElementsByTagName("p")[0].getElementsByTagName("a")[0].textContent.toLowerCase();
    tid = tid.replace(/\s+/g, "_");
    tid = tid.replace(/[^a-zA-z0-9]/g, "");
    tid = tid.replace(/__/g, "_");
    if (tid.length > 50) {
      tid=tid.substr(0,50);
      while (tid.length>=1 && tid.charAt(tid.length-1)!="_") {
        tid = tid.substr(0, tid.length-1)
      }
     tid = tid.substr(0, tid.length-1)
    }
    newstr = "https://www.reddit.com/" + "r/"+ sbr + "/comments/" + nid + "/" + tid;
    a[x].setAttribute("href", newstr);
  }
  a[x].removeAttribute("data-inbound-url");
}