If your company uses Yammer you may be frustrated like I was that there is no way to mark multiple (or all) message in your Yammer Inbox as read. If you Google "Yammer mark all messages as read" you will quickly find others wanting to do the same thing with various solutions; many (if not all) utilizing JavaScript.
I took the JavaScript posted here and tested it out in Chrome using the JavaScript console (Ctrl+Shift+J). That worked for me for the most part except that it seemed to get into an endless loop. It would mark everything as read, but it would never stop and I would have to kill my instance of Chrome. I do have quite a bit of programming experience, but not with JavaScript and jQuery. After a few hours of tinkering I came up with this...
var numMessagesToMark = prompt("How many messages do you want to mark as read?");
var numMessagesMarked = 0;
var yamTime = 1000;
var goBack = function() {
history.back();
setTimeout(clickLink, yamTime);
}
var clickLink = function() {
var $element = jQuery('.yj-inbox-list--messages li:first a');
if (($element.length) && (numMessagesMarked < numMessagesToMark)) {
$element.click();
numMessagesMarked++;
setTimeout(goBack, yamTime);
}
}
clickLink();
It simply asks you how many messages you want to mark as read and it does so starting with the most recent. The reason I did this is that if you have more than approximately 20 unread messages Yammer will not display them all. You can expose more of them by scrolling down, finding and clicking the "More" button. You still will only be able to clear as many unread messages as are exposed. If you try to do more the JavaScript will just "read" messages that have already been read.
At the advice a co-worker of mine who is web developer I made my JavaScript into a bookmarklet. To do that I first compressed or minified my code. I am sure there are lots of tools/sites that can do this for you. I used JSCompress: Minify Javascript Online / Online JavaScript Compression. I took the result and wrapped it with "javascript:(function(){" and "})();" as shown in this example to get this...
javascript:(function(){var numMessagesToMark=prompt("How many messages do you want to mark as read?"),numMessagesMarked=0,yamTime=1e3,goBack=function(){history.back(),setTimeout(clickLink,yamTime)},clickLink=function(){var e=jQuery(".yj-inbox-list--messages li:first a");e.length&&numMessagesToMark>numMessagesMarked&&(e.click(),numMessagesMarked++,setTimeout(goBack,yamTime))};clickLink();})();
I couldn't figure out how to create the bookmarklet directly so I create some random bookmark and then I edited the Name to something descriptive and the URL to the minified JavaScript surrounded by "javascript:(function(){" and "})();".
Now I have a bookmark that when I click it I am asked how many messages I want to mark as read.
Before doing that I need to navigate to my Yammer Inbox. If I have more than 20 unread messages I need to scroll down and click the "More" button to expose more unread messages if I want to clear more that what is exposed by default.
Unfortunately, even after you have read all the items in your Yammer Inbox it will still say that you have 1 unread message. At least our installation of Yammer does.
As I said earlier, I am not a JavaScript or JQuery programmer. There are likely numerous ways to simplify and improve this. I am just sharing what worked for me and hopefully it will help you out as is or give you an idea on how you can take it further.
Enjoy,
Noel