Reddit Link Hijack Remover

Remove viglink & outbound tracking redirects from reddit

当前为 2016-07-09 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name           Reddit Link Hijack Remover
// @author	       jmesmon
// @description    Remove viglink & outbound tracking redirects from reddit
// @include        *://reddit.com/*
// @include        *://*.reddit.com/*
// @grant          none
// @version 0.0.1.20160709181519
// @namespace https://greasyfork.org/users/49902
// ==/UserScript==
(function () {
  'use strict';
  function cl(ac) {
    var a = ac.querySelectorAll('a[data-href-url]');
    var ct_out = 0,
    ct_aff = 0,
    ct = 0;
    for (var i = 0; i < a.length; i++) {
      var url = a[i].getAttribute('data-href-url');
      if (url) {
        if (a[i].getAttribute('data-affiliate-url')) {
          a[i].setAttribute('data-affiliate-url', url);
          ct_aff++;
        }
        if (a[i].getAttribute('data-outbound-url')) {
          a[i].setAttribute('data-outbound-url', url);
          ct_out++;
        }
        ct++;
      }
    }
    console.log('>>>');
    console.log('Outbound redirects removed: ' + ct_out);
    console.log('Affiliate redirects removed: ' + ct_aff);
    console.log('Total redirects removed: ' + ct);
    console.log('<<<');
  }
  
  var tbls = document.querySelector('#siteTable');
  var obs = new MutationObserver(function (r, self) {
    for (var i = 0; i < r.length; i++) {
      var ad = r[i].addedNodes;
      for (var j = 0; j < ad.length; j++) {
        var n = ad[j];
        cl(n);
      }
    }
  });
  obs.observe(tbls, {
    childList: true
  });
  
  cl(document);
}) ();