Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save brunomarks7/9e6461e014620d5998334440a91dc031 to your computer and use it in GitHub Desktop.
Save brunomarks7/9e6461e014620d5998334440a91dc031 to your computer and use it in GitHub Desktop.
Script para ser usado com extensão do Chrome Tampermonkey para remover CPF de clientes em NFes no formato etiqueta, no TinyERP, em função do LGPD
// ==UserScript==
// @name TinyERP - Remove CPF do cliente em NF em formato etiqueta
// @namespace http://tampermonkey.net/
// @version 0.1
// @author https://github.com/brunomarks7
// @match *://erp.tiny.com.br/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
// ==/UserScript==
(function () {
'use strict';
main();
function main() {
if (document.domain === "erp.tiny.com.br") {
const cpfs = getCPFs();
cpfs.map(item => {
if (validaCpf(item.innerText)) {
item.parentNode.remove();
item.remove();
}
})
}
}
function getCPFs() {
return [...document.querySelectorAll('.nobrk')]
}
function validaCpf(str) {
str = str.replace('.', '');
str = str.replace('.', '');
str = str.replace('-', '');
let cpf = str;
let numeros, digitos, soma, i, resultado, digitos_iguais;
digitos_iguais = 1;
if (cpf.length < 11) {
return false;
}
for (i = 0; i < cpf.length - 1; i++) {
if (cpf.charAt(i) != cpf.charAt(i + 1)) {
digitos_iguais = 0;
break;
}
}
if (!digitos_iguais) {
numeros = cpf.substring(0, 9);
digitos = cpf.substring(9);
soma = 0;
for (i = 10; i > 1; i--) {
soma += numeros.charAt(10 - i) * i;
}
resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
if (resultado != digitos.charAt(0)) {
return false;
}
numeros = cpf.substring(0, 10);
soma = 0;
for (i = 11; i > 1; i--) {
soma += numeros.charAt(11 - i) * i;
}
resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
if (resultado != digitos.charAt(1)) {
return false;
}
return true;
}
else {
return false;
}
}
})();
@brunomarks7
Copy link
Author

O arquivo verifica o HTML da página de NFs em formato de etiqueta, loopa as tags usadas nos campos de CPF e verifica se é um CPF válido. Se for válido ele deleta apenas da visualização da tela de impressão.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment