Skip to content

Instantly share code, notes, and snippets.

@fredley
Created February 24, 2015 21:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fredley/720c3b24c2674c19cacc to your computer and use it in GitHub Desktop.
Save fredley/720c3b24c2674c19cacc to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name It's Never Friday
// @description Detects links to Rebecca Black's Friday
// @version 1.0.0
// @include *://chat.meta.stackoverflow.com/rooms/*
// @include *://chat.meta.stackexchange.com/rooms/*
// @include *://chat.stackexchange.com/rooms/*
// @include *://chat.stackoverflow.com/rooms/*
// @include *://chat.askubuntu.com/rooms/*
// @run-at document-end
// ==/UserScript==
function livequery(e){e.extend(e.fn,{livequery:function(t,i,n){var s,r=this;return e.isFunction(t)&&(n=i,i=t,t=void 0),e.each(e.livequery.queries,function(e,u){return r.selector!=u.selector||r.context!=u.context||t!=u.type||i&&i.$lqguid!=u.fn.$lqguid||n&&n.$lqguid!=u.fn2.$lqguid?void 0:(s=u)&&!1}),s=s||new e.livequery(this.selector,this.context,t,i,n),s.stopped=!1,s.run(),this},expire:function(t,i,n){var s=this;return e.isFunction(t)&&(n=i,i=t,t=void 0),e.each(e.livequery.queries,function(r,u){s.selector!=u.selector||s.context!=u.context||t&&t!=u.type||i&&i.$lqguid!=u.fn.$lqguid||n&&n.$lqguid!=u.fn2.$lqguid||this.stopped||e.livequery.stop(u.id)}),this}}),e.livequery=function(t,i,n,s,r){return this.selector=t,this.context=i,this.type=n,this.fn=s,this.fn2=r,this.elements=[],this.stopped=!1,this.id=e.livequery.queries.push(this)-1,s.$lqguid=s.$lqguid||e.livequery.guid++,r&&(r.$lqguid=r.$lqguid||e.livequery.guid++),this},e.livequery.prototype={stop:function(){var e=this;this.type?this.elements.unbind(this.type,this.fn):this.fn2&&this.elements.each(function(t,i){e.fn2.apply(i)}),this.elements=[],this.stopped=!0},run:function(){if(!this.stopped){var t=this,i=this.elements,n=e(this.selector,this.context),s=n.not(i);this.elements=n,this.type?(s.bind(this.type,this.fn),i.length>0&&e.each(i,function(i,s){e.inArray(s,n)<0&&e.event.remove(s,t.type,t.fn)})):(s.each(function(){t.fn.apply(this)}),this.fn2&&i.length>0&&e.each(i,function(i,s){e.inArray(s,n)<0&&t.fn2.apply(s)}))}}},e.extend(e.livequery,{guid:0,queries:[],queue:[],running:!1,timeout:null,checkQueue:function(){if(e.livequery.running&&e.livequery.queue.length)for(var t=e.livequery.queue.length;t--;)e.livequery.queries[e.livequery.queue.shift()].run()},pause:function(){e.livequery.running=!1},play:function(){e.livequery.running=!0,e.livequery.run()},registerPlugin:function(){e.each(arguments,function(t,i){if(e.fn[i]){var n=e.fn[i];e.fn[i]=function(){var t=e,i=n.apply(this,arguments);return t.livequery.run(),i}}})},run:function(t){void 0!=t?e.inArray(t,e.livequery.queue)<0&&e.livequery.queue.push(t):e.each(e.livequery.queries,function(t){e.inArray(t,e.livequery.queue)<0&&e.livequery.queue.push(t)}),e.livequery.timeout&&clearTimeout(e.livequery.timeout),e.livequery.timeout=setTimeout(e.livequery.checkQueue,20)},stop:function(t){void 0!=t?e.livequery.queries[t].stop():e.each(e.livequery.queries,function(t){e.livequery.queries[t].stop()})}}),e.livequery.registerPlugin("append","prepend","after","before","wrap","attr","removeAttr","addClass","removeClass","toggleClass","empty","remove","html"),e(function(){e.livequery.play()})}function inject(){for(var e=0;e<arguments.length;++e)if("function"==typeof arguments[e]){var t=document.createElement("script");t.type="text/javascript",t.textContent="("+arguments[e].toString()+")(jQuery)",document.body.appendChild(t)}}window.checkFor="https://www.youtube.com/watch?v=kfVsfOSbJY0",inject(livequery,function(e){function t(t){var i=new Date;return 5==i.getDay()?void e(this).on("click",function(e){e.preventDefault(),window.location=window.checkFor}):void e.bjax({url:t.attr("href"),type:"GET",redirect:!0,success:function(i){i.responseText.indexOf("Rebecca Black")>-1?(console.log(t.attr("href")+"Looks like an RB link!"),t.css("color","#f00 !important"),t.html("CAUTION: REBECCA BLACK LINK ("+t.html()+")")):(console.log("trying "+t.attr("href")+" again"),e.bjax({url:t.attr("href"),type:"GET",success:function(e){e.responseText.indexOf("Rebecca Black")>-1&&(console.log(t.attr("href")+"Looks like an RB link!"),t.css("color","#f00 !important"),t.html("CAUTION: REBECCA BLACK LINK ("+t.html()+")"))},error:function(){console.log("fail")}}))},error:function(){console.log("fail")}})}function i(){e("li").each(function(){e(this).hasClass("checked")||(e(this).addClass("checked"),e(this).find("a").length>0&&e(this).find("a").each(function(){t(e(this))}))})}function n(){e(".message").each(function(){e(this).hasClass("checked")||(e(this).addClass("checked"),e(this).find(".content").first().find("a").length>0&&e(this).find(".content").first().find("a").each(function(){t(e(this))}))})}e.bjax=function(e){function t(e){return!s.test(e)&&/:\/\//.test(e)}var i=location.protocol,n=location.hostname,s=RegExp(i+"//"+n),r="http"+(/^https/.test(i)?"s":"")+"://query.yahooapis.com/v1/public/yql?callback=?",u="use 'http://www.datatables.org/javascript/execute.xml' as j; select * from j where code='response.object = y.rest(\"{URL}\").followRedirects(true).get();'",o="use 'http://www.datatables.org/javascript/execute.xml' as j; select * from j where code='response.object = y.rest(\"{URL}\").followRedirects(false).get();'";return function(i){var n=i.url;if(/get/i.test(i.type)&&!/json/i.test(i.dataType)&&t(n)){i.url=r,i.dataType="json";var s=i.redirect?u:o;i.data={q:s.replace("{URL}",n+(i.data?(/\?/.test(n)?"&":"?")+jQuery.param(i.data):"")),format:"xml"},!i.success&&i.complete&&(i.success=i.complete,delete i.complete),i.success=function(e){return function(t){e&&e.call(this,{res:t,responseText:(t.results[0]||"").replace(/<script[^>]+?\/>|<script(.|\s)*?\/script>/gi,"")},"success")}}(i.success)}return e.apply(this,arguments)}}(e.ajax),e(document).ready(function(){var t=setInterval(function(){e(".message").length>0&&(n(),e("#chat .message").livequery(n),e("#starred-posts li").livequery(i),clearInterval(t))},500)})});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment