Utente:Codicorumus/WWH counter.js

Da Wikinotizie, le notizie a contenuto aperto

Nota: dopo aver pubblicato, potrebbe essere necessario pulire la cache del proprio browser per vedere i cambiamenti.

  • Firefox / Safari: tieni premuto il tasto delle maiuscole Shift e fai clic su Ricarica, oppure premi Ctrl-F5 o Ctrl-R (⌘-R su Mac)
  • Google Chrome: premi Ctrl-Shift-R (⌘-Shift-R su un Mac)
  • Internet Explorer / Edge: tieni premuto il tasto Ctrl e fai clic su Aggiorna, oppure premi Ctrl-F5
  • Opera: premi Ctrl-F5.
/*
 *  data in function setOldCountersUpdate() are updated up to 16.53.23 (UTC) 3 November 2011
 *
 *  --------------------------------------------------------------------------------------------
 *   For licensing, (no)warrant and description, see the script pointed by 'nextStageScriptUrl'
 *  --------------------------------------------------------------------------------------------
 *
 */

( function scriptWrapper() {

  var
  // stage-variable values
  stage = 0,
  stageDescription = 'starting script, which also sets main-data',
  nextStageScriptUrl = 'http://it.wikinews.org/w/index.php?title=Utente:Codicorumus/WWH_counter_main.js&action=raw&ctype=text/javascript',
  // these default values are fixed at any stage, but could be patched at stage 0
  // global object : built at stage 0, retrieved at others
  Pcc,
  // global names for 'Pcc' :
  // default values are fixed at any stage, but could be patched at stage 0
  pccS, pccL,
  // stage 0 only
  info = 'This script inserts in page two tables containing \
the global and page count of signatures by country. \
However, only page count, if the global one is not available. (v.id : Codicorumus.0.9)';

  // this function is the same at any stage
  ( function setGlobalObject() {
    // stage-specific tasks are included, but the most specific must be outside

    // these default values are fixed at any stage, but could be patched at stage 0
    pccS = 'Pcc';
    pccL = 'PerCountryCounterScript';
    // fixed-value at any stage
    var uuid = '0bccbaba-2da8-4f42-9aa1-115160719149';

    var scriptUrl = ( function getScriptUrl() {

      var scripts = document.getElementsByTagName( 'script' );
      if ( scripts ) {
        for ( var i in scripts ) {

          }
      }

    } )();

    function tryNames( patch ) {

      function checkType( type, property ) {

        if ( typeof property != 'string' ) {
          return typeof window[pccSPatch] == type
          && typeof window[pccLPatch] == type;
        } else {
          return typeof window[pccSPatch][property] == type
          && typeof window[pccLPatch][property] == type;
        }

      }

      function checkValue( property, value ) {

        return checkType( typeof value, property )
        && window[pccSPatch][property] == value
        && window[pccLPatch][property] == value;

      }

      // if patch == '' tries default names

      var
      pccSPatch = pccS + patch,
      pccLPatch = pccL + patch;

      // patched names are yet unused
      if ( checkType( 'undefined' ) && stage == 0 ) return true;

      if ( checkType( 'object' ) ) {
        if ( checkValue( 'uuid', uuid ) ) {
          if ( checkValue( 'stage', stage - 1 ) ) {
            // running new stage
            return true;
          }
          // script rerunning or running wrong stage
          var errorMessage = 'PerCountryCounter script aborted : rerunning or running wrong stage.';
          console.log( errorMessage );
          throw errorMessage;
        }
      }

      // patched name not fits, try next
      return false;

    }

    if ( !tryNames( '' ) ) {
      // default global names must be patched
      for ( var patchNumber = 1; true; patchNumber++ ) {
        var patch = '_' + patchNumber;
        if ( tryNames( patch ) ) {
          pccS += patch;
          pccL += patch;
          break;
        }
      }
    }

    if ( stage == 0 ) {
      Pcc = {
        'info' : info,
        'uuid' : uuid,
        'stage' : 0,
        'stages' : [ [ stageDescription, null ] ],
        'nextStageScriptUrl' : nextStageScriptUrl
      };
      window[pccS] = window[pccL] = Pcc;
    } else {
      Pcc = window[pccS];
      Pcc.stage = stage;
      Pcc.stages.push( [ stageDescription, Pcc.nextStageScriptUrl ] );
      Pcc.nextStageScriptUrl = nextStageScriptUrl;
    }

  } )();

  // this function and/or function setOldCounters() in main script
  // must be updated before the number of new signatures could reach 5000
  // 'country name' : 781, // sets/updates number of signatures
  Pcc.OldCountersUpdate = ( function setOldCountersUpdate() {

    return {
'Afghanistan':1,
'Albania':1,
'Algeria':1,
'Argentina':14,
'Armenia':2,
'Australia':14,
'Austria':5,
'Bangladesh':1,
'Belarus':5,
'Belgien':2,
'Belgium':9,
'Bolivia':1,
'Bosnia And Herzegovina':1,
'Brazil':26,
'Bulgaria':4,
'Canada':19,
'Chile':2,
'China':9,
'Colombia':6,
'Croatia':2,
'Cyprus':1,
'Czech Republic':6,
'Denmark':8,
'Deutschland':1392,
'Dänemark':2,
'Ecuador':10,
'Egypt':7,
'El Salvador':1,
'Estonia':1,
'Europäische Union':1,
'Finland':3,
'France':27,
'French Polynesia':1,
'Georgia':1,
'Germany':85,
'Greece':4,
'Guatemala':1,
'Hong Kong':2,
'Hungary':6,
'Iceland':1,
'India':129,
'Indonesia':1,
'Iran, Islamic Republic Of':4,
'Israel':1,
'Italy':755,
'Japan':5,
'Jersey':1,
'Jordan':3,
'Kazakhstan':3,
'Kenya':3,
'Kuwait':1,
'Lao People\'s Democratic Republic':1,
'Latvia':2,
'Libyan Arab Jamahiriya':1,
'Liechtenstein':1,
'Lithuania':1,
'Luxemburg':6,
'Malaysia':2,
'Mexico':13,
'Moldova':1,
'Morocco':2,
'Nepal':1,
'Netherlands':14,
'New Zealand':1,
'Norway':5,
'Pakistan':1,
'Peru':5,
'Philippines':2,
'Poland':7,
'Portugal':5,
'Qatar':1,
'Romania':18,
'Russian Federation':40,
'RÉunion':2,
'San Marino':1,
'Saudi Arabia':1,
'Schweiz':42,
'Serbien und Montenegro':1,
'Singapore':10,
'Slovakia':1,
'Slovenia':9,
'South Africa':2,
'South Korea':17,
'Spain':17,
'Sri Lanka':1,
'Sweden':5,
'Switzerland':22,
'Syrian Arab Republic':1,
'Taiwan':2,
'Thailand':4,
'Tunisia':1,
'Turkey':8,
'UK':28,
'Ukraine':11,
'United Arab Emirates':1,
'United States':77,
'Venezuela':4,
'Viet Nam':4,
'other':3,
'Österreich':92
};

  } )();

  // given the json-like part for 'setOldCountersUpdate()', returns the text for the whole function
  Pcc.getOldCountersUpdateString = function( jsonString ) {

    return '\
  Pcc.OldCountersUpdate = ( function setOldCountersUpdate() {\n\
\n\
    return ' + jsonString + ';\n\
\n\
  } )();\n';

  }

  // next stage
  mw.loader.load( nextStageScriptUrl );

} )();