michael@0: /* -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: function findBody(node) michael@0: { michael@0: if (node.nodeType != Node.ELEMENT_NODE) { michael@0: return null; michael@0: } michael@0: var children = node.childNodes; michael@0: if (children == null) { michael@0: return null; michael@0: } michael@0: var length = children.length; michael@0: var child = null; michael@0: var count = 0; michael@0: while (count < length) { michael@0: child = children[count]; michael@0: if (child.tagName == "BODY") { michael@0: dump("BODY found"); michael@0: return child; michael@0: } michael@0: var body = findBody(child); michael@0: if (null != body) { michael@0: return body; michael@0: } michael@0: count++; michael@0: } michael@0: return null; michael@0: } michael@0: michael@0: // Given the body element, find the first table element michael@0: function findTable(body) michael@0: { michael@0: // XXX A better way to do this would be to use getElementsByTagName(), but michael@0: // it isn't implemented yet... michael@0: var children = body.childNodes michael@0: if (children == null) { michael@0: return null; michael@0: } michael@0: var length = children.length; michael@0: var child = null; michael@0: var count = 0; michael@0: while (count < length) { michael@0: child = children[count]; michael@0: if (child.nodeType == Node.ELEMENT_NODE) { michael@0: if (child.tagName == "TABLE") { michael@0: dump("TABLE found"); michael@0: break; michael@0: } michael@0: } michael@0: count++; michael@0: } michael@0: michael@0: return child; michael@0: } michael@0: michael@0: // Change the table's caption michael@0: function changeCaption(table) michael@0: { michael@0: // Get the first element. This is the caption (maybe). We really should michael@0: // check... michael@0: var caption = table.firstChild michael@0: michael@0: // Get the caption text michael@0: var text = caption.firstChild michael@0: michael@0: // Append some text michael@0: text.append(" NEW TEXT") michael@0: } michael@0: michael@0: changeCaption(findTable(findBody(document.documentElement))) michael@0: