Skip to content

Instantly share code, notes, and snippets.

@tegomass
Last active January 15, 2019 23:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tegomass/61083a3ea54fb6327b9c11cedbf3d161 to your computer and use it in GitHub Desktop.
Save tegomass/61083a3ea54fb6327b9c11cedbf3d161 to your computer and use it in GitHub Desktop.
Add a button in the top-left of Gmail to resize the image in the body of your mails if they are larger than a specified value
// ==UserScript==
// @name gmail image resizer
// @namespace https://gist.github.com/tegomass/61083a3ea54fb6327b9c11cedbf3d161
// @description Add a button in the top-left of Gmail to resize the image in the body of your mails if they are larger than a specified value
// @include https://mail.google.com/*
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js
// @require https://gist.githubusercontent.com/tegomass/734b5a868f9222a6c1a89a42232768b5/raw/
// @exclude %exclude%
// @version 1.1
// @grant GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a design change introduced in GM 1.0,
It restores the sandbox.
*/
// @version 1.1
// Add click on tr to resize image
//
$(function(){
var config = {
width: 200,
additionalText: ' | ',
gmailClass: '.gs'
};
waitForGmail(function(){
if ($('#tego').length){
return;
}
console.log('resized button added !');
$('#gbwa').append('<span id="tego">resize</span>').click(resizedIMG);
function resizedIMG() {
//$('#\\:2').find('img').each(function(index, el) {
$(config.gmailClass).find('img').each(function(index, el) {
if (typeof $(this).attr('width') !== 'undefined') {
if ($(this).attr('width') > config.width) {
$(this).after(config.additionalText)
$(this).attr('width', config.width)
$(this).attr('height', 'auto')
}
} else {
$(this).attr('width', config.width)
$(this).attr('height', 'auto')
}
});
}
console.log('TR HERE')
$('body').on('click', 'img', function(){
console.log($(this).attr('src'))
})
$('body').on('click', 'tr', function(){
console.log($("div[title*='Tout imprimer']"))
resizedIMG();
})
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment