User:Tim Starling/Formula wikifier

The formula wikifier is currently available on the internet at [1]. Don't get too excited - it doesn't actually work straight from the website. I'm not exactly a crack JavaScript programmer - does anyone know if there's a way of getting around the security restriction my script suffers?

Other stuff: it only works in IE, it could be made 30 times faster with a small amount of programming effort, and I've only tested in IE 6.

Anyway, here's the code:


<html>
<frameset cols="270,*">
<frame name="fJsframe" src="jsframe.html">
<frame name="fContent" src="http://www.wikipedia.org">
</frameset>
</html>

jsframe.html

<html>
<script>
<!--
function wikify()
{
elements=[
"H",
"Hydrogen",
"He",
"Helium",
"Li",
"Lithium",
"Be",
"Beryllium",
"B",
"Boron",
"C",
"Carbon",
"N",
"Nitrogen",
"O",
"Oxygen",
"F",
"Fluorine",
"Ne",
"Neon",
"Na",
"Sodium",
"Mg",
"Magnesium",
"Al",
"Aluminium",
"Si",
"Silicon",
"P",
"Phosphorus",
"S",
"Sulfur",
"Cl",
"Chlorine",
"Ar",
"Argon",
"K",
"Potassium",
"Ca",
"Calcium",
"Sc",
"Scandium",
"Ti",
"Titanium",
"V",
"Vanadium",
"Cr",
"Chromium",
"Mn",
"Manganese",
"Fe",
"Iron",
"Co",
"Cobalt",
"Ni",
"Nickel",
"Cu",
"Copper",
"Zn",
"Zinc",
"Ga",
"Gallium",
"Ge",
"Germanium",
"As",
"Arsenic",
"Se",
"Selenium",
"Br",
"Bromine",
"Kr",
"Krypton",
"Rb",
"Rubidium",
"Sr",
"Strontium",
"Y",
"Yttrium",
"Zr",
"Zirconium",
"Nb",
"Niobium",
"Mo",
"Molybdenum",
"Tc",
"Technetium",
"Ru",
"Ruthenium",
"Rh",
"Rhodium",
"Pd",
"Palladium",
"Ag",
"Silver",
"Cd",
"Cadmium",
"In",
"Indium",
"Sn",
"Tin",
"Sb",
"Antimony",
"Te",
"Tellurium",
"I",
"Iodine",
"Xe",
"Xenon",
"Cs",
"Cesium",
"Ba",
"Barium",
"La",
"Lanthanum",
"Hf",
"Hafnium",
"Ta",
"Tantalum",
"W",
"Tungsten",
"Re",
"Rhenium",
"Os",
"Osmium",
"Ir",
"Iridium",
"Pt",
"Platinum",
"Au",
"Gold",
"Hg",
"Mercury (element)",
"Tl",
"Thallium",
"Pb",
"Lead",
"Bi",
"Bismuth",
"Po",
"Polonium",
"At",
"Astatine",
"Rn",
"Radon",
"Fr",
"Francium",
"Ra",
"Radium",
"Ac",
"Actinium",
"Rf",
"Rutherfordium",
"Db",
"Dubnium",
"Sg",
"Seaborgium",
"Bh",
"Bohrium",
"Hs",
"Hassium",
"Mt",
"Meitnerium",
"Uun",
"Ununnilium",
"Uuu",
"Unununium",
"Uub",
"Ununbium",
"Uuq",
"Ununquadium",
"Uuh",
"Unuhexium",
"Uuo",
"Ununoctium",
"Ce",
"Cerium",
"Pr",
"Praseodymium",
"Nd",
"Neodymium",
"Pm",
"Promethium",
"Sm",
"Samarium",
"Eu",
"Europium",
"Gd",
"Gadolinium",
"Tb",
"Terbium",
"Dy",
"Dysprosium",
"Ho",
"Holmium",
"Er",
"Erbium",
"Tm",
"Thulium",
"Yb",
"Ytterbium",
"Lu",
"Lutetium",
"Th",
"Thorium",
"Pa",
"Protactinium",
"U",
"Uranium",
"Np",
"Neptunium",
"Pu",
"Plutonium",
"Am",
"Americium",
"Cm",
"Curium",
"Bk",
"Berkelium",
"Cf",
"Californium",
"Es",
"Einsteinium",
"Fm",
"Fermium",
"Md",
"Mendelevium",
"No",
"Nobelium",
"Lr",
"Lawrencium"]

	tr = top.fContent.document.selection.createRange();
	output = "";
	for (p=0; p<tr.text.length; p++) {
		found = false;
		for (i=0; i<230 && !found; i+=2) {
			if (elements[i] == tr.text.substr(p, 2)) {
				output += "[[" + elements[i+1] + "|" + elements[i] + "]]";
				found = true;
				p++;
			}
		}
		for (i=0; !found && i<230; i+=2) {
			if (elements[i] == tr.text.substr(p,1)) {
				output += "[[" + elements[i+1] + "|" + elements[i] + "]]";
				found = true;
			}
		}
		if (!found) {
			output+=tr.text.substr(p,1);
		}
	}
	tr.text = output;
}

//-->
</script>

<p>URL: <input name=eUrl type=text value=http://www.wikipedia.org width=250>
<input type=button value="Go" onclick="top.fContent.location=eUrl.value">
<p><input type=button name=cbWikify value="Wikify" onClick="wikify()">

</html>

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.