uso-mirror

redirects userscripts.org to userscripts-mirror.org

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 or Violentmonkey 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.

(У мене вже є менеджер скриптів, дайте мені встановити його!)

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        uso-mirror
// @namespace   trespassersW
// @description redirects userscripts.org to userscripts-mirror.org
// @include *
// @exclude http*://www.google.com/reader/*
// @version 1.1.11
// @created 2014-06-07
// @updated 2014-06-08
// @run-at document-start
// @grant GM_none
// ==/UserScript==

(function () { "use strict";
var W =  window;
function _log(s){
 //console.log(s);
}
function toObj(s) {
 var r = {}, c = s.split('&'), t;
 for(var i = 0; i < c.length; i++) {
 t = c[i].split('=');
 r[decodeURIComponent(t[0])] = decodeURIComponent(t[1]);
 }
 return r;
}
function anchorMatch(a) {
  for(var k=0; a && k< 5; k++,a=a.parentNode) if(a.localName == 'a') return a;
  return null;
}
var re= /^(http)s?\:\/\/(.*?)\buserscripts\.org(\:8080)?\/(.*)/;
function onDown(e) {
  var h,m, a = anchorMatch(e.target);
  if(a && a.localName == "a"){
    h=a.getAttribute("href");
    if(location.host.indexOf("google")>-1){
      m=a.getAttribute("onmousedown");
      if(m && m.indexOf("return") === 0) { //
        a.removeAttribute("onmousedown");
      }
      if(h) {
         if(h.indexOf("http://") === 0) h = h.substr(h.indexOf("/", 7));
         else if(h.indexOf("https://") === 0) h = h.substr(h.indexOf("/", 8));
         if(h.indexOf("/url?") === 0) {
           _log('spoil '+h);
           h = toObj(h.substr(5));
           a.setAttribute('href', decodeURIComponent(h.url || h.q));
         }
      }   
    }
  
    h=a.getAttribute("href");
    if(!( h && (h=h.match(re)) && h.length==5 )) return;
       h = h[1]+"://userscripts-mirror.org/"+h[4];
       a.setAttribute('href', h);
      _log('USOmirror: '+a.href);
  }
}
 W.addEventListener("mousedown", onDown, true);
 _log('uso-mirror');
})();