Repository navigation
Expand file tree
/
Copy pathcron-builder.html
More file actions
90 lines (86 loc) · 3.18 KB
/
Copy pathcron-builder.html
File metadata and controls
90 lines (86 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Cron Builder</title>
<script type="application/masscode-tool+json">
{
"schemaVersion": 1,
"name": "Cron Builder",
"description": "Build a daily or weekly five-field cron schedule and preview upcoming UTC runs.",
"category": "generators",
"author": "massCode",
"authorUrl": "https://github.com/massCodeIO",
"license": "MIT",
"keywords": ["cron", "schedule", "utc"]
}
</script>
</head>
<body>
<h1>Cron Builder</h1>
<p class="mc-muted">Preview uses UTC. Your scheduler may use a different timezone.</p>
<div class="mc-card mc-grid">
<label>Time (UTC) <input type="time" id="time" value="09:00"></label>
<fieldset>
<legend>Days of the week</legend>
<label><input type="checkbox" value="0" checked> Sun</label>
<label><input type="checkbox" value="1" checked> Mon</label>
<label><input type="checkbox" value="2" checked> Tue</label>
<label><input type="checkbox" value="3" checked> Wed</label>
<label><input type="checkbox" value="4" checked> Thu</label>
<label><input type="checkbox" value="5" checked> Fri</label>
<label><input type="checkbox" value="6" checked> Sat</label>
</fieldset>
<div class="mc-row">
<label>Expression <input id="expression" readonly></label>
<button type="button" id="copy" class="mc-btn-primary">Copy expression</button>
</div>
<p id="status" class="mc-error" role="status"></p>
</div>
<h2>Next five runs</h2>
<ol id="runs"></ol>
<script>
const get = id => document.getElementById(id)
const days = Array.from(document.querySelectorAll('input[type=checkbox]'))
function update() {
const selected = days.filter(input => input.checked).map(input => Number(input.value))
const time = get('time').value
const runs = get('runs')
runs.replaceChildren()
get('status').textContent = ''
get('copy').disabled = !time || !selected.length
if (get('copy').disabled) {
get('expression').value = ''
get('status').textContent = 'Choose a time and at least one day.'
return
}
const [hour, minute] = time.split(':').map(Number)
const dayField = selected.length === 7 ? '*' : selected.join(',')
get('expression').value = `${minute} ${hour} * * ${dayField}`
const now = new Date()
const day = new Date(now)
day.setUTCHours(hour, minute, 0, 0)
while (runs.children.length < 5) {
if (day > now && selected.includes(day.getUTCDay())) {
const row = document.createElement('li')
row.textContent = day.toISOString().slice(0, 16).replace('T', ' ') + ' UTC'
runs.append(row)
}
day.setUTCDate(day.getUTCDate() + 1)
}
}
for (const input of [get('time'), ...days])
input.addEventListener('input', update)
get('copy').addEventListener('click', async () => {
get('status').textContent = ''
try {
await window.massCode.copy(get('expression').value)
}
catch {
get('status').textContent = 'The copy request could not be completed.'
}
})
update()
</script>
</body>
</html>