-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuserscript.js
81 lines (69 loc) · 1.98 KB
/
userscript.js
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
// ==UserScript==
// @name AttestationCovid Autofiller
// @version 0.1
// @description Auto fill out the Covid 19 travel certificate from URL
// @author Alexis Ries
// @match https://media.interieur.gouv.fr/*
// @grant none
// ==/UserScript==
const $ = document.querySelector.bind(document);
const $$ = document.querySelectorAll.bind(document);
const getCurrentTime = () => {
const date = new Date();
return date.toLocaleTimeString('fr-FR', { hour: '2-digit', minute: '2-digit' });
}
function extractQueryString() {
var params = {};
var url = new URL(window.location);
for(var hashParam of url.hash.substr(1).split(/&/)) {
var kv = decodeURIComponent(hashParam).split(/=/);
if (kv[0] == "reason") {
if (!("reasons" in params)) {
params["reasons"] = [];
}
params["reasons"].push(kv[1]);
} else {
params[kv[0]] = kv[1];
}
}
return params;
}
function autofill (formInputs, reasonInputs) {
var urlParams = extractQueryString();
var formInputTypes = ["text", "number", "time"];
formInputs.forEach((input) => {
if (formInputTypes.indexOf(input.type) > -1) {
console.log(input.name);
if (input.name in urlParams) {
input.value = urlParams[input.name];
} else if (input.name == "heuresortie") {
input.value = getCurrentTime();
}
}
});
reasonInputs.forEach((input) => {
if (input.type == "checkbox" && input.name == "field-reason") {
if ("reasons" in urlParams) {
urlParams["reasons"].forEach(function(paramValue) {
if (input.value == paramValue) {
input.checked = true;
return;
}
}
);
}
}
});
}
function autogen(formInputs) {
$("#generate-btn").click();
}
function gofill() {
const formInputs = $$('#form-profile input')
const reasonInputs = [...$$('input[name="field-reason"]')]
autofill(formInputs, reasonInputs)
autogen();
}
(function() {
gofill()
})();