User:Para/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.
var notices = {

WN_SFMLN:
 { begin: '1 February 2008 00:00 UTC',
   corners: [ [39.6,-128.3], [35.7,-115.8] ],
   text: 'Bay area Wikipedians may be interested in the <a href="http://lists.wikimedia.org/pipermail/wikimedia-sf/">wikimedia-sf mailing list</a>.'
 },

TEST:
 { begin: '15 March 2009 00:00 UTC',
   corners: [ [36,35], [34,32] ],
   text: 'Party at Cyprus? Join us!'
 },

NYC:
 { begin: '15 March 2009 00:00 UTC',
   corners: [ [42,-76], [40,-72] ],
   text: 'Wikipedia Takes the Bronx Zoo!'
 }
 

/*******************************************
 *             End of list.
 *           Edit only above!
 *
 * Format is:
 * 
 * ID:
 * { begin: 'date',
 *   corners: [ [lat,lon], [lat,lon] ],
 *   text: 'message'
 * }
 *
 * Don't forget the comma between notices!
 *
 *******************************************/
}


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

  var now = new Date();

  for (var id in notices) {

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

      var notice = notices[id];
      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)
           && minlat<geoip.latitude && geoip.latitude<maxlat
           && minlon<geoip.longitude && geoip.longitude<maxlat
         ) {

        insertsub = document.getElementById('contentSub');
        insertsub.innerHTML += '<div class="plainlinks" id="geonotice'+id+'" style="width:98%; margin:5px auto 0; background:transparent; text-align:right"><font size="+1" color="#000">'+notice.text+'</font><br/><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></div>';

      }

    }
  }
}