commit 35efd798defcd254b995ae80a789774e64a82c11
parent 77a9bac69152a5a1360f1753dbcd8fa510effb38
Author: Dan Stillman <dstillman@zotero.org>
Date: Mon, 16 Jan 2012 23:07:56 -0500
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.
Diffstat:
2 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/chrome/content/zotero/xpcom/utilities.js b/chrome/content/zotero/xpcom/utilities.js
@@ -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;
}
}
diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js
@@ -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) {