Chrome Extension, Convert Lbs to Kg

I’m from Australia and we don’t use pounds so I’ve modified the 4chan/fit/ lbs;kgs extension with some help from another forums to convert everything when you mouse over. It’s very handy.

I have no idea where to put this thread, but this forum is where I use it the most…

You just put this in a text file;

// @name Tnation lbs;kgs
// @namespace unit_conversion
// @description Converts between metric and customary units on 4chan.
// @include http://tnation.T-Nation.com/free_online_forum/*
// ==/UserScript==

(function ()
{

var posts = document.getElementsByTagName(‘blockquote’);
var linkReg = /(<a .?/a>|http:.?( |$))/gm;
var regExp = /((.\d|\d)[,.'\d]*[\d]|(.\d|\d))/gm;
var foundMatch = null;
var linkRanges;
var i = 0;

ps = document.getElementsByTagName(‘p’);
for(i=0;i<ps.length;i++){
temp=ps[i].innerHTML;
ps[i].innerHTML=‘converting’;
ps[i].innerHTML=convertNumbers(temp);
}

function convertNumbers(fullText) {
if (foundMatch = regExp.exec(fullText)) {
checkLinks(fullText);
var isLink = false;
if (linkRanges.length > 0) {
for (var i=0; i<linkRanges.length; i++) {
if (foundMatch.index > linkRanges[i][0] && foundMatch.index < linkRanges[i][1]) {
isLink = true;
regExp.lastIndex = linkRanges[i][1];
break;
};
};
};
if (!isLink) {
if (!(foundMatch.index > 0 && fullText.substr(foundMatch.index-1,1).match(/[a-wyzA-WYZ$â?¬]/))) {
if (!(fullText.length > regExp.lastIndex && fullText.substr(regExp.lastIndex,1).match(/[%$â?¬]/))) {
if (fullText.length > regExp.lastIndex && fullText.substr(regExp.lastIndex,6).match(/(kg|lb|kilo|

pound|cm|inch|[‘"])/) && fullText.substr(regExp.lastIndex,2).match(/( [klpci]|['"].)/)) {
var numType = fullText.substr(regExp.lastIndex,2).replace(’ ‘,’');
} else {
var numType = ‘’;
};
var tempReplace = foundMatch[0];
if (foundMatch.index > 0 && fullText.substr(foundMatch.index-1,1).match(/./)) {tempReplace =

tempReplace.replace(/^./,‘’)};
var replacement = replaceText(tempReplace, numType);
fullText = fullText.substr(0,foundMatch.index) + fullText.substr(foundMatch.index).replace

(tempReplace, replacement);
regExp.lastIndex = foundMatch.index + replacement.length;
};
};
};
fullText = convertNumbers(fullText);
};
return fullText;
};

function replaceText(matchText, numType) {
var newText = ‘<span style=“cursor:default;” title="’;
var cleanNumber = matchText.replace(/,/g,‘’).replace(/.+/,‘.’).replace(/‘+/,"’“);
var numSplit = ;
if (cleanNumber.match(/'/)) {
numSplit = cleanNumber.split(”'");
if (numSplit.length > 2) {return matchText};
numSplit[0] = Number(numSplit[0]);
numSplit[1] = Number(numSplit[1]);
numType = ‘i’;
} else {
cleanNumber = Number(cleanNumber);
};

switch (numType.charAt(0)){
	case 'k':
		newText += Math.round(cleanNumber * 2.2 * 100) / 100 + ' lb';
		break;
	case 'l':
	case 'p':
		newText += Math.round(cleanNumber / 2.2 * 100) / 100 + ' kg';
		break;
	case 'c':
		if (cleanNumber > 30.48) {
			newText += Math.floor(cleanNumber / 2.54 / 12) + "'" + Math.round(cleanNumber / 2.54 % 12) + "''";
		} else {
			newText += Math.round(cleanNumber / 2.54 * 100) / 100 + ' in';
		};
		break;
	case '"':
	case "'":
	case 'i':
		if (numSplit.length == 2) {
			newText += Math.round((numSplit[0] * 2.54 * 12 + numSplit[1] * 2.54) * 100) / 100 + ' cm';
		} else {
			if (numType.match(/('[^']|^'$)/)) {
				newText += Math.round(cleanNumber * 2.54 * 12 * 100) / 100 + ' cm';
			} else {
				newText += Math.round(cleanNumber * 2.54 * 100) / 100 + ' cm';
			};
		};
		break;
	default:
		newText += Math.round(cleanNumber / 2.2 * 100) / 100 + ' kg / ' + Math.round(cleanNumber * 2.2 * 100) / 100 + ' 

lb’;
};

newText += '">' + matchText + '</span>';
return newText;

};

function checkLinks(checkText) {
linkRanges = ;
var i = 0;
var newMatch = null;

while (newMatch = linkReg.exec(checkText)) {
	linkRanges[i] = new Array(newMatch.index, linkReg.lastIndex);
	i++;
};

};

})();

And chance the extension in the file name to “.js” then drag it into chrome and let it install.

whuuuuuuuuu

… or instead, you could divide the number by 2.2

Eg. 220 lbs / 2.2 = 100 kg

kinda simple really.

AND it works both ways. 100kg x 2.2 = 220lbs.

Amazing.

If you guys would just switch to lbs we wouldn’t have this problem

GTFO OP!!!

oh and wormwood, I would appreciate it if you would stop stealing my pictures and putting them up as your avi. kthanxbye

[quote]overstand wrote:
If you guys would just switch to lbs we wouldn’t have this problem[/quote]

Kgs are amazing!

Funny thing in England - anyone old enough to be around before it changed to Kgs, has no idea how much a kg is. anyone under that age has no idea what a lb is.

[quote]rugggby wrote:

[quote]overstand wrote:
If you guys would just switch to lbs we wouldn’t have this problem[/quote]

Kgs are amazing!

Funny thing in England - anyone old enough to be around before it changed to Kgs, has no idea how much a kg is. anyone under that age has no idea what a lb is.

[/quote]

Then how did you come to know of BOTH of these elusive measuring units young and talented adventurer? Are you a witch of some sorts? Or perhaps the chosen one!

Make haste. You must bridge the gap between this ‘young’ and this ‘old’ you speak of. Be the bringer of knowledge and all of England shall soon know of these ‘kilograms’ and these ‘lbs’.

oooh someone must be old and bitter.

I know because everytime i talk to my dad about weights he always asks me what is it in lbs. So i googled how to convert.

My boss has no idea either because ‘he never learnt it at school’ … do you want me to draw you a picture?

[quote]rugggby wrote:
oooh someone must be old and bitter.

I know because everytime i talk to my dad about weights he always asks me what is it in lbs. So i googled how to convert.

My boss has no idea either because ‘he never learnt it at school’ … do you want me to draw you a picture?[/quote]

To be honest I am just busting your balls because age has nothing to do with it.

Stubbornness and ignorance are the causes and this is the case world wide.

It takes five seconds to find out the conversion rate.

[quote]Animal Within wrote:

[quote]rugggby wrote:
oooh someone must be old and bitter.

I know because everytime i talk to my dad about weights he always asks me what is it in lbs. So i googled how to convert.

My boss has no idea either because ‘he never learnt it at school’ … do you want me to draw you a picture?[/quote]

To be honest I am just busting your balls because age has nothing to do with it.

I agree. I was just generalizing that there are 2 types of people.

Stubbornness and ignorance are the causes and this is the case world wide.

It takes five seconds to find out the conversion rate.[/quote]

That was supposed to say…

I agree… and obviously I was generalising when it came to the two types of people

Lbs to kg is 2.2046.

For me weight it’s not an issue, 2.2 back and forth, but height it’s more complicated, since converting feet and inches is a bit more annoying.

Then there’s “stones” and stuff like that. I mean…really?

[quote]Edevus wrote:
For me weight it’s not an issue, 2.2 back and forth, but height it’s more complicated, since converting feet and inches is a bit more annoying.

Then there’s “stones” and stuff like that. I mean…really?[/quote]

Completely agree. Height is a complete pain… luckily I have an app that does it for me! Although it isn’t 100% accurate

You can also just type “100 lbs to kg” or whatever into a google search bar and it will perform the conversion. Not really necessary with kg and lbs but I find it useful for more difficult conversions.

[quote]gregron wrote:
oh and wormwood, I would appreciate it if you would stop stealing my pictures and putting them up as your avi. kthanxbye[/quote]

This thread is now about this post.

[quote]rugggby wrote:
… or instead, you could divide the number by 2.2

Eg. 220 lbs / 2.2 = 100 kg

kinda simple really.

AND it works both ways. 100kg x 2.2 = 220lbs.

Amazing.[/quote]

Any number in kg = over 9,000 in lbs. Fact.

It’s really a lot easier to just mouse over the number…

And this is more for Australians.

[quote]WormwoodTheory wrote:
whuuuuuuuuu[/quote]
Try being a coder sometime.