Save real target URLs from Google search results

"Save Link as Zotero Item" previously saved Google's tracking page
instead of the real destination. This can be extended to other sites
if necessary.
This commit is contained in:
Dan Stillman 2012-01-16 23:07:56 -05:00
parent 77a9bac691
commit 35efd798de
2 changed files with 29 additions and 0 deletions

View File

@ -1417,5 +1417,32 @@ Zotero.Utilities = {
}
}
}
},
/**
* Get the real target URL from an intermediate URL
*/
"resolveIntermediateURL":function(url) {
var patterns = [
// Google search results
{
regexp: /^https?:\/\/(www.)?google\.(com|(com?\.)?[a-z]{2})\/url\?/,
variable: "url"
}
];
for (var i=0, len=patterns.length; i<len; i++) {
if (!url.match(patterns[i].regexp)) {
continue;
}
var matches = url.match(new RegExp("&" + patterns[i].variable + "=(.+?)(&|$)"));
if (!matches) {
continue;
}
return decodeURIComponent(matches[1]);
}
return url;
}
}

View File

@ -3197,6 +3197,8 @@ var ZoteroPane = new function()
var self = this;
url = Zotero.Utilities.resolveIntermediateURL(url);
Zotero.MIME.getMIMETypeFromURL(url, function (mimeType, hasNativeHandler) {
// If native type, save using a hidden browser
if (hasNativeHandler) {