[Greasemonkey] GM closing tags automatically?

Ryan Forsythe ryan at flamingweasel.com
Fri Sep 16 01:45:04 EDT 2005


I'm having an odd issue with the output from a GM script, and I'm  
unsure where to begin debugging. I've got a function which builds  
rows of a table, which then get collected together and used as a  
replacement on the document.body.innerHTML. The problem is something  
is "correcting" the HTML getting output by this function. So my code  
looks something like this:

function row(stuff) {
     var buff = '<tr><td>rowname</td><td>'
     for (;;;) {
         //stuff processing & output
     }
     buff += '</td>';
     return buff
}

function main(txt) {
     // lots of stuff here

     new_section = '<table>';
     new_section += row(a);
     new_section += row(b);
     new_section += '</table>';

     return txt.replace(nasty_re, new_section);
}

window.addEventListener('load',
             function() {
               document.body.innerHTML = main(document.body.innerHTML);
             },
             true);

But what gets output (ie, what I see when I highlight the replaced  
section and view selection source in FF) is not only not what I  
expected (eg, multiple <table>s instead of just one), but includes  
tags I don't have in my code at all, like <tbody>. Is this something  
others have seen with GM? Is there a better way to construct a hunk  
of html to sidestep this issue?

Thanks in advance,
Ryan


More information about the Greasemonkey mailing list