Making a GreaseMonkey script to redirect...

RemadERemadE Global Moderator
edited July 2012 in Tech & Games
Ok so here in the UK (and other places), The Pirate Bay's official site has been blocked and so can be accessed through, for arguments sake, a mirror, for example. One of the dozens of mirrors.

So when I am on Google, looking for a torrent, I was wondering if, when I click on a link which is the official site (and would thus be blocked here in the UK) I could get it to divert through the mirror instead, and end up at the same page?

I know GreaseMonkey is Java-based, but I was looking for tutorials or code to redirect, and it all seems to be "Oh I'm not saying because it could be used for malicious reasons" or "edit your hosts.txt file" (which the former is clearly not in my case and the latter I don't fancy doing).

So any tips? And Java coders out there? Or anyone know of any good GreaseMonkey (or GreaseMonkey-specific Java) code sites out there? This could be a big hitter for the UK if it could be made. Plus I'm sure I'm looking at it way too deeply, making things a lot more complex - as I usually do.

Comments

  • SlartibartfastSlartibartfast Global Moderator -__-
    edited July 2012
    greasemoney is JavaScript, completely different from java. search userscripts.org for examples and solutions.
  • RemadERemadE Global Moderator
    edited July 2012
    greasemoney is JavaScript, completely different from java. search userscripts.org for examples and solutions.

    Ah cheers - I can't believe I still make rookie errors like that. When I was younger and getting into Visual basic, I saw VB and VB.Net then thought they were the same.
    Oh how wrong I was.
    Will check out userscripts as I am pretty familiar with that site, especially with my current C++ projects. Fankoo :)
  • thomasthomas Semo-Regulars
    edited July 2012
    How did you do?
  • RemadERemadE Global Moderator
    edited July 2012
    I was about halfway through researching (it's been a busy few days) but am still determined to do it. Right now I'm designing a frontpage for a friends' website but will get back on this as soon as I can. C++ is where I am focused mostly but I shall try my hardest at getting a working script :)
  • thomasthomas Semo-Regulars
    edited July 2012
    Don't need to re-invent the wheel :D Found exactly what you needed.
    // ==UserScript==
    
    // @name           TPB URL Redirector
    
    // @namespace      http://userscripts.org/users/437040 *NOTE: Changed from original for Google Redirection
    
    // @description    Redirects The Pirate Bay's .org and .se domain to a proxy.
    
    // @include        *thepiratebay*
    // @include        *google*
    
    // @version        0.1.4
    
    // ==/UserScript==
    
    
    
    var proxySite = 'tpb.pirateparty.org.uk';
    
    
    
    //------------------------------------------
    
    
    
    function get_anchors(){
    
           var anchors = new Array();
    
           var elms = document.getElementsByTagName('a');
    
           for(var i=0; i<elms.length; i++){
    
                if(elms[i].href) anchors.push(elms[i]);
    
           }
    
           return anchors;
    
        }
    
    
    
    var allLinks, thisLink;
    
    allLinks = get_anchors();
    
    
    
    for (var i = 0; i < allLinks.length; i++) {
    
        thisLink = allLinks[i];
    
    	
    
        if (thisLink.href.match('www.thepiratebay.org')) {
    
    		thisLink.href = thisLink.href.replace('www.thepiratebay.org', proxySite);
    
    	}
    
    	
    
    	else if (thisLink.href.match('thepiratebay.org')) {
    
    		thisLink.href = thisLink.href.replace('thepiratebay.org', proxySite);
    
    	}
    
    	
    
    	else if (thisLink.href.match('www.thepiratebay.se')) {
    
    		thisLink.href = thisLink.href.replace('www.thepiratebay.se', proxySite);
    
    	}
    
    	
    
    	else if (thisLink.href.match('thepiratebay.se')) {
    
    		thisLink.href = thisLink.href.replace('thepiratebay.se', proxySite);
    
    	}
    
    }
    
    
    ]
  • bornkillerbornkiller Administrator In your girlfriends snatch
    edited July 2012
    thomas wrote: »
    Don't need to re-invent the wheel :D Found exactly what you needed.
    If it works for GM it'll work for Midori.

    Saved for future reference if it ever happens in my corner of the world.

    5char brah! :thumbsup:
  • RemadERemadE Global Moderator
    edited July 2012
    Lol, and there was me looking up Javascript until late at night listening to ambient music, tearing my hair out.

    Thanks a bunch for the script :D will take it apart and learn from it :thumbsup:
  • Darth BeaverDarth Beaver Meine Ehre heißt Treue
    edited July 2012
  • RemadERemadE Global Moderator
    edited July 2012
    I know, I know - It's just finding the proxies and all available Google servers which confused me when trying to code my own one. That said the one you posted there, Beaver, does seem a great template. I think I'll be dedicating my nights of usual programming and learning chemistry with checking out basic Javascript and userscripts :thumbsup:
  • Darth BeaverDarth Beaver Meine Ehre heißt Treue
    edited July 2012
    You know when I take over the world all you brilliant young lads here will have really good jobs doing things you're not permitted to now, right?
Sign In or Register to comment.