Opmerking: na het publiceren is het wellicht nodig uw browsercache te legen om de veranderingen te zien.

  • Firefox / Safari: houd Shift ingedrukt terwijl u:je op Vernieuwen klikt of druk op Ctrl-F5 of Ctrl-R (⌘-Shift-R op een Mac)
  • Google Chrome: druk op Ctrl-Shift-R (⌘-Shift-R op een Mac)
  • Edge: houd Ctrl ingedrukt terwijl u:je op Vernieuwen klikt of druk op Ctrl-F5.
/*** Amsterdamconstructie linkkleuringen
 *
 * Sumurai8 - 04-12-2012
 *
 * http://nl.wikipedia.org/w/api.php?action=query&prop=links&pllimit=50&titles=Amsterdam&redirects&format=jsonfm
 * http://nl.wikipedia.org/w/api.php?action=query&titles=Amsterdam%20(doorverwijspagina)|aaasdfasdf&indexpageids&format=jsonfm
**/
function adamlink() {
  //Dit is de kleur van de adamconstructielinks
  var ADAMLINKCOLOR = "#FF00FF";

  adamlinkengine( ADAMLINKCOLOR );
}


function adamlinkengine( kleurtje, gplcontinue ) {
  var options = {
      action: 'query',
      titles: mw.config.get( 'wgPageName' ),
      generator: 'links',
      gpllimit: '50',
      format: 'json',
      redirects: ''
    };

  if( gplcontinue != undefined ) {
    options['gplcontinue'] = gplcontinue;
  }    

  $.getJSON(
    mw.config.get( 'wgScriptPath' ) + "/api.php", options,
    function( data ) {

      if( data['query'] ) {
        var titlelist = [];
        var redirects = {};
        $.each( data['query']['pages'], function( index, value ) {
          if( index >= 0 ) {
            titlelist.push( value['title'] );
          }
        } );

        //Als er redirects zijn op deze pagina, log die dan zodat we het later kunnen gebruiken
        if( data['query']['redirects'] ) {
          $.each( data['query']['redirects'], function( index, value ) {
            if( redirects[ value['to'] ] ) {
              redirects[ value['to'] ].push( value['from'] );
            }
            else {
              redirects[ value['to'] ] = [ value['from'] ];
            }
          } );
        }

        var titlelist2 = titlelist.slice( 0 );
        for( i = 0; i < titlelist.length; i++ ) {
          titlelist[ i ] = titlelist[ i ] + " (doorverwijspagina)";
        }

        $.post(
          mw.config.get( 'wgScriptPath' ) + "/api.php", {
            action: 'query',
            titles: titlelist.join( "|" ),
            format: 'json' },
          function( data2 ) {
            $.each( data2['query']['pages'], function( i, linkobj ) {
              //Als pageid bestaat, dan bestaat de pagina. We moeten de bijbehorende link een kleurtje geven.
              if( linkobj['pageid'] ) {
                var re = new RegExp( (mw.config.get( 'wgServer' ) + mw.config.get( 'wgArticlePath' )).replace( '$1', encodeURI( titlelist2[ titlelist.indexOf( linkobj['title'] ) ].replace(/ /g, '_'))).replace(/'/g, "%27" ).replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") + '(#.*)?$' );
                $.each( $('a'), function( i, val ) {
                  if( val['href'].match( re ) && titlelist2[ titlelist.indexOf( linkobj['title'] ) ] != mw.config.get('wgPageName') ) {
                    val.style.color = kleurtje;
                    if( val.classList ) {
                      val.classList.add( "adamlink" );
                    }
                  }
                } );

                //Als er redirects zijn voor deze pagina, dan kleuren we de bijbehorende redirects ook
                if( redirects[ titlelist2[ titlelist.indexOf( linkobj['title'] ) ] ] ) {
                  $.each( redirects[ titlelist2[ titlelist.indexOf( linkobj['title'] ) ] ], function( i, val ) {
                    if( !val.match( /hoofdbetekenis/g ) ) {
                      re = new RegExp( (mw.config.get( 'wgServer' ) + mw.config.get( 'wgArticlePath' )).replace( '$1', encodeURI( val.replace(/ /g, '_') ).replace(/'/g, "%27" ).replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") ) + '(#.*)?$' );
                      $.each( $('a'), function( i2, val2 ) {
                        if( val2['href'].match( re ) ) {
                          val2.style.color = kleurtje;
                          if( val2.classList ) {
                            val2.classList.add( "adamlink" );
                          }
                        }
                      } );
                    }
                  } );
                }
              }
            } );
          }
        );

        if( data['query-continue'] && data['query-continue']['links'] && data['query-continue']['links']['gplcontinue'] ) {
          adamlinkengine( kleurtje, data['query-continue']['links']['gplcontinue'] );
        }          
      }
    }
  );
}

jQuery( document ).ready( function( $ ) {
  window.setTimeout("adamlink()", 250);
} );