-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCitaAutoComplete.user.js
More file actions
148 lines (133 loc) · 5.88 KB
/
CitaAutoComplete.user.js
File metadata and controls
148 lines (133 loc) · 5.88 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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// ==UserScript==
// @name Cita AutoComplete
// @namespace http://xpam.net/
// @version 0.5
// @description AutoComplete of the cita form
// @author Andrey Luzhin
// @include https://sede.administracionespublicas.gob.es/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Configuration
const fullName = "John Smith";
const documentID = "000000000";
const documentDate = "01/01/2020";
const phoneNumber = "000000000";
const eMail = "none@none.com";
const countryCode = "149"; // Rusia
const proceduralAction = "4010"; // POLICIA-TOMA DE HUELLAS (EXPEDICIÓN DE TARJETA) Y RENOVACIÓN DE TARJETA DE LARGA DURACIÓN
const provinciaFormURL = "/icpplustie/citar?p=8&locale=es"; // Barcelona
const isPassport = true; // if "true" - using passport, instead of NIE
const isDate = false; // if "true" - fill date field. It's possible to fill the date field with an empty value, but it's safer not to touch anything that is not required.
// Constants
const path = window.location.pathname;
const page = path.split("/").pop();
const firstPage = ['/icpplustie/icpplustieb/acOpcDirect',
'/icpplustie/icpplustieb/index.html',
'/icpplustie/icpplustieb/index',
'/icpplustieb/acOpcDirect',
'/icpplustieb/index.html',
'/icpplustieb/index',
'/icpplustieb/',
'/icpplustie/acOpcDirect',
'/icpplustie/index.html',
'/icpplustie/index',
'/icpplustie/']; // There are a lot of ways to get to the front page, so I'm listing everything I've got.
// Field value setting function. Check for element existance
function setFieldValue(f, v) {
var e = document.getElementById(f);
if (e) e.value=v;
}
// Autoclick element function. Check for element existance
function clickElement(e) {
var ac = document.getElementById(e);
if (ac) ac.click();
}
// Select Barcelona on the front page
if (firstPage.includes(path)) {
var frm = document.getElementById('form');
if (frm) {
if (frm.nodeName == "SELECT") { // to make sure, that we change the select field
frm.value=provinciaFormURL; // quick but dirty
if (frm.options[frm.selectedIndex].text != 'Barcelona') alert('Something wrong!'); // quick check for form change
}
}
/* // If they will change select url again, should use something like this:
var formProvince = document.getElementById('form');
if (formProvince) {
if (formProvince.nodeName == "SELECT") { // to make sure, that we change the select field
for (i = 0; i < formProvince.length; i++) {
if (formProvince.options[i].text == 'Barcelona') {
formProvince.options[i].selected = true;
break;
}
}
}
}
*/
clickElement('btnAceptar');
}
// Select procedure (second page)
if (page == 'citar') {
setFieldValue('tramiteGrupo[1]', proceduralAction);
/* // more accurate, but have disadvantages
var formProcedure = document.getElementById('tramiteGrupo[1]');
if (formProcedure) {
for (i = 0; i < formProcedure.length; i++) {
if (formProcedure.options[i].text == 'POLICIA-TOMA DE HUELLAS (EXPEDICIÓN DE TARJETA) Y RENOVACIÓN DE TARJETA DE LARGA DURACIÓN') {
formProcedure.options[i].selected = true;
break;
}
}
}
*/
clickElement('btnAceptar');
}
// Agreement of procedure (third page)
if (page == 'acInfo') {
clickElement('btnEntrar');
// they changed moment of notification, about absence of citas
var bte = document.getElementById('btnEntrar');
if (bte === null) { // NB: if they change id of "Entrar" button, this script will stop working properly
//alert('No cita');
//clickElement('btnVolver'); // No cita, click "Volver"
}
}
// Fill first form (fourth page)
if (page == 'acEntrada') {
// If document type is passport, selecting right radio button
if (isPassport) clickElement('rdbTipoDocPas');
// Document Number. One field for both NIE and passport
setFieldValue('txtIdCitado', documentID);
// Name and surname, in upper case
setFieldValue('txtDesCitado', fullName.toUpperCase());
// Date
if (isDate) setFieldValue('txtFecha', documentDate);
// Country selection
setFieldValue('txtPaisNac', countryCode);
// clickElement(, 'btnAceptar'); // ReCaptcha, no autoclick possible at this time
}
// Click "Solicitar Cita" (fifth page)
if (page == 'acValidarEntrada') clickElement('btnEnviar');
// Selection of the police department (sixth page)
if (page == 'acCitar') {
// Always select default option, if you want to select department manually, comment next string
clickElement('btnSiguiente'); // if Cita exists, proceed
// If cita not exists
var bts = document.getElementById('btnSiguiente');
if (bts === null) { // NB: if they change id of "Siguiente" button, this script will stop working properly
//Uncomment next string for autorepeat if no cita exists
//clickElement('btnSalir'); // No cita, click "Salir"
}
}
// Second form filling (seventh page)
if (page == 'acVerFormulario') {
// Phone number
setFieldValue('txtTelefonoCitado', phoneNumber);
// e-mail
setFieldValue('emailUNO', eMail);
setFieldValue('emailDOS', eMail);
clickElement('btnSiguiente');
}
})();