User:SoledadKabocha/contentLinkRedirectNo.js

function addRedirectNoSub( idToExamine, throwErrorIfNotFound, requireRedirectClass ) { var a = document.getElementById( idToExamine ); if( !a ) { if ( throwErrorIfNotFound ) { throw new Error( 'CLRN failed to find id ' + idToExamine ); }   else return; } a = a.getElementsByTagName( 'A' ); if( a.length === 0 ) return;

for ( var i = 0; i < a.length; i++ ) { var curLink = $( a[i] ); // 'redirect' class is added by linkclassifier. // Others are built-in MediaWiki features. if ( !requireRedirectClass || curLink.hasClass( 'mw-redirect' ) || curLink.hasClass( 'redirect' )                              || curLink.hasClass( 'allpagesredirect' )                               || curLink.hasClass( 'redirect-in-category' )                               || curLink.hasClass( 'watchlistredir' ) )                             { if ( curLink.hasClass( 'external' ) || curLink.hasClass( 'extiw' ) ) continue; var shouldApplyRN = true; if ( $.isArray( window.CLRNclassList ) ) { for ( var j = 0; j < window.CLRNclassList.length; j++ ) { if ( curLink.hasClass( window.CLRNclassList[j] ) ) { shouldApplyRN = false; break; }       }        if ( window.CLRNlistIsWhitelist === true ) shouldApplyRN = !shouldApplyRN; }     if ( !shouldApplyRN ) continue;

var origHref = curLink.attr( 'href' ); if ( origHref ) { if ( /([\?&](action|diff|oldid|redirect)=|Special(:|%3[Aa]))/.test( origHref ) ) continue; var anchorPos = origHref.indexOf( '#' ); var fixedHref = origHref; if ( anchorPos != -1 ) { if ( window.CLRNstripAnchors === true ) { fixedHref = origHref.substr( 0, anchorPos ); }         else { continue; } }       if ( origHref.indexOf( '%3F' ) != -1 ) { // If page title has a question mark, we must convert pretty URLs to long URLs; // otherwise the server will misinterpret the existing question mark. // XXX: There should be a mw.util function to do this job... var wAP = mw.config.get( 'wgArticlePath' ).replace( '$1', '' ); var wSP = mw.config.get( 'wgScript'     ) + '?title=';

fixedHref = fixedHref.replace( wAP, wSP ); }       fixedHref += ( fixedHref.indexOf( '?' ) == -1 ? '?' : '&' ) + 'redirect=no'; curLink.attr( 'href', fixedHref ); }   }  } }

function addRedirectNo { addRedirectNoSub( 'bodyContent',        true,  true ); addRedirectNoSub( 'ca-talk',           false, false ); addRedirectNoSub( 'ca-nstab-main',     false, false ); addRedirectNoSub( 'ca-nstab-user',     false, false ); addRedirectNoSub( 'ca-nstab-project',  false, false ); addRedirectNoSub( 'ca-nstab-image',    false, false ); addRedirectNoSub( 'ca-nstab-mediawiki', false, false ); addRedirectNoSub( 'ca-nstab-template', false, false ); addRedirectNoSub( 'ca-nstab-help',     false, false ); addRedirectNoSub( 'ca-nstab-category', false, false ); addRedirectNoSub( 'ca-nstab-portal',   false, false );

//DIRTY HACK just because I didn't want to clutter my common.js further. //In common.js, I am adding a sepia filter as a "poor man's f.lux." //My portlets are already too cluttered, so this lets me run this script //to remove the sepia effect as well. $( '#content' ).addClass( 'disablesepia' ); }

if ( !window.CLRNNoAutoStart ) { $( addRedirectNo ); }