User:Equazcion/DynaThank.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
This user script seems to have a documentation page at User:Equazcion/DynaThank. |
if (mw.config.get('wgAction') == 'history'){
// Append the toggle link
$('#histlegend hr')
.before(' <b>·</b> ' +
'<span style="white-space:nowrap;">' +
'<a class="dynathank dtoff plainlinks" style="color:#910300" href="#bzzdf">Thank a user</a>' +
'</span>');
// 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('<span class="dynathanks" hidden="hidden"> | <a class="mw-thanks-thank-link" data-revision-id="' +
rev + '" title="Send a thank you notification to this user" href="#">thank</a></span>');
*/