commit c8696b9bfae464c8427d0d359ec520330707e512 Author: Guillaume Dott Date: Wed Feb 13 14:20:08 2019 +0100 first commit diff --git a/Allergies-1.1.js b/Allergies-1.1.js new file mode 100644 index 0000000..4995307 --- /dev/null +++ b/Allergies-1.1.js @@ -0,0 +1,51 @@ +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; +}; diff --git a/CoraDrive_allergies.user.js b/CoraDrive_allergies.user.js new file mode 100644 index 0000000..1666d98 --- /dev/null +++ b/CoraDrive_allergies.user.js @@ -0,0 +1,13 @@ +// ==UserScript== +// @name Cora Drive allergies +// @namespace http://amnesix.eu +// @description Affiche une alerte lorsqu'un produit contient un des ingrédients interdits +// @include https://www.coradrive.fr/* +// @include http://www.coradrive.fr/* +// @version 1.5 +// @grant none +// @require http://files.amnesix.eu/~guillaume/allergies/Allergies-1.1.js +// ==/UserScript== +(function() { + document.querySelectorAll('.rnd8 .bloc_info h4').forEach(Allergies.process); +})(); diff --git a/Courses_U_allergies.user.js b/Courses_U_allergies.user.js new file mode 100644 index 0000000..0ced443 --- /dev/null +++ b/Courses_U_allergies.user.js @@ -0,0 +1,20 @@ +// ==UserScript== +// @name Courses U allergies +// @namespace http://amnesix.eu +// @description Affiche une alerte lorsqu'un produit contient un des ingrédients interdits +// @include https://www.coursesu.com/* +// @include http://www.coursesu.com/* +// @version 2.1 +// @grant none +// @require http://files.amnesix.eu/~guillaume/allergies/Allergies-1.1.js +// ==/UserScript== +(function() { + document.querySelectorAll('#listeInfosProduitsZone .infos').forEach(Allergies.process); + + var productModalZone = document.getElementById('productModalZone'); + var observer = new MutationObserver(function(mutations) { + var composition = mutations[0].addedNodes[0].querySelector('.composition'); + Allergies.process(composition); + }); + observer.observe(productModalZone, {childList: true}); +})();