Created
May 7, 2014 18:57
-
-
Save fredley/6abe0386a58a66c99f2d to your computer and use it in GitHub Desktop.
Hide chat messages containing certain words
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 Ignore | |
// @description Ignore things! | |
// @version 1.0 | |
// @include http://chat.meta.stackoverflow.com/rooms/* | |
// @include http://chat.meta.stackexchange.com/rooms/* | |
// @include http://chat.stackexchange.com/rooms/* | |
// @include http://chat.stackoverflow.com/rooms/* | |
// @include http://chat.askubuntu.com/rooms/* | |
// @run-at document-end | |
// ==/UserScript== | |
// --- INSTRUCTIONS --- | |
// Add things you would like to ignore here | |
// Search is case insensitive, by word | |
// 'MLP' matches MLP, Mlp and mlp, but not mlpfim | |
window.IGNORE_LIST = [ | |
'MLP', | |
'https://www.youtube.com/watch?v=kfVsfOSbJY0', | |
]; | |
function livequery($) { | |
/*! Copyright (c) 2010 Brandon Aaron (http://brandonaaron.net) | |
* Dual licensed under the MIT (MIT_LICENSE.txt) | |
* and GPL Version 2 (GPL_LICENSE.txt) licenses. | |
* | |
* Version: 1.1.1 | |
* Requires jQuery 1.3+ | |
* Docs: http://docs.jquery.com/Plugins/livequery | |
*/ | |
$.extend($.fn, { | |
livequery: function(type, fn, fn2) { | |
var self = this, q; | |
if ($.isFunction(type)) | |
fn2 = fn, fn = type, type = undefined; | |
$.each( $.livequery.queries, function(i, query) { | |
if ( self.selector == query.selector && self.context == query.context && | |
type == query.type && (!fn || fn.$lqguid == query.fn.$lqguid) && (!fn2 || fn2.$lqguid == query.fn2.$lqguid) ) | |
return (q = query) && false; | |
}); | |
q = q || new $.livequery(this.selector, this.context, type, fn, fn2); | |
q.stopped = false; | |
q.run(); | |
return this; | |
}, | |
expire: function(type, fn, fn2) { | |
var self = this; | |
if ($.isFunction(type)) | |
fn2 = fn, fn = type, type = undefined; | |
$.each( $.livequery.queries, function(i, query) { | |
if ( self.selector == query.selector && self.context == query.context && | |
(!type || type == query.type) && (!fn || fn.$lqguid == query.fn.$lqguid) && (!fn2 || fn2.$lqguid == query.fn2.$lqguid) && !this.stopped ) | |
$.livequery.stop(query.id); | |
}); | |
return this; | |
} | |
}); | |
$.livequery = function(selector, context, type, fn, fn2) { | |
this.selector = selector; | |
this.context = context; | |
this.type = type; | |
this.fn = fn; | |
this.fn2 = fn2; | |
this.elements = []; | |
this.stopped = false; | |
this.id = $.livequery.queries.push(this)-1; | |
fn.$lqguid = fn.$lqguid || $.livequery.guid++; | |
if (fn2) fn2.$lqguid = fn2.$lqguid || $.livequery.guid++; | |
return this; | |
}; | |
$.livequery.prototype = { | |
stop: function() { | |
var query = this; | |
if ( this.type ) | |
this.elements.unbind(this.type, this.fn); | |
else if (this.fn2) | |
this.elements.each(function(i, el) { | |
query.fn2.apply(el); | |
}); | |
this.elements = []; | |
this.stopped = true; | |
}, | |
run: function() { | |
if ( this.stopped ) return; | |
var query = this; | |
var oEls = this.elements, | |
els = $(this.selector, this.context), | |
nEls = els.not(oEls); | |
this.elements = els; | |
if (this.type) { | |
nEls.bind(this.type, this.fn); | |
if (oEls.length > 0) | |
$.each(oEls, function(i, el) { | |
if ( $.inArray(el, els) < 0 ) | |
$.event.remove(el, query.type, query.fn); | |
}); | |
} | |
else { | |
nEls.each(function() { | |
query.fn.apply(this); | |
}); | |
if ( this.fn2 && oEls.length > 0 ) | |
$.each(oEls, function(i, el) { | |
if ( $.inArray(el, els) < 0 ) | |
query.fn2.apply(el); | |
}); | |
} | |
} | |
}; | |
$.extend($.livequery, { | |
guid: 0, | |
queries: [], | |
queue: [], | |
running: false, | |
timeout: null, | |
checkQueue: function() { | |
if ( $.livequery.running && $.livequery.queue.length ) { | |
var length = $.livequery.queue.length; | |
while ( length-- ) | |
$.livequery.queries[ $.livequery.queue.shift() ].run(); | |
} | |
}, | |
pause: function() { | |
$.livequery.running = false; | |
}, | |
play: function() { | |
$.livequery.running = true; | |
$.livequery.run(); | |
}, | |
registerPlugin: function() { | |
$.each( arguments, function(i,n) { | |
if (!$.fn[n]) return; | |
var old = $.fn[n]; | |
$.fn[n] = function() { | |
var jQuery = $; | |
var r = old.apply(this, arguments); | |
jQuery.livequery.run(); | |
return r; | |
} | |
}); | |
}, | |
run: function(id) { | |
if (id != undefined) { | |
if ( $.inArray(id, $.livequery.queue) < 0 ) | |
$.livequery.queue.push( id ); | |
} | |
else | |
$.each( $.livequery.queries, function(id) { | |
if ( $.inArray(id, $.livequery.queue) < 0 ) | |
$.livequery.queue.push( id ); | |
}); | |
// Clear timeout if it already exists | |
if ($.livequery.timeout) clearTimeout($.livequery.timeout); | |
$.livequery.timeout = setTimeout($.livequery.checkQueue, 20); | |
}, | |
stop: function(id) { | |
if (id != undefined) | |
$.livequery.queries[ id ].stop(); | |
else | |
$.each( $.livequery.queries, function(id) { | |
$.livequery.queries[ id ].stop(); | |
}); | |
} | |
}); | |
$.livequery.registerPlugin('append', 'prepend', 'after', 'before', 'wrap', 'attr', 'removeAttr', 'addClass', 'removeClass', 'toggleClass', 'empty', 'remove', 'html'); | |
$(function() { $.livequery.play(); }); | |
} | |
function inject() { | |
for (var i = 0; i < arguments.length; ++i) { | |
if (typeof(arguments[i]) == 'function') { | |
var script = document.createElement('script'); | |
script.type = 'text/javascript'; | |
script.textContent = '(' + arguments[i].toString() + ')(jQuery)'; | |
document.body.appendChild(script); | |
} | |
} | |
} | |
inject(livequery, function ($) { | |
function ignore(){ | |
$('.message').each(function(){ | |
if(!$(this).hasClass('checked')){ | |
var message = $(this).find('.content').html() | |
if (message){ | |
var words = message.split(' '); | |
$(this).addClass('checked'); | |
for(var i = 0;i<words.length;i++){ | |
if(IGNORE_LIST.indexOf(words[i].toLowerCase()) > 0){ | |
console.log(words[i] + ' found, message removed'); | |
$(this).remove(); | |
return; | |
} | |
} | |
} | |
} | |
}); | |
} | |
$(document).ready(function() { | |
var tmp = IGNORE_LIST.join('~!*~').toLowerCase(); | |
IGNORE_LIST = tmp.split('~!*~'); | |
var init = setInterval(function(){ | |
if($('.message').length > 0){ | |
$('#chat .message').livequery(ignore); | |
clearInterval(init); | |
} | |
}, 500); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment