// ==UserScript==
// @name Drag to Resize Image
// @namespace
// @description Click and Drag to resize images. Ctrl+Click to disable resizing. Right Click to restore image to original size. Based on code in Reddit Enhancement Suite.
// @author Kabaka, MajorVictory87
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js
// @include *
// @version 1.3
// @downloadURL https://update.greasyfork.icu/scripts/4269/Drag%20to%20Resize%20Image.user.js
// @updateURL https://update.greasyfork.icu/scripts/4269/Drag%20to%20Resize%20Image.meta.js
// ==/UserScript==
/*
* Drag to Resize - Drag images to resize them no matter where you are.
*
* The image resizing code was extracted from honestbleeps's
* (steve@honestbleeps.com) Reddit Enhancement Suite, a GPL
* Greasemonkey script. The idea was, as far as I know, all his. What
* I've done is duplicated that feature in this script and started
* adding on things to make it useful in different contexts.
*
* Because it now runs everywhere, it will likely break some web
* sites. And it definitely opens up doors for some silliness such as
* making images hilariously gigantic. If this script causes you to
* lose data, money, or time, don't hold me responsible!
*
*
* Instructions:
*
* To resize an image, hold the left mouse button and drag. Down and to the
* right will expand. Up and to the left will shrink. Images aligned to the
* right will expand in an unusual way. Sorry.
*
* To reset an image to original size, right-click it.
*
* To drag an image without resizing (as if the script were not installed),
* hold control (or command on Mac) and drag.
*
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
var imageData = Array();
/*
* Find all img elements on the page and feed them to makeImageZoomable().
* Also, record the image's original width in imageData[] in case the user
* wants to restore size later.
*/
function findAllImages()
{
var imgs = document.getElementsByTagName('img');
for (i=0; i 5) {
var prevwidth = parseInt(e.target.style.width.replace('px', ''));
e.target.style.maxWidth = e.target.style.width = Math.floor(((getDragSize(e)) * DragData.width / DragData.delta)) + "px";
e.target.style.maxHeight = '';
e.target.style.height = 'auto';
e.target.style.zIndex = 1000; // Make sure the image is on top.
if(e.target.style.position == '') {
e.target.style.position = 'relative';
}
imageData[e.target].resized = (prevwidth - parseInt(e.target.style.width.replace('px', '')));
}
}
}, false);
imgTag.addEventListener('mouseout', function(e) {
if (DragData.dragging) {
DragData.dragging = false;
e.preventDefault();
return false;
}
return true;
}, true);
imgTag.addEventListener('mouseup', function(e) {
if (DragData.dragging) {
DragData.dragging = false;
e.preventDefault();
return false;
}
return true;
}, true);
imgTag.addEventListener('click', function(e)
{
if(e.ctrlKey != 0)
return true;
if(e.metaKey != null && e.metaKey != 0) // Can be on some platforms
return true;
console.log("Click [click]: "+e.button);
console.log("Resize [click]: "+imageData[e.target].resized);
if (!isNaN(imageData[e.target].resized) && imageData[e.target].resized != 0) {
e.preventDefault();
return false;
}
return true;
}, true);
}
findAllImages();
document.addEventListener('dragstart', function() {return false}, false);