Automatically add link protector to server links

Asked

Viewed 630 times

1

Ola would like to know how I can use Javascript or PHP to put this url http://anunciad.com.br?AuID=16958&Aurl= before the addresses of the download servers I automatically use these servers Skydrive, Clouddrive, Pcloud, Bitcasa, Meocloud, Lolabits, Google, Clouddriver I wore the Adfly it has a Javascript script that automatically adds the address at the beginning of these Urls to the address of the protector. With all this new protector do not have this kind of scripts.

2 answers

4


With Javascript native as follows:

var links = document.getElementsByTagName("a");

for (i = 0; i < links.length; i++) {
    var link = links[i];
    var urlProtegida = "http://anunciad.com.br?AuID=16958&Aurl=" + link.href;

    link.href = urlProtegida;
}

Or with jQuery:

$("a").each(function() {
    var urlProtegida = "http://anunciad.com.br?AuID=16958&Aurl=" + $(this).attr("href");

    $(this).attr("href", urlProtegida);
});

With jQuery it is still possible make a filter to change only the links whose URL contains the domain of any of the mentioned servers in your question.

// Lista de bases de URLs dos servidores.
var urlsBases = ["meocloud.pt", "mega.co.nz", "outro.servidor.com"];

for (var i = 0; i < urlsBases.length; i++) {
    var serverUrlBase = urlsBases[i];

    // OBS: é necessário colocar entre aspas simples a url no filtro do jQuery por atributo.
    $("a[href*='" + serverUrlBase + "']").each(function() {
        var urlProtegida = "http://anunciad.com.br?AuID=16958&Aurl=" + $(this).attr("href");

        $(this).attr("href", urlProtegida);
    });
}
  • In case both take any item with http:// and put it automatically right ?

  • Yeah. That’s what I’m talking about. In case you need to pick only specific links I can update the answer to do this filtering and so grab only the links you need to protect.

  • If you can do this thank you immensely because this is exactly what I need in case you give it to me for the hosts I want more than one in case a listing.

  • 1

    In the case of https://meocloud.pt/, http://mega.co.nz urls etc.

  • @Rodrigo made the change. There you in your URL list bases the other urls of the servers you need to protect.

  • Grateful for the help.

  • I think I did something wrong by putting <script src="protector.js"></script> and creating a file. js and put this jquery code no more put the link url no know what I did wrong. I put it before the </head>

  • Did you import jQuery? If possible, please create a fiddle of your code for me to analyze what may be missing. To create the fiidle you access the site http://www.jsfiddle.net puts your code there and gives me the link.

  • The link http://jsfiddle.net/bajw0hchis here/

  • I found the bug, @Rodrigo. I missed putting simple quotes surrounding the URL in the jQuery attribute filter in $("a[href*='" + serverUrlBase + "']"). Now I’ve updated my answer, and the right thing is $("a[href='" + serverUrlBase + "']")* (note that I have added simple quotes after = and before ]). Try it this way now and it will work.

  • Unfortunately it’s not working yet.

  • @Rodrigo In my fiddle is working ok. https://jsfiddle.net/UlyssesAlves/23bqqf0j/3/ Are you executing the code in $(Document). ready() ? Sometimes that’s it. You just created the function but didn’t call it, and so it’s not doing anything. Have a look at my fiddle please (https://jsfiddle.net/UlyssesAlves/23bqqf0j/3/). I first created the function and then called it in $(Document). ready and worked.

Show 7 more comments

-1

Try it like this:

$urlBase = 'http://anunciad.com.br?AuID=16958&Aurl=';

$urlTotal = $urlBase . 'www.skydrive.com/arquivo1.mp3';
  • I appreciate the most needed help actually of the method posted by Ulysses so that put automatically in the case in specific Urls the protector.

  • It was bad I had only cleared the question as accept more des I marked to have seen the above answer that was what I wanted. And know that the method also and applicable more would only suit me if I already had content and how I use Wordpress for me in Javascript and better.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.