User:Equazcion/DynaThank.js
if (mw.config.get('wgAction') == 'history'){
// Append the toggle link
$('#histlegend hr')
.before(' · ' +
'' +
'Thank a user' +
'');
// Iterate through the History lines and hide the thank links, also remove its displayed pipe separator (|)
$('ul#pagehistory li').each(function(){
if ($(this).find('.mw-thanks-thank-link').length > 0){
$(this).find('.mw-thanks-thank-link').attr('hidden','').css('color','#910300');
$(this).contents().filter(function(){
return this.nodeType != 1 && $.trim($(this).text()) != '';
}).slice(-2, -1).replaceWith('');
}
});
// Define the animation that plays when toggling to momentarily highlight lines where thank is being displayed
function flash(obj){
obj.css('transition','');
obj.css('background','#FFF2F2');
setTimeout(function(){
obj.css('transition','background-color 500ms ease-out');
setTimeout(function(){
obj.css('background','');
setTimeout(function(){
obj.css('transition','');
},500);
},50);
},50);
}
// Set the toggle link click function
$('.dynathank').click(function(){
if ($('.dynathank').hasClass('dtoff')){
$('.dynathank').removeClass('dtoff');
// Iterate through the History lines, displaying the thank links and re-inserting their pipe separators (|)
$('ul#pagehistory li').each(function(){
if ($(this).find('.mw-thanks-thank-link').length > 0){
flash($(this));
$(this).find('.mw-thanks-thank-link').before(' | ');
$(this).find('.mw-thanks-thank-link').fadeIn(200);
}
});
} else {
$('.dynathank').addClass('dtoff');
// Iterate through the History lines, hiding the thank links and removing their pipe separators (|)
$('ul#pagehistory li').each(function(){
if ($(this).find('.mw-thanks-thank-link').length > 0){
flash($(this));
$(this).find('.mw-thanks-thank-link').fadeOut(200, function(){
$(this).parent().contents().filter(function(){
return this.nodeType != 1 && $.trim($(this).text()) != '';
}).slice(-2, -1).replaceWith('');
});
}
});
}
});
}
/* Thank link creation code (for use with li.each), would become useful if history thank links are removed in MediaWiki:
var rev = $(this).find('input:first').attr('value');
$(this).find('span.mw-history-undo').after(' | thank');
- /