gmailEnlargePreview

By Keigo Tanaka Last update 4 hours ago — Installed 378 times.

There are 2 previous versions of this script.

// ==UserScript==
// @name	gmailEnlargePreview
// @author	keigo
// @version	0.4
// @namespace	http://greasemonkey.hippo.fm/gmailEnlargePreview
// @include	https://mail.google.com/*
// @include	http://mail.google.com/*
// @description	Enlarge image attachment for Gmail.
// ==/UserScript==

// Bugs..
// When the thread has many mails and many attachments, it could failed to convert links.
// I could not recognize the bug correctly. (maybe it occurs when the thread has more than 5 mails and it is expanded. )
// I doubt using 'gmail.getActiveViewElement().getElementsByTagName("img");' is wrong but how do I do it ?

// 0.2
// wrap with "window.setTimeout(function() { ... }, 0);

// 0.3
// fix

// 0.4
// fix

window.addEventListener('load', function() {
	if (unsafeWindow.gmonkey) {
		unsafeWindow.gmonkey.load('1.0', function(gmail) {
			window.setTimeout(function() {
				function rewriteImgTags() {
					if (gmail.getActiveViewType() == "cv") {
						var attachImgs = gmail.getActiveViewElement().getElementsByTagName("img");
						for (i = 0; i < attachImgs.length; i++) {
							if (attachImgs[i].className == "tFroq") {
								attachImgs[i].width = "500";

								attachImgs[i].src.match(/(.*)\?(.*)th=([a-z0-9]+)&(.*)$/);
								var thVal    = RegExp.$3
								attachImgs[i].src.match(/(.*)\?(.*)attid=([0-9.]+)&(.*)$/);
								var attidVal = RegExp.$3

								attachImgs[i].src = "?attid=" + attidVal + "&disp=emb&view=att&th=" + thVal;
							}
						}
					}
				}
				gmail.registerViewChangeCallback(rewriteImgTags);
				rewriteImgTags();
			}, 0);
		});
	}
}, true);