Skip to content

Instantly share code, notes, and snippets.

@dantetesta
Last active March 27, 2024 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dantetesta/c5925eba5640283ef3f1d027f694f4fc to your computer and use it in GitHub Desktop.
Save dantetesta/c5925eba5640283ef3f1d027f694f4fc to your computer and use it in GitHub Desktop.
<script>
jQuery(document).ready(function() {
// Inicializa a mensagem com uma template string vazia
let msgzap = '';
// Itera de 1 a 10, construindo a mensagem a partir dos elementos .txt1 até .txt10
for (let i = 1; i <= 10; i++) {
let textContent = jQuery(`.txt${i}`).text().trim();
// Adiciona o texto à mensagem msgzap com a formatação desejada
switch(i) {
case 1:
msgzap += `*${textContent}*\n`;
break;
case 2:
msgzap += `🤯 *${textContent}* \n\n`;
break;
case 3:
msgzap += `~de~ ${textContent}\n`;
break;
case 4:
msgzap += `*por* ${textContent}\n\n`;
break;
case 5:
msgzap += `🚚 *${textContent}*\n\n`;
break;
default:
msgzap += `${textContent}\n${i < 10 ? '\n' : ''}`; // Adiciona quebra de linha extra exceto no último item
break;
}
}
// Adiciona evento de clique no botão para copiar msgzap para a área de transferência
jQuery('#btn').click(function() {
// Cria e usa um textarea temporário para copiar o texto
var textareaTemporario = document.createElement('textarea');
jQuery(textareaTemporario).css({
position: 'fixed', // Evita possíveis problemas de layout
left: '-9999px' // Move o textarea fora da tela
});
document.body.appendChild(textareaTemporario);
jQuery(textareaTemporario).val(msgzap); // Utiliza a variável 'msgzap'
jQuery(textareaTemporario).select();
document.execCommand('copy');
document.body.removeChild(textareaTemporario);
// Feedback visual no botão
var textoOriginal = jQuery(this).find('.elementor-button-text').text();
jQuery(this).find('.elementor-button-text').text('Copiado!');
setTimeout(() => {
jQuery(this).find('.elementor-button-text').text(textoOriginal);
}, 3000);
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment