这对我有用。它将页面上的所有链接替换为附加的 Google Mobilizer URL。
if (!(
// Except when on ...
(/google.com\/search/.test(document.URL))
|| (/google.*\/gwt/.test(document.URL))
)){
var link = document.body.getElementsByTagName("a");
for (var i = 0; i < link.length; i++) {
if (!(
//Only for external links
(link[i].hostname == window.location.hostname)
//And except for links that contain...
|| (/google\./.test(link[i].href))
|| (/stack/.test(link[i].href))
|| (/reddit\./.test(link[i].href))
//And except for Null & Javascript-purpose links...
|| (/\0/.test(link[i].href))
)){
//Mobilize all links (append mobilizer URL)
link[i].href = link[i].href.replace("http","http://google.com/gwt/x?u=http")
}
}
}
else if (/google.*\/gwt/.test(document.URL)){
// But when on Google Mobilizer site itself, ...
var link = document.body.getElementsByTagName("a")
for (var i = 0; i < link.length; i++) {
if ((/gwt\/x\/e\?/.test(link[i].href))) {
//De-mobilize (just) "View page directly" link (because it unnecessarily prompts for redirection)
var inner = link[i].href.indexOf('http',1);
inner = inner>-1 ? link[i].href.substr(inner,link[i].href.indexOf('&',inner)-inner) : false;
if (inner)
link[i].href = inner;
}
}
}
它还会检查if
链接是否属于父站点域,并且不会更改它们。