User:Aude/geonotice.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//<source lang="JavaScript">

var notices = {

AmbassadorsDC:
{
  begin : '14 November 2010 00:00 UTC',
  end: '28 November 2010 00:00 UTC',
  corners: [ [40,-76], [37.5,-78] ],
  text: 'ZOMG!!!! there is a meetup coming up soon! You must be there!'
},

DubaiMeetup:
{
  begin : '23 November 2010 22:00 UTC',
  end : '4 December 2010 14:00 UTC',
  corners: [ [27, 57], [22, 50] ],
  text: 'Join other Wikipedians and Wikimedia Foundation Executive Director <a href="http://wikimediafoundation.org/wiki/User:Sue_Gardner">Sue Gardner</a> for a meetup in <a href="http://en.wikipedia.org/wiki/Wikipedia:Meetup/Dubai_1">Dubai</a> on 4 December!'
}

/*******************************************
 *             End of list.
 *           Edit only above!
 *
 * Format is:
 * 
 * ID:
 * { begin: 'date',
 *   end: 'date',
 *   corners: [ [lat,lon], [lat,lon] ],
 *   text: 'message'
 * }
 *
 * There should be a commas between the notices, but not after the last one.
 *
 *******************************************/
}

if (typeof(geoip) != 'undefined') {

  var now = new Date();

  for (var id in notices) {

    if (!document.cookie.match('hidegeonotice'+id+'=1')) {

      var notice = notices[id];
      if (!notice || !notice.corners) continue;
      var minlat = Math.min(notice.corners[0][0], notice.corners[1][0]);
      var maxlat = Math.max(notice.corners[0][0], notice.corners[1][0]);
      var minlon = Math.min(notice.corners[0][1], notice.corners[1][1]);
      var maxlon = Math.max(notice.corners[0][1], notice.corners[1][1]);

      if ( now.getTime() > Date.parse(notice.begin)
           && now.getTime() < Date.parse(notice.end)
           && minlat<geoip.latitude && geoip.latitude<maxlat
           && minlon<geoip.longitude && geoip.longitude<maxlon
         ) {

        insertsub = document.getElementById('contentSub');
        insertsub.innerHTML += '<div class="plainlinks" id="geonotice'+id+'" style="width:98%; margin:5px auto 0; background:transparent; text-align:left; line-height: 1.8em;"><font size="+1">'+notice.text+'</font> <small><i>[<a href="#" onClick="var date = new Date(); date.setTime(date.getTime()+8640000000);document.cookie = \'hidegeonotice'+id+'=1; expires=\' + date.toGMTString() + \'; path=/\';document.getElementById(\'geonotice'+id+'\').style.visibility = \'hidden\';return false">hide</a>]</i></small></div>';

      }

    }
  }
}


//</source>