zzw
6 小时以前 7839e940bac9cc90fc6d8d322051d80fd7f40ec8
emergency-repair-web/src/utils/sensitive.js
@@ -12,6 +12,16 @@
    !(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) {
@@ -57,11 +67,16 @@
    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)
    })
@@ -74,7 +89,9 @@
  }
  if (root.nodeType === 3) {
    replaceTextNode(root)
    if (!isInsideTableCell(root)) {
      replaceTextNode(root)
    }
    return
  }
@@ -85,9 +102,10 @@
    {
      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
      }
    }
  )
@@ -107,7 +125,9 @@
  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) {