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 ?
– Striffer
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.
– Ulysses Alves
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.
– Striffer
In the case of https://meocloud.pt/, http://mega.co.nz urls etc.
– Striffer
@Rodrigo made the change. There you in your URL list bases the other urls of the servers you need to protect.
– Ulysses Alves
Grateful for the help.
– Striffer
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>
– Striffer
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.
– Ulysses Alves
The link http://jsfiddle.net/bajw0hchis here/
– Striffer
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.
– Ulysses Alves
Unfortunately it’s not working yet.
– Striffer
@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.
– Ulysses Alves