Nimai
Oct-11-2007, 12:31 PM
Somebody stop me! I'm going GreaseMonkey http://youngpup.net/z_dropbox/greasespot_favicon.ico (http://www.greasespot.net/%22) crazy!
Here's a script that adds a No Crop button to the Pro Pricing page. Click the button to set all print sizes that would require cropping to zero, preventing customers from buying them. I made this work based off of the size of the image being priced, so it should work for any sized image. I only intend to use it for square ones, like my screen shot below. I'm also combining this with my Pro Pricing Photo customization so that I can quickly disable all but the square prints for my square-crop photos.
http://img215.imageshack.us/img215/9383/smugnocropwm7.jpg
Here's the code, or install straight from my scripts on userscripts.org (http://userscripts.org/users/35458;scripts)
// ==UserScript==
// @namespace http://nimai.smugmug.com/greasemonkey/nocrop
// @name SmugMug Pro Pricing No-Crop
// @description Adds a "No Crop" button to the pro pricing page for images in SmugMug which will set the price to zero (hide from sale) all print sizes that would require cropping
// @include http://*.smugmug.com/photos/tools.mg*tool=proprices
// ==/UserScript==
function getElementsByClass(searchClass,node,tag,text) {
var classElements = new Array();
if (node == null) node = document;
if (tag == null) tag = '*';
var els = node.getElementsByTagName(tag);
var elsLen = els.length;
var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
var textPattern = null;
if (text) textPattern = new RegExp(text);
for (i = 0, j = 0; i < elsLen; i++) {
if (pattern.test(els[i].className) ) {
if (textPattern==null || textPattern.test(els[i].textContent) ) {
classElements[j] = els[i];
j++;
}
}
}
return classElements;
}
function calcAspect( width, height ) {
return (width>height)?(width/height):(height/width);
}
function makeNoCrop() {
var image = getElementsByClass('imgBorder')[0];
var imageAspect = calcAspect( image.width, image.height );
var getDimensions = new RegExp('([0-9\.]+) [xX] ([0-9\.]+)');
var isWallet = new RegExp('4 Wallets.*');
var tds = document.getElementsByTagName('td');
var itemDim, itemAspect;
for( var i=0; i<tds.length; ++i ) {
var item = tds[i].textContent;
if( isWallet.test(item) )
itemAspect = 3.5/2.5;
else {
itemDim = getDimensions.exec( item );
itemAspect = itemDim ? calcAspect(itemDim[1],itemDim[2]) : null;
}
if( itemAspect ) {
if( Math.abs(itemAspect-imageAspect) > 0.05 ) {
var priceBox = tds[i].parentNode.getElementsByTagName('input')[0];
priceBox.value = '0';
}
}
}
}
if( getElementsByClass('title',null,null,'image') ) {
var toolsbox = getElementsByClass('toolsbox')[0];
var newRow = toolsbox.insertRow(1);
newRow.insertCell(0);
var newCell = newRow.insertCell(1);
newCell.setAttribute('align','left');
newRow.insertCell(2);
var noCropBut = document.createElement('input');
noCropBut.setAttribute('type','button');
noCropBut.setAttribute('class','smbuttons');
noCropBut.addEventListener('click', makeNoCrop, true);
noCropBut.value = 'No Crop';
newCell.appendChild( noCropBut );
}
Here's a script that adds a No Crop button to the Pro Pricing page. Click the button to set all print sizes that would require cropping to zero, preventing customers from buying them. I made this work based off of the size of the image being priced, so it should work for any sized image. I only intend to use it for square ones, like my screen shot below. I'm also combining this with my Pro Pricing Photo customization so that I can quickly disable all but the square prints for my square-crop photos.
http://img215.imageshack.us/img215/9383/smugnocropwm7.jpg
Here's the code, or install straight from my scripts on userscripts.org (http://userscripts.org/users/35458;scripts)
// ==UserScript==
// @namespace http://nimai.smugmug.com/greasemonkey/nocrop
// @name SmugMug Pro Pricing No-Crop
// @description Adds a "No Crop" button to the pro pricing page for images in SmugMug which will set the price to zero (hide from sale) all print sizes that would require cropping
// @include http://*.smugmug.com/photos/tools.mg*tool=proprices
// ==/UserScript==
function getElementsByClass(searchClass,node,tag,text) {
var classElements = new Array();
if (node == null) node = document;
if (tag == null) tag = '*';
var els = node.getElementsByTagName(tag);
var elsLen = els.length;
var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
var textPattern = null;
if (text) textPattern = new RegExp(text);
for (i = 0, j = 0; i < elsLen; i++) {
if (pattern.test(els[i].className) ) {
if (textPattern==null || textPattern.test(els[i].textContent) ) {
classElements[j] = els[i];
j++;
}
}
}
return classElements;
}
function calcAspect( width, height ) {
return (width>height)?(width/height):(height/width);
}
function makeNoCrop() {
var image = getElementsByClass('imgBorder')[0];
var imageAspect = calcAspect( image.width, image.height );
var getDimensions = new RegExp('([0-9\.]+) [xX] ([0-9\.]+)');
var isWallet = new RegExp('4 Wallets.*');
var tds = document.getElementsByTagName('td');
var itemDim, itemAspect;
for( var i=0; i<tds.length; ++i ) {
var item = tds[i].textContent;
if( isWallet.test(item) )
itemAspect = 3.5/2.5;
else {
itemDim = getDimensions.exec( item );
itemAspect = itemDim ? calcAspect(itemDim[1],itemDim[2]) : null;
}
if( itemAspect ) {
if( Math.abs(itemAspect-imageAspect) > 0.05 ) {
var priceBox = tds[i].parentNode.getElementsByTagName('input')[0];
priceBox.value = '0';
}
}
}
}
if( getElementsByClass('title',null,null,'image') ) {
var toolsbox = getElementsByClass('toolsbox')[0];
var newRow = toolsbox.insertRow(1);
newRow.insertCell(0);
var newCell = newRow.insertCell(1);
newCell.setAttribute('align','left');
newRow.insertCell(2);
var noCropBut = document.createElement('input');
noCropBut.setAttribute('type','button');
noCropBut.setAttribute('class','smbuttons');
noCropBut.addEventListener('click', makeNoCrop, true);
noCropBut.value = 'No Crop';
newCell.appendChild( noCropBut );
}