475 lines
22 KiB
HTML
475 lines
22 KiB
HTML
<!DOCTYPE html>
|
|||
|
|
<html lang="en">
|
||
|
|
<head>
|
||
|
|
<meta charset="UTF-8">
|
||
|
|
<title>Current Local Weather Conditions (Packet Radio)</title>
|
||
|
|
<style>
|
||
|
|
* { box-sizing: border-box; }
|
||
|
|
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, monospace; background: #eef2f7; color: #222; padding: 20px; margin: 0; }
|
||
|
|
.container { max-width: 960px; margin: 0 auto; background: #fff; padding: 24px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
|
||
|
|
.header { background: #0277bd; color: white; padding: 12px; border-radius: 6px; text-align: center; margin-bottom: 18px; }
|
||
|
|
.header h2 { margin: 0; font-size: 1.3rem; letter-spacing: 1px; }
|
||
|
|
.header p { margin: 4px 0 0 0; font-size: 0.85rem; opacity: 0.9; }
|
||
|
|
fieldset { border: 1px solid #81d4fa; border-radius: 6px; padding: 14px; margin-bottom: 14px; background: #f9fdff; }
|
||
|
|
legend { font-weight: bold; padding: 0 8px; font-size: 0.85rem; color: #0277bd; }
|
||
|
|
.row { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 10px; }
|
||
|
|
.col { flex: 1; min-width: 140px; display: flex; flex-direction: column; }
|
||
|
|
.label-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
|
||
|
|
label { font-size: 0.8rem; font-weight: 600; color: #333; }
|
||
|
|
input[type="text"], select, textarea { padding: 7px 8px; font-size: 0.88rem; border: 1px solid #999; border-radius: 4px; font-family: inherit; width: 100%; }
|
||
|
|
textarea { resize: vertical; min-height: 60px; }
|
||
|
|
.btn-now { background: #4a5568; color: #fff; padding: 4px 8px; font-size: 0.72rem; border-radius: 4px; border: none; cursor: pointer; }
|
||
|
|
.btn-now:hover { background: #2d3748; }
|
||
|
|
.conditions-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; font-size: 0.82rem; margin-top: 6px; }
|
||
|
|
.actions { display: flex; gap: 10px; margin: 18px 0; }
|
||
|
|
button.main-btn { flex: 1; padding: 12px; font-size: 0.95rem; font-weight: bold; border: none; border-radius: 6px; cursor: pointer; }
|
||
|
|
.btn-generate { background: #0277bd; color: #fff; }
|
||
|
|
.btn-generate:hover { background: #014f7c; }
|
||
|
|
.btn-save { background: #5c6bc0; color: #fff; }
|
||
|
|
.btn-save:hover { background: #3f51b5; }
|
||
|
|
.btn-copy { background: #2e7d32; color: #fff; }
|
||
|
|
.btn-copy:hover { background: #1b5e20; }
|
||
|
|
.btn-clear { background: #c62828; color: #fff; flex: 0.35; }
|
||
|
|
pre { background: #181c20; color: #39ff14; padding: 14px; border-radius: 6px; overflow-x: auto; font-family: "Courier New", Courier, monospace; font-size: 0.82rem; line-height: 1.32; min-height: 150px; }
|
||
|
|
.nav-bar { margin-bottom: 12px; font-size: 0.85rem; }
|
||
|
|
.nav-bar a { color: #0277bd; text-decoration: none; font-weight: bold; }
|
||
|
|
|
||
|
|
/* Modal Save Dialog Window */
|
||
|
|
.save-modal-backdrop {
|
||
|
|
display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
|
||
|
|
background: rgba(0,0,0,0.55); z-index: 99999; justify-content: center; align-items: center;
|
||
|
|
}
|
||
|
|
.save-modal-backdrop.active { display: flex; }
|
||
|
|
.save-modal-window {
|
||
|
|
background: #ffffff; padding: 24px 28px; border-radius: 10px; width: 92%; max-width: 480px;
|
||
|
|
box-shadow: 0 10px 30px rgba(0,0,0,0.3); border: 1px solid #cbd5e1; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
||
|
|
}
|
||
|
|
.save-modal-window h3 { margin: 0 0 8px 0; font-size: 1.25rem; color: #1e293b; font-weight: bold; }
|
||
|
|
.save-modal-window p { margin: 0 0 16px 0; font-size: 0.88rem; color: #64748b; line-height: 1.4; }
|
||
|
|
.save-modal-window input[type="text"] {
|
||
|
|
width: 100%; padding: 10px 12px; font-size: 0.95rem; border: 2px solid #94a3b8; border-radius: 6px;
|
||
|
|
margin-bottom: 20px; font-family: inherit; box-sizing: border-box; text-transform: none;
|
||
|
|
}
|
||
|
|
.save-modal-window input[type="text"]:focus { border-color: #2563eb; outline: none; }
|
||
|
|
.save-modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
|
||
|
|
.save-modal-btn { padding: 9px 18px; font-size: 0.9rem; font-weight: bold; border-radius: 6px; border: none; cursor: pointer; }
|
||
|
|
.save-modal-btn-confirm { background: #2563eb; color: #ffffff; }
|
||
|
|
.save-modal-btn-confirm:hover { background: #1d4ed8; }
|
||
|
|
.save-modal-btn-cancel { background: #e2e8f0; color: #334155; }
|
||
|
|
.save-modal-btn-cancel:hover { background: #cbd5e1; }
|
||
|
|
|
||
|
|
</style>
|
||
|
|
</head>
|
||
|
|
<body>
|
||
|
|
<div class="container">
|
||
|
|
<div class="nav-bar"><a href="../index.html">← Back to Packet Forms Hub</a></div>
|
||
|
|
<div class="header">
|
||
|
|
<h2>CURRENT LOCAL WEATHER CONDITIONS</h2>
|
||
|
|
<p>Winlink / Packet Radio Surface Weather Observation Form</p>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<form id="localWxForm" onsubmit="event.preventDefault(); return false;">
|
||
|
|
<fieldset>
|
||
|
|
<legend>1-7. STATION & LOCATION INFORMATION</legend>
|
||
|
|
<div class="row">
|
||
|
|
<div class="col" style="max-width: 140px;"><label for="call">1. Callsign</label><input type="text" id="call" placeholder="N0CALL"></div>
|
||
|
|
<div class="col"><label for="repName">2. Observer Name</label><input type="text" id="repName" placeholder="Full Name"></div>
|
||
|
|
<div class="col">
|
||
|
|
<div class="label-row">
|
||
|
|
<label for="dtLocal">3. Date / Time (Local/UTC)</label>
|
||
|
|
<button type="button" class="btn-now" id="btnDateNow">Current UTC</button>
|
||
|
|
</div>
|
||
|
|
<input type="text" id="dtLocal" placeholder="YYYY-MM-DD HHMMZ">
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class="row">
|
||
|
|
<div class="col" style="flex: 2;"><label for="locName">4. Location Landmark / Address</label><input type="text" id="locName" placeholder="Street or landmark"></div>
|
||
|
|
<div class="col"><label for="city">5. City</label><input type="text" id="city"></div>
|
||
|
|
<div class="col" style="max-width: 80px;"><label for="state">6. State</label><input type="text" id="state" placeholder="TX" maxlength="2"></div>
|
||
|
|
<div class="col"><label for="county">7. County</label><input type="text" id="county"></div>
|
||
|
|
</div>
|
||
|
|
<div class="row">
|
||
|
|
<div class="col"><label for="lat">8. Latitude</label><input type="text" id="lat" placeholder="30.2672"></div>
|
||
|
|
<div class="col"><label for="lon">9. Longitude</label><input type="text" id="lon" placeholder="-97.7431"></div>
|
||
|
|
<div class="col"><label for="mgrs">10. MGRS</label><input type="text" id="mgrs"></div>
|
||
|
|
<div class="col" style="max-width: 120px;"><label for="grid">11. Grid</label><input type="text" id="grid" placeholder="EM10dj"></div>
|
||
|
|
</div>
|
||
|
|
</fieldset>
|
||
|
|
|
||
|
|
<fieldset>
|
||
|
|
<legend>12-14. SKY COVER & CURRENT PHENOMENA</legend>
|
||
|
|
<div class="row">
|
||
|
|
<div class="col" style="max-width: 200px;">
|
||
|
|
<label for="unitChoice">12. Default Units</label>
|
||
|
|
<select id="unitChoice">
|
||
|
|
<option value="Imperial" selected>Imperial (F, mph, inHg, in)</option>
|
||
|
|
<option value="Metric">Metric (C, km/h, mb, mm)</option>
|
||
|
|
</select>
|
||
|
|
</div>
|
||
|
|
<div class="col">
|
||
|
|
<label for="skyCover">13. Sky Cover</label>
|
||
|
|
<select id="skyCover">
|
||
|
|
<option value="CLEAR (0/8)">Clear (0/8)</option>
|
||
|
|
<option value="FEW CLOUDS (1/8-2/8)">Few Clouds (1/8 - 2/8)</option>
|
||
|
|
<option value="PARTLY CLOUDY (3/8-5/8)" selected>Partly Cloudy (3/8 - 5/8)</option>
|
||
|
|
<option value="MOSTLY CLOUDY (6/8-7/8)">Mostly Cloudy (6/8 - 7/8)</option>
|
||
|
|
<option value="OVERCAST (8/8)">Overcast (8/8)</option>
|
||
|
|
<option value="OBSCURED">Obscured Sky</option>
|
||
|
|
</select>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<label>14. Current Conditions & Phenomena (Check all that apply):</label>
|
||
|
|
<div class="conditions-grid">
|
||
|
|
<label><input type="checkbox" value="FOG"> Fog</label>
|
||
|
|
<label><input type="checkbox" value="MIST"> Mist</label>
|
||
|
|
<label><input type="checkbox" value="HAZE"> Haze</label>
|
||
|
|
<label><input type="checkbox" value="SMOKE"> Smoke</label>
|
||
|
|
<label><input type="checkbox" value="RAIN (LIGHT)"> Rain (Light)</label>
|
||
|
|
<label><input type="checkbox" value="RAIN (MOD/HEAVY)"> Rain (Mod/Heavy)</label>
|
||
|
|
<label><input type="checkbox" value="RAIN SHOWER"> Rain Shower</label>
|
||
|
|
<label><input type="checkbox" value="DRIZZLE"> Drizzle</label>
|
||
|
|
<label><input type="checkbox" value="FREEZING RAIN"> Freezing Rain</label>
|
||
|
|
<label><input type="checkbox" value="THUNDERSTORM"> Thunderstorm</label>
|
||
|
|
<label><input type="checkbox" value="TS IN VICINITY"> TS in Vicinity</label>
|
||
|
|
<label><input type="checkbox" value="HAIL"> Hail</label>
|
||
|
|
<label><input type="checkbox" value="SNOW"> Snow</label>
|
||
|
|
<label><input type="checkbox" value="BLOWING SNOW"> Blowing Snow</label>
|
||
|
|
<label><input type="checkbox" value="ICE PELLETS"> Ice Pellets</label>
|
||
|
|
<label><input type="checkbox" value="TORNADO/FUNNEL"> Funnel / Tornado</label>
|
||
|
|
</div>
|
||
|
|
</fieldset>
|
||
|
|
|
||
|
|
<fieldset>
|
||
|
|
<legend>15-27. INSTRUMENT MEASUREMENTS</legend>
|
||
|
|
<div class="row">
|
||
|
|
<div class="col"><label for="temp">15. Temperature (°F/°C)</label><input type="text" id="temp" placeholder="72"></div>
|
||
|
|
<div class="col"><label for="humidity">16. Humidity (%)</label><input type="text" id="humidity" placeholder="65"></div>
|
||
|
|
<div class="col"><label for="dewPoint">17. Dew Point (°F/°C)</label><input type="text" id="dewPoint" placeholder="58"></div>
|
||
|
|
</div>
|
||
|
|
<div class="row">
|
||
|
|
<div class="col"><label for="barometer">18. Barometer (inHg/mb)</label><input type="text" id="barometer" placeholder="29.92"></div>
|
||
|
|
<div class="col">
|
||
|
|
<label for="barTrend">19. 3-Hour Pressure Trend</label>
|
||
|
|
<select id="barTrend">
|
||
|
|
<option value="Steady" selected>Steady</option>
|
||
|
|
<option value="Falling Rapidly">Falling Rapidly</option>
|
||
|
|
<option value="Falling Slowly">Falling Slowly</option>
|
||
|
|
<option value="Rising Rapidly">Rising Rapidly</option>
|
||
|
|
<option value="Rising Slowly">Rising Slowly</option>
|
||
|
|
</select>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class="row">
|
||
|
|
<div class="col"><label for="windSpeed">20. Wind Speed</label><input type="text" id="windSpeed" placeholder="8"></div>
|
||
|
|
<div class="col">
|
||
|
|
<label for="windDir">21. Wind Direction</label>
|
||
|
|
<select id="windDir">
|
||
|
|
<option value="Calm">Calm</option><option value="Variable">Variable</option>
|
||
|
|
<option value="N">North</option><option value="NE">NE</option><option value="E">East</option><option value="SE">SE</option>
|
||
|
|
<option value="S" selected>South</option><option value="SW">SW</option><option value="W">West</option><option value="NW">NW</option>
|
||
|
|
</select>
|
||
|
|
</div>
|
||
|
|
<div class="col"><label for="windGust">22. Wind Gust</label><input type="text" id="windGust" placeholder="15"></div>
|
||
|
|
<div class="col"><label for="maxGust">23. Max Gust (Past Hr)</label><input type="text" id="maxGust" placeholder="22"></div>
|
||
|
|
</div>
|
||
|
|
<div class="row">
|
||
|
|
<div class="col"><label for="rain1hr">24. Rain (Past 1 Hr)</label><input type="text" id="rain1hr" placeholder="0.25"></div>
|
||
|
|
<div class="col"><label for="rainTotal">25. Rain Total (Event)</label><input type="text" id="rainTotal" placeholder="1.10"></div>
|
||
|
|
<div class="col"><label for="snow1hr">26. Snow (Past 1 Hr)</label><input type="text" id="snow1hr" placeholder="0"></div>
|
||
|
|
<div class="col"><label for="snowTotal">27. Snow Total</label><input type="text" id="snowTotal" placeholder="0"></div>
|
||
|
|
</div>
|
||
|
|
</fieldset>
|
||
|
|
|
||
|
|
<fieldset>
|
||
|
|
<legend>28-29. NWS ALERTS & NOTES</legend>
|
||
|
|
<div class="row">
|
||
|
|
<div class="col" style="max-width: 170px;">
|
||
|
|
<label for="nwsLevel">28. NWS Alert Level</label>
|
||
|
|
<select id="nwsLevel">
|
||
|
|
<option value="NONE Issued" selected>NONE Issued</option>
|
||
|
|
<option value="ADVISORY">ADVISORY</option>
|
||
|
|
<option value="WATCH">WATCH</option>
|
||
|
|
<option value="WARNING">WARNING</option>
|
||
|
|
</select>
|
||
|
|
</div>
|
||
|
|
<div class="col"><label for="nwsAlertDesc">Alert Specifics</label><input type="text" id="nwsAlertDesc" placeholder="e.g. Flash Flood Warning until 2100Z"></div>
|
||
|
|
</div>
|
||
|
|
<div class="row">
|
||
|
|
<div class="col"><label for="comments">29. Notes / Local Impact</label><textarea id="comments" rows="3" placeholder="Local observations, roadway impacts, localized drainage issues..."></textarea></div>
|
||
|
|
</div>
|
||
|
|
</fieldset>
|
||
|
|
|
||
|
|
<div class="actions">
|
||
|
|
<button type="button" class="main-btn btn-generate" id="btnGen">Generate Packet ASCII</button>
|
||
|
|
<button type="button" class="main-btn btn-save" id="btnSaveHtml">Save as HTML</button>
|
||
|
|
<button type="button" class="main-btn btn-copy" id="btnCopy">Copy ASCII</button>
|
||
|
|
<button type="button" class="main-btn btn-clear" id="btnClear">Reset</button>
|
||
|
|
</div>
|
||
|
|
</form>
|
||
|
|
|
||
|
|
<label style="font-weight:bold;">Formatted ASCII for Packet / BBS Transmission:</label>
|
||
|
|
<pre id="outputPre">Fill in the fields above and click "Generate Packet ASCII"...</pre>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<script>
|
||
|
|
function setUTC() {
|
||
|
|
const now = new Date();
|
||
|
|
const y = now.getUTCFullYear();
|
||
|
|
const m = String(now.getUTCMonth()+1).padStart(2,'0');
|
||
|
|
const d = String(now.getUTCDate()).padStart(2,'0');
|
||
|
|
const hh = String(now.getUTCHours()).padStart(2,'0');
|
||
|
|
const mm = String(now.getUTCMinutes()).padStart(2,'0');
|
||
|
|
document.getElementById('dtLocal').value = y + '-' + m + '-' + d + ' ' + hh + mm + 'Z';
|
||
|
|
}
|
||
|
|
|
||
|
|
function clean(id) {
|
||
|
|
const el = document.getElementById(id);
|
||
|
|
return el ? (el.value || '').trim() : '';
|
||
|
|
}
|
||
|
|
|
||
|
|
function pad(str, len) {
|
||
|
|
str = (str || '').toString();
|
||
|
|
return str + ' '.repeat(Math.max(0, len - str.length));
|
||
|
|
}
|
||
|
|
|
||
|
|
function wrapText(str, width) {
|
||
|
|
if (!str) return [];
|
||
|
|
let lines = [];
|
||
|
|
str.split('\n').forEach(function(paragraph) {
|
||
|
|
let words = paragraph.split(' ');
|
||
|
|
let cur = '';
|
||
|
|
words.forEach(function(w) {
|
||
|
|
if ((cur + (cur ? ' ' : '') + w).length <= width) {
|
||
|
|
cur += (cur ? ' ' : '') + w;
|
||
|
|
} else {
|
||
|
|
if (cur) lines.push(cur);
|
||
|
|
cur = w;
|
||
|
|
}
|
||
|
|
});
|
||
|
|
if (cur) lines.push(cur);
|
||
|
|
});
|
||
|
|
return lines;
|
||
|
|
}
|
||
|
|
|
||
|
|
function generateASCII() {
|
||
|
|
try {
|
||
|
|
const div = '='.repeat(78);
|
||
|
|
const sub = '-'.repeat(78);
|
||
|
|
|
||
|
|
const call = clean('call').toUpperCase() || 'N0CALL';
|
||
|
|
const name = clean('repName').toUpperCase() || 'N/A';
|
||
|
|
const dt = clean('dtLocal') || 'N/A';
|
||
|
|
const loc = clean('locName').toUpperCase() || 'N/A';
|
||
|
|
const city = clean('city').toUpperCase();
|
||
|
|
const st = clean('state').toUpperCase();
|
||
|
|
const county = clean('county').toUpperCase();
|
||
|
|
|
||
|
|
const lat = clean('lat') || 'N/A';
|
||
|
|
const lon = clean('lon') || 'N/A';
|
||
|
|
const mgrs = clean('mgrs').toUpperCase() || 'N/A';
|
||
|
|
const grid = clean('grid').toUpperCase() || 'N/A';
|
||
|
|
|
||
|
|
const unit = clean('unitChoice');
|
||
|
|
const sky = clean('skyCover');
|
||
|
|
|
||
|
|
let conds = [];
|
||
|
|
document.querySelectorAll('.conditions-grid input[type="checkbox"]').forEach(function(cb) {
|
||
|
|
if (cb.checked) conds.push(cb.value);
|
||
|
|
});
|
||
|
|
const condStr = conds.length ? conds.join(', ') : 'NONE';
|
||
|
|
|
||
|
|
const temp = clean('temp') || 'N/A';
|
||
|
|
const hum = clean('humidity') || 'N/A';
|
||
|
|
const dew = clean('dewPoint') || 'N/A';
|
||
|
|
const bar = clean('barometer') || 'N/A';
|
||
|
|
const trend = clean('barTrend');
|
||
|
|
const wspd = clean('windSpeed') || '0';
|
||
|
|
const wdir = clean('windDir');
|
||
|
|
const gust = clean('windGust') || '0';
|
||
|
|
const maxg = clean('maxGust') || '0';
|
||
|
|
const r1 = clean('rain1hr') || '0';
|
||
|
|
const rtot = clean('rainTotal') || '0';
|
||
|
|
const s1 = clean('snow1hr') || '0';
|
||
|
|
const stot = clean('snowTotal') || '0';
|
||
|
|
|
||
|
|
const nws = clean('nwsLevel');
|
||
|
|
const nwsDesc = clean('nwsAlertDesc').toUpperCase();
|
||
|
|
const cmt = clean('comments').toUpperCase() || 'NONE';
|
||
|
|
|
||
|
|
let wrappedCmt = wrapText(cmt, 72).map(function(l){ return ' ' + l; }).join('\n');
|
||
|
|
|
||
|
|
const out = div + '\n' +
|
||
|
|
'CURRENT LOCAL SURFACE WEATHER OBSERVATION (PACKET ASCII)\n' +
|
||
|
|
div + '\n' +
|
||
|
|
'CALLSIGN : ' + pad(call, 14) + ' OBSERVER: ' + pad(name, 22) + ' DATE/TIME: ' + dt + '\n' +
|
||
|
|
'LOCATION : ' + loc + '\n' +
|
||
|
|
'AREA : ' + (city ? city + ', ' : '') + st + (county ? ' (' + county + ' CO)' : '') + '\n' +
|
||
|
|
'COORDS : LAT: ' + pad(lat, 10) + ' LON: ' + pad(lon, 10) + ' MGRS: ' + pad(mgrs, 14) + ' GRID: ' + grid + '\n' +
|
||
|
|
sub + '\n' +
|
||
|
|
'UNITS: ' + unit + ' | SKY COVER: ' + sky + '\n' +
|
||
|
|
'CURRENT PHENOMENA: ' + condStr + '\n' +
|
||
|
|
sub + '\n' +
|
||
|
|
'TEMP : ' + pad(temp, 8) + ' HUMIDITY: ' + pad(hum + '%', 8) + ' DEW POINT: ' + dew + '\n' +
|
||
|
|
'PRESSURE: ' + pad(bar, 8) + ' 3-HR TREND: ' + trend + '\n' +
|
||
|
|
'WIND : ' + wspd + ' from ' + wdir + ' (GUST: ' + gust + ' | PEAK: ' + maxg + ')\n' +
|
||
|
|
'RAIN : 1-HR: ' + pad(r1, 8) + ' TOTAL: ' + rtot + '\n' +
|
||
|
|
'SNOW : 1-HR: ' + pad(s1, 8) + ' TOTAL: ' + stot + '\n' +
|
||
|
|
sub + '\n' +
|
||
|
|
'NWS ALERT: ' + nws + (nwsDesc ? ' (' + nwsDesc + ')' : '') + '\n' +
|
||
|
|
'NOTES / OBSERVATIONS:\n' + wrappedCmt + '\n' +
|
||
|
|
div;
|
||
|
|
|
||
|
|
document.getElementById('outputPre').textContent = out;
|
||
|
|
} catch(err) {
|
||
|
|
alert("Error generating text: " + err.message);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
function copyASCII() {
|
||
|
|
const txt = document.getElementById('outputPre').textContent;
|
||
|
|
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||
|
|
navigator.clipboard.writeText(txt).then(function() {
|
||
|
|
alert("Local Weather report copied to clipboard!");
|
||
|
|
}).catch(function() {
|
||
|
|
fallbackCopy();
|
||
|
|
});
|
||
|
|
} else {
|
||
|
|
fallbackCopy();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function fallbackCopy() {
|
||
|
|
const pre = document.getElementById('outputPre');
|
||
|
|
const range = document.createRange();
|
||
|
|
range.selectNode(pre);
|
||
|
|
window.getSelection().removeAllRanges();
|
||
|
|
window.getSelection().addRange(range);
|
||
|
|
document.execCommand('copy');
|
||
|
|
alert("Copied to clipboard!");
|
||
|
|
}
|
||
|
|
|
||
|
|
function clearForm() {
|
||
|
|
if(confirm("Reset Local Weather form?")) {
|
||
|
|
document.getElementById('localWxForm').reset();
|
||
|
|
document.getElementById('outputPre').textContent = 'Fill in the fields above and click "Generate Packet ASCII"...';
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
document.getElementById('btnDateNow').addEventListener('click', setUTC);
|
||
|
|
document.getElementById('btnGen').addEventListener('click', generateASCII);
|
||
|
|
document.getElementById('btnSaveHtml').addEventListener('click', openSaveModal);
|
||
|
|
document.getElementById('btnCopy').addEventListener('click', copyASCII);
|
||
|
|
document.getElementById('btnClear').addEventListener('click', clearForm);
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
// File Name Modal Window & HTML Exporter
|
||
|
|
function openSaveModal() {
|
||
|
|
var now = new Date();
|
||
|
|
var dStr = now.toISOString().slice(0, 10);
|
||
|
|
var defName = 'local_weather_' + dStr + '.html';
|
||
|
|
var modal = document.getElementById('saveModalBackdrop');
|
||
|
|
var input = document.getElementById('saveModalFileName');
|
||
|
|
if (input) input.value = defName;
|
||
|
|
if (modal) modal.classList.add('active');
|
||
|
|
setTimeout(function() {
|
||
|
|
if (input) { input.focus(); input.select(); }
|
||
|
|
}, 50);
|
||
|
|
}
|
||
|
|
|
||
|
|
function closeSaveModal() {
|
||
|
|
var modal = document.getElementById('saveModalBackdrop');
|
||
|
|
if (modal) modal.classList.remove('active');
|
||
|
|
}
|
||
|
|
|
||
|
|
function executeSaveHTML() {
|
||
|
|
var input = document.getElementById('saveModalFileName');
|
||
|
|
var chosenName = input ? input.value.trim() : '';
|
||
|
|
if (!chosenName) return;
|
||
|
|
if (!chosenName.toLowerCase().endsWith('.html') && !chosenName.toLowerCase().endsWith('.htm')) {
|
||
|
|
chosenName += '.html';
|
||
|
|
}
|
||
|
|
closeSaveModal();
|
||
|
|
|
||
|
|
document.querySelectorAll('input[type="text"]').forEach(function(el) { el.setAttribute('value', el.value); });
|
||
|
|
document.querySelectorAll('input[type="checkbox"], input[type="radio"]').forEach(function(el) {
|
||
|
|
if (el.checked) el.setAttribute('checked', 'checked');
|
||
|
|
else el.removeAttribute('checked');
|
||
|
|
});
|
||
|
|
document.querySelectorAll('textarea').forEach(function(el) { el.textContent = el.value; });
|
||
|
|
document.querySelectorAll('select').forEach(function(el) {
|
||
|
|
Array.from(el.options).forEach(function(opt) {
|
||
|
|
if (opt.value === el.value) opt.setAttribute('selected', 'selected');
|
||
|
|
else opt.removeAttribute('selected');
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
var pre = document.getElementById('ascii-report') || document.getElementById('outputPre') || document.getElementById('preview') || document.getElementById('outputArea');
|
||
|
|
if (pre) pre.textContent = pre.textContent;
|
||
|
|
|
||
|
|
var clonedDoc = document.documentElement.cloneNode(true);
|
||
|
|
var modalInClone = clonedDoc.querySelector('#saveModalBackdrop');
|
||
|
|
if (modalInClone) modalInClone.classList.remove('active');
|
||
|
|
|
||
|
|
var htmlContent = '<!DOCTYPE html>\n' + clonedDoc.outerHTML;
|
||
|
|
var blob = new Blob([htmlContent], { type: 'text/html;charset=utf-8' });
|
||
|
|
var url = URL.createObjectURL(blob);
|
||
|
|
var a = document.createElement('a');
|
||
|
|
a.href = url;
|
||
|
|
a.download = chosenName;
|
||
|
|
document.body.appendChild(a);
|
||
|
|
a.click();
|
||
|
|
document.body.removeChild(a);
|
||
|
|
URL.revokeObjectURL(url);
|
||
|
|
}
|
||
|
|
|
||
|
|
window.addEventListener('DOMContentLoaded', function() {
|
||
|
|
var cancelBtn = document.getElementById('saveModalCancelBtn');
|
||
|
|
var confirmBtn = document.getElementById('saveModalSaveBtn');
|
||
|
|
var modalInput = document.getElementById('saveModalFileName');
|
||
|
|
var modalBackdrop = document.getElementById('saveModalBackdrop');
|
||
|
|
|
||
|
|
if (cancelBtn) cancelBtn.addEventListener('click', closeSaveModal);
|
||
|
|
if (confirmBtn) confirmBtn.addEventListener('click', executeSaveHTML);
|
||
|
|
if (modalInput) {
|
||
|
|
modalInput.addEventListener('keydown', function(e) {
|
||
|
|
if (e.key === 'Enter') { e.preventDefault(); executeSaveHTML(); }
|
||
|
|
if (e.key === 'Escape') { e.preventDefault(); closeSaveModal(); }
|
||
|
|
});
|
||
|
|
}
|
||
|
|
if (modalBackdrop) {
|
||
|
|
modalBackdrop.addEventListener('click', function(e) {
|
||
|
|
if (e.target === modalBackdrop) closeSaveModal();
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
var btnSaveMain = document.getElementById('btnSaveHtml');
|
||
|
|
if (btnSaveMain) {
|
||
|
|
// Clear existing inline handlers just in case
|
||
|
|
btnSaveMain.onclick = null;
|
||
|
|
btnSaveMain.addEventListener('click', openSaveModal);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
</script>
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
<!-- Custom File Name Modal Window -->
|
||
|
|
<div id="saveModalBackdrop" class="save-modal-backdrop">
|
||
|
|
<div class="save-modal-window">
|
||
|
|
<h3>Save Form as HTML</h3>
|
||
|
|
<p>Enter a name for the saved offline HTML file:</p>
|
||
|
|
<input type="text" id="saveModalFileName" spellcheck="false">
|
||
|
|
<div class="save-modal-actions">
|
||
|
|
<button type="button" class="save-modal-btn save-modal-btn-cancel" id="saveModalCancelBtn">Cancel</button>
|
||
|
|
<button type="button" class="save-modal-btn save-modal-btn-confirm" id="saveModalSaveBtn">Save File</button>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
</body>
|
||
|
|
</html>
|