HowTo? rewrite a URL

chbataka

Beta Tester
Maybe you misunderstood my question and I thought my question was terrible. Let me change the question.

So, what I want to do is replacing all href links
http://media.site1.ac.jp/r/a/n/d/o/m/a/s/c/i/i.mp4
(all the href links end with ".mp4")
to
https://api.cloudconvert.com/convert?apikey=MYAPI&inputformat=mp4&outputformat=mp4&input=download&file=http://media.site1.ac.jp/r/a/n/d/o/m/a/s/c/i/i.mp4&converteroptions[video_codec]=H264&converteroptions[video_bitrate]=300
(I want to add "https://api.cloud....." and parameters.)

at http://www.site1.ac.jp/a/n/o/t/h/e/r/r/a/n/d/o/m/a/s/c/i/i/
(I want to apply the rule only at "www.site1.ac.jp")


How about this? thank you.
(this is re-post of the post above with forum tags)


Maybe you misunderstood my question and I thought my question was terrible. Let me change the question.

So, what I want to do is replacing all href links
HTML:
<a href="http://randomascii.site1.ac.jp/r/a/n/d/o/m/a/s/c/i/i.mp4"> <div>Play sample</div> </a>
(all the href links end with ".mp4" and include "site1.ac.jp")
to
HTML:
<a href="https://api.cloudconvert.com/convert?apikey=MYAPI&inputformat=mp4&outputformat=mp4&input=download&file=http://randomascii.site1.ac.jp/r/a/n/d/o/m/a/s/c/i/i.mp4&converteroptions[video_codec]=H264&converteroptions[video_bitrate]=160&converteroptions[video_qscale]=-1&converteroptions[video_crf]=-1&converteroptions[faststart]=true&converteroptions[audio_codec]=AAC&converteroptions[audio_bitrate]=24&converteroptions[audio_channels]=1&converteroptions[audio_frequency]=44100&converteroptions[audio_normalize]=%2B10dB&converteroptions[video_profile]=main&converteroptions[video_profile_level]=4.0&timeout=55&wait=true&download=inline&save=true"> <div>Play sample</div> </a>
(I want to add "https://api.cloud....." and parameters.)

at
Code:
http://www.site1.ac.jp/a/n/o/t/h/e/r/r/a/n/d/o/m/a/s/c/i/i/
(I want to apply the rule only at "www.site1.ac.jp")


How about this? Thank you.
 

chbataka

Beta Tester
By the way, I wrote AG filter for this and it doesn't work. Why?

Code:
||site1.ac.jp^$replace=/(http:\/\/.+?site1\.ac\.jp\/.+?\.mp4)/https:\/\/api\.cloudconvert\.com\/convert\?apikey=MYAPI&inputformat=mp4&outputformat=mp4&input=download&file=\$1&converteroptions[video_codec]=H264&converteroptions[video_bitrate]=160&converteroptions[video_qscale]=-1&converteroptions[video_crf]=-1&converteroptions[faststart]=true&converteroptions[audio_codec]=AAC&converteroptions[audio_bitrate]=24&converteroptions[audio_channels]=1&converteroptions[audio_frequency]=44100&converteroptions[audio_normalize]=%2B10dB&converteroptions[video_profile]=main&converteroptions[video_profile_level]=4\.0&timeout=55&wait=true&download=inline&save=true/ig,domain=site1.ac.jp
Is filter too long?
 

avatar

Administrator
Staff member
Administrator
Hard to say, you should check that all special regexp symbols are escaped.

You'd better debug the regular expression on http://www.regexr.com/ before using it in a rule.

Also for your particular question I'd prefer to use JS rules, so that you could handle links created by page scripts.
For instance, you can take this script:
Code:
window.addEventListener('load', function() {
    var links = document.querySelectorAll('a[href^="http"]');
    var iLinks = links.length;
    while (iLinks--) {
        var link = links[iLinks];
        var href = link.getAttribute('href');
        if (href.indexOf('site1.ac.jp') >= 0) {
            href = 'SOME_PREFIX' + href;
            link.setAttribute('href', href);
        }
    }
});
And then use http://closure-compiler.appspot.com/home to convert it to one-line script:
Code:
window.addEventListener("load",function(){for(var b=document.querySelectorAll('a[href^="http"]'),c=b.length;c--;){var d=b[c],a=d.getAttribute("href");0<=a.indexOf("site1.ac.jp")&&(a="SOME_PREFIX"+a,d.setAttribute("href",a))}});
And then use this one line script as AG JS rule:
Code:
example.org#%#window.addEventListener("load",function(){for(var b=document.querySelectorAll('a[href^="http"]'),c=b.length;c--;){var d=b[c],a=d.getAttribute("href");0<=a.indexOf("site1.ac.jp")&&(a="SOME_PREFIX"+a,d.setAttribute("href",a))}});
 

chbataka

Beta Tester
Hard to say, you should check that all special regexp symbols are escaped.

You'd better debug the regular expression on http://www.regexr.com/ before using it in a rule.

Also for your particular question I'd prefer to use JS rules, so that you could handle links created by page scripts.
For instance, you can take this script:
Code:
window.addEventListener('load', function() {
    var links = document.querySelectorAll('a[href^="http"]');
    var iLinks = links.length;
    while (iLinks--) {
        var link = links[iLinks];
        var href = link.getAttribute('href');
        if (href.indexOf('site1.ac.jp') >= 0) {
            href = 'SOME_PREFIX' + href;
            link.setAttribute('href', href);
        }
    }
});
And then use http://closure-compiler.appspot.com/home to convert it to one-line script:
Code:
window.addEventListener("load",function(){for(var b=document.querySelectorAll('a[href^="http"]'),c=b.length;c--;){var d=b[c],a=d.getAttribute("href");0<=a.indexOf("site1.ac.jp")&&(a="SOME_PREFIX"+a,d.setAttribute("href",a))}});
And then use this one line script as AG JS rule:
Code:
example.org#%#window.addEventListener("load",function(){for(var b=document.querySelectorAll('a[href^="http"]'),c=b.length;c--;){var d=b[c],a=d.getAttribute("href");0<=a.indexOf("site1.ac.jp")&&(a="SOME_PREFIX"+a,d.setAttribute("href",a))}});

Thank you.

The code which wrote still doesn't work even after I checked it on regexr.com probably because the element in that page is generated by Javascripts.


As you said, I'll insert your script instead.

Thank you!!
 

mobamoba

New Member
I'm trying to do a very simple replace in the Android app but am too much of a newb to figure it out so would appreciate help. I'd like replace:

Code:
https://www.site.com/name/login.php
to:

Code:
https://www.site.com/YYY/name/login.php
Is this possible in Android? Thanks.
 

avatar

Administrator
Staff member
Administrator
Something like this I guess:
Code:
||example.org^$replace=/site.com\/name/site.com\/YYY\/name/
 

avatar

Administrator
Staff member
Administrator
Code:
||example.org^$replace=/www\.example\.org\/subdomain\//www\.example\.org\/SOMETHING\/subdomain\//
Does the User Filter works on SSL sites in Android?
Yes if you have HTTPS filtering enabled.
 

mobamoba

New Member
Aha. Well I think I see why it's not working then. I'm using Nougat 7.1.1 and I can't enable HTTPS filtering - it allows me to install the cert but won't let me enable the filter. Should I open up a new thread for that?
 

avatar

Administrator
Staff member
Administrator
Nougat 7.1.1 and I can't enable HTTPS filtering - it allows me to install the cert but won't let me enable the filter.
Weird, I am also no Nougat, but there's no issues with https filtering. What do you mean by "enabling filter"?
 
Top