User:Galobtter/scripts/WatchlistLinksNewTab.js: Difference between revisions

Content deleted Content added
+
 
(2 intermediate revisions by the same user not shown)
Line 1:
/* Make links in watchlist open in a new tab. */
$.ready.then( function main() {
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Watchlist' ) {
var prevPostRequest;
$.ready.then( function () {
var fixLinks = function () {
console.log( 'watchlish fixing starting');
// target = "_blank" means open in new context (usually new tab)
$( '.mw-changeslist a' ).each( function () {
var href = $( this'.mw-changeslist a' ).prop( 'hreftarget', '_blank' );
};
$( this ).on( 'click', function ( e ) {
 
e.preventDefault();
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Watchlist' ) {
window.open( href, '_blank' );
$.ready.then( fixLinks() );
} );
/* Rerun every time update watchlist */
$( document ).ajaxSend( function ( event, request, settings ) {
/**
* Should not update on regular pings by the watchlist checking for an update
* Wait for the next ping after a post request
* (which is involved in updating watchlist)
} );*/
if ( settings.type === 'POST' ) {
prevPostRequest = true;
return;
}
if (
prevPostRequest &&
settings.url.indexOf( 'Special:Watchlist' ) === -1 &&
settings.type === 'GET'
) {
fixLinks();
prevPostRequest = false;
}
} );
}
console.log( 'watchlish fixing completed');
}() );