Last active
August 29, 2015 14:26
-
-
Save nchaly/034d3393a9159571f126 to your computer and use it in GitHub Desktop.
A script to mark all yammer inbox items as read
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Mark All Read | |
| // @namespace Yammer | |
| // @description Marks all incoming messages as read | |
| // @include https://www.yammer.com/* | |
| // @version 1 | |
| // @grant none | |
| // ==/UserScript== | |
| var limit = 300; | |
| var marked = 0; | |
| var goBack = function() { | |
| history.back(); | |
| if(marked >= limit) { | |
| console.log('Limit reached: ' + limit); | |
| marked = 0; | |
| return; | |
| } | |
| setTimeout(clickNextIncomingMessageLink, 250); | |
| } | |
| // Clicks incoming message. This opens | |
| // the conversation page, so we should go back then. | |
| var clickNextIncomingMessageLink = function() { | |
| var $element = jQuery('ul.yj-inbox-list--messages li.yj-unread-item:first a'); | |
| var $moreLink = jQuery('#morebutton button'); | |
| if ($element.length) { | |
| $element.click(); | |
| marked += 1; | |
| setTimeout(goBack, 250); | |
| } | |
| else if ($moreLink.length) { | |
| $moreLink.click(); | |
| setTimeout(clickNextIncomingMessageLink, 1500); | |
| } | |
| } | |
| $(function(){setTimeout(function(){ | |
| var btn = $('<a id="mcMarkAllAsRead" style="font-size:small;" href="javascript://">' + | |
| '<span>∀</span></a>'); | |
| var c = $("li[data-qaid='inbox_button'] a"); | |
| if(c) { | |
| setTimeout(function(){ | |
| btn.insertAfter(c); | |
| btn.click(function(){ | |
| var inboxTag = '#/inbox/index'; | |
| var url = window.location.href; | |
| var i = url.indexOf('#'); | |
| i = i < 0 ? url.length : i; | |
| var yammer = url.substr(0, i) | |
| window.location.href = yammer + inboxTag; | |
| setTimeout(clickNextIncomingMessageLink, 1000); | |
| } | |
| ); | |
| console.log('mc-added'); | |
| }, 500); | |
| } | |
| else { | |
| console.log('mc-err'); | |
| throw new Error("Cannot find a place to put a 'mark all as read' button."); | |
| } | |
| }, 3000);}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment