PageSourceSearch

https://calcula-afip.web.app/popup.js

js calcula-afip.web.app collected 2026-10-03 12:18:59 UTC 9,298 bytes, 354 lines download raw bytes

1var tasa;
2var rate;
3
4$(document).ready(init);
5
6function init () {
7	console.log('ready');
8	console.log('v. 0.1');
9	
10	$('#get-usd').val('');
11	$('#get-precio').attr('placeholder','loading...');	
12	
13	// get value rate USD/EUR;
14	getRate = fnGetValues('rate');  
15
16	if (getRate != 'USD' && getRate != 'EUR' ) {		
17		console.log('Rate = ' + getRate + '..error');
18		getRate='USD';
19		fnSetValues('rate','USD');	
20	};
21
22	// config getRate select
23	var src = getRate;    
24    if (getRate == "EUR") {        
25		fnChangeClass('get-usd','euro');		
26		fnChangeClass('get-precio','euro');				
27	}else{
28		fnChangeClass('get-usd','dolar');		
29		fnChangeClass('get-precio','dolar');				
30    }
31
32    //set mode ligth/dark
33    var mode = fnGetValues('mode');
34    if (mode=='dark') {    	
35    	document.body.className="dark";
36    }else{
37    	document.body.className="ligth";
38	}
39
40	fnSetValues('sitio',1);
41
42	getParam();
43	consulta();	
44}
45
46function getParam() {
47	var param = window.location.search;
48	console.log(param);
49	if(param){
50		var value = param.substring(3,param.length);
51		document.getElementById('get-precio').value=value;
52		console.log(value);
53	}else{
54		
55	}
56	calcula();	
57}
58
59/*
60function consulta () {
61
62	console.clear();
63	
64	var sitio = fnGetValues('sitio');
65	var src = fnGetValues('rate');
66	var aduana = fnGetValues('optaduana');		
67	
68	// chrome.runtime.sendMessage({action:"cotiza"},function (response) {
69	// 	console.log('enviando peticion: cotiza');
70	// 	console.log('La respuesta es: ' + response);
71	// 	if(response){
72	// 		showFade(response);
73	// 	}
74    // });	
75	
76	console.log('Consultando Rate:' + src , 'Sitio:' + sitio , 'Aduana:' + aduana);	
77}*/
78
79function showFade(resultado) {	
80	
81	if(undefined != resultado) {		
82		var usd=resultado;		
83		var fixusd = usd;	
84		var tipo = fnGetValues('rate');		
85		
86		if (tipo=='USD') {
87			var txt = 'AR$ = 1 U$D';
88			var mensaje='Cotizacion actual del dolar: ';
89			var color = 'olive' 				
90		}else{
91			var txt = 'AR$ = 1 EUR';    		    	
92			var mensaje='Cotizacion actual Euro: ';
93			var color = '#65469b'  //violeta 	    	
94		};	
95
96		//efecto loading
97		$("#loading").fadeOut(600, function () {					
98			$("#get-usd").hide().fadeIn(300).val(fixusd);						
99			$("#txttitulo").hide().fadeIn(300).text(txt);												
100			$('#get-precio').attr('placeholder','Importe');									
101			$("#get-precio").focus();			
102		});	
103		var msj=mensaje;
104		var fixusd = parseFloat(usd).toFixed(2);	
105		// if (fixusd!=undefined) {
106		// 	chrome.browserAction.setBadgeText({text: fixusd}); // We have 10+ unread items.	
107		// 	chrome.browserAction.setBadgeBackgroundColor({color:color});		
108		// 	chrome.browserAction.setTitle({title : msj + fixusd});
109		// };		
110	
111	
112	}else{	    
113	    $("#get-usd").hide().fadeIn(200).val('');
114	}
115
116}	
117
118//**********************************************************//
119
120//funciones
121function fnGetValues (value) {
122	var obj = localStorage.getItem(value);
123	return obj;
124}
125
126function fnSetValues (field,value) {
127	localStorage.setItem(field,value);
128}
129
130function fnRateChange (getRate) {		
131	if (getRate == 'USD') {			    				
132		fnSetValues('rate','EUR');
133		fnChangeClass('get-usd','euro');
134		fnChangeClass('get-precio','euro');
135		$('#txttitulo').text('AR$ = 1 EUR');
136	}else{			
137		fnSetValues('rate','USD');						
138		fnChangeClass('get-usd','dolar');		
139		fnChangeClass('get-precio','dolar');		
140		$('#txttitulo').text('AR$ = 1 USD');
141	};	
142	consulta();
143}
144
145//cambiar clase CSS usd/euro
146function fnChangeClass (id,src) {		
147	document.getElementById(id).className=src;	
148}
149
150function fixvalues (values) {
151	var obj=parseFloat(values).toFixed(2);
152	return obj;
153}
154
155//Solo permite introducir numeros.
156function soloNumeros(e){  	 	
157  	var key = window.event ? e.which : e.keyCode;	
158	var el = e.srcElement.value;	
159	if(key == 8 || key == 13 || key == 46 || key == 0 || key ==110 || key == 190) {
160		//return true;		
161		if(el.indexOf('.') > -1){
162			e.preventDefault();								
163		}
164	}
165	else{
166		if (key < 48 || key > 57) {			
167			e.preventDefault();
168		}
169  	}
170}
171
172function calcula () {
173
174	var usd = document.getElementById("get-usd").value; //cotizacion del dolar
175	var precio = document.getElementById("get-precio").value;	//importe de la compra en usd		
176	var preciousd=(usd * precio); // usd to ars importe de la compra
177	
178	var afip35  = parseFloat(preciousd) * 0.35;
179
180	//impuesto aduanero
181	var aduana = fnaduana(usd,precio); 
182	
183	//calcula AFIP / impuesto solidario
184	var afip = fnafip(preciousd);		
185	
186	//TASA CORREO(140pe)
187	var tasa = fntasa();		
188	
189	var total = parseFloat(preciousd) + parseFloat(afip) + parseFloat(afip35) +  parseFloat (aduana) + parseFloat(tasa);
190	
191	//mostrar datos 
192	document.getElementById("afip").value=fixvalues(afip);		
193	document.getElementById("afip35").value=fixvalues(afip35);		
194	document.getElementById('tasa').value=fixvalues(tasa);
195	document.getElementById("aduana").value=fixvalues(aduana);
196	document.getElementById("total").value=fixvalues(preciousd);	
197	document.getElementById("preciototal").value=fixvalues(total);
198	
199	document.getElementById("total2").innerText='ARS: ' + fixvalues(total);
200
201	console.log('----------------------------------')		
202	console.log('Precio ARS: ' + usd);
203	console.log('Aduana: ' + aduana);	
204	console.log('AFIP: ' + afip);
205	console.log('Correo: ' + tasa);		
206	console.log('Total General: ' + total);
207	
208	var w = document.body.clientWidth;
209	if(w < 500){	
210		if(total > 0 ){
211			$([document.documentElement, document.body]).animate({
212				scrollTop: $("#get-precio").offset().top
213			}, 400);	
214		}
215		else{
216			$([document.documentElement, document.body]).animate({
217				scrollTop: $(document.body).offset().top
218			}, 300);
219		}
220	}
221	
222		
223}
224
225//eventos
226document.addEventListener('DOMContentLoaded', function() {		
227	
228	//iniciar siempre form popup
229	localStorage.setItem('attach',"false");
230
231	//verifica estado del localstorage para checkbox
232	getStatus = localStorage.getItem('optaduana');    
233    if (getStatus == "true") {
234        document.getElementById("optaduana").checked=true;
235    }   
236
237    var elem = document.getElementById('get-precio');
238
239	elem.addEventListener('keypress',soloNumeros,false);
240	elem.addEventListener('keyup',calcula,false);
241	elem.addEventListener('focus',calcula);	    
242
243	//evento click del checkbox 
244	document.getElementById('optaduana').addEventListener('click', function() {			
245		if (this.checked==true){
246			localStorage.setItem('optaduana','true');
247			document.getElementById('optcorreo').checked=true;
248			document.getElementById('tasa').value=parseFloat('140').toFixed(2);		
249		}else{
250			localStorage.setItem('optaduana','false');			
251			document.getElementById('optcorreo').checked=false;
252			document.getElementById('tasa').value=parseFloat('0').toFixed(2);
253		}
254		calcula();		
255	});
256
257	//TASA CORREO
258	document.getElementById('optcorreo').addEventListener('click',function(){
259		fntasa();					
260		calcula();
261	});
262
263	//edit valor del dolar
264	document.getElementById('edit').addEventListener('click', function() {		
265		document.getElementById("get-usd").disabled=false;
266		document.getElementById("get-usd").focus();
267		document.getElementById("get-usd").select();
268	});
269
270	var el = document.getElementById('get-precio');
271	if(el.value<0){				
272		var preciousd=0;		
273		el.style.color='red';	
274	}else{
275		el.style.color='white';
276	}
277	
278	
279	//desahabiliar edit getdolar una vez que pierde el foco	
280	var obj=document.getElementById("get-usd")	
281	obj.addEventListener('blur', function () {	
282		this.disabled=true;		
283	});
284
285	obj.addEventListener('keypress', function(e) {		
286		var key = window.event ? e.which : e.keyCode;		
287		if(key == 13 ) {
288			this.disabled=true;
289			document.getElementById('get-precio').focus();						
290		}
291	});
292
293	
294	document.getElementById("optrate").addEventListener('click', function () { 											
295		getRate = fnGetValues('rate');	
296		fnRateChange(getRate);						
297	});	
298
299	document.getElementById('btndark').addEventListener('click',dark);
300	
301	function dark () {		
302		var mode=fnGetValues('mode');
303		if(mode=='dark'){
304			document.body.className=null;				
305			fnSetValues('mode','ligth');
306		}else{
307			document.body.className='dark';				
308			fnSetValues('mode','dark');			
309		}
310	}	
311
312	document.getElementById('wp').addEventListener('click',function(){
313		var value = document.getElementById('get-precio').value;
314		if(value){
315			var url = 'https://api.whatsapp.com/send?text=https://calcula-afip.web.app/?=v' + value;
316			this.href = url;
317		}else{
318			alert('Ingrese un importe valido ');
319			$('#get-precio').focus();
320		}	
321
322	})
323		
324});
325
326//verificar estado del check para calcular true=aduana
327function fnaduana (usd,precio) {
328	var aduana=0;
329	var elem = document.getElementById("optaduana");
330	if (elem.checked){													
331		if (precio>50){
332			aduana = (precio - 50) *  0.50 * usd; // ars aduana	%50		
333		}
334	}
335	return aduana; 
336}
337
338//dolar solidario
339function fnafip (preciousd) {			
340	var afip = parseFloat(preciousd * 0.3).toFixed(2);
341	return afip;	
342}
343
344//tasa correo
345function fntasa () {
346	var el = document.getElementById('optcorreo');
347
348	if (el.checked==true) {
349		return parseFloat(140);
350	}
351	else{
352		return parseFloat(0);
353	}
354}

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.