old_contents: var elements = document.getElementsByTagName('*');
  
  for (var i = 0; i < elements.length; i++) {
      var element = elements[i];
  
      for (var j = 0; j < element.childNodes.length; j++) {
          var node = element.childNodes[j];
  
          if (node.nodeType === 3) {
              var text = node.nodeValue;
              var replacedText = text.replace(/Brexit/gi, 'breakfast');
  
              if (replacedText !== text) {
                  element.replaceChild(document.createTextNode(replacedText), node);
              }
          }
      }
  }
new_contents: var elements = document.getElementsByTagName('*');
  
  for (var i = 0; i < elements.length; i++) {
      var element = elements[i];
  
      for (var j = 0; j < element.childNodes.length; j++) {
          var node = element.childNodes[j];
  
          if (node.nodeType === Node.TEXT_NODE) {
              var text = node.nodeValue;
              var replacedText = text.replace(/Brexit/gi, 'breakfast');
  
              if (replacedText !== text) {
                  element.replaceChild(document.createTextNode(replacedText), node);
              }
          }
      }
  }
subject: Use constant for better understandability.