Google-Redirect

From Brett
Revision as of 07:21, 4 March 2014 by WikiSysop (Talk | contribs) (URLs attempted for handling)

Jump to: navigation, search

Sometimes I encounter Google results pages but as service is unreliable here in China, I often want to get directly to the result rather than having the vain hope of waiting to go through Google.

http://www.google.com.hk/url?q=<SOME QUERY HERE><SOME ARGS HERE>&url=<ESCAPED URI COMPONENT HERE>

It is too much of a pain to type out decodeURIComponent on the relevant portion of the URL, so I worked with the following...

While this bookmarklet will do the trick if already loaded:

var url = window.location.href.match(/[?&]url=([^&]*)(?=&|$)/);
url = url && url[1];
window.location = decodeURIComponent(url);

(or in bookmarklet form:)

javascript:(function()%7Bvar%20url%20%3D%20window.location.href.match(%2F%5B%3F%26%5Durl%3D(%5B%5E%26%5D*)(%3F%3D%26%7C%24)%2F)%3Burl%20%3D%20url%20%26%26%20url%5B1%5D%3Bwindow.location%20%3D%20decodeURIComponent(url)%7D)()

...usually Firefox just keeps on running, so I made the following page, google-redirect.html

(T'would be nice if Firefox could allow multi-line locations in bookmarks for preserving the line breaks of bookmarklets--dare I, moreover, dream of syntax highlighting here courtesy of an add-on? Would that it were, would that it might... For now, I'm just pasting the same code another time in the description so I can at least read it; hopefully I will always remember to update such bookmarklets in both the location and description (and deal with the annoyance of needing to add it after "javascript:").)

<script>
var url = window.location.href.match(/[?&]url=([^&]*)(?=&|$)/);
url = url && url[1];
url = decodeURIComponent(url).match(/[?&]url=([^&]*)(?=&|$)/);
url = url && url[1];
window.location = decodeURIComponent(url);
</script>

...and I made a bookmark leading to it, but leading to:

file:///C:/Users/<my-path>/google-redirect.html?url=%s

...and with the keyword "redir", so I could quickly hit ctrl-l to get into the location bar, copy-paste the URL, type "redir" and space and then paste (ctrl-x) to redirect quickly to whatever URL was appended at the end of the URL. Probably sounds convoluted unless you've had to deal with the Google issues as over here. This also has the advantage of not needing the maintenance trouble described above for bookmarklets.