Dare to try out the Harvest Festival 2024!?
MediaWiki:VanaTime.js: Difference between revisions
From HorizonXI Wiki
Starfox9507 (talk | contribs) No edit summary |
Starfox9507 (talk | contribs) No edit summary |
||
Line 4: | Line 4: | ||
//*************************** | //*************************** | ||
The following are valid class tags: | // Add the class tags below to incorporate current guild times | ||
page-alchemy_hours | // <b><p class="page-alchemy_hours"></p></b> | ||
page-blacksmith_hours | |||
page-bonework_hours | // The following are valid class tags: | ||
page-goldsmith_hours | // page-alchemy_hours | ||
page-cloth_hours | // page-blacksmith_hours | ||
page-wood_hours | // page-bonework_hours | ||
page-leather_hours | // page-goldsmith_hours | ||
page-fishing_hours | // page-cloth_hours | ||
page-cooking_hours | // page-wood_hours | ||
// page-leather_hours | |||
// page-fishing_hours | |||
// page-cooking_hours | |||
Revision as of 16:22, 5 November 2023
//********************************************************************* // Javascript below contributes to live Vana'diel Time listed in Sidebar // All code taken from: https://www.pyogenes.com/ffxi/timer/v2.html //*************************** // Add the class tags below to incorporate current guild times // <b><p class="page-alchemy_hours"></p></b> // The following are valid class tags: // page-alchemy_hours // page-blacksmith_hours // page-bonework_hours // page-goldsmith_hours // page-cloth_hours // page-wood_hours // page-leather_hours // page-fishing_hours // page-cooking_hours basisDate = new Date(); basisDate.setUTCFullYear(2002, 5, 23); // Set date to 2003-06-23 basisDate.setUTCHours(15, 0, 0, 0); // Set time to 15:00:00.0000 Mndate = new Date(); Mndate.setUTCFullYear(2004, 0, 25); // Set date to 2004-01-25 Mndate.setUTCHours(2, 31, 12, 0); // Set time to 02:31:12.0000 msGameDay = (24 * 60 * 60 * 1000 / 25); // milliseconds in a game day msRealDay = (24 * 60 * 60 * 1000); // milliseconds in a real day VanaDay = new Array("Firesday", "Earthsday", "Watersday", "Windsday", "Iceday", "Lightningday", "Lightsday", "Darksday"); DayColor = new Array("#FF0000", "#AAAA00", "#0000DD", "#00AA22", "#7799FF", "#AA00AA", "#AAAAAA", "#333333"); //PhaseName = new Array("Full Moon","Waning Gibbous","Last Quarter","Waning Crescent","New Moon","Waxing Crescent","First Quarter","Waxing Gibbous"); PhaseName = new Array('\u{1F315}','\u{1F316}','\u{1F317}','\u{1F318}','\u{1F311}','\u{1F312}','\u{1F313}','\u{1F314}'); function resetGameTime() { // **** Game time var now = new Date(); vanaDate = ((898 * 360 + 30) * msRealDay) + (now.getTime() - basisDate.getTime()) * 25; vYear = Math.floor(vanaDate / (360 * msRealDay)); vMon = Math.floor((vanaDate % (360 * msRealDay)) / (30 * msRealDay)) + 1; vDate = Math.floor((vanaDate % (30 * msRealDay)) / (msRealDay)) + 1; vHour = Math.floor((vanaDate % (msRealDay)) / (60 * 60 * 1000)); vMin = Math.floor((vanaDate % (60 * 60 * 1000)) / (60 * 1000)); vSec = Math.floor((vanaDate % (60 * 1000)) / 1000); vDay = Math.floor((vanaDate % (8 * msRealDay)) / (msRealDay)); if (vYear < 1000) { VanaYear = "0" + vYear; } else { VanaYear = vYear; } if (vMon < 10) { VanaMon = "0" + vMon; } else { VanaMon = vMon; } if (vDate < 10) { VanaDate = "0" + vDate; } else { VanaDate = vDate; } if (vHour < 10) { VanaHour = "0" + vHour; } else { VanaHour = vHour; } if (vMin < 10) { VanaMin = "0" + vMin; } else { VanaMin = vMin; } if (vSec < 10) { VanaSec = "0" + vSec; } else { VanaSec = vSec; } // Moon phase var timenow = new Date(); var localTime = timenow.getTime(); var moonDays = (Math.floor((localTime - Mndate.getTime()) / msGameDay)) % 84; var mnElapsedTime = (localTime - Mndate.getTime()) % msGameDay; // determine phase percentage moonpercent = - Math.round((42 - moonDays) / 42 * 100); if (moonpercent <= -94) { mnPhase = 0; optPhase = 4; toNextPhase = (3 - moonDays) * msGameDay - mnElapsedTime; toOptimalPhase = (38 - moonDays) * msGameDay - mnElapsedTime; } else if (moonpercent >= 90) { mnPhase = 0; optPhase = 4; toNextPhase = (87 - moonDays) * msGameDay - mnElapsedTime; toOptimalPhase = (38 + 84 - moonDays) * msGameDay - mnElapsedTime; } else if (moonpercent >= -93 && moonpercent <= -62) { mnPhase = 1; optPhase = 4; toNextPhase = (17 - moonDays) * msGameDay - mnElapsedTime; toOptimalPhase = (38 - moonDays) * msGameDay - mnElapsedTime; } else if (moonpercent >= -61 && moonpercent <= -41) { mnPhase = 2; optPhase = 4; toNextPhase = (25 - moonDays) * msGameDay - mnElapsedTime; toOptimalPhase = (38 - moonDays) * msGameDay - mnElapsedTime; } else if (moonpercent >= -40 && moonpercent <= -11) { mnPhase = 3; optPhase = 4; toNextPhase = (38 - moonDays) * msGameDay - mnElapsedTime; toOptimalPhase = (38 - moonDays) * msGameDay - mnElapsedTime; } else if (moonpercent >= -10 && moonpercent <= 6) { mnPhase = 4; optPhase = 0; toNextPhase = (45 - moonDays) * msGameDay - mnElapsedTime; toOptimalPhase = (80 - moonDays) * msGameDay - mnElapsedTime; } else if (moonpercent >= 7 && moonpercent <= 36) { mnPhase = 5; optPhase = 0; toNextPhase = (58 - moonDays) * msGameDay - mnElapsedTime; toOptimalPhase = (80 - moonDays) * msGameDay - mnElapsedTime; } else if (moonpercent >= 37 && moonpercent <= 56) { mnPhase = 6; optPhase = 0; toNextPhase = (66 - moonDays) * msGameDay - mnElapsedTime; toOptimalPhase = (80 - moonDays) * msGameDay - mnElapsedTime; } else if (moonpercent >= 57 && moonpercent <= 89) { mnPhase = 7; optPhase = 0; toNextPhase = (60 - moonDays) * msGameDay - mnElapsedTime; toOptimalPhase = (80 - moonDays) * msGameDay - mnElapsedTime; } mnpercent = PhaseName[mnPhase] + Math.abs(moonpercent) + "%"; if (moonpercent <= 5 && moonpercent >= -10) { mnpercent = "<FONT COLOR='#FF0000'>" + mnpercent+ "</FONT>"; } else if (moonpercent >= 90 || moonpercent <= -95) { mnpercent = "<FONT COLOR='#0000FF'>" + mnpercent+ "</FONT>"; } //nextPhase = "Next phase (" + PhaseName[(mnPhase + 1) % 8] + "): " + formatCountdown(toNextPhase); //nextOptPhase = "Next " + PhaseName[optPhase] + ": " + formatCountdown(toOptimalPhase); //draw to sidebar element VanaTime = "<div><li><b>" + VanaHour + ":" + VanaMin + "</b> ~ " + VanaYear + "-" + VanaMon + "-" + VanaDate + "</li>"; VanaTime += "<li><span style=\"font-weight: bold; font-size:14px; color:" + DayColor[vDay] + "\" >" + VanaDay[vDay] + "</span><span style=\"font-size:14px;\"> ~ " + mnpercent + "</span></li>"; VanaTime += "</div>"; alchemy_hours = guildHelper(8, 23, 6); blacksmith_hours = guildHelper(8, 23, 2); bonework_hours = guildHelper(8, 23, 3); goldsmith_hours = guildHelper(8, 23, 4); cloth_hours = guildHelper(6, 21, 0); wood_hours = guildHelper(6, 21, 0); leather_hours = guildHelper(3, 18, 4); fishing_hours = guildHelper(3, 18, 5); cooking_hours = guildHelper(5, 20, 7); // Do not alter this line. This updates sidebar text for current time document.getElementById("n-vanatime").innerHTML = VanaTime; const page_vanatime = document.getElementsByClassName("page-vanatime"); for (var i = 0; i < page_vanatime.length; i = i+1) { page_vanatime[i].textContent = VanaTime; } const alchemy_hours = document.getElementsByClassName("page-alchemy_hours"); for (var i = 0; i < page_alchemy_hours.length; i = i+1) { page_alchemy_hours[i].textContent = alchemy_hours; } const page_blacksmith_hours = document.getElementsByClassName("page-blacksmith_hours"); for (var i = 0; i < page_blacksmith_hours.length; i = i+1) { page_blacksmith_hours[i].textContent = blacksmith_hours; } const page_bonework_hours = document.getElementsByClassName("page-bonework_hours"); for (var i = 0; i < page_bonework_hours.length; i = i+1) { page_bonework_hours[i].textContent = bonework_hours; } const page_goldsmith_hours = document.getElementsByClassName("page-goldsmith_hours"); for (var i = 0; i < page_goldsmith_hours.length; i = i+1) { page_goldsmith_hours[i].textContent = goldsmith_hours; } const page_cloth_hours = document.getElementsByClassName("page-cloth_hours"); for (var i = 0; i < page_cloth_hours.length; i = i+1) { page_cloth_hours[i].textContent = cloth_hours; } const page_wood_hours = document.getElementsByClassName("page-wood_hours"); for (var i = 0; i < page_wood_hours.length; i = i+1) { page_wood_hours[i].textContent = wood_hours; } const page_leather_hours = document.getElementsByClassName("page-leather_hours"); for (var i = 0; i < page_leather_hours.length; i = i+1) { page_leather_hours[i].textContent = leather_hours; } const page_fishing_hours = document.getElementsByClassName("page-fishing_hours"); for (var i = 0; i < page_fishing_hours.length; i = i+1) { page_fishing_hours[i].textContent = fishing_hours; } const page_cooking_hours = document.getElementsByClassName("page-cooking_hours"); for (var i = 0; i < page_cooking_hours.length; i = i+1) { page_cooking_hours[i].textContent = cooking_hours; } setTimeout("resetGameTime()", 50); } function guildHelper(open, close, holiday) { var timenow = new Date(); var localTime = timenow.getTime(); var elapsedTime = (localTime - basisDate.getTime()) % msGameDay; var dayStart = localTime - elapsedTime; // this conversion factor tells us time elapsed since the game day started in milliseconds var convFactor = 60 * 60 * 1000 / 25; vanaDate = ((898 * 360 + 30) * msRealDay) + (localTime - basisDate.getTime()) * 25; vDay = Math.floor((vanaDate % (8 * msRealDay)) / (msRealDay)); open = open * convFactor; close = close * convFactor; openTime = open + dayStart; closeTime = close + dayStart; outputTxt = ""; guildCountdown = 0; if (openTime >= localTime) { guildCountdown = openTime - localTime; outputTxt2 = "Currently Closed. Open tomorrow."; outputTxt1 = "Opens in:"; } else if ((openTime < localTime) && (closeTime > localTime)) { guildCountdown = closeTime - localTime; outputTxt2 = "Currently Open for business."; outputTxt1 = "Closes in: "; } else if (closeTime <= localTime) { guildCountdown = (msGameDay - elapsedTime) + open; outputTxt2 = "Currently Closed. Open tomorrow."; outputTxt1 = "Opens in: "; } // adjust for holiday if ((holiday == vDay) && (closeTime > localTime)) { guildCountdown = (msGameDay - elapsedTime) + open; outputTxt2 = "Currently Closed for Holiday."; outputTxt1 = "Opens in: "; } else if (((vDay + 1) == holiday) && (closeTime <= localTime)) { guildCountdown = (msGameDay - elapsedTime) + open + msGameDay; outputTxt2 = "Currently Closed. Holiday tomorrow."; outputTxt1 = "Opens in: "; } return outputTxt1 + formatCountdown(guildCountdown) + ". " + outputTxt2; } function formatCountdown(varTime) { var dayLeft = varTime / msRealDay; var hourLeft = (dayLeft - Math.floor(dayLeft)) * 24; var minLeft = (hourLeft - Math.floor(hourLeft)) * 60; var secLeft = Math.floor((minLeft - Math.floor(minLeft)) * 60); var formattedTime = ''; dayLeft = Math.floor(dayLeft); hourLeft = Math.floor(hourLeft); minLeft = Math.floor(minLeft); if (minLeft < 10) {minLeft = '0' + minLeft;} if (secLeft < 10) {secLeft = '0' + secLeft;} if (dayLeft > 0) { formattedTime = dayLeft + ':'; if (hourLeft < 10) { formattedTime = formattedTime + '0' + hourLeft + ':'; } else { formattedTime = formattedTime + hourLeft + ':'; } } else if (hourLeft > 0) { formattedTime = hourLeft + ':'; } formattedTime = formattedTime + minLeft + ':' + secLeft; return formattedTime; } resetGameTime(); //*********************************************************************