Sunday, September 22, 2013

[Tutorial] How to mark all channels as read and clear backlog from view on IRC Cloud

IRC Cloud, still in beta, is a BNC service for IRC that keeps you connected from your browser and mobile devices. IRC Cloud, despite in beta, has grown to over 14,000 users and continues to grow every day as existing users send invites to their friends and people request an invite from their website.

This post pertains to the web app specifically, as it involves JavaScript. Although not relevant, the Android and iOS are natively coded and use IRC Cloud's API instead of using a web frame.
How to mark all channels as 'read'
On IRC Cloud, unless you modify the options for that channel or server window, it will notify you of unreal messages or otherwise activity. For channels that you are not active in, or don't wish to be bugged about activity all the time, you can click Options -> Track unread messages.

However, for channels that you do pay attention to and wish to mark as read without actually visiting the channel, the following JavaScript command will allow you to mark all channels as read without actually visiting them:
SESSION.buffers.each(function (b) { b.setLastSeen(b.messages.last()) })
How to clear the backlog from the browser's memory
At the time of this writing, IRC Cloud hasn't actually add a built-in way for automatically clearing out the old backlog from your browser's memory. The only way to clear it currently is to refresh the page, but with this nifty command you can clear the backlog for the currently selected channel.
$(cbv().scroll.log.el).empty()
After entering this command, your backlog should magically disappear. The actual real backlog won't disappear from IRC Cloud itself, but it will disappear from your browser window. However, if you have new backlog fill up your window enough to make the scroll bar appear, you can scroll up and your previously cleared backlog will be fetched and will appear again. There isn't much desire to do this though if your goal is to clear backlog from memory.

How to enter these commands
Now that I've shown you the commands, knowing how to enter them would be desired. To enter these commands, your browser window or tab that contains the IRC Cloud web app must be in your active view and you must open your web inspector and click the "Console" tab. Then you can simply copy and paste the commands and press enter. A popular way to open up your browser's web inspector is to right click on the IRC Cloud page and choose "Inspect Element".

JavaScript Bookmarks
You can also add these commands on your bookmarks bar in the form of a JavaScript bookmark. Basically, when the IRC Cloud tab/window is active and you click the bookmark, the JavaScript will be launched into the console.

To make a JavaScript bookmark, simply add a bookmark with javascript: attached in front of a command.

For example, on Chrome I would click the star button on the URL bar and add a bookmark as usual. I would then edit that bookmark by changing the title of it and changing the URL to:
javascript:<command>
So here are the two JavaScript commands that I discussed, in bookmark form:
javascript:SESSION.buffers.each(function (b) { b.setLastSeen(b.messages.last()) })
javascript:$(cbv().scroll.log.el).empty()
Note
Now that I have explained the commands, I must put a little disclaimer. Although IRC Cloud is fairly stable despite being in a beta state, the code for the web app can change at any time and therefor these commands can cease to work at any time. If these commands do change and I am able to provide a fix, I will.

In addition, these commands are not officially supported. Using these commands could potentially make IRC Cloud hang, although in my testing the commands ran just fine. If something does hang, don't say that I didn't warn you.

Conclusion
Hope you enjoyed the tutorial on making IRC Cloud a better experience by using power user commands. Although the commands could break while IRC Cloud is in beta, I think they are very useful and believe that others will find them useful too.