User:Sunrise/Scripts/AjaxInlineDiffs.js
Appearance
< User:Sunrise | Scripts
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:Sunrise/Scripts/AjaxInlineDiffs. |
/**
* A script that combines the Ajax watchlist
* User:Theopolisme/Scripts/ajaxWatchlist.js
* with the inline diff link script
* User:Writ Keeper/Scripts/commonHistory.js
* by Theopolisme and Writ Keeper respectively.
*/
( function ( $, mw ) {
"use strict";
function updateWatchlist () {
var $loadingIndicator = $( '.watchlistLoadingIndicator' ),
$content = $( '#mw-content-text' ),
$ajaxWatchlist = $( '#ajaxWatchlist' );
// If this is the first time we run the script, wrap everything
// after and including the watchlist form in a div with the id
// "ajaxWatchlist".
if ( $ajaxWatchlist.length === 0 ) {
$content.find( '#mw-watchlist-form' ).nextAll().addBack().wrapAll( '<div id="ajaxWatchlist"></div>' );
$ajaxWatchlist = $( '#ajaxWatchlist' );
}
// Create a new loading indicator if it doesn't already
// exist. If it already exists, just show it.
if ( $loadingIndicator.length === 0 ) {
$loadingIndicator = $( '<span>' )
.appendTo( '.firstHeading' )
.addClass( 'watchlistLoadingIndicator' )
.append(
$.createSpinner( {
size: 'medium',
type: 'inline'
} ),
' Updating watchlist...'
);
} else {
$loadingIndicator.show();
}
// Make the ajax request to actually update the watchlist
$.ajax( {
url: location.href,
dataType: 'html',
success: function ( data ) {
// If the watchlist contents have changed, update the page
// to display the new contents.
var $newContent = $( data ).find( '#mw-content-text #mw-watchlist-form' ).nextAll().addBack(); // Same selector as $ajaxWatchlist
if ( $ajaxWatchlist.text() !== $newContent.text() ) {
$ajaxWatchlist.empty().append( $newContent );
mw.hook( 'wikipage.content' ).fire( $ajaxWatchlist ); // So scripts will run on the updated content
}
$loadingIndicator.hide();
},
error: function () {
// Hide the indicator and then display an error notification
$loadingIndicator.hide();
mw.notify( 'ajaxWatchlist: Unable to automatically update watchlist.' );
},
complete: function () {
// Each time the Ajax request runs, load commonHistory.js
mw.loader.load('//en.wikipedia.org/w/index.php?title=User%3AWrit%A0Keeper%2FScripts%2FcommonHistory.js&action=raw&ctype=text/javascript');
}
} );
}
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Watchlist' ) {
// Add custom css for the loading indicator
mw.util.addCSS( '.watchlistLoadingIndicator { float: right; font-size: 12px; } ' );
// Run updateWatchlist() every 20 seconds by default (can be configured via window.watchlistUpdateFrequency)
mw.loader.using( [ 'jquery.spinner' ], function () {
setInterval( updateWatchlist, window.watchlistUpdateFrequency || 20000 );
} );
}
}( jQuery, mediaWiki ) );