Last active
March 21, 2016 02:50
-
-
Save Buildstarted/10709076 to your computer and use it in GitHub Desktop.
Ignore script for TamperMonkey
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 JabbR Script | |
// @namespace http://jabbr.buildstarted.com/ | |
// @version 0.2 | |
// @description Ignores users in a persistent basis | |
// @match https://jabbr.net/* | |
// @copyright 2012+, You | |
// @require http://code.jquery.com/jquery-latest.js | |
// ==/UserScript== | |
var ignoredUsers = []; | |
var usernames = []; | |
var rooms = []; | |
var muteAll = false; | |
if (unsafeWindow.localStorage["ignored-users"]) { | |
ignoredUsers = JSON.parse(unsafeWindow.localStorage["ignored-users"]); | |
} | |
if (unsafeWindow.localStorage["banned-users"]) { | |
usernames = JSON.parse(unsafeWindow.localStorage["banned-users"]); | |
} | |
unsafeWindow.$.connection.chat.server.updateActivity = function() { | |
var def = $.Deferred(); | |
def.resolve(); | |
return def; | |
} | |
var origChatMessageHandler = unsafeWindow.chat.ui.addChatMessage; | |
unsafeWindow.chat.ui.addChatMessage = function (message, roomName) { | |
if (rooms.indexOf(roomName) !== -1 || muteAll) { | |
console.info('message from:', message.name, 'ignored'); | |
return; | |
} | |
if (unsafeWindow.$.inArray(message.name, ignoredUsers) > -1) { | |
console.info('message from:', message.name, 'ignored'); | |
return; | |
} else { | |
origChatMessageHandler.apply(this, [message, roomName]); | |
} | |
} | |
var origAddUserHandler = unsafeWindow.$.connection.chat.client.addUser; | |
unsafeWindow.$.connection.chat.client.addUser = function (user, room, isOwner) { | |
if (unsafeWindow.$.inArray(user.Name, usernames) > -1) { | |
var newId = unsafeWindow.chat.utility.newId(); | |
var activeRoom = unsafeWindow.$.connection.chat.state.activeRoom; | |
unsafeWindow.$.connection.chat.server.send({id:newId, content:"/kick " + user.Name, room: activeRoom}); | |
return; | |
} | |
origAddUserHandler(user,room,isOwner); | |
}; | |
var origSendMessageHandler = unsafeWindow.$(unsafeWindow.chat.ui).data('events').jabbr[2].handler; | |
unsafeWindow.$(unsafeWindow.chat.ui).unbind(unsafeWindow.chat.ui.events.sendMessage); | |
unsafeWindow.$(unsafeWindow.chat.ui).bind(unsafeWindow.chat.ui.events.sendMessage, function(ev, msg, msgId, isCommand) { | |
if (msg[0] === '/') { | |
var parts = msg.substr(1).split(' '); | |
if (parts.length > 0) { | |
switch(parts[0]) { | |
case 'mute': | |
if (parts.length > 1) { | |
if (parts[1] === "all") { | |
if (muteAll) { | |
unsafeWindow.chat.ui.addNotificationToActiveRoom("Unmuting all rooms"); | |
} else { | |
unsafeWindow.chat.ui.addNotificationToActiveRoom("Muting all rooms"); | |
} | |
muteAll = !muteAll; | |
} | |
} else { | |
var room = unsafeWindow.$("li.current").attr("data-name"); | |
if (rooms.indexOf(room) !== -1) { | |
//remove | |
rooms.splice(rooms.indexOf(room), 1); | |
unsafeWindow.chat.ui.addNotificationToActiveRoom("Unmuting '" + room + "'"); | |
} else { | |
rooms.push(room); | |
unsafeWindow.chat.ui.addNotificationToActiveRoom("Muting '" + room + "'"); | |
} | |
} | |
return; | |
case 'ignore': | |
var username = parts[1]; | |
if (username[0] === '@') { | |
username = username.substring(1); | |
} | |
unsafeWindow.chat.ui.addNotificationToActiveRoom("adding '" + username + "' to ignore list"); | |
ignoredUsers.push(username); | |
unsafeWindow.localStorage["ignored-users"] = JSON.stringify(ignoredUsers); | |
return; | |
case 'unignore': | |
var username = parts[1]; | |
if (username[0] === '@') { | |
username = username.substring(1); | |
} | |
unsafeWindow.chat.ui.addNotificationToActiveRoom("removing '" + username + "' from ignore list"); | |
ignoredUsers.splice(ignoredUsers.indexOf(username), 1); | |
unsafeWindow.localStorage["ignored-users"] = JSON.stringify(ignoredUsers); | |
return; | |
case 'ignored': | |
unsafeWindow.chat.ui.addNotificationToActiveRoom("ignored users:" + ignoredUsers.join(", ")); | |
return; | |
case 'push': | |
var username = parts[1]; | |
if (username[0] === '@') { | |
username = username.substring(1); | |
} | |
unsafeWindow.chat.ui.addNotificationToActiveRoom("adding '" + username + "' from ban list"); | |
usernames.push(username); | |
unsafeWindow.localStorage["banned-users"] = JSON.stringify(usernames); | |
return; | |
case 'pop': | |
var username = parts[1]; | |
if (username[0] === '@') { | |
username = username.substring(1); | |
} | |
unsafeWindow.chat.ui.addNotificationToActiveRoom("removing '" + username + "' from ban list"); | |
usernames.splice(usernames.indexOf(username), 1); | |
unsafeWindow.localStorage["banned-users"] = JSON.stringify(usernames); | |
return; | |
case 'clear': | |
var room = unsafeWindow.$("li.current").attr("data-name"); | |
$("#messages-" + room).children().remove(); | |
return; | |
} | |
} | |
} | |
origSendMessageHandler.apply(this, [ev, msg, msgId, isCommand]); | |
}); | |
unsafeWindow.$.connection.chat.server.updateActivity = function() { | |
var def = $.Deferred(); | |
def.resolve(); | |
return def; | |
} | |
unsafeWindow.$.connection.chat.server.typing = function() { | |
var def = $.Deferred(); | |
def.resolve(); | |
return def; | |
} | |
unsafeWindow.addTweet = function (tweet) { | |
// Keep track of whether we're near the end, so we can auto-scroll once the tweet is added. | |
console.log(tweet.url); | |
var nearEnd = unsafeWindow.chat.ui.isNearTheEnd(), | |
elements = null, | |
tweetSegment = '/status/', | |
id = tweet.url.substring(tweet.url.indexOf(tweetSegment) + tweetSegment.length); | |
// Grab any elements we need to process. | |
elements = unsafeWindow.$('div.tweet_' + id) | |
// Strip the classname off, so we don't process this again if someone posts the same tweet. | |
.removeClass('tweet_' + id); | |
// Process the template, and add it in to the div. | |
unsafeWindow.$('#tweet-template').tmpl(tweet).appendTo(elements); | |
// If near the end, scroll. | |
if (nearEnd) { | |
unsafeWindow.chat.ui.scrollToBottom(); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment