Skip to content

Instantly share code, notes, and snippets.

@jose-villegas
Last active October 16, 2015 21:09
Show Gist options
  • Save jose-villegas/26aab2c3d8c4fb7fa9e3 to your computer and use it in GitHub Desktop.
Save jose-villegas/26aab2c3d8c4fb7fa9e3 to your computer and use it in GitHub Desktop.
// tube favicon
(function() {
var link = document.createElement('link');
link.type = 'image/x-icon';
link.rel = 'shortcut icon';
link.href = 'http://boards.420chan.org/static/images/board_icons/b_icon_64.png';
document.getElementsByTagName('head')[0].appendChild(link);
}());
function formatUserlistItem(a) {
var e = {
name: a.data("name") || "",
rank: a.data("rank"),
profile: a.data("profile") || {
image: "",
text: ""
},
leader: a.data("leader") || !1,
icon: a.data("icon") || !1,
afk: a.data("afk") || !1
},
s = $(a.children()[1]);
s.removeClass(), s.css("font-style", ""), s.addClass(getNameColor(e.rank));
var t = e.name.replace(/[^\w-]/g, "\\$");
s.addClass("userlist-" + t), a.find(".profile-box").remove(), e.afk ? a.addClass("userlist_afk") : a.removeClass("userlist_afk"), a.data("meta") && a.data("meta").muted ? a.addClass("userlist_muted") : a.removeClass("userlist_muted"), a.data("meta") && a.data("meta").smuted ? a.addClass("userlist_smuted") : a.removeClass("userlist_smuted");
var o = null;
s.mouseenter(function(s) {
o && o.remove();
var t = s.clientY + 5,
d = s.clientX;
o = $("<div/>").addClass("profile-box linewrap").css("top", t + "px").appendTo(a), e.profile.image && $("<img/>").addClass("profile-image").attr("src", e.profile.image).appendTo(o), $("<strong/>").text(e.name).appendTo(o);
var l = a.data("meta") || {};
l.ip && ($("<br/>").appendTo(o), $("<em/>").text(l.ip).appendTo(o)), l.aliases && ($("<br/>").appendTo(o), $("<em/>").text("aliases: " + l.aliases.join(", ")).appendTo(o)), $("<hr/>").css("margin-top", "5px").css("margin-bottom", "5px").appendTo(o), $("<p/>").text(e.profile.text).appendTo(o), $("body").hasClass("synchtube") && (d -= o.outerWidth()), o.css("left", d + "px")
}), s.mousemove(function(a) {
var e = a.clientY + 5,
s = a.clientX;
$("body").hasClass("synchtube") && (s -= o.outerWidth()), o.css("left", s + "px").css("top", e + "px")
}), s.mouseleave(function() {
o.remove()
});
var d = a.children()[0];
d.innerHTML = "", e.leader && $("<span/>").addClass("glyphicon glyphicon-star-empty").appendTo(d), e.afk && (s.css("font-style", "italic"), $("<span/>").addClass("glyphicon glyphicon-time").appendTo(d)), e.icon && $("<span/>").addClass("glyphicon " + e.icon).prependTo(d)
}
///////// -------------- Enhanced Taima Chat -------------- /////////
var insertionQueryURL = 'https://cdn.rawgit.com/naugtur/insertionQuery/master/insQ.min.js';
var jsCookieURL = 'https://cdnjs.cloudflare.com/ajax/libs/js-cookie/2.0.3/js.cookie.min.js';
var mBufferModalURL = 'https://cdn.rawgit.com/jose-villegas/169bf76fd4512b514ec5/raw/599fd6e7bfdcbb9ba964f19f1cd2dbf30f8ed5cb/chat_modal.html';
// vocaroo embed code
var vocaroo = '<object type="application/x-shockwave-flash" style="width: 148px; height: 44px" ';
vocaroo += 'data="http://vocaroo.com/player.swf?playMediaID=$1&server=m1.vocaroo.com&autoplay=0">';
// button to access enhhanced chat options, appened to the chat header (top)
var mBufferButton = '<button id="mBufferButton" class="btn label pull-right pointer ';
mBufferButton += 'label-default" data-toggle="modal" data-target="#mBuffer-Settings">Settings</button>';
if (!$('#mBufferButton').length) {
$('#chatheader').append(mBufferButton);
}
// hover image link holder, initially hidden, absolute-relative to <body>
var popupDisplay = '<img id="popup-display" class="popup-imagelink" style="display:none;" src="#" />';
if (!$('#popup-display').length) {
$('body').append(popupDisplay);
}
// enhanced chat settings window modal
if (!$('#mBuffer-SettingsUI').length) {
$('body').append('<div id="mBuffer-SettingsUI"></div>');
$('#mBuffer-SettingsUI').load(mBufferModalURL);
}
var taimaEnhancedChat = function() {
// replaces [img=<source url>] with a custom macro
$("#messagebuffer div").each(function() {
// obtains the last <span> with the actual chat message
var childrenMsg = $(this).children(':last');
var currentMsg = childrenMsg.html();
var custoImg = "",
sourceURL = "";
// undefined case, mostly to ignore "connected" message
if (!childrenMsg || !currentMsg) return;
// replaces [img=<source url>] with a custom macro
if (currentMsg.match(/\[img=(.+)\]/)) {
// gotta remove the last two characters that get added to hrefs >>> "] <<<
sourceURL = childrenMsg.find('a:first').attr('href').slice(0, -2);
if ($('#imgMacroCheckbox').prop('checked')) {
custoImg = '<img class="channel-emote" src="' + sourceURL + '">';
} else {
custoImg = '<a href="' + sourceURL + '">' + sourceURL + '</a>';
}
currentMsg = currentMsg.replace(/\[img=(.+)\]/, custoImg);
childrenMsg.html(currentMsg);
// replaces [webm="<source url>"] with a custom macro for webm
} else if (currentMsg.match(/\[webm=(.+)\]/)) {
sourceURL = childrenMsg.find('a:first').attr('href').slice(0, -2);
// if enabled change for a custom macro with webm source, otherwise just the link
if ($('#webmMacroCheckbox').prop('checked')) {
custoImg = '<video class="channel-emote" autoplay controls loop muted="true" ';
custoImg += 'src="' + sourceURL + '">HTML5 Video Unsupported.</video>';
} else {
custoImg = '<a href="' + sourceURL + '">' + sourceURL + '</a>';
}
currentMsg = currentMsg.replace(/\[webm=(.+)\]/, custoImg);
childrenMsg.html(currentMsg);
}
// link enhancement options
childrenMsg.find('a').each(function() {
// vocaroo links get auto embed in chat
if ($(this).is(':contains("vocaroo")') && $('#embedVocarooCheckbox').prop('checked')) {
// extract the vocaroo id and replace it in the embed object
vocaroo_id = $(this).attr('href').split('i/')[1];
$(this).html(vocaroo.replace('$1', vocaroo_id));
// links to images show on mousehover a mini-macro equivalent with absolute positioning
} else if (/\.(?:jpg|jpeg|gif|png|bmp)$/i.test($(this).attr('href')) && $('#imgHoverCheckbox').prop('checked')) {
// on mouse hover show mini-macro with current link image
$(this).on('mouseenter', function(env) {
$('.popup-imagelink').attr('src', $(this).attr('href'));
$('.popup-imagelink').css({
left: env.pageX + 30,
top: env.pageY - 15
}).show();
$(this).on('mouseleave', function() {
$('.popup-imagelink').hide();
});
});
}
});
});
};
// cookies setup for enhanced chat menu options
$.getScript(jsCookieURL, function() {
// set cookies if they don't exist first time
if (!Cookies.get('custom_macros.allow_webm')) {
Cookies.set('custom_macros.allow_webm', false, {
expires: 365
});
$('#webmMacroCheckbox').prop('checked', false);
}
if (!Cookies.get('custom_macros.allow_images')) {
Cookies.set('custom_macros.allow_images', true, {
expires: 365
});
$('#imgMacroCheckbox').prop('checked', true);
}
if (!Cookies.get('link_options.hover_images')) {
Cookies.set('link_options.hover_images', true, {
expires: 365
});
$('#imgHoverCheckbox').prop('checked', true);
}
if (!Cookies.get('link_options.embed_vocaroo')) {
Cookies.set('link_options.embed_vocaroo', true, {
expires: 365
});
$('#embedVocarooCheckbox').prop('checked', true);
}
// store changes to cookies and show values stores to modal interface
if (Cookies.get('custom_macros.allow_webm')) {
$('#webmMacroCheckbox').on('change', function() {
Cookies.set('custom_macros.allow_webm', $(this).prop('checked'), {
expires: 365
});
});
$('#webmMacroCheckbox').prop('checked', Cookies.get('custom_macros.allow_webm') == 'true');
}
if (Cookies.get('custom_macros.allow_images')) {
$('#imgMacroCheckbox').on('change', function() {
Cookies.set('custom_macros.allow_images', $(this).prop('checked'), {
expires: 365
});
});
$('#imgMacroCheckbox').prop('checked', Cookies.get('custom_macros.allow_images') == 'true');
}
if (Cookies.get('link_options.hover_images')) {
$('#imgHoverCheckbox').on('change', function() {
Cookies.set('link_options.hover_images', $(this).prop('checked'), {
expires: 365
});
});
$('#imgHoverCheckbox').prop('checked', Cookies.get('link_options.hover_images') == 'true');
}
if (Cookies.get('link_options.embed_vocaroo')) {
$('#embedVocarooCheckbox').on('change', function() {
Cookies.set('link_options.embed_vocaroo', $(this).prop('checked'), {
expires: 365
});
});
$('#embedVocarooCheckbox').prop('checked', Cookies.get('link_options.embed_vocaroo') == 'true');
}
// execute once cookies are stored
if (Cookies.get('custom_macros.allow_webm') && Cookies.get('custom_macros.allow_images') &&
Cookies.get('link_options.hover_images') && Cookies.get('link_options.embed_vocaroo')) {
// execute on DOMReady
taimaEnhancedChat();
// on chat settings changed redo function on messagebuffer
$('#mBuffer-Settings-Close').on('click', function() {
taimaEnhancedChat();
});
// load insertion query script from naugtur, uses CSS animate for a 'Non-dom-event way to catch nodes showing up'
$.getScript(insertionQueryURL, function() {
insertionQ('#messagebuffer div').every(function(element) {
//callback on every new div element inside #messagebuffer
taimaEnhancedChat();
});
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment