-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
43 lines (34 loc) · 1.29 KB
/
script.js
File metadata and controls
43 lines (34 loc) · 1.29 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
const texts = [
"firstname", "lastname",
"address", "zipcode", "city",
"birthday", "placeofbirth",
]
const checks = [
"travail", "enfants", "convocation", "achats", "sport_animaux", "courses", "sante",
"famille", "handicap", "missions", "judiciaire",
]
function createLink() {
var obj = {};
texts.forEach(x => obj[x] = document.getElementById("field-" + x).value);
checks.forEach(x => obj[x] = document.getElementById("ox-" + x).checked);
var str = Object.keys(obj).map(x => x + '=' + obj[x]).join("&");
var link = document.querySelector("#link > a");
var uri = window.location.origin + "/#" + str;
link.href = uri;
link.innerText = "Attestation personnalisée"
window.location = uri;
}
function onLoad() {
if (str = window.location.hash.substr(1)) {
for (const [key, value] of new URLSearchParams(str)) {
if (texts.includes(key))
document.getElementById("field-" + key).value = value;
if (checks.includes(key))
document.getElementById("checkbox-" + key).checked =
(value === 'true');
}
document.getElementById("generate-btn").click();
}
}
window.addEventListener("DOMContentLoaded", e => onLoad());
window.addEventListener("focus", e => onLoad());