View Single Post
Old 02-08-2014, 04:08 AM  
Emil
Confirmed User
 
Emil's Avatar
 
Join Date: Feb 2007
Location: Sweden
Posts: 5,650
Convert LBS to Kilo, gallons to liters, miles to km... (and the other way around)

Create a new bookmark with this javascript in the URL, when you click the bookmark it will convert the stuff on the page.

Code:
javascript:(function(){regex=/(\.?\d+(?:\.\d*)?)\s*?(lb|pound|#|kg|stone|gallon|gal|liter|litre|l|oz|fl oz|cup|mile|km|meter|m|cm)s?(?!\w)/ig;lbs_kg_factor=2.20462262;stone_kg_factor=6.35029318;l_gal_factor=3.78541178;floz_l_factor=0.0295735296;cup_l_factor=0.236588236;mile_km_factor=1.609344;function format(a,b){return a+' <em style="color:#999;">('+b+')</em>'}function convert(a,b,c,d){if(d==null)d=10;a=a/b;return Math.round(d*a)/d+" "+c}function convert_cm_to_feet_and_inches(a){feet=Math.floor(a/30.48);inches=Math.floor(a%(30.48/2.54));return feet+"′"+inches+'″'}function replace(a,b,d,e,s){b=parseFloat(b);d=d.toLowerCase();var c=0;switch(d){case'lb':case'pound':case'#':c=convert(b,lbs_kg_factor,'kg');break;case'kg':c=convert(b,1/lbs_kg_factor,'lbs',2.0);break;case'stone':c=convert(b,1/stone_kg_factor,'kg');break;case'gallon':case'gal':c=convert(b,1/l_gal_factor,'l');break;case'liter':case'litre':case'l':c=convert(b,l_gal_factor,'gal');break;case'oz':case'fl oz':c=convert(b,1/floz_l_factor,'l');break;case'cup':c=convert(b,1/cup_l_factor,'l');break;case'mile':c=convert(b,1/mile_km_factor,'km');break;case'km':c=convert(b,mile_km_factor,'miles');break;case'meter':case'm':c=convert_cm_to_feet_and_inches(b*100);break;case'cm':c=convert_cm_to_feet_and_inches(b);break}return format(a,c)}document.body.innerHTML=document.body.innerHTML.replace(regex,replace)})();
Try it out:
150 kg
4.3 miles
900 lbs
5.4 stone
7 litre
2 gallon
__________________
Free 🅑🅘🅣🅒🅞🅘🅝🅢 Every Hour (Yes, really. Free ₿itCoins.)
(Signup with ONLY your Email and Password. You can also refer people and get even more.)
Emil is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote