// ==UserScript== // @name SIGA Share Menu Userscript // @namespace http://tampermonkey.net/ // @version 2.9.2 // @description Este userscript añade botones para compartir el menú desde SIGA // @author carlosepcc,jesusfvb // @match https://alimentacion.uci.cu/ // @icon https://www.google.com/s2/favicons?sz=64&domain=uci.cu // @updateURL https://raw.githubusercontent.com/carlosepcc/share-menu-userscript/main/share-menu-userscript.js // @downloadURL https://raw.githubusercontent.com/carlosepcc/share-menu-userscript/main/share-menu-userscript.js // @grant none // ==/UserScript== (function () { "use strict"; const userStyle = document.createElement("style") const notificationHidePosition = '-180px' const notificationShowPosition = '20px' userStyle.innerText = ` .panel-flat{transition:0.5s} .panel-flat.panel-default-flat{cursor:pointer;} .panel-flat:hover{box-shadow:-2px 2px 8px 0 #0002;transform:translate(1px, 1px)} .notification-text{ color:#000a;font:700 1.2em; } .panel-heading-flat>.actions{padding:4px} #notification{transition:0.5s;position:fixed;left:2px;bottom:${notificationHidePosition}; z-index:1000; border:1px solid #0001;background:#fffa;backdrop-filter:blur(16px); box-shadow:-2px 2px 8px 0 #0005;min-width:20em;} #notification pre { resize:both; margin-top:12px; max-height:80px; overflow:auto; background:none; } .panel-flat{max-width:320px;} /*Para que no se solapen cuando el ancho del viewport es pequeño*/ .actions{ display:flex; flex-direction:column; } .share-container>*{flex-grow:1} .share-container:last-child{flex-grow: 2} .actions>.share-container{ display:flex; justify-content: space-between; } .actions .btn {border:1px solid #fff2 } .notification-text::before{content:'✔ ';color:green;} details{color:#000c;} summary{font-weight:bold;width:100%} ` document.head.appendChild(userStyle) document.querySelector("#panel_0").style.height="fit-content" var actionsContainer = `
Mostrar menú modificado ◢
`; function getTableData(table) { return Array.from(table.querySelectorAll(".row>div:first-child>label")).map( (item) => item.innerText ); } function getMenu(menuElement) { return { fecha: menuElement.querySelector("h2").innerText, desayuno: getTableData(menuElement.querySelector("table:nth-child(1)")), almuerzo: getTableData(menuElement.querySelector("table:nth-child(2)")), comida: getTableData(menuElement.querySelector("table:nth-child(3)")), }; } function getStringMenu(menu) { return `${menu.fecha} ᴅᴇsᴀʏᴜɴᴏ ${menu.desayuno.join("\n")} ᴀʟᴍᴜᴇʀᴢᴏ ${menu.almuerzo.join("\n")} ᴄᴏᴍɪᴅᴀ ${menu.comida.join("\n")} menuuci.t.me `; } var menuObj var texto function prettifyMenu(string) { const rules = [ { s: /\./g, r: "" }, //Elimina todos los periods { s: /,/g, r: " " }, //Elimina todas las comas { s: /tme/g, r: "t.me" }, { s: /menuucit/g, r: "menuuci.t" }, { s: /\s*\(\d.*\)/g, r: "" }, //Elimina todas las cadenas de cantidades del producto Ej: "(50 g )" { s: / 50 g/g, r: "" }, // Elimina " 50 g" - Para la cadena "Pan 50 g" { s: /Lunes/g, r: "**Lunes**" }, { s: /Martes/g, r: "**Martes**" }, { s: /Miércoles/g, r: "**Miércoles**" }, { s: /Jueves/g, r: "**Jueves**" }, { s: /Viernes/g, r: "**Viernes**" }, { s: /Sábado/g, r: "**Sábado**" }, { s: /Domingo/g, r: "**Domingo**" }, { s: /\/\d+\n/g, r: "\n" }, //Borrar el año /\n { s: /\/07/g, r: " de julio" }, { s: /\/08/g, r: " de agosto" }, { s: /\/09/g, r: " de septiembre" }, { s: /\/10/g, r: " de octubre" }, { s: /\/11/g, r: " de noviembre" }, { s: /\/12/g, r: " de diciembre" }, { s: /\/01/g, r: " de enero" }, { s: /\/02/g, r: " de febrero" }, { s: /\/03/g, r: " de marzo" }, { s: /\/04/g, r: " de abril" }, { s: /\/05/g, r: " de mayo" }, { s: /\/06/g, r: " de junio" }, { s: /\((.*?) estudiantes/g, r: "(estudiantes" }, { s: /\((.*?) trabajadores/g, r: "(trabajadores" }, { s: /Plato fuerte/g, r: "❔ Plato fuerte" }, { s: /Vianda/g, r: "🥔 Vianda" }, { s: /Yuca/g, r: "🥔 Yuca" }, { s: /Malanga/g, r: "🥔 Malanga" }, { s: /Papa/g, r: "🥔 Papa" }, { s: /Ensalada/g, r: "🥬 Ensalada" }, { s: /🥬 Ensalada de pepino/g, r: "🥒 Ensalada de pepino" }, { s: /Arroz/g, r: "🍚 Arroz" }, { s: /🍚 Arroz congris/g, r: "🍛 Arroz congris" }, { s: /🍚 Arroz moros/g, r: "🍛 Arroz moros" }, { s: /Huevo/g, r: "🥚 **Huevo**" }, { s: /\*\*Huevo\*\* hervido/g, r: "**Huevo hervido**" }, { s: /🥚 \*\*Huevo\*\* frito/g, r: "🍳 **Huevo frito**" }, { s: /Pan/g, r: "🍔 Pan" }, { s: /Sopa/g, r: "🍜 Sopa" }, { s: /Potaje/g, r: "🥘 Potaje" }, { s: /Caldosa/g, r: "🥘 Caldosa" }, { s: /Boniat/g, r: "🥔 Boniat" }, { s: /Picadillo/g, r: "🧆 **Picadillo**" }, { s: /\*\*Picadillo\*\* de masa de chorizo/g, r: "**Picadillo de masa de chorizo**", }, { s: /Pollo/g, r: "🍗 **Pollo**" }, { s: /\*\*Pollo\*\* asado/g, r: "**Pollo asado**" }, { s: /\*\*Pollo\*\* frito/g, r: "**Pollo frito**" }, { s: /Salchicha/g, r: "🌭 **Salchicha**" }, { s: /Perr/g, r: "🌭 Perr" }, { s: /Mermelada/g, r: "🍯 Mermelada" }, { s: /Refresco/g, r: "🥃 Refresco" }, { s: /Calabaza/g, r: "🎃 Calabaza" }, { s: /Embutido/g, r: "🥩️ **Embutido**" }, { s: /Chorizo/g, r: "🥩️ **Chorizo**" }, { s: /Ropa vieja/g, r: "🥩️ **Ropa vieja**" }, { s: /Mayonesa/g, r: "🧈 Mayonesa" }, { s: /Pasta/g, r: "🧈 Pasta" }, { s: /Palitroques/g, r: "🥖 Palitroques" }, { s: /Plátano/g, r: "🍌 Plátano" }, { s: /Fufú/g, r: "🍌 Fufú" }, { s: /Aporreado/g, r: "🥩️ **Aporreado**" }, { s: /🥩️ \*\*Aporreado\*\* de pollo/g, r: "🍗 **Aporreado de pollo**" }, { s: /🥩️ \*\*Aporreado\*\* de pescado/g, r: "🐟 **Aporreado de pescado**" }, { s: /Jamonada/g, r: "🥩️ **Jamonada**" }, { s: /Jamon/g, r: "🥩️ **Jamón**" }, { s: /Pescado /g, r: "🐟 **Pescado **" }, { s: /Mortadella/g, r: "🥩️ **Mortadella**" }, { s: /Croqueta/g, r: "🥓 **Croqueta**" }, { s: /\*\*Croqueta\*\*s/g, r: "**Croquetas**" }, { s: /Hígado/g, r: "🥩️ **Hígado**" }, { s: /\*\*Hígado\*\* de res/g, r: "**Hígado de res**" }, { s: /Cerdo/g, r: "🥩️ **Cerdo**" }, { s: /\*\*Cerdo\*\* guisado/g, r: "**Cerdo guisado**" }, { s: /Fiambre/g, r: "🥩️ **Fiambre**" }, { s: /\*\*Fiambre\*\* de cerdo/g, r: "**Fiambre de cerdo**" }, { s: /Hamburguesa/g, r: "🍘 **Hamburguesa**" }, { s: /Dulce/g, r: "🥐 Dulce" }, { s: /Melon/g, r: "🍉️ Melón" }, { s: /Melón/g, r: "🍉️ Melón" }, { s: /Mango/g, r: "🥭 Mango" }, { s: /Piña/g, r: "🍍 Piña" }, { s: /🥐 Dulce de frutabomba/g, r: "🍈 Dulce de frutabomba" }, { s: /Machuquillo/g, r: "🧆 Machuquillo" }, ]; rules.forEach((rule) => { string = string.replace(rule.s, rule.r); }); return string; } Array.from(document.getElementsByClassName("panel-title-flat")).forEach( (item, index) => item.insertAdjacentHTML("afterend", actionsContainer) ) function start (menuNode) { menuObj = getMenu(menuNode); texto = getStringMenu(menuObj); texto = prettifyMenu(texto); menuNode.querySelectorAll('.menu-preview').forEach(element => {element.innerText = texto}) } var notificationElement = `
Acción realizada con éxito
` document.body.insertAdjacentHTML("beforeend",notificationElement) var notificationNode = document.getElementById("notification") function notificate(message = "Acción realizada con éxito"){ notificationNode.firstElementChild.innerHTML = `

${message}

${texto ?? 'El texto está vacío'}
` notificationNode.style.bottom = notificationShowPosition notificationNode.open = true; setTimeout(() => { notificationNode.style.bottom = notificationHidePosition }, 3000); //Ocultar la notificación automáticamente } function copyText(){ navigator.clipboard.writeText(texto); //Copiar al portapapeles notificate('Copiado correctamente') //Notificar console.log(texto); } function shareText(urlTemplate){ window.open(urlTemplate.replace('{text}',encodeURI(texto))) } document.body.addEventListener("click", e => {notificationNode.style.bottom = notificationHidePosition}) Array.from(document.getElementsByName("copy-button")).forEach(item => { item.addEventListener("click", event => { event.stopPropagation() start(event.target.parentElement.parentElement.parentElement.parentElement) copyText() }); }); Array.from(document.querySelectorAll(".btn-share")).forEach(item => { item.addEventListener("click", event => { event.stopPropagation() start(event.target.parentElement.parentElement.parentElement.parentElement.parentElement) shareText(item.dataset.shareurl) }); }); Array.from(document.querySelectorAll("summary")).forEach(item => { item.addEventListener("click", event => { event.stopPropagation() start(event.target.parentElement.parentElement.parentElement.parentElement) }); }); Array.from(document.querySelectorAll(".panel-flat")).forEach(item => { item.addEventListener("auxclick", event => { if (event.button == 1) { event.stopPropagation() start(item) copyText() } }) item.title = "Haga click medio del ratón para copiar el texto modificado." }); })();