| | |
| | | !(realName.startsWith('[') && realName.endsWith(']')) |
| | | } |
| | | |
| | | // Table body cells render stored data, so they keep the codenames from the |
| | | // source instead of being rewritten like headers, labels and placeholders. |
| | | function isInsideTableCell(node) { |
| | | const element = node && node.nodeType === 1 ? node : node && node.parentElement |
| | | if (!element || !element.closest) { |
| | | return false |
| | | } |
| | | return !!element.closest('td') |
| | | } |
| | | |
| | | function replaceAsciiCodename(value, codename, realName) { |
| | | const pattern = new RegExp('(^|[^A-Za-z0-9])' + codename + '(?=$|[^A-Za-z0-9])', 'g') |
| | | return value.replace(pattern, function (match, prefix) { |
| | |
| | | return |
| | | } |
| | | if (root.nodeType === 1) { |
| | | attributes.forEach(function (attribute) { |
| | | replaceAttribute(root, attribute) |
| | | }) |
| | | if (!isInsideTableCell(root)) { |
| | | attributes.forEach(function (attribute) { |
| | | replaceAttribute(root, attribute) |
| | | }) |
| | | } |
| | | } |
| | | root.querySelectorAll('[placeholder], [title], [aria-label]').forEach(function (element) { |
| | | if (isInsideTableCell(element)) { |
| | | return |
| | | } |
| | | attributes.forEach(function (attribute) { |
| | | replaceAttribute(element, attribute) |
| | | }) |
| | |
| | | } |
| | | |
| | | if (root.nodeType === 3) { |
| | | replaceTextNode(root) |
| | | if (!isInsideTableCell(root)) { |
| | | replaceTextNode(root) |
| | | } |
| | | return |
| | | } |
| | | |
| | |
| | | { |
| | | acceptNode: function (node) { |
| | | const parent = node.parentElement |
| | | return parent && !SKIPPED_TAGS[parent.tagName] |
| | | ? NodeFilter.FILTER_ACCEPT |
| | | : NodeFilter.FILTER_REJECT |
| | | if (!parent || SKIPPED_TAGS[parent.tagName] || isInsideTableCell(parent)) { |
| | | return NodeFilter.FILTER_REJECT |
| | | } |
| | | return NodeFilter.FILTER_ACCEPT |
| | | } |
| | | } |
| | | ) |
| | |
| | | observer = new MutationObserver(function (mutations) { |
| | | mutations.forEach(function (mutation) { |
| | | if (mutation.type === 'characterData') { |
| | | replaceTextNode(mutation.target) |
| | | if (!isInsideTableCell(mutation.target)) { |
| | | replaceTextNode(mutation.target) |
| | | } |
| | | return |
| | | } |
| | | mutation.addedNodes.forEach(function (node) { |