# “Clear all messages” function in Chat

Currently it is possible to clear all messages with the scriptlet

javascript:void(\$('#chat').empty())


but I prefer having a specific in-page button or command (e.g. /clear).

(Added): It could look like this:

and would allow users to get rid of things they don't care for (e.g., funny gifs they don't find funny) without resorting to flags or arguments.

-
Why would you want to remove all of the previous context of the current conversations? –  jjnguy Aug 6 '10 at 19:22

We're never to old for userscripts right?

// ==UserScript==
// @name         Clear Chat Button
// @namespace    http://your.homepage/
// @version      1.0
// @description  Nukes everything in chat
// @author       UniKitty
// @match        http://chat.stackexchange.com/rooms/*
// @match        http://chat.meta.stackexchange.com/rooms/*
// @match        http://chat.stackoverflow.com/rooms/*
// @grant        none
// ==/UserScript==

function go() {
var clearButton = document.createElement('button');
clearButton.setAttribute("class", "button");
clearButton.setAttribute("id", "clear-chat");
clearButton.innerHTML = "Clear Chat";
if (confirm('Are you sure you want to clear the messages?')) {
document.getElementById('chat').style.display = "none";
}
});

var showButton = document.createElement('button');
showButton.setAttribute("class", "button");
showButton.setAttribute("id", "show-chat");
showButton.innerHTML = "Refresh Chat";
document.getElementById('chat').style.display = "";
});

var chatButtonContainer = document.getElementById('chat-buttons');
chatButtonContainer.appendChild(clearButton);
chatButtonContainer.appendChild(showButton);
}

go();


This adds in a button to chat:

When you click it, there's a poopup asking for confirmation.

And boom! Everything is gone!

To install it, just copy the text into a file and save it as something.user.js. Then install something like greasemonkey and drag the file into firefox (or chrome). Then install the userscript!
Sound effects not included

-
To get it back, reload the page –  Uniforms For Sale Jul 7 at 14:48
Actually now just press "Refresh Chat" –  Uniforms For Sale Jul 7 at 14:59

The whole point of the chat is to show "saved state" of the room every time you enter.

If we wanted busted old statelessness, we'd use IRC, no?

-
I don't mean statelessness on the server side, but that after user has read every old messages, can clear the chat area on the client side so that it's easier to spot what's new. Think the IRC /clear command. –  kennytm Aug 7 '10 at 6:52
@kennytm the dotted line tells you this per the /faq –  Jeff Atwood Aug 7 '10 at 7:02
Except the user can't decide where the line is put. At least for me, the system often put the line too old than where I finished. –  kennytm Aug 7 '10 at 9:03
how is the line location chosen? –  lathomas64 Aug 11 '10 at 19:16
If you are used to IRC though it would be nice to have a similar feature to clear the previous posts from the browser, it doesn't need to affect other users, just clear your view. –  kamui Nov 24 '11 at 14:51
There is a damn good reason for a /clear: People posting pictures of Justin Bieber in the chat. –  ThiefMaster Jun 25 '12 at 16:21