|
// DomChange Function |
|
var observeDOM = (function(){ |
|
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver, |
|
eventListenerSupported = window.addEventListener; |
|
|
|
return function(obj, callback){ |
|
if( MutationObserver ){ |
|
// define a new observer |
|
var obs = new MutationObserver(function(mutations, observer){ |
|
if( mutations[0].addedNodes.length || mutations[0].removedNodes.length ) |
|
callback(); |
|
}); |
|
// have the observer observe foo for changes in children |
|
obs.observe( obj, { childList:true, subtree:true }); |
|
} |
|
else if( eventListenerSupported ){ |
|
obj.addEventListener('DOMNodeInserted', callback, false); |
|
obj.addEventListener('DOMNodeRemoved', callback, false); |
|
} |
|
} |
|
})(); |
|
|
|
// Cut URL Part |
|
|
|
function cutUrl(str) { |
|
var matched = str.match(/([^/]*\/){4}/); |
|
return matched ? matched[0] : str/* or null if you wish */; |
|
} |
|
|
|
|
|
|
|
var poster_avatar, |
|
poster_avatar_big, |
|
last_reply_avatar, |
|
last_reply_avatar_med, |
|
started_by_name, |
|
last_reply_name, |
|
started_by_url, |
|
last_reply_url; |
|
|
|
|
|
//$('.topic-list thead tr').prepend('<th>Avatar</th>') |
|
|
|
function showAvatars(thisObj) { |
|
poster_avatar = $('.posters a:first-child img', thisObj).attr('src'); |
|
poster_avatar_big = poster_avatar.replace("25","80"); |
|
last_reply_avatar = $('.posters .latest img', thisObj).attr('src'); |
|
last_reply_avatar_mid = last_reply_avatar.replace("25","40"); |
|
|
|
started_by_name = $('.posters a:first-child', thisObj).data('user-card'); |
|
last_reply_name = $('.posters .latest', thisObj).data('user-card'); |
|
|
|
started_by_url = cutUrl( $('.main-link .title', thisObj).attr('href') ); |
|
last_reply_url = $('.activity a', thisObj).attr('href'); |
|
|
|
$('.main-link', thisObj).prepend('<div class="thread_thumbs"><img src="'+poster_avatar_big+'" class="thread-started-by"><img src="'+last_reply_avatar_mid+'" class="thread-last-reply"></div>'); |
|
|
|
if ($(".topic-post-badges" , thisObj).length){ |
|
$(".main-link .topic-post-badges" , thisObj).after('<div class="thread-quick-links"></div>'); |
|
} else { |
|
$(".main-link .title" , thisObj).after('<div class="thread-quick-links"></div>'); |
|
} |
|
|
|
$('.thread-quick-links', thisObj).append('<div><a href="'+started_by_url+'">Started</a> by ' + started_by_name + '</div><div> <a href="'+last_reply_url+'">Last reply</a> by ' + last_reply_name + '</div>' ) |
|
|
|
|
|
$('.topic-list-item').addClass('old-forum-loaded'); |
|
} |
|
|
|
function hideCustomTags(thisObj) { |
|
/*hide post if found any of these tags*/ |
|
var blacklist = ["audio", "photography", "video", "3d", "graphics"]; |
|
/*but show posts if included these tags (when using multiple tags) */ |
|
var whitelist = ["code","web_design","wordpress"]; |
|
|
|
var foundtags = []; |
|
|
|
$('.discourse-tag', thisObj).each(function() { |
|
foundtags.push($(this).text()); |
|
}); |
|
|
|
for (var i = 0; i < foundtags.length; i++) { |
|
if (blacklist.indexOf(foundtags[i]) > -1) { |
|
thisObj.hide(); |
|
break; |
|
} |
|
} |
|
|
|
|
|
for (var g = 0; g < foundtags.length; g++) { |
|
if (whitelist.indexOf(foundtags[g]) > -1) { |
|
thisObj.show(); |
|
break; |
|
} |
|
} |
|
|
|
} |
|
|
|
$('.topic-list-item').each(function() { |
|
showAvatars( $(this) ); |
|
hideCustomTags( $(this) ); |
|
}); |
|
|
|
|
|
observeDOM( document.getElementById('main-outlet') ,function(){ |
|
setTimeout(function(){ |
|
$('.topic-list-item').not('.old-forum-loaded').each(function() { |
|
showAvatars( $(this) ); |
|
hideCustomTags( $(this) ); |
|
}); |
|
},1000) |
|
}); |