HTML Comments Display

By JoeSimmons Last update Dec 30, 2008 — Installed 242 times.

Tip: Getting comments the "xpath" way

in
Subscribe to Tip: Getting comments the "xpath" way 2 posts, 2 voices



grey Scriptwright

Here's some sample code showing how you can get the html comments using xpath instead of regexp.

var htmlComments = document.evaluate(
				'//comment()', document, null,
				XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null
			);

for (var i = 0; i < htmlComments.snapshotLength; i++)
	GM_log('\nFound html comment:\n' + htmlComments.snapshotItem(i).data); // Log to console

 
JoeSimmons Script's Author

Thanks.

Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel