User:Technical 13/SandBox/NoThanks.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:Technical 13/SandBox/NoThanks. |
/* This is the beta version of this script, for the stable version see: [[User:Technical_13/Scripts/NoThanks.js]] or use the documentation link above ↑ */
/* Diff pages */
if (wgAction != 'history') { // Haven't found what is the special setting for viewing diffs yet...
$('a.mw-thanks-thank-link').replaceWith('-⊗-');
$('div#mw-diff-ntitle1').html($('div#mw-diff-ntitle1').html().replace(' (-⊗-)', ''));
}
/* History pages */
if (wgAction == 'history') {
$('li').each(function () {
var $elem = $(this);
$elem.children('a.mw-thanks-thank-link').replaceWith('-⊗-');
// For history pages with undo links (or some other link)
// $elem.html($elem.html().replace(' | -⊗-', ''));
// For history pages with no other links
// if ($elem.children('span.comment').html().length == 0){
// $elem.children('span.mw-changeslist-separator:last').replaceWith('-⊗-');
// $elem.html($elem.html().replace(' -⊗- ', ''));
// }
// $elem.html($elem.html().replace(' (-⊗-)', ''));
});
}
var thankedHistory = {
maxHistory: 100,
load: function() {
var cookie = $.cookie( 'thanks-thanked' );
if ( cookie === null ) {
return [];
}
return unescape( cookie ).split( ',' );
},
push: function( $thankLink ) {
var saved = this.load();
saved.push( $thankLink.attr( 'data-revision-id' ) );
if ( saved.length > this.maxHistory ) { // prevent forever growing
saved = saved.slice( saved.length - this.maxHistory );
}
$.cookie( 'thanks-thanked', escape( saved.join( ',' ) ) );
}
};
$( 'a.mw-thanks-thank-link' ).click( function( e ) {
var $thankLink = $( this ), source;
e.preventDefault();
if ( mw.config.get( 'wgAction' ) === 'history' ) {
source = 'history';
} else {
source = 'diff';
}
( new mw.Api ).get( {
'action' : 'thank',
'rev' : $thankLink.attr( 'data-revision-id' ),
'source' : source,
'token' : mw.user.tokens.values.editToken
} )
.done( function( data ) {
$thankLink.before( mw.message( 'thanks-thanked', mw.user ).escaped() );
$thankLink.remove();
thankedHistory.push( $thankLink );
} )
.fail( function( errorCode, details ) {
// TODO: use something besides alert for the error messages
switch( errorCode ) {
case 'invalidrevision':
alert( mw.msg( 'thanks-error-invalidrevision' ) );
break;
case 'ratelimited':
alert( mw.msg( 'thanks-error-ratelimited' ) );
break;
default:
alert( mw.msg( 'thanks-error-undefined' ) );
}
} );
} );