A simple script to alter the current URL

2,342 views
Skip to first unread message

Michael George Lerner

unread,
Jul 10, 2007, 1:28:14 PM7/10/07
to greasemonkey-users
Hi,

I read a lot of journal articles that require subscriptions. When I'm
at home, that means that I need to send everything through my school's
proxy server so that all of the subscription business is taken care of
automatically. I'd like a script that will automatically send various
URLs through that proxy. So, I'd like it to do two things:

1) Automatically change http://scholar.google.com/<whatever> into
http://scholar.google.com.proxy.lib.umich.edu/<whatever> and

2) give me a bookmark or key combination or something that will add
proxy.lib.umich.edu to the end of the current domain.

Unfortunately for me, I don't really know anything about greasemonkey.
Is it easy to write a script to do such a thing?

Thank you,

-Michael Lerner

Godmar Back

unread,
Jul 10, 2007, 2:10:30 PM7/10/07
to greasemon...@googlegroups.com
LibX does this, see http://www.lib.umich.edu/betas/libx/index.html
Use the right-click option and select "Reload via.."

- Godmar

Vectorspace

unread,
Jul 10, 2007, 2:15:37 PM7/10/07
to greasemon...@googlegroups.com
Save this as the target of a bookmark:

javascript:var url=location.href;var
d=location.hostname;url=url.replace(d,d+".proxy.lib.umich.edu");alert(url);location.href=url;void
0;

Click it and it will apply the desired effect. That is called a
bookmarklet - a bookmark that is a javascript instruction.

Problem is, I don't think your method of sticking the proxy info after
the domain will work.

Take http://www.google.com
Change it to this:
http://www.google.com.proxy.lib.umich.edu
And I get University of Michigan login - this is correct, I assume.

However, take this:
http://www.google.com/search?q=search
Change it to this::
http://www.google.com.proxy.lib.umich.edu/search?q=search
And you are taken to the wrong place:
http://proxy.lib.umich.edu/search?q=search


"1) Automatically change http://scholar.google.com/<whatever> into http://scholar.google.com.proxy.lib.umich.edu/<whatever>" - that does not work, if <whatever> is blank, as far as I can see

Michael George Lerner

unread,
Jul 10, 2007, 2:21:32 PM7/10/07
to greasemonkey-users
That's very cool. I'd rather have something that automatically changed
the scholar.google.com links without requiring me to click anything,
but this certainly does most of what I want.

Thanks!

-Michael

On Jul 10, 2:10 pm, "Godmar Back" <god...@gmail.com> wrote:
> LibX does this, seehttp://www.lib.umich.edu/betas/libx/index.html


> Use the right-click option and select "Reload via.."
>
> - Godmar
>

> On 7/10/07, Michael George Lerner <mgler...@gmail.com> wrote:
>
>
>
> > Hi,
>
> > I read a lot of journal articles that require subscriptions. When I'm
> > at home, that means that I need to send everything through my school's
> > proxy server so that all of the subscription business is taken care of
> > automatically. I'd like a script that will automatically send various
> > URLs through that proxy. So, I'd like it to do two things:
>

> > 1) Automatically changehttp://scholar.google.com/<whatever> into

Michael George Lerner

unread,
Jul 10, 2007, 2:23:29 PM7/10/07
to greasemonkey-users
On Jul 10, 2:15 pm, Vectorspace <vectorsp...@ntlworld.com> wrote:
> Save this as the target of a bookmark:
>
> javascript:var url=location.href;var
> d=location.hostname;url=url.replace(d,d+".proxy.lib.umich.edu");alert(url);location.href=url;void
> 0;
>
> Click it and it will apply the desired effect. That is called a
> bookmarklet - a bookmark that is a javascript instruction.

That's a cool idea. Thanks.

> Problem is, I don't think your method of sticking the proxy info after
> the domain will work.
>

> Takehttp://www.google.com


> Change it to this:http://www.google.com.proxy.lib.umich.edu
> And I get University of Michigan login - this is correct, I assume.
>
> However, take this:http://www.google.com/search?q=search
> Change it to this::http://www.google.com.proxy.lib.umich.edu/search?q=search
> And you are taken to the wrong place:http://proxy.lib.umich.edu/search?q=search

That's because the proxy is trying to outsmart you. It only works for
certain sites. I think they only want you to use it as a proxy for
library-related business, rather than using it as a generic proxy.

Thanks,

-michael

>
> "1) Automatically changehttp://scholar.google.com/<whatever> intohttp://scholar.google.com.proxy.lib.umich.edu/<whatever>" - that does not work, if <whatever> is blank, as far as I can see


>
> Michael George Lerner wrote:
> > Hi,
>
> > I read a lot of journal articles that require subscriptions. When I'm
> > at home, that means that I need to send everything through my school's
> > proxy server so that all of the subscription business is taken care of
> > automatically. I'd like a script that will automatically send various
> > URLs through that proxy. So, I'd like it to do two things:
>

> > 1) Automatically changehttp://scholar.google.com/<whatever> into

esquifit

unread,
Jul 10, 2007, 5:25:04 PM7/10/07
to greasemon...@googlegroups.com
While you can certainly achieve this via GM, there are a number of
extensions for Firefox that accomplish similar tasks [1]. It seems
that [2] is appropriate for your needs (check the extension's homepage
[3], and choose the second proxy type, 'NYUD Style')

Another possibility is to create a proxy auto-config ('pac') file
[4][5]. This is probably more involved than a GM script but it has
the advantage that it also works in others browsers, at least in IE.

[1] https://addons.mozilla.org/it/firefox/search?q=proxy&status=4&show=50
[2] https://addons.mozilla.org/it/firefox/addon/2232
[3] http://httproxy.mozdev.org/
[4] http://wp.netscape.com/eng/mozilla/2.0/relnotes/demo/proxy-live.html
[5] http://nscsysop.hypermart.net/proxypac.html

2007/7/10, Michael George Lerner <mgle...@gmail.com>:

Michael George Lerner

unread,
Jul 10, 2007, 7:50:37 PM7/10/07
to greasemonkey-users
OK, I've settled on a two-part solution:

1) Making scholar.google.com go through my proxy fixes all of the
subsequent links so everything just works. So, I wrote a simple little
greasemonkey script to turn scholar.google.com into
scholar.google.com.proxy.lib.umich.edu :

// ==UserScript==
// @name AutoUMichScholarProxy
// @namespace http://www.umich.edu/~mlerner
// @description force scholar.google.com to go through
proxy.lib.umich.edu
// @include http://scholar.google.com/*
// ==/UserScript==

window.location.href =
window.location.href.replace('scholar.google.com',
'scholar.google.com.proxy.lib.umich.edu');

2) For the rare case where I'm actually following a direct link to
some journal article, I'm using LibX's option to right-click and
select "Reload via.. [my proxy]." I'd be a little happier if I could
bind that to some key combination like ctrl-whatever, but I don't know
how to do that.

Thanks,

-Michael

On Jul 10, 2:10 pm, "Godmar Back" <god...@gmail.com> wrote:

> LibX does this, seehttp://www.lib.umich.edu/betas/libx/index.html


> Use the right-click option and select "Reload via.."
>
> - Godmar
>

> On 7/10/07, Michael George Lerner <mgler...@gmail.com> wrote:
>
>
>
> > Hi,
>
> > I read a lot of journal articles that require subscriptions. When I'm
> > at home, that means that I need to send everything through my school's
> > proxy server so that all of the subscription business is taken care of
> > automatically. I'd like a script that will automatically send various
> > URLs through that proxy. So, I'd like it to do two things:
>

> > 1) Automatically changehttp://scholar.google.com/<whatever> into

Michael George Lerner

unread,
Jul 11, 2007, 12:45:07 PM7/11/07
to greasemonkey-users
Wow .. oops!

That worked like a charm from home. At work, however, it's a different
story. Proxy.lib.umich.edu is smarter than me yet again: if you go to
scholar.google.com.proxy.lib.umich.edu from on campus, you're
redirected to scholar.google.com. So, my script had an infinite loop.
Oops. I'm at school now, so I can't test it, but I think this cheap
hack should work: the user just remembers to go to (or bookmarks)
www.scholar.google.com, and my script turns that into
scholar.google.com.proxy.lib.umich.edu. That only hits once, because
it gets rid of the www after the first rewriting of the URL. Meh. If
it gets any more complicated, I'll probably just use one of the larger
solutions that esquifit suggested.

Is there some obvious way to make my original script turn
scholar.google.com into scholar.proxy.lib.umich.edu without going into
an infinite loop?

Thanks,

-michael

// ==UserScript==
// @name AutoUMichScholarProxy
// @namespace http://www.umich.edu/~mlerner
// @description force scholar.google.com to go through
proxy.lib.umich.edu

// @include http://www.scholar.google.com/*
// ==/UserScript==

window.location.href =
window.location.href.replace('www.scholar.google.com',
'scholar.google.com.proxy.lib.umich.edu');

Reply all
Reply to author
Forward
0 new messages