Skip to content

Instantly share code, notes, and snippets.

@eddydg
Created April 6, 2020 09:50
Show Gist options
  • Save eddydg/d251fed075c92e3469912dd93c04598d to your computer and use it in GitHub Desktop.
Save eddydg/d251fed075c92e3469912dd93c04598d to your computer and use it in GitHub Desktop.
A
// https://media.interieur.gouv.fr/deplacement-covid-19/
/* Add custom generation time field */
function updateGenHour(time) {
const times = time.split(":");
Date.prototype.getHours=()=>times[0];
Date.prototype.getMinutes=()=>times[1];
}
const temp = document.createElement("div");
temp.innerHTML = '<div class="form-group"> <label for="field-heure">Heure de génération</label> <div class="input-group align-items-center"> <input type="time" class="form-control" onchange="updateGenHour(this.value)" id="field-heuregen"> </div> </div>';
const now = new Date();
now.setMinutes(now.getMinutes() - 10);
temp.querySelector("#field-heuregen").value = now.getHours() + ":" + now.getMinutes();
const anchor = document.querySelector("#form-profile > p");
anchor.parentNode.insertBefore(temp.firstChild, anchor);
/* Bookmarklet version */
function u(e){const t=e.split(":");Date.prototype.getHours=(()=>t[0]),Date.prototype.getMinutes=(()=>t[1])}const n=document.createElement("div");n.innerHTML='<div class="form-group"> <label for="field-heure">Heure de génération</label> <div class="input-group align-items-center"> <input type="time" class="form-control" onchange="u(this.value)" id="field-heuregen"> </div> </div>';const i=new Date;i.setMinutes(i.getMinutes()-10),n.querySelector("#field-heuregen").value=i.getHours()+":"+i.getMinutes();const a=document.querySelector("#form-profile > p");a.parentNode.insertBefore(n.firstChild,a);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment