// ==UserScript==
// @name           PlayThisGene
// @namespace      http://alf.hubmed.org
// @description    Convert a gene sequence to MIDI
// @include        http://www.ncbi.nlm.nih.gov/entrez/viewer.fcgi?db=nucleotide*fasta*
// ==/UserScript==

var data = document.evaluate("//div[@class='recordbody']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if (!data) return;

var form = <form xmlns="http://www.w3.org/1999/xhtml" action="http://www.doe-mbi.ucla.edu/cgi/pettit/gene2musicweb" method="POST" id="gene2music"><input xmlns="http://www.w3.org/1999/xhtml" type="hidden" name="useraddr" value="gene2music@mailinator.com"/><input xmlns="http://www.w3.org/1999/xhtml" type="hidden" name="insequence" id="insequence" value=""/><input xmlns="http://www.w3.org/1999/xhtml" type="submit" name="choice" value="Play this gene"/></form>;

data.parentNode.insertBefore((new DOMParser).parseFromString(form.toXMLString(), 'text/xml').firstChild, data);

var sequence = data.innerHTML;
sequence = sequence.replace(/^.*?\n/, "");
sequence = sequence.replace(/\n/, "");
document.getElementById('insequence').value = sequence;
