Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-08-2013, 09:10 PM   PM User | #1
HelpMeOut
New to the CF scene

 
Join Date: Jan 2013
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
HelpMeOut is an unknown quantity at this point
Noob needs help (chrome extension)

Hey. To be perfectly honest, i don't know ANY JS coding what so ever.
I know some C#, so i understand the basic behind the JS coding...

My problem is probably simple (for those of you who knoe JS).

Since youtube updated theyre UI, i have been constantly annoyed with all the "recommended for you" videos appearing.
So i downloaded a chrome extension wich redirects you from "youtube.com" to "youtubecn.com" (youtube for countries where normal youtube is blocked).
I thought i could simply change "youtubecn.com" to "youtube.com/feed/subscriptions".

Turns out it wasnt that easy as the extension detects that the only thing between "www." and ".com" is "youtube" in both cases instead of "youtubecn"
Can someone please make this redirect me from "youtube.com" to "youtube.com/feed/subscriptions"?

Code:
var l=location.href;
if(l.match("youtube")){	l=l.replace("www.youtube.com","youtube.com/feed/subscriptions");
	location.href=l;
}
HelpMeOut is offline   Reply With Quote
Old 01-08-2013, 09:21 PM   PM User | #2
HelpMeOut
New to the CF scene

 
Join Date: Jan 2013
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
HelpMeOut is an unknown quantity at this point
Did this. Solved the problem (slitely... cant watch videos without going to youtube.com/feed/subscriptions)
Code:
var l=location.href;
if(l.match("youtube.com/feed/subscriptions")){	return;}
if(l.match("youtube")){	l=l.replace("www.youtube.com","youtube.com/feed/subscriptions");	location.href=l;}
please help me :P

Last edited by HelpMeOut; 01-08-2013 at 09:28 PM..
HelpMeOut is offline   Reply With Quote
Old 01-09-2013, 06:13 PM   PM User | #3
007julien
Regular Coder

 
Join Date: May 2012
Location: France
Posts: 115
Thanks: 0
Thanked 17 Times in 15 Posts
007julien is an unknown quantity at this point
You have to use a regular expressions (defined with to / delimiters or new RegExp(string)) with the methods : replace, match or test (which simply return a boolean on success).

Some caution is needed with addresses that contain special characters such as dots (which represents any characters in regular expressions and must be preceded by a backslash to regain their initial sense) and slashes (the delimiters which must too be preceded by a backslash).
Then the right syntax could be
Code:

// To replace youtube.com by youtube.com/feed/subscriptions
var url="http://www.youtube.com/foobar";
var newUrl=url.replace(/youtube\.com/,'youtube.com/feed/subscriptions');
alert(newUrl)
// To test for youtube.com/feed/subscriptions"
var url="youtube.com/feed/subscriptions/foobar"
alert(/youtube\.com\/feed\/subscriptions/.test(url))
EDIT : With the constructor var rgx=new RegExp("myString") there is an other problem with backslashes (which mean in a string : the following characters is a control character). Then they should be doubled !

Last edited by 007julien; 01-10-2013 at 10:27 AM..
007julien is offline   Reply With Quote
Old 01-10-2013, 07:55 PM   PM User | #4
HelpMeOut
New to the CF scene

 
Join Date: Jan 2013
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
HelpMeOut is an unknown quantity at this point
Lightbulb

Quote:
Originally Posted by 007julien View Post
You have to use a regular expressions (defined with to / delimiters or new RegExp(string)) with the methods : replace, match or test (which simply return a boolean on success).

Some caution is needed with addresses that contain special characters such as dots (which represents any characters in regular expressions and must be preceded by a backslash to regain their initial sense) and slashes (the delimiters which must too be preceded by a backslash).
Then the right syntax could be
Code:

// To replace youtube.com by youtube.com/feed/subscriptions
var url="http://www.youtube.com/foobar";
var newUrl=url.replace(/youtube\.com/,'youtube.com/feed/subscriptions');
alert(newUrl)
// To test for youtube.com/feed/subscriptions"
var url="youtube.com/feed/subscriptions/foobar"
alert(/youtube\.com\/feed\/subscriptions/.test(url))
EDIT : With the constructor var rgx=new RegExp("myString") there is an other problem with backslashes (which mean in a string : the following characters is a control character). Then they should be doubled !
For some reason it didn't work...
If you are using google chrome and would like to try out to find a code that works:
Download: https://chrome.google.com/webstore/d...hecaiacd?hl=en

then go to: C:\Users\[Your user name]\AppData (may be a hidden folder)\local\google\Chrome\User Data\Default\Extensions

Then find the folder wich contains the youtube mirror extension.
For me its: ffnjkadalnonednoaalcmebihecaiacd

Edit "ytm.js" until the extension works :P
(Everytime you have edited ytm.js you need to restart chrome).
HelpMeOut is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:03 AM.


Advertisement
Log in to turn off these ads.