allergies-userscripts/Allergies-1.1.js

52 lines
1.2 KiB
JavaScript

var Allergies = {};
Allergies.allergenes = [
'miel',
'paprika',
'piment',
'poivre de cayenne',
'poivron',
'chorizo',
'carvi',
'cumin',
'curry',
'anis',
'camomille',
"cire d'abeille",
'e160c',
'e901',
'celeri',
'céleri'
];
Allergies.process = function(element) {
var found = Allergies.check_allergenes(element.textContent);
if(found.length > 0) {
element.insertBefore(Allergies.warning(found), element.firstChild);
}
};
Allergies.check_allergenes = function(text) {
var lower_text = text.toLowerCase();
return Allergies.allergenes.filter(function(allergene) { return lower_text.indexOf(allergene) >= 0 });
};
Allergies.warning = function(found) {
var div = document.createElement('div');
var warning_message = document.createElement('p');
warning_message.style.color = '#F00';
warning_message.style.fontSize = '3em';
warning_message.style.fontWeight = 'bold';
warning_message.textContent = "ATTENTION";
div.appendChild(warning_message);
var message = document.createElement('p');
message.textContent = "Ce produit contient les allergènes suivants : " + found.join(', ');
message.style.fontSize = '18px';
message.style.marginTop = '0';
div.appendChild(message);
return div;
};