Created
November 22, 2012 15:18
-
-
Save DEADB33F/4131661 to your computer and use it in GitHub Desktop.
Reddit.com - Highlight unread modmail.
This file contains 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 reddit.com - Highlight unread modmail | |
// @namespace v1 | |
// @include http://www.reddit.com/message/moderator/* | |
// @include http://www.reddit.com/r/*/about/message/inbox/* | |
// ==/UserScript== | |
function main() | |
{ | |
var ALL=0, UNREAD=1, | |
now = new Date().getTime(), | |
last = JSON.parse( localStorage['modmail_last_visited']||'{}' ), | |
count = 0, | |
user = reddit.logged, | |
page = localStorage['modmail_page']||ALL; | |
// Highlight unread messages | |
$('.thing.message .entry').each(function(){ | |
var thing=$(this), | |
subreddit = thing.find('.head a:last').text().slice(3,-1), | |
timestamp = new Date( thing.find('.head time').attr('datetime') ).getTime(); | |
if( timestamp > last[subreddit] ){ thing.addClass('new').css('background-color','#FFFDCC'); count++ }; | |
}); | |
// Display numer of unread messages | |
$('.menuarea') | |
.append('<span><b>'+count+'</b> - new message'+(count==1?'':'s') ) | |
.find('a').click(function(){ hideOld( this.textContent=='all'?0:1 ); return false }); | |
// Hide read messages | |
function hideOld( bool ){ | |
console.log('bool:',bool) | |
$('.menuarea li').removeClass('selected').eq(bool).addClass('selected'); | |
if( bool*1 ) $('#siteTable>.message').hide().has('.entry.new').show(); | |
else $('#siteTable>.message').show(); | |
localStorage['modmail_page'] = bool; | |
} | |
hideOld( page ); | |
// Update last read times | |
$('.correspondent.reddit').text(function(_,sr,c){last[sr.slice(3)]=now}); | |
localStorage['modmail_last_visited'] = JSON.stringify( last ); | |
} | |
// Add script to the main page scope | |
var script = document.createElement("script");script.textContent = "(" + main.toString() + ")();";document.body.appendChild( script ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment