HowTo? rewrite a URL

Larry Laffer

New Member
Hi,

is AG capable to rewrite URLs (if yo I was glad, you could provide an example HowTo (maybe just for my case))?

I want/need to rewrite any www to m in youtube URLs.
Example: rewrite
https://www.youtube.com/watch?v=ncgFQAISaGo

to
https://m.youtube.com/watch?v=ncgFQAISaGo


Thank you
 

Alex302

Filters Developer
Staff member
Administrator
Hi
You can try this rule for changing UserAgent
Code:
youtube.com#%#var originalUserAgent = navigator.userAgent; Object.defineProperty(navigator, 'userAgent', { get: function() { return originalUserAgent + ' [COLOR="#0000FF"]Edge[/COLOR]'; } });
or
Code:
youtube.com#%#var originalUserAgent = navigator.userAgent; Object.defineProperty(navigator, 'userAgent', { get: function() { return '[COLOR="#0000FF"]Your UserAgent[/COLOR]'; } });
Useragent samples(mobile):
http://www.useragentstring.com/pages/Android Webkit Browser/

Code:
youtube.com#%#var originalUserAgent = navigator.userAgent; Object.defineProperty(navigator, 'userAgent', { get: function() { return 'Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30'; } });
 

Blaz

Moderator & Translator
Staff member
Moderator
Avatar, when the correct user agent is used, the user gets redirected to mobile page.
 

Larry Laffer

New Member
@Alex302:
to rewrite the UA doesn't help me: I'm on ur-iPad (besides: how much more 'mobile' can a UA be??), using ur-Safari.
Whenever I click a youtube-link the outdated app is opened (/w YT telling me it was outdated and not supported anymore). So I needed to rewrite the URL before/whilst the page is loaded (i.e. in the page source of the page loaded/displayed).

@Blaz:
actually today it was about YT, still a working example of a URL rewrite was a great template for further tuning. Besides this redirecting does not work on iPad (also newer ones) as instead opening the link in browser the dedicated app is opened.

So @avatar wasn't wrong, globally (template) as well as specific to my question (I need another URL in the <a href...>, not another UA when actually requesting the link).


Any way to achieve that using AG?
 
Last edited by a moderator:

avatar

Administrator
Staff member
Administrator
Yeah, it's possible and the best way to do it is to make a userscript.

Please remind me of this tomorrow, I will do it.
 

avatar

Administrator
Staff member
Administrator
Oh, I am sorry, my bad.

So, regarding the rewrite, that's impossible to do "before" the page load, it is only possible with JS.
But here are some good news: it is possible to remove the app binding from the page code.

The thing is that binding is done with the following code:
Code:
  <link rel="alternate" href="ios-app://544007664/vnd.youtube/www.youtube.com/">
Simply remove it using this rule:
Code:
$$link[href="ios-app://"]
 

chbataka

Beta Tester
Hi staff members,
I want to replace
<div class="btn"><a href="http://mov.bestonlinecramschoolever.ed.jp/sample/01002.mp4" class="play-btn" cid="teacher01-calculus02" onmousedown="al_recommend.al_log_sample_video('',2,'teacher01-calculus02','sp_search__','digital_videoa',1)"><div>play sample</div></a></div> <div class="clear"></div>​
with
<div class="btn"><a href="https://freemoviecompressor.com/source=http://mov.bestonlinecramschoolever.ed.jp/sample/01002.mp4&h264&300kbps" class="play-btn" cid="teacher01-calculus02" onmousedown="al_recommend.al_log_sample_video('',2,'teacher01-calculus02','sp_search__','digital_videoa',1)"><div>play sample</div></a></div> <div class="clear"></div>​
But AG can't do this, right? If AG can't rewrite href, do I need to use userscript?
Please tell me how to handle this.

I'm using AG on Android 5.0 as local VPN.

p.s. "01002" is random number.
p.s. URL for original website is http://www.bestonlinecramschoolever.ed.jp/
(bestonlinecramschoolever.ed.jp and freemoviecompressor.com are just example domains and don't actually exist.)

Still don't have time, sorry:(

Meanwhile, I've prepared a separate repository for userscritps created by our team:
https://github.com/AdguardTeam/Userscripts

And created a new task there - to create a userscript rewriting URLs.
https://github.com/AdguardTeam/Userscripts/issues/3

By the way, userscripts there are still unavailable.
 
Last edited:

Alex302

Filters Developer
Staff member
Administrator
Hi staff members,
I want to replace
<div class="btn"><a href="http://mov.bestonlinecramschoolever.ed.jp/sample/01002.mp4" class="play-btn" cid="teacher01-calculus02" onmousedown="al_recommend.al_log_sample_video('',2,'teacher01-calculus02','sp_search__','digital_videoa',1)"><div>play sample</div></a></div> <div class="clear"></div>​
with
<div class="btn"><a href="https://freemoviecompressor.com/source=http://mov.bestonlinecramschoolever.ed.jp/sample/01002.mp4&h264&300kbps" class="play-btn" cid="teacher01-calculus02" onmousedown="al_recommend.al_log_sample_video('',2,'teacher01-calculus02','sp_search__','digital_videoa',1)"><div>play sample</div></a></div> <div class="clear"></div>​
But AG can't do this, right? If AG can't rewrite href, do I need to use userscript?
Please tell me how to handle this.

I'm using AG on Android 5.0 as local VPN.

p.s. "01002" is random number.
p.s. URL for original website is http://www.bestonlinecramschoolever.ed.jp/
(bestonlinecramschoolever.ed.jp and freemoviecompressor.com are just example domains and don't actually exist.)




By the way, userscripts there are still unavailable.
Please check these rules
Code:
||bestonlinecramschoolever.ed.jp^$replace=/(\/sample[\s\S]*?>)*(mp4")/\$1mp4&h264&300kbps"/
||bestonlinecramschoolever.ed.jp^$replace=/(\/sample[\s\S]*?>)*(mp4")/\$1mp4&h264&300kbps"/,important
They are supported only by desktop and Android apps,
 

chbataka

Beta Tester
Please check these rules
Code:
||bestonlinecramschoolever.ed.jp^$replace=/(\/sample[\s\S]*?>)*(mp4")/\$1mp4&h264&300kbps"/
||bestonlinecramschoolever.ed.jp^$replace=/(\/sample[\s\S]*?>)*(mp4")/\$1mp4&h264&300kbps"/,important
They are supported only by desktop and Android apps,
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.
 
Last edited:
Top