PageSourceSearch

https://loja.correios.com.br/public-resources/js/lojaweb/menu.js

js correios.com.br collected 2026-09-24 07:27:06 UTC 4,203 bytes, 168 lines download raw bytes

1import * as alertas from '../../core/js/alerta.js';
2import * as modal from "../../core/js/modal.js";
3
4//window.onload = async function () {//quando toda a tela estiver carregada	
5  // verificaItensCarrinho();
6//};
7
8window.addEventListener("load", async () => {
9  
10	const usuario = document.getElementById("usuario");
11    
12	if (usuario && usuario.textContent.trim() !== "") {		 
13	   verificaItensCarrinho();
14	} else {
15		atualizarCarrinho(0);	   	  
16	}
17	
18});
19
20
21async function verificaItensCarrinho() {	
22	
23	const urlValidacao = `${ctx}/carrinho/quantidade-itens`;
24	//let btnItenscarrinho = document.getElementById("quantidade-itens");
25	
26   try{		
27		const responseValidacao =  await fetch(urlValidacao, {
28			method: 'GET',
29			headers: {
30				'Accept': 'application/json'
31			},
32		 });
33		 	
34		 const retornoJson=await responseValidacao.json();
35		 
36		if (!responseValidacao.ok) {								
37					
38			alertas.abre(retornoJson.mensagem, 3, 'OK');			
39			return;	
40		}		  	
41		  
42		   atualizarCarrinho(retornoJson.mensagem);	
43			
44  } catch (error) {
45	console.log("Erro ao processar resposta qtditens ");
46  	alertas.abre("Não foi possível exibir a quantidade de itens do carrinho.", 4, 'OK');
47  }	
48}
49
50const container = document.getElementById("anos-filatelia");
51const anoAtual = new Date().getFullYear();
52const anoFinal = anoAtual - 10; // Ano final
53
54for (let ano = anoAtual; ano >= anoFinal; ano--) {
55	    const link = document.createElement("a");
56		link.className = "link-btn btn-txt"
57		
58	    link.href = `${ctx}/produtos/filatelia/${ano}`;		
59	    link.textContent = ano;
60	    container.appendChild(link);
61		
62}
63
64var botaoLupa = document.getElementById("botao-lupa");	
65var texto = document.querySelector('input[type=search]'); 
66	
67botaoLupa.addEventListener("click", () => {	
68	if (texto.value.trim() == ''){
69			alertas.abre('Informe um critério para a pesquisa.', 3, 'OK');
70			return;
71	}else{
72		window.location.href = `${ctx}/lojaweb?texto=${texto.value}`;
73	}
74			
75 });
76  
77 var btnCarrinho = document.getElementById("btn-carrinho")
78 btnCarrinho.addEventListener("click", () => {
79	
80	let qtdItensCarrinho = document.getElementById("quantidade-itens").textContent;
81	
82	const usuario = document.getElementById("usuario");
83	
84	const url = window.location.href;
85			
86 	if (usuario && qtdItensCarrinho == 0){		
87		alertas.abre("Seu carrinho está vazio.", 3, 'OK');
88		return;		   
89 	}else{
90		
91		window.location.href = `${ctx}/carrinho/detalha-itens`;//exibir tela carrinho
92		
93	}
94			
95  });
96  	
97  
98  function atualizarCarrinho(qtd) {
99	
100    const badge = document.getElementById("quantidade-itens");
101	
102    if (qtd > 0) {
103		badge.textContent=qtd     
104    } else {
105      badge.style.display = "none";
106    }
107  }
108  
109  
110  //teste lateral menu dinamico
111document.addEventListener("DOMContentLoaded", async () => {	
112		 
113	let tipoCategoria = "servicos";
114	let urlValidacao = `${ctx}/lojaweb/pesquisar?limiteRegistros=10&tipoCategoria=${tipoCategoria}`;
115
116	try {
117		const responseValidacao = await fetch(urlValidacao, {
118			method: 'GET',
119			headers: {
120				'Accept': 'application/json'
121			},
122		});
123
124		const retornoJson = await responseValidacao.json();
125
126		if (!responseValidacao.ok) {
127			console.error("Não foi possível trazer os serviços");
128			return;
129		}
130		const container = document.getElementById('menu-servicos');
131		
132		if (!container) {
133			console.error("Container não encontrado");
134			return;
135		}		
136
137		if (Array.isArray(retornoJson)) {
138
139			retornoJson.forEach(servico => {				
140				
141				const link = document.createElement('a');
142				link.className = 'link-btn btn-txt';
143				link.href = `${ctx}/servicos/item/${servico.codigoServico}`;
144				const nomeClass= servico.codigoGrupo === "000010" ? "ic-envio" : "ic-carta";
145				
146				link.innerHTML = `<i class=${nomeClass}></i><span>${servico.nomeComercial}</span>`;					
147				
148				// Adiciona evento de clique para armazenar no sessios do usuario
149				//link.addEventListener('click', (e) => {
150					//sessionStorage.setItem('grupoSelecionado', servico.codigoGrupo);
151										
152				// });	
153									
154				container.appendChild(link);	
155			
156			});
157
158		} else {
159			console.error("Não existe serviços");			
160		}
161
162	} catch (error) {
163		console.error("Erro na consulta a serviços" + error);
164		
165	}	
166
167});
168

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.