Skip to content

Instantly share code, notes, and snippets.

@mattpolito
Forked from sparkertime/gist:868498
Created April 7, 2011 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattpolito/908483 to your computer and use it in GitHub Desktop.
Save mattpolito/908483 to your computer and use it in GitHub Desktop.
Senor CrankyPants
/* MrCrankyPants - block users and images from Propane!
* to use, place it in ~/Library/Application Support/Propane/unsupported/caveatPatchor.js (yes, it must be that file name)
*
* Created by ripping code off of https://gist.github.com/825404 and https://gist.github.com/310162
*/
Campfire.MrCrankyPants = Class.create({
options: {
blockedUsers: ['Abe L.', 'George W.'],
usersDisallowedToPostImages: ['Theodore R.'],
replacements: ['quack!', 'moo!', 'bark!']
},
initialize: function(chat) {
this.chat = chat;
var messages = this.chat.transcript.messages;
for (var i = 0; i < messages.length; i++) {
this.scrubMessage(messages[i]);
}
},
scrubMessage: function(message) {
this.unloadImages(message);
this.blockUsers(message);
},
blockUsers: function(message) {
if(!this.options.blockedUsers.include(message.author())) return;
message.bodyElement().innerHTML = '[USER BLOCKED] '+ this.randomMessage();
},
randomMessage: function(message) {
var min = 0;
var max = this.options.replacements.length;
var index = Math.floor(Math.random() * max);
return this.options.replacements[index];
},
unloadImages: function(message){
if(!this.options.usersDisallowedToPostImages.include(message.author())) return;
var images = message.bodyElement().select('img');
images.each( function (img) {
if(!img.hasClassName('file_icon')) {
img.replace('[IMAGE BLOCKED] ' + img.src);
}
});
var links = message.bodyElement().select('a');
links.each( function (a) {
a.classNames().each ( function(name) {a.removeClassName(name)});
});
},
onMessagesInsertedBeforeDisplay: function(messages) {
for (var i = 0; i < messages.length; i++) {
this.scrubMessage(messages[i]);
}
}
});
Campfire.Responders.push("MrCrankyPants");
window.chat.installPropaneResponder("MrCrankyPants", "mrcrankypants");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment