Change the location by saving the following as a bookmarklet:
javascript:(function(){
location.href = location.href.replace(
location.hostname, location.hostname + '.ezproxy.its.uu.se'
);
})()
However, the above first needs you to tell Firefox to load the original URL (so: you'll have to press Return in the location bar) to get the location object populated. Instead, to be prompted for a URL rather than first having your browser (try to) load it:
javascript:(function(){
var url = prompt('Type URL to browse');
var suffix = '.ezproxy.its.uu.se';
/* Don't know how the proxy would handle https or specific ports;
* let's just copy them...
* $1 = optional protocol, like 'http[s]://'
* $2 = domain, like 'superuser.com'
* $3 = optional port, like ':8080'
* $4 = rest of the URL, like '/questions/154689/ .. page/154692#154692'
*/
url = url.replace(
/(\w*:\/\/)?([^:\/]*)(:[0-9]*)?(.*)/, '$1$2' + suffix + '$3$4'
);
if(url.indexOf('http') != 0){
url = 'http://' + url;
}
location.href = url;
})()
And once you've switched to using the proxy, you can use some jQuery magic to rewrite each location in the HTML that is served by the proxy -- but only needed if it doesn't do that for you on the fly. To be saved as a user script (like for Greasemonkey), with some initial code to first ensure jQuery is available, and to only be included for the domain of your proxy server (hence only when you're browsing using that proxy):
// ==UserScript==
// @name Rewrite URLs to use proxy
// @namespace http://superuser.com/questions/154689/
// @description Rewrites absolute URLs to use proxy
// @include http://*.ezproxy.its.uu.se/*
// ==/UserScript==
var $;
var suffix = '.ezproxy.its.uu.se';
// Rewrites an attribute to include the proxy server address, if a full
// domain is specified in that attribute.
function rewriteAttr(attrName){
$('[' + attrName + ']').attr(attrName, function(){
// Don't know how the proxy would handle https or specific ports;
// let's just copy them...
// $1 = protocol, like 'http[s]://'
// $2 = domain, like 'superuser.com'
// $3 = optional port, like ':8080'
// $4 = rest of the URL, like '/questions/154689/ .. page/154692#154692'
return $(this).attr(attrName).replace(
/(\w*:\/\/)([^:\/]*)(:[0-9]*)?(.*)/, '$1$2' + suffix + '$3$4'
);
});
}
// Rewrite anchors such a <a href="http://superuser.com/xyz"> and references
// like <link rel="stylesheet" href="http://sstatic.net/su/all.css">
function letsJQuery() {
rewriteAttr('href');
rewriteAttr('src');
}
// Loads jQuery if required.
// See http://joanpiedra.com/jquery/greasemonkey/
(function(){
if (typeof unsafeWindow.jQuery == 'undefined') {
var GM_Head = document.getElementsByTagName('head')[0]
|| document.documentElement;
var GM_JQ = document.createElement('script');
GM_JQ.src =
'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';
GM_JQ.type = 'text/javascript';
GM_JQ.async = true;
GM_Head.insertBefore(GM_JQ, GM_Head.firstChild);
}
GM_wait();
})();
// Check if jQuery's loaded
function GM_wait() {
if (typeof unsafeWindow.jQuery == 'undefined') {
window.setTimeout(GM_wait, 100);
} else {
$ = unsafeWindow.jQuery.noConflict(true);
letsJQuery();
}
}