-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
176 lines (138 loc) · 4.37 KB
/
popup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
async function getData() {
try {
const response = await fetch('indiapincodes.json');
const resJson = await response.json();
return resJson;
} catch (error) {
let contexterr = `<div class="alert alert-danger mt-3" role="alert">
Something went wrong data not recived.....
</div>`
$("#contentdiv").html(contexterr);
console.warn('getData error', error);
}
return null;
}
function Areafinder(book,state,key,Displaycontent){
let givenstate = state;
let finderkey = key.toLowerCase()
let statelist = []
let resultlist=[]
let id;
for(id=0; id < book.length; id++){
if (book[id].stateName == givenstate){
statelist.push(id);
continue;
}else{
continue;
}
}
if (statelist.length > 0){
let intial;
for(intial=0; intial < statelist.length; intial++){
let predifineword = book[statelist[intial]].officeName
let area = predifineword.toLowerCase()
if (area.indexOf(finderkey)!= -1){
resultlist.push(statelist[[intial]])
}
}
}
if (resultlist.length > 0){
contentDisplay(book,resultlist,Displaycontent)
}else{
let errov = "Hint Is Invalid"
dispalyerror(errov,key,Displaycontent)
}
}
function contentDisplay(book,idarr,Displaycontent){
var contcontainer =" "
var i;
for (i=0; i< idarr.length; i++){
let Zipcode = book[idarr[i]].pincode
let state = book[idarr[i]].stateName
let district =book[idarr[i]].districtName
let area = book[idarr[i]].officeName
let taluk = book[idarr[i]].taluk
let contenttohtml = `<div class="card text-dark bg-light mb-3 mt-2" style="max-width: 18rem;">
<div class="card-header"><span>${i+1}</span> Pincode of ${Zipcode} </div>
<div class="card-body">
<h5 class="card-title">State of ${state}</h5>
<p class="card-text">
<strong>District :</strong> ${district} <br>
<strong>Taluk :</strong> ${taluk} <br>
<strong>Area :</strong> ${area} <br>
</p>
</div>
</div>`;
contcontainer += contenttohtml
}
$(Displaycontent).html(contcontainer);
}
function Pincodefinder(book,key,givenstate,displaycontent){
numkey = Number(key)
var id;
var listreslut = []
var listreslutsat =[]
for(var ids=0; ids < book.length; ids++){
if (book[ids].stateName == givenstate){
listreslutsat.push(ids);
continue;
}else{
continue;
}
}
for(id=0; id < listreslutsat.length; id++){
var bookpin = book[listreslutsat[id]].pincode
if (bookpin == numkey){
listreslut.push(listreslutsat[id])
continue;
}
else{
continue;
}
}
if(listreslut.length > 0){
contentDisplay(book,listreslut,displaycontent)
}else{
let errv = "Not Get Infomation"
dispalyerror(errv,key,displaycontent)
}
}
function dispalyerror(errorop,key,Displaycontent){
let contexterr = `<div class="alert alert-danger mt-3" role="alert">
${errorop}.. { ${key} }
</div>`
$(Displaycontent).html(contexterr);
}
$(document).ready(function(){
$("#toarea").click(function(){
$("#areaform").removeClass('not-visiblity');
$('#pinform').addClass('not-visiblity');
$('#topincode').removeClass('not-visiblity');
$("#toarea").addClass("not-visiblity");
});
$("#topincode").click(function(){
$("#pinform").removeClass('not-visiblity');
$('#areaform').addClass('not-visiblity');
$('#toarea').removeClass('not-visiblity');
$("#topincode").addClass("not-visiblity");
});
});
$("#pinserach").click(function() {
let pincode = document.getElementById("Pincode").value
chrome.storage.local.get(["stateNameStores"], function(datas){
getData().then(data => Pincodefinder(data,pincode,datas.stateNameStores,"#contentdiv"));
})
});
$("#areaserach").click(function() {
let areastring = document.getElementById("area").value
chrome.storage.local.get(["stateNameStores"], function(datas){
getData().then(data => Areafinder(data,datas.stateNameStores,areastring,"#contentdiv"));
})
});
document.querySelector('#optionstogo').addEventListener("click",function() {
if (chrome.runtime.openOptionsPage) {
chrome.runtime.openOptionsPage();
} else {
window.open(chrome.runtime.getURL('options.html'));
}
});