Created
October 31, 2017 13:02
-
-
Save dvingerh/2323f5686114305ead0203caae4c7b42 to your computer and use it in GitHub Desktop.
Useful for emote servers. Whenever there's an unread message in a guild, this script will automatically mark it as read.
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 Discord Auto Mark As Read Guilds | |
// @description Useful for emote servers. Whenever there's an unread message in a guild, this script will automatically mark it as read. | |
// @namespace Violentmonkey Scripts | |
// @grant GM_addStyle | |
// @require http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js | |
// @require https://raw.githubusercontent.com/pie6k/jquery.initialize/master/jquery.initialize.min.js | |
// @match *://discordapp.com/* | |
// | |
// ==/UserScript== | |
var ignore_guild_ids = [ | |
"210989405286957059" | |
]; | |
$(".badge").initialize( function(){ | |
jQuery.fn.simulateClick = function() { | |
return this.each(function() { | |
if('createEvent' in document) { | |
var doc = this.ownerDocument, | |
evt = doc.createEvent('MouseEvents'); | |
evt.initMouseEvent('contextmenu', true, true, doc.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null); | |
this.dispatchEvent(evt); | |
} | |
}); | |
}; | |
var guild_item = $(this).parent().find('a').eq(0); | |
var guild_id = $(guild_item).attr('href').split('/')[2]; | |
if ($.inArray(guild_id, ignore_guild_ids) === -1){ | |
$(guild_item).simulateClick('contextmenu'); | |
setTimeout(function(){ | |
var context_menu = $("div [class^='context-menu']"); | |
var mark_read_item = $(context_menu).find(".item").eq(0); | |
mark_read_item.trigger('click'); | |
$(guild_item).simulateClick('contextmenu'); | |
setTimeout(function(){ | |
context_menu = $("div [class^='context-menu']"); | |
var mute_bug_fix = $(context_menu).find(".item").eq(1); | |
$(mute_bug_fix).simulateClick('contextmenu'); | |
}, 10); | |
}, 10); | |
console.log("Unread badge was detected, marked guild with id '" + guild_id + "' as read"); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment