Code Monkey home page Code Monkey logo

units-safari-extension's Introduction

Units

Safari extension to convert imperial units embedded in text to their metric equivalent.

Download

Download from here

Example

6'2" will be replaced with 6'2" (187.96cm)

Unit support

For now it supports the following conversions:

  • Feet + inches to cm or m
  • Lbs to kg
  • Miles to km
  • Miles per gallon to litres per 100 km
  • Miles per hour to KM/H
  • Time 1/21/16 1pm to 21.01.2016 13:00

Bookmarklet

If you don't use Safari, the code still works as a bookmarklet. Created using bookmarkleter

Paste the following as your bookmark URL:

javascript:!function(){function%20t(t){return%22%20(%22+t+%22)%22}function%20n(n,e,r,a,o,d){r=null!=r%26%26r.trim().length%3E0%3Fr:0;var%20u=Math.round(100*(30.48*parseInt(e,10)+2.54*parseInt(r,10)))/100;if(Number.isNaN(u))return%20n;var%20i=void%200!=d%3Fd.slice(0,o):%22%22;return%20i=i.split(%22%22).reverse().join(%22%22),/^(%3F:[^0-9]+%3F)'\s/.test(i)%3Fn:u%3E230%3Fn+t(Math.round(u)/100+%22m%22):n+t(u+%22cm%22)}function%20e(t,n){if(t%3C=1)return%220%22+t;var%20e=n-Math.ceil(Math.log10(t));return%200==e%3Ft:%220%22.repeat(e)+t}function%20r(t,n){if(t.nodeType===Node.TEXT_NODE)for(var%20e=0,a=n.length;e%3Ca;++e)t.nodeValue=t.nodeValue.replace(n[e].pattern,n[e].func);else%20if(t.nodeType===Node.ELEMENT_NODE%26%26!o.includes(t.tagName.toLowerCase()))for(var%20e=0,d=t.childNodes.length;e%3Cd;++e)r(t.childNodes[e],n)}var%20a=[{pattern:/(\d+)'(%3F:(\d+)(%22|'')|(%3F=[\s,\.]))/g,func:n},{pattern:/(\d+)ft%20%3F(\d*)in/g,func:n},{pattern:/(\d+\.%3F\d*)%20%3Fpounds%3F/gi,func:function(n,e,r,a){return%20n+t(Math.round(.453592*parseFloat(e)*100)/100+%22kg%22)}},{pattern:/(\d+\.%3F\d*)%20%3Flbs%3F/gi,func:function(n,e,r,a){return%20n+t(Math.round(.453592*parseFloat(e)*100)/100+%22kg%22)}},{pattern:/((\d+,%3F)+\.%3F\d*)%20%3Fmiles%3F/gi,func:function(n,e,r,a){var%20e=parseFloat(e.replace(%22,%22,%22%22));return%20n+t(Math.round(1.60934*e*100)/100+%22km%22)}},{pattern:/(\d+\.%3F\d*)%20%3Fmpg/gi,func:function(n,e,r,a){return%20n+t(Math.round(235.214/parseFloat(e)*100)/100+%22L%20/%20100km%22)}},{pattern:/(\d+\.%3F\d*)%20%3Fmph/gi,func:function(n,e,r,a){return%20n+t(Math.round(1.60934*parseFloat(e)*100)/100+%22km/h%22)}},{pattern:/(\d{1,2}):%3F(\d{0,2})\s*(%3F:(p|a)\.%3Fm\.%3F|(midnight|noon|[mn]\b))/gi,func:function(n,r,a,o,d,u,i){var%20s=parseInt(r),p=parseInt(a)||0;return%20void%200!=o%3F%22p%22==o.toLowerCase()%26%26s%3C12%3Fs+=12:%22a%22==o.toLowerCase()%26%2612==s%26%26(s=0):void%200!=d%26%26(d.toLowerCase().startsWith(%22n%22)%26%2612==s%3Fs=12:d.toLowerCase().startsWith(%22m%22)%26%2612==s%26%26(s=0)),n+t(e(s,2)+%22:%22+e(p,2))}},{pattern:/(\d{1,2})\/(\d{1,2})\/(\d{4}|\d{2})\b(%3F:\s[\w\s\.:]+\s\((\d{2}:\d{2})\))%3F/gi,func:function(n,r,a,o,d,u,i){var%20s=parseInt(r),p=parseInt(a),c=parseInt(o),f=(new%20Date).getUTCFullYear();if(s%3E12)return%20n;c%3C100%26%26(c+=2e3+c%3Ef%3F1900:2e3);var%20l=e(p,2)+%22.%22+e(s,2)+%22.%22+c;return%20void%200===d%3Fn+t(l):n.slice(0,n.lastIndexOf(%22(%22))+t(l+%22%20%22+d)}}],o=[%22code%22,%22pre%22,%22xmp%22];r(document.body,a)}();

Contributions welcome

Contributors

Manu Wallner Carlos Fenollosa

units-safari-extension's People

Contributors

mirosval avatar cfenollosa avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.