Created
July 14, 2012 06:12
-
-
Save jcuffe/3109650 to your computer and use it in GitHub Desktop.
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
new (function(window, document, $) | |
{ | |
var cosby_tpl; | |
var macinyos = false; | |
var amiyos = false; | |
var z = 1000; | |
/** | |
* It's Cosby time. | |
*/ | |
var its_cosby_time = function() | |
{ | |
var w = cosby_tpl.clone(); | |
var i = Math.round(Math.random() * 14) + 1; | |
var img = $(new Image()); | |
img.load(function() | |
{ | |
var extra_w = 0; | |
var h4 = w.find('h4'); | |
h4.css({ | |
'padding': '2px 0', | |
'font-size': '12px', | |
'font-style': 'normal' | |
}); | |
if (macinyos) | |
{ | |
h4.css({ | |
'background': 'transparent url(http://fi.somethingawful.com/219/macinyos/window_title.png) no-repeat center left', | |
'color': '#000' | |
}); | |
h4.empty().append('<b style="background-color: #fff; margin-left: 28px; padding: 0 5px;">Cosby.jpg</b>'); | |
} | |
else if (amiyos) | |
{ | |
extra_w = 16; | |
} | |
else | |
{ | |
h4.css({ | |
'padding': '3px 8px' | |
}); | |
} | |
$('body').append(w); | |
var width = img[0].naturalWidth + extra_w; | |
var height = img[0].naturalHeight + w.find('h4').outerHeight(); | |
w.css({ | |
'left': Math.round(Math.random() * ($(window).width() - width)), | |
'top': Math.round(Math.random() * ($(window).height() - height)), | |
'width': width, | |
'height': height, | |
'z-index': z++ | |
}); | |
w.append(img); | |
w.dblclick(function() | |
{ | |
$(this).remove(); | |
}); | |
w.mousedown(function(e) | |
{ | |
var t = $(this); | |
var o = t.offset(); | |
t.data({ | |
'cx': e.pageX - o.left, | |
'cy': e.pageY - o.top | |
}); | |
t.css('z-index', z++); | |
t.addClass('dragging'); | |
e.stopPropagation(); | |
e.preventDefault(); | |
}); | |
}); | |
img.attr('draggable', 'false'); | |
img.attr('src', 'http://fi.somethingawful.com/219/cosby/' + i + '.jpg'); | |
return false; | |
}; | |
$(document).ready(function() | |
{ | |
if (window.location.pathname == '/showthread.php') | |
{ | |
var quote_bg = $('ul.postbuttons img[alt="Quote"]').first().css('background-image'); | |
macinyos = /macinyos/.test(quote_bg); | |
amiyos = /amiyos/.test(quote_bg); | |
var color = $('body').css('background-color'); | |
cosby_tpl = $('<div class="cosby bbc-block"><h4>Cosby.jpg</h4></div>'); | |
cosby_tpl.css({ | |
'background-color': color, | |
'z-index': z, | |
'position': 'fixed', | |
'top': 100, | |
'left': 100, | |
'border': '1px solid', | |
'margin': 0, | |
'user-select': 'none', | |
'-webkit-user-select': 'none', | |
'-moz-user-select': 'none', | |
'cursor': 'url("http://fi.somethingawful.com/219/cosby/pudding_cursor.png"), default' | |
}); | |
color = $('table.post').first().css('color'); | |
var tpl = $('<li><button><em>NICE!</em></button></li>'); | |
var button; | |
tpl.find('button').css({ | |
'background-color': 'transparent', | |
'border': '1px solid', | |
'border-right': '2px solid', | |
'color': color, | |
'cursor': 'pointer', | |
'height': '20px', | |
'line-height': '13px', | |
'font-size': '14px', | |
'vertical-align': 'top' | |
}); | |
$('table.post ul.postbuttons').each(function() | |
{ | |
button = tpl.clone(); | |
button.click(its_cosby_time); | |
$(this).append(button); | |
}); | |
$(window).mouseup(function(e) | |
{ | |
$('.dragging').removeClass('dragging'); | |
}); | |
$(window).mousemove(function(e) | |
{ | |
var dragging = $('.dragging').last(); | |
if (dragging.length < 1) | |
{ | |
return; | |
} | |
var newX = e.clientX - dragging.data('cx'); | |
var newY = e.clientY - dragging.data('cy'); | |
dragging.css({ | |
'left': newX, | |
'top': newY | |
}); | |
e.preventDefault(); | |
e.stopPropagation(); | |
}); | |
// Is it Cosby time? | |
var userid = /bbuserid=(\d+)/.exec(document.cookie) || 0; | |
if (userid) | |
{ | |
userid = parseInt(userid[1], 10); | |
} | |
if (userid === 155056 || Math.round(Math.random() * 200) === 0) | |
{ | |
setTimeout(its_cosby_time, 10000); | |
} | |
} | |
}); | |
})(window, document, jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment