Skip to content

Instantly share code, notes, and snippets.

@leomelzer
Created August 2, 2009 13:44
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 leomelzer/160087 to your computer and use it in GitHub Desktop.
Save leomelzer/160087 to your computer and use it in GitHub Desktop.
ever wondered how big this product you are looking at right now in some online-shop really is? try this bookmarklet!
javascript:(function(raw)%20{var%20units%20=%20[%27mm%27,%20%27cm%27,%20%27in%27,%20%27inch%27];var%20unit%20=%20%27mm%27;for%20(var%20i%20=%200;%20i%20<%20units.length;%20i++)%20{if%20(raw.indexOf(units[i])%20!=%20-1)%20{if%20(units[i]%20==%20%27inch%27)%20{unit%20=%20%27in%27;}else%20{unit%20=%20units[i];}}}if%20(raw.indexOf(%22n%22)%20!=%20-1)%20{var%20parts%20=%20raw.split(%22n%22);}else%20{var%20parts%20=%20raw.split(%27x%27);}if%20(parts.length%20<=%201)%20{alert(%27No%20valid%20data%20found%20in%20text-selection...%27);return%20false;}var%20cleaned%20=%20[];var%20clean_index%20=%200;for%20(var%20i%20=%200;%20i%20<%20parts.length;%20i++)%20{parts[i]%20=%20parts[i].replace(/,/g,%20%27.%27);parts[i]%20=%20parts[i].replace(/[a-z%C3%A4%C3%B6%C3%BC%C3%84%C3%96%C3%9C:]/gi,%20%27%27);parts[i]%20=%20parts[i].replace(/\(.*\)/g,%20%27%27);parts[i]%20=%20parts[i].replace(/s+/,%20%27%27);if%20(parts[i]%20!=%20%27%27)%20{cleaned[clean_index++]%20=%20parts[i].trim();}}parts%20=%20cleaned;var%20model%20=%20document.createElement(%27div%27);with(model)%20{style.position%20=%20%27absolute%27;style.zIndex%20=%2010000;style.top%20=%20%2720px%27;style.left%20=%20%2740px%27;style.backgroundColor%20=%20%27#000%27;style.opacity%20=%20%270.8%27;style.width%20=%20parts[0]%20+%20unit;style.height%20=%20parts[1]%20+%20unit;}document.getElementsByTagName(%27body%27)[0].appendChild(model);if%20(parts[2]%20!=%20undefined)%20{var%20model_side%20=%20document.createElement(%27div%27);with(model_side)%20{style.position%20=%20%27absolute%27;style.zIndex%20=%2010001;style.top%20=%20%2720px%27;style.left%20=%20(parts[0]%20*%201.5)%20+%20unit;style.backgroundColor%20=%20%27#000%27;style.opacity%20=%20%270.8%27;style.width%20=%20parts[2]%20+%20unit;style.height%20=%20parts[1]%20+%20unit;}document.getElementsByTagName(%27body%27)[0].appendChild(model_side);}})(document.getSelection());
/*
* ever wondered how big this product you are looking at right now in some online-shop really is? try this bookmarklet!
* select the text that describes the measurements and execute the bookmarklet.
* tested with strings like "53mm x 82mm x 21mm" and some tech-specs on apple.com
*/
(function(raw) {
var units = ['mm', 'cm', 'in', 'inch'];
var unit = 'mm';
for (var i = 0; i < units.length; i++) {
if (raw.indexOf(units[i]) != -1) {
if (units[i] == 'inch') {
unit = 'in';
}
else {
unit = units[i];
}
}
}
if (raw.indexOf("n") != -1) {
var parts = raw.split("n");
}
else {
var parts = raw.split('x');
}
if (parts.length <= 1) {
alert('No valid data found in text-selection...');
return false;
}
var cleaned = [];
var clean_index = 0;
for (var i = 0; i < parts.length; i++) {
parts[i] = parts[i].replace(/,/g, '.');
parts[i] = parts[i].replace(/[a-zäöüÄÖÜ:]/gi, '');
parts[i] = parts[i].replace(/\(.*\)/g, '');
parts[i] = parts[i].replace(/s+/, '');
if (parts[i] != '') {
cleaned[clean_index++] = parts[i].trim();
}
}
parts = cleaned;
var model = document.createElement('div');
with(model) {
style.position = 'absolute';
style.zIndex = 10000;
style.top = '20px';
style.left = '40px';
style.backgroundColor = '#000';
style.opacity = '0.8';
style.width = parts[0] + unit;
style.height = parts[1] + unit;
}
document.getElementsByTagName('body')[0].appendChild(model);
if (parts[2] != undefined) {
var model_side = document.createElement('div');
with(model_side) {
style.position = 'absolute';
style.zIndex = 10001;
style.top = '20px';
style.left = (parts[0] * 1.5) + unit;
style.backgroundColor = '#000';
style.opacity = '0.8';
style.width = parts[2] + unit;
style.height = parts[1] + unit;
}
document.getElementsByTagName('body')[0].appendChild(model_side);
}
})(document.getSelection());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment