Vkontakte.ru safe url

Заменяет некоторые "зловредные" ссылки на прямые.

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

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

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.

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

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           Vkontakte.ru safe url
// @namespace      lmrvsk
// @description    Заменяет некоторые "зловредные" ссылки на прямые.
// @include        http://vkontakte.ru/*
// @include        http://vk.com/*
// @version 0.0.1.20140602145320
// ==/UserScript==

var fixlinks = [
  "//a[contains(@href, '/away.php?')][contains(@href, 'tumblr.com')]",
  "//a[contains(@href, '/away.php?')][contains(@href, 'blogspot.com')]",
  "//a[contains(@href, '/away.php?')][contains(@href, '.tomsk.ru')]",
  "//a[contains(@href, '/away.php?')][contains(@href, 'rapidshare.com')]",
  "//a[contains(@href, '/away.php?')][contains(@href, 'rapidshare.de')]",
  "//a[contains(@href, '/away.php?')][contains(@href, 'depositfiles.com')]",
  "//a[contains(@href, '/away.php?')][contains(@href, 'megashare.com')]",
  "//a[contains(@href, '/away.php?')][contains(@href, 'hotfile.com')]",
  "//a[contains(@href, '/away.php?')][contains(@href, 'vip-file.com')]",
  "//a[contains(@href, '/away.php?')][contains(@href, 'fileserve.com')]",
  "//a[contains(@href, '/away.php?')][contains(@href, 'filesonic.com')]",
  "//a[contains(@href, '/away.php?')][contains(@href, 'letitbit.net')]",
  "//a[contains(@href, '/away.php?')][contains(@href, 'bitshare.com')]",
  "//a[contains(@href, '/away.php?')][contains(@href, 'turbobit.net')]",
];

function $x(p, c) {
    if (!c) c = document;
    var i, arr = [], xpr = document.evaluate(p, c, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
    for (i = 0; item = xpr.snapshotItem(i); i++) arr.push(item);
    return arr;
}

fixlinks.forEach(
    function(xpath) {
        $x(xpath).forEach(
            function(item) {
            	var awurl = /(.+)\&h=(.+)/;
				item.href = item.href.replace(awurl, '$1');
				awurl = /http:\/\/(.+)\/away\.php\?to=(.+)/;
				item.href = decodeURIComponent(item.href.replace(awurl, '$2'));
            }
        )
    }
)