first version

This commit is contained in:
rpaoloni 2020-10-30 17:45:01 +01:00
parent 0376f5e5b8
commit 7f7cb6a2b2
6 changed files with 188 additions and 0 deletions

165
main.js Normal file
View File

@ -0,0 +1,165 @@
"use strict";
const DATA_KEY = 'pas-data-64a755500efe9b8275422e16f551bc06'
const FIELD_NAMES = [
'firstname',
'lastname',
'birthday',
'placeofbirth',
'firstname',
'birthday',
'placeofbirth',
'address',
'city',
'zipcode',
'datesortie',
'heuresortie'
];
function get_fields()
{
const fields = {};
for (let i = 0; i < FIELD_NAMES.length; i++)
{
let field_id = 'field-' + FIELD_NAMES[i];
fields[FIELD_NAMES[i]] = document.getElementById(field_id);
}
return fields;
}
function get_checkbox()
{
const checkbox_names = [
'travail',
'achats',
'sante',
'famille',
'handicap',
'sport_animaux',
'convocation',
'missions',
'enfants'
];
const checkbox = {};
for (let i = 0; i < checkbox_names.length; i++)
{
let checkbox_id = 'checkbox-' + checkbox_names[i];
checkbox[checkbox_names[i]] = document.getElementById(checkbox_id);
}
return checkbox;
}
function load_data() {
const stored = window.localStorage.getItem(DATA_KEY);
if(stored)
{
return JSON.parse(stored);
}
else
{
const data = {
'fields': {},
'checkbox': []
};
for (let field in FIELD_NAMES)
{
data['fields'][FIELD_NAMES[field]] = '';
}
return data;
}
}
function save_data(fields, checkbox)
{
console.debug('saving_data')
const data = {
'fields': {},
'checkbox': []
};
for (let field in fields)
{
let value = fields[field];
data['fields'][field] = value.value;
}
for (let box_name in checkbox)
{
let checked = checkbox[box_name].checked;
if (checked)
{
data['checkbox'].push(box_name);
}
}
window.localStorage.setItem(DATA_KEY, JSON.stringify(data));
console.debug('data-saved')
}
function fill_form(fields, checkbox)
{
const data = load_data();
const date = new Date();
for (let field in fields)
{
let element = fields[field];
if (field === 'datesortie')
{
const day = date.getDate();
const month = date.getMonth() + 1;
const year = date.getFullYear();
const date_string = year.toString() + '-' + month.toString() + '-' + day.toString();
element.value = date_string;
}
else if (field === 'heuresortie')
{
const hours = date.getHours();
const minutes = date.getMinutes();
const time_string = hours.toString() + ':' + minutes.toString();
element.value = time_string;
}
else
{
element.value = data['fields'][field];
}
}
for (let box in checkbox)
{
if(data['checkbox'].includes(box))
{
checkbox[box].checked = true;
}
else
{
checkbox[box].checked = false;
}
}
}
function main(main)
{
console.log('starting PAS');
console.debug('retrieve fields');
const fields = get_fields();
console.debug('retrieve checkbox');
const checkbox = get_checkbox();
console.debug('retrieve generate_button');
const generateButton = document.getElementById('generate-btn');
console.debug('attach to validation');
generateButton.onclick = function(event){save_data(fields, checkbox);}
console.debug('trying to fill the form');
fill_form(fields, checkbox);
console.debug('setup done');
}
try
{
main();
}
catch(error)
{
console.error(error);
}

21
manifest.json Normal file
View File

@ -0,0 +1,21 @@
{
"manifest_version": 2,
"name": "PAS",
"version": "1.0",
"description": "Enregistre et préremplis les autorisations de sortie sur le site https://media.interieur.gouv.fr/deplacement-covid-19/ Le code source est siponible a l'adresse: https://git.katzei.fr/meewan/pas",
"icons": {
"48": "media/icon-48.png"
},
"content_scripts": [
{
"matches": ["https://media.interieur.gouv.fr/deplacement-covid-19/"],
"js": ["main.js"]
}
]
}

BIN
media/icon-48.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

BIN
media/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

2
packer.sh Executable file
View File

@ -0,0 +1,2 @@
#/bin/bash
zip -r -FS ../pas.zip * --exclude *.git* --exclude packer.sh

BIN
pas-1.0-an+fx.xpi Normal file

Binary file not shown.