Welcome to Laser Pointer Forums - discuss green laser pointers, blue laser pointers, and all types of lasers

LPF Donation via Stripe | LPF Donation - Other Methods

Links below open in new window

ArcticMyst Security by Avery

Need help programming

Joined
May 31, 2009
Messages
3,239
Points
63
ok hey guys,
This is for all the greasemonkey and firefox guru's

Just need to know how to redirect a url if the url = a specific url (lol i know bear with me)

Example if i type in "http://www.google.com" i want greasemonkey to redirect from google to.. for example "http://www.yahoo.com" how can i do this...

I used my limited knowledge of javascript to do this small snipet of code

// ==UserScript==
// @name google redirector
// @namespace "http://yahoo.com"
// @description redirects google.* to yahoo!!
// @include http://www.google.*
// @include http://*.google.com/*
// ==/UserScript==
<script type="text/javascript">
if window.location = http://www.google.*
{
window.location = "http://www.yahoo.com"
}
</script>

delete " its so i can type the code with out it linking to the site!

is this correct?? because i cant get it to work!! any suggestions would be appreciated!! and +rep for sure!!
 
Last edited:





Joined
Dec 26, 2007
Messages
6,129
Points
0
Sorry man, I can help you with assembler, actionscript 2.0, C, visual basic, pal-gal programming, pascal and robix...but not with greasemonkey :p


Also, WHY IN HELL would you want to go to yahoo when you can use mighty Google!
 
Joined
May 31, 2009
Messages
3,239
Points
63
It was just an example.. btw pascal FTW!! I love that programming language.. its really fun to progam in.. anyway thanks niko.. I guess it back to complie..test..edit..compile..test..edit for me :yabbem:
 
Joined
Nov 22, 2008
Messages
1,506
Points
48
The window.location bit is fine, but IIRC you don't need the script tags, and your if statement is not working properly. Look up javascript string operators and comparators, and the statement being evaluated needs to be bracketed as in the example below.

The best way to debug the logic itself is to type the code, on one line, into the address bar, sandwiched between "javascript:" and ";" like below.

Code:
javascript:if(true){window.location="http://lol.com"};
Try using the substring finder from the site below toget the start of the URL:
Title: Javascript check to see if string starts with ’ste’ OR ‘Ste’ « Fahdi’s Weblog :Fahd Murtaza:
 
Joined
May 31, 2009
Messages
3,239
Points
63
so you saying use this

javascript:if(window.location="http://www.google.com){window.location="http://lol.com"};

or

if window.location="http://google.com"
javascript:if(true){window.location="http://lol.com"};

Thanks in advance!
 
Joined
May 31, 2009
Messages
3,239
Points
63
Never mind i got it to work! code if you want it is

// ==UserScript==
// @name google redirector
// @namespace "http://black-google.com"
// @description redirects google.* to google black!
// @include http://www.google.*
// @include http://*.google.com/*
// ==/UserScript==
javascript:if(true){window.location="http://www.black-google.org"};

Delete the " in the third line!

BTW +REP FOR YOU!! THANK YOU VERY MUCH!!

-Adrian
 
Joined
Nov 22, 2008
Messages
1,506
Points
48
Hi,
you might want to remove the line:
// @include http://*.google.com/*
if you ever use google docs or gmail - this will interfere with how they operate. Other than that, glad to hear it worked OK. Thanks for the +rep.
 




Top