MCPcopy Create free account
hub / github.com/Useful-Scripts-Extension/useful-script / openDatePicker

Function openDatePicker

scripts/web_timer_main.js:225–257  ·  view source on GitHub ↗
(
  x,
  y,
  date = new Date(),
  minDate = null,
  maxDate = null
)

Source from the content-addressed store, hash-verified

223}
224
225function openDatePicker(
226 x,
227 y,
228 date = new Date(),
229 minDate = null,
230 maxDate = null
231) {
232 return new Promise((resolve) => {
233 let input = document.createElement("input");
234 input.type = "date";
235 input.value = formatDate(date);
236 if (minDate)
237 input.min = minDate instanceof Date ? formatDate(minDate) : minDate;
238 if (maxDate)
239 input.max = maxDate instanceof Date ? formatDate(maxDate) : maxDate;
240 input.style = `position: fixed; top: ${y}px; left: ${x}px; visibility: hidden;`;
241 input.addEventListener("change", (e) => {
242 let selectedDate = new Date(e.target.value);
243 input.remove();
244 resolve(selectedDate);
245 });
246 document.body.appendChild(input);
247 setTimeout(() => {
248 input.showPicker();
249 function remove() {
250 resolve(null);
251 input.remove();
252 document.removeEventListener("click", remove);
253 }
254 document.addEventListener("click", remove);
255 }, 10);
256 });
257}
258
259function showData({
260 fromDate = new Date(),

Callers 1

initFunction · 0.85

Calls 2

formatDateFunction · 0.70
removeMethod · 0.45

Tested by

no test coverage detected