-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTieReceiveCitaAutoComplete.user.js
194 lines (169 loc) · 7.33 KB
/
TieReceiveCitaAutoComplete.user.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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
// ==UserScript==
// @name Cita AutoComplete
// @namespace http://xpam.net/
// @version 0.1
// @description AutoComplete of the cita for TIE card receive
// @author Andrey Luzhin
// @author Vadim Reutskiy
// @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 proceduralPlace = 16; //
const proceduralAction = "4036"; // POLICIA - RECOGIDA DE TARJETA DE IDENTIDAD DE EXTRANJERO (TIE)
const provinceName = "Barcelona"
const isPassport = false; // 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',
'/icpplustieb/acOpcDirect',
'/icpplustieb/index',
'/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)) {
// If they will change select url again, should use something like this:
var formProvince = document.getElementById('form');
if (formProvince) {
// console.info(formProvince);
if (formProvince.nodeName == "SELECT") { // to make sure, that we change the select field
var isProvinceFound = false;
for (var i = 0; i < formProvince.length; i++) {
if (formProvince.options[i].text == provinceName) {
formProvince.options[i].selected = true;
isProvinceFound = true;
break;
}
}
if (!isProvinceFound) {
alert(`Province '${provinceName}' not found; check provinceName constant in code.`);
}
}
}
if (isProvinceFound) {
clickElement('btnAceptar');
}
}
// Select procedure (second page)
if (page == 'citar') {
setFieldValue('sede', proceduralPlace);
setFieldValue('tramiteGrupo[0]', 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('btnEnviar'); // ReCaptcha, no autoclick possible at this time
}
// Click "Solicitar Cita" (fifth page)
if (page == 'acValidarEntrada') clickElement('btnEnviar');
// Selection of the police department (sixth page) AGAIN
if (page == 'acCitar') {
// If cita not exists
if (document.getElementsByClassName("mf-msg__info").length != 0) {
var noSitaAvailableNow =
document.getElementsByClassName("mf-msg__info")[0].innerHTML.includes('En este momento no hay')
if (noSitaAvailableNow) { // 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"
}
} else {
// Always select default option, if you want to select department manually, comment next string
// clickElement('btnSiguiente'); // if Cita exists, proceed
// idSede
var formProceduralPlace = document.getElementById('idSede');
if (formProceduralPlace) {
console.info(formProceduralPlace);
if (formProceduralPlace.nodeName == "SELECT") { // to make sure, that we change the select field
var isPlaceFound = false;
for (i = 0; i < formProceduralPlace.length; i++) {
if (formProceduralPlace.options[i].value == proceduralPlace) {
formProceduralPlace.options[i].selected = true;
isPlaceFound = true;
break;
}
}
if (!isPlaceFound) {
//alert(`Place with ID '${proceduralPlace}' not found; we need to try again.`);
clickElement('btnSalir'); // No cita, click "Salir"
} else {
const hooray = new Audio("https://freesound.org/data/previews/403/403057_7025862-lq.mp3");
hooray.play()
clickElement('btnSiguiente'); // if Cita exists, proceed
}
}
}
}
}
// Second form filling (seventh page)
if (page == 'acVerFormulario') {
// Phone number
setFieldValue('txtTelefonoCitado', phoneNumber);
// e-mail
setFieldValue('emailUNO', eMail);
setFieldValue('emailDOS', eMail);
clickElement('btnSiguiente');
}
})();