MediaWiki:Common.js
Note: After saving, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/* Any JavaScript here will be loaded for all users on every page load. */ $(function () { var myElement = document.getElementById('jsexample'); function daysInYear(year) { if(year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0)) { // Leap year return 366; } else { // Not a leap year return 365; } } function dayOfYear(dn, mn, yn) { // d is a Date object var d1 = new Date(yn,0,1,12,0,0); // noon on Jan. 1 var d2 = new Date(yn,mn-1,dn,12,0,0); // noon on input date var ddiff = Math.round((d2-d1)/864e5); return ddiff+1; } function calculate () { var day = document.getElementById('day').value; var month = document.getElementById('month').value; var year = document.getElementById('year').value; var hour = document.getElementById('hour').value; var minute = document.getElementById('minute').value; var ydays = daysInYear(year); var aday = dayOfYear(day, month, year); var tmp = ((1/ydays * ( aday - 1 + hour/24 + minute/1440)) - 2323 + year/1); var stardate = 1000 * ( year/1 + (1/ydays * ( aday - 1 + hour/24 + minute/1440)) -2323 ); document.getElementById('stardate_out').innerHTML = stardate; } function calculate_out () { var stardate = document.getElementById('stardate_in').value; var tmp = stardate/1000 + 2323; var year = Math.floor(tmp); var ydays = daysInYear(year); var tmpd = (tmp - year) * ydays + 1; var aday = Math.floor(tmpd); var d1 = new Date(year,0,1,12,0,0); // noon on Jan. 1 var d2 = (aday - 1)*864e5 + d1.getTime(); var mydate = new Date(d2); var day = mydate.getDate(); var month = mydate.getMonth() + 1; var tmph = (tmpd - aday) * 24; var hour = Math.floor(tmph); var tmpz = (tmph - hour) * 60; var minute = Math.floor(tmpz); document.getElementById('year_out').innerHTML = year; document.getElementById('month_out').innerHTML = month; document.getElementById('day_out').innerHTML = day; document.getElementById('hour_out').innerHTML = hour; document.getElementById('minute_out').innerHTML = minute; } myElement.innerHTML = "Test<table><tr><td>Tag: </td><td><input type='text' id='day'></td> </tr><tr><td>Monat: </td><td><input type='text' id='month'></td><tr><td>Jahr: </td><td><input type='text' id='year'></td> </tr><tr><td>Stunde: </td><td><input type='text' id='hour'></td> </tr><tr><td>Minute: </td><td><input type='text' id='minute' onKeyUp='calculate()'> </td> <td> = <span id='stardate_out'></span></td> </tr></table>Sternzeit: <input type='text' id='stardate_in' onKeyUp='calculate_out()' > = <span id='day_out'></span>.<span id='month_out'></span>.<span id='year_out'></span>,<span id='hour_out'></span>:<span id='minute_out'></span>"; }());