User:BorisTM/NatOrganicBoxInfo.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:BorisTM/NatOrganicBoxInfo. |
//<pre>
var obj,ip,ip_eq,prop_Name,prop_Value,st_new,t_Crit,t_CritVal,vr_Str;
var i,i_L,i1,i2,i3,i1L,i2L,i3L;
var code_Storage;
var wiki="/wiki/";
var TD_style_2="colspan='2' style='background-color: #FFFFFF;";
var TD_style_4="colspan='4' style='background-color: #FFFFFF;";
var TD_style_sec="colspan='4' style='background-color: #F8EABA; font-weight: bold; text-align: center;";
var new_Text,new_A,new_BR,new_BUTTON,new_DIV,new_Elem,new_FORM,new_H5,new_I,new_INPUT,new_LABEL;
var new_OPTION,new_SELECT,new_SPAN,new_SUB,new_SUP,new_TD,new_TR,num_colSPan,v_href,v_id,v_title;
var myRegExp=/[\S]/;
var inf=new Array();
var opt_value=new Array("all","cb","imi","na","pp","ps","sm","som");
var opt_text=new Array("All","Cell biology","Inorganic","Nucleic acids","Polypeptides","Polysaccharides","Small molecules","Synthetic");
function check_ForDiv() {
if (!document.getElementById('footer')) {
setTimeout('check_ForDiv()',200);
}
else {
build_search_form();
if (document.getElementById('bioChemInfoBox')) {
obj=document.getElementById('bioChemInfoBox');
build_InfoBox();
}
}
}
function build_InfoBox() {
// ------------ Get the data
vr_Str=obj.innerHTML;
ip=vr_Str.indexOf('^^',vr_Str.indexOf('theBoxInfo'));
if (ip > 0) {
vr_Str=vr_Str.substring(ip-(-2),vr_Str.lastIndexOf('</P',vr_Str.lastIndexOf('</DIV')));
var tem=vr_Str.split('^^');
i1L=tem.length;
for (i1=0; i1<i1L; i1++) {
ip_eq=tem[i1].indexOf('=');
prop_Name=clear_Spaces(tem[i1].substring(0,ip_eq));
ip_eq += 1;
prop_Value=clear_Spaces(tem[i1].substring(ip_eq));
inf[prop_Name]=prop_Value;
}
}
// ------------ Sets the TABLE's attributes
obj.setAttribute("align","right");
obj.style.backgroundColor="#C0C090";
obj.cellPadding="2";
obj.cellSpacing="1";
obj.style.margin="0 0 0.5em 0.5em";
obj.setAttribute("width","326");
obj.style.borderWidth="1px";
obj=obj.firstChild;
obj.removeChild(obj.firstChild);
// ------------ Builds the NAME header
if (!inf['name'] || inf['name']=="") {
vr_Str=document.title;
firstIndex=vr_Str.indexOf(":")>0?vr_Str.indexOf(":")+1:0;
inf['name']=vr_Str.substring(firstIndex,vr_Str.indexOf(" - Wikipedia, the free encyclopedia"));
}
build_TR(document.createTextNode(inf['name']),"4","#F8EABA");
// ------------ Builds the IMAGE section
build_TR("","4");
if (!inf['image'] || inf['image']=="") inf['image']=inf['name']+".png";
if (!inf['width'] || inf['width']=="") inf['width']=320;
code_Storage = "<a href='"+wiki+"Image:"+inf['image']+"' class='internal' ";
code_Storage += "title='The structure of "+inf['name']+"'><img style='border-width: 0px;' ";
code_Storage += "src='/media/wikipedia/en/2/23/"+inf['image']+"' ";
code_Storage += "alt='The structure of "+inf['name']+"' width='"+inf['width']+"' /></a>";
new_TD.innerHTML=code_Storage;
/* ---------------------------------------
Builds the GENERAL header
--------------------------------------- */
build_TR(document.createTextNode("General"),"4","#F8EABA");
// ------------ Builds the IUPAC NAME section
if (!inf['IUPAC'] || inf['IUPAC']=="") inf['IUPAC']="?";
build_TR(build_wiki_A("IUPAC_nomenclature","IUPAC_nomenclature","Chemical name"),"4");
build_TR("","4");
new_TD.innerHTML=inf['IUPAC'];
// ------------ Builds the SYNONYMS section
if (inf['synonyms'] && !(inf['synonyms']=="")) {
build_TR(build_wiki_A("Synonyms","Synonyms","Synonyms"),"4");
build_TR("","4");
new_TD.innerHTML=inf['synonyms'];
}
// ------------ Builds the ABBREVIATION section
if (inf['abbreviations'] && !(inf['abbreviations']=="")) {
build_TR(build_wiki_A("Abbreviations","Abbreviations","Abbreviations"),"2");
build_TD(document.createTextNode(inf['abbreviations']));
new_TD.setAttribute("verticalAlign","top");
}
// ------------ Builds the FORMULA section
if (!inf['formula'] || inf['formula']=="") inf['formula']="?";
build_TR(build_wiki_A("Chemical formula","Chemical formula","Chemical formula"),"2");
new_TD.setAttribute("verticalAlign","top");
new_TD.setAttribute("whiteSpace","nowrap");
new_TD.setAttribute("width","50%");
build_TD("");
new_TD.innerHTML=inf['formula'];
new_TD.setAttribute("width","50%");
/* ---------------------------------------
Builds the PHYSICAL PROPERTIES header
--------------------------------------- */
build_TR(document.createTextNode("Physical properties"),"4","#F8EABA");
// ------------ Builds the MAS, DENSITY, and TEMPERATURES sections
new_TR=document.createElement("TR");
obj.appendChild(new_TR);
if (!inf['mass'] || inf['mass']=="") inf['mass']="?";
build_TD_phys("<a id='id_M'>M</a> (g/mol)","Molecular_mass","Molecular_mass","id_M");
if (!inf['density'] || inf['density']=="") inf['density']="?";
build_TD_phys("<a id='id_rho'>ρ</a> (g/mol)","Density","Density","id_rho");
if (!inf['Tm'] || inf['Tm']=="") inf['Tm']="?";
build_TD_phys("<a id='id_Tm'>T<sub><i>m</i></sub></a> (°C)","Melting_point","Melting point","id_Tm");
if (!inf['Td']) {
build_TD_phys("<a id='id_Tb'>T<sub><i>b</i></sub></a> (°C)","Boiling_point","Boiling point","id_Tb");
t_CritVal=(!inf['Tb'] || inf['Tb']=="")?'?':inf['Tb'];
}
else {
build_TD_phys("<a id='id_Td'>T<sub><i>d</i></sub></a> (°C)","Decomposition_temperature","Decomposition temperature","id_Td");
t_CritVal=(!(inf['Td']==""))?inf['Td']:'?';
}
new_TR=document.createElement("TR");
obj.appendChild(new_TR);
build_TD_phys(inf['mass']);
build_TD_phys(inf['density']);
build_TD_phys(inf['Tm']);
build_TD_phys(t_CritVal);
/* ---------------------------------------
Builds the CHEMICAL PROPERTIES header
--------------------------------------- */
build_TR(document.createTextNode("Chemical properties"),"4","#F8EABA");
// ------------ Builds the pKi section
build_acid_base("pI","Isoelectric_point","Isoelectric point","p<i>I</i></a>");
// ------------ Builds the pKa section
build_acid_base("pKa","Acid_dissociation_constant","Acid dissociation constant","p<i>K</i><sub>a</sub></a>");
// ------------ Builds the H-BOND ACCEPTOR section
build_H_bond("h_bond_acceptor"," acceptors");
// ------------ Builds the H-BOND DONOR section
build_H_bond("h_bond_donor"," donors");
// ------------ Builds the TAUTOMERS section
if (inf['tautomers'] && !(inf['tautomers']=="")) {
build_TR(build_wiki_A("Tautomers","Tautomer","Tautomers"),"2");
build_TD(document.createTextNode(inf['tautomers']));
}
/* ---------------------------------------
Builds the MISCELLANEOUS header
--------------------------------------- */
build_TR(document.createTextNode("Miscellaneous"),"4","#F8EABA");
// ------------ Builds the CAS section
if (!inf['CAS'] || inf['CAS']=="") inf['CAS']="?";
build_TR(build_wiki_A("CAS_registry_number","CAS registry number","CAS"),"2");
build_TD(build_ref_A(inf['CAS']));
// ------------ Builds the EINECS section
if (inf['EINECS'] && !(inf['EINECS']=="")) {
build_TR(build_wiki_A("EINECS_number","EINECS","EINECS"),"2");
build_TD(document.createTextNode(inf['EINECS']));
}
// ------------ Builds the PubChem section
if (!inf['PubChem'] || inf['PubChem']=="") inf['PubChem']="?";
build_TR(build_wiki_A("PubChem","PubChem","PubChem"),"2");
build_TD(build_ref_A(inf['PubChem']));
/* ------------ Builds the SMILES section
if (!inf['SMILES'] || inf['SMILES']=="") inf['SMILES']="?";
build_TR(build_wiki_A("SMILES","SMILES","SMILES"),"4");
build_TR(document.createTextNode(inf['SMILES']),"4");
*/
}
function build_search_form() {
obj=document.getElementById("p-search");
obj.firstChild.nextSibling.firstChild.innerHTML="Wiki search";
obj=obj.parentNode;
obj=document.getElementById("p-tb");
new_DIV=document.createElement("DIV");
new_DIV.className="portlet";
new_DIV.setAttribute("id","molbio-search");
obj.parentNode.insertBefore(new_DIV,obj);
new_H5=document.createElement("H5");
new_DIV.appendChild(new_H5);
new_LABEL=document.createElement("LABEL");
new_Text=document.createTextNode("mol-bio search");
new_LABEL.appendChild(new_Text);
new_H5.appendChild(new_LABEL);
new_Elem=document.createElement("DIV");
new_DIV.appendChild(new_Elem);
new_Elem.className="pBody";
new_FORM=document.createElement("FORM");
new_Elem.appendChild(new_FORM);
new_FORM.setAttribute("id","searchabbrev");
new_FORM.setAttribute("action","http://www.molbiology.com/search.php");
new_FORM.setAttribute("method","post");
new_INPUT=document.createElement("INPUT");
new_FORM.appendChild(new_INPUT);
new_INPUT.setAttribute("name","abbrev");
new_INPUT.setAttribute("type","text");
new_INPUT.setAttribute("size","14");
new_INPUT.setAttribute("maxlength","100");
new_BR=document.createElement("BR");
new_FORM.appendChild(new_BR);
new_SELECT=document.createElement("SELECT");
new_FORM.appendChild(new_SELECT);
new_SELECT.setAttribute("name","categ");
new_SELECT.style.align="center";
new_SELECT.style.margin="2px";
i_L=opt_value.length;
for (i=0; i<i_L; i++) {
new_OPTION=document.createElement("OPTION");
new_SELECT.appendChild(new_OPTION);
new_OPTION.value=opt_value[i];
new_Text=document.createTextNode(opt_text[i]);
new_OPTION.appendChild(new_Text);
}
new_BR=document.createElement("BR");
new_FORM.appendChild(new_BR);
new_INPUT=document.createElement("INPUT");
new_FORM.appendChild(new_INPUT);
new_INPUT.className="searchButton";
new_INPUT.setAttribute("type","submit");
new_INPUT.setAttribute("value","Go get it!");
}
function clear_Spaces(st_old) {
i2L=st_old.length;
for (i2=0; i2<i2L; i2++) {
if (myRegExp.test(st_old.charAt(i2))) {break;}
}
for (i3=i2L; i3>i2; i3--) {
if (myRegExp.test(st_old.charAt(i3))) {break;}
}
st_new=st_old.substring(i2,(i3-(-1)));
return st_new;
}
function build_acid_base(f_acid_prop,f_a_href,f_a_title,f_a_text) {
if (inf[f_acid_prop] && !(inf[f_acid_prop]=="")) {
build_TR("","2");
code_Storage = "<a href='"+wiki+f_a_href+"' title='"+f_a_title+"'>";
code_Storage += f_a_text;
new_TD.innerHTML=code_Storage;
new_TD.style.fontWeight="bold";
build_TD("");
new_TD.innerHTML=inf[f_acid_prop];
}
}
function build_H_bond (f_h_bond,f_a_add_text) {
if (inf[f_h_bond] && !(inf[f_h_bond]=="")) {
build_TR(build_wiki_A("Hydrogen_bond","Hydrogen bond","H-bond"),"2");
new_Text=document.createTextNode(f_a_add_text);
new_TD.appendChild(new_Text);
new_TD.style.fontWeight="bold";
new_TD.style.whiteSpace="nowrap";
build_TD(document.createTextNode(inf[f_h_bond]));
}
}
function build_wiki_A(f_v_href,f_v_title,f_a_text) {
new_Text=document.createTextNode(f_a_text);
new_A=document.createElement("A");
new_A.style.fontWeight="bold";
f_v_href=wiki+f_v_href;
add_href(f_v_href,f_v_title);
return new_A;
}
function build_TD_phys(f_a_text,f_a_href,f_a_title,f_a_id) {
new_TD=document.createElement("TD");
new_TR.appendChild(new_TD);
new_TD.setAttribute("bgColor","#FFFFFF");
new_TD.style.textAlign="center";
new_TD.innerHTML=f_a_text;
if (f_a_href) {
new_TD.setAttribute("verticalAlign","top");
new_TD.setAttribute("width","25%");
new_A=document.getElementById(f_a_id);
v_href=wiki+f_a_href;
new_A.setAttribute("href",v_href);
new_A.title=f_a_title;
new_A.style.fontWeight="bold";
}
}
function build_ref_A(f_v_num) {
new_Text=document.createTextNode(f_v_num);
if (!(f_v_num=="?")) {
new_A=document.createElement("A");
new_A.className="external text";
new_A.setAttribute("id",v_id);
if (f_v_num.indexOf("-")>0) {
var regExpNum=/\d/; vr_Str=""; i_L=f_v_num.length;
for (i=0; i<i_L; i++) {
if (regExpNum.test(f_v_num.charAt(i))) {vr_Str += ("" + f_v_num.charAt(i));}
}
i_L=vr_Str.length;
for (i=i_L; i<9; i++) {vr_Str = "0" + vr_Str;}
v_title="CAS_"+vr_Str;
v_href="http://chem.sis.nlm.nih.gov/chemidplus/ProxyServlet?objectHandle=DBMaint&";
v_href +="actionHandle=default&nextPage=jsp/chemidlite/ResultScreen.jsp&";
v_href +="TXTSUPERLISTID="+vr_Str;
}
else {
v_title="PubChem_"+f_v_num;
v_href="http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?cid="+f_v_num;
}
add_href(v_href,v_title);
}
else new_A=document.createTextNode(f_v_num);
return new_A;
}
function add_href(f_v_href,f_v_title) {
new_A.setAttribute("href",f_v_href);
new_A.title=f_v_title;
new_A.appendChild(new_Text);
}
function build_TR(f_any_Element,f_td_colspan,f_td_bgColor){
num_colSPan=f_td_colspan;
new_TR=document.createElement("TR");
build_TD(f_any_Element,f_td_bgColor);
obj.appendChild(new_TR);
}
function build_TD(f_any_Element,f_td_bgColor) {
new_TD=document.createElement("TD");
new_TR.appendChild(new_TD);
if (f_any_Element) new_TD.appendChild(f_any_Element);
new_TD.setAttribute("colSpan",num_colSPan);
if (f_td_bgColor) {
new_TD.setAttribute("bgColor",f_td_bgColor);
new_TD.style.fontWeight="bold";
new_TD.style.textAlign="center";
}
else new_TD.setAttribute("bgColor","#FFFFFF");
}
check_ForDiv();
//</pre>