Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· OpenAIHugging Face Arena Human Preference 55K

Js code for replacing some words in whatsapp web

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with gpt-3.5-turbo-1106’s answer.
  1. User

    Js code for replacing some words in whatsapp web

  2. Assistant

    To replace some words in WhatsApp Web using JavaScript, you can use the replace() method. Here's an example code snippet:

    // Get the message container element
    var messageContainer = document.querySelector('.message-container');
    
    // Get all the messages inside the container
    var messages = messageContainer.querySelectorAll('.message-in');
    
    // Iterate through each message
    messages.forEach(function(message) {
      // Get the message text
      var messageText = message.innerText;
    
      // Replace specific words using the replace() method
      var modifiedMessageText = messageText.replace('word1', 'replacement1')
                                           .replace('word2', 'replacement2');
    
      // Update the message text with the modified one
      message.innerText = modifiedMessageText;
    });
    

    In the above code, we first select the message container element using querySelector(). Then, we select all the messages inside the container using querySelectorAll(). We iterate through each message using forEach() and get the inner text of the message using innerText. We then use the replace() method to replace specific words with their replacements. Finally, we update the message text with the modified one by assigning it to innerText.

    Note: This code assumes that you have already logged in to WhatsApp Web and the messages are visible on the screen.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.