User:Pigsonthewing/sandbox/GeoNotice js

function geoWikiLinker (str, page, text) { text = text || page; return mw.html.element(		'a', {			href: mw.util.wikiGetlink( page ),			title: page		}, text	); } if ( Geo !== undefined ) { var now = new Date, id, notice, insertsub, minlat, maxlat, minlon, maxlon, regexForInternalLinks = /\[\[([^{|}\[\]\n]+)(?:\|(.*?))?\]\]/g; for (id in notices) { if (!document.cookie.match('hidegeonotice'+id+'=1')) { notice = notices[id]; if (!notice || !notice.corners) { continue; }     minlat = Math.min(notice.corners[0][0], notice.corners[1][0]); maxlat = Math.max(notice.corners[0][0], notice.corners[1][0]); minlon = Math.min(notice.corners[0][1], notice.corners[1][1]); 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<Geo.lat && Geo.lat<maxlat           && minlon<Geo.lon && Geo.lon<maxlon         ) { insertsub = document.getElementById('contentSub'); mw.util.addCSS( [           '#contentSub .geonotice {',                'width:98%;',                'margin:5px auto 0;',                'background:transparent;',                'text-align:left;',                'line-height:1.8em;',            '}',            '#contentSub .geonotice span {',                'font-size:170%;',            '}',            '#contentSub .geonotice small {',                'font-style:italic;',            '}'        ].join( ' ' ) ); insertsub.innerHTML += ''+ ' '+notice.text.replace( regexForInternalLinks, geoWikiLinker )+' '+ ' ['+                   'hide'+ '] ';     }    }  } }