1 | // jshint esversion: 8, -W069 |
||
2 | |||
3 | const whois = require('../common/whoisWrapper'), |
||
4 | parseRawData = require('../common/parseRawData'); |
||
0 ignored issues
–
show
Unused Code
introduced
by
![]() |
|||
5 | |||
6 | const { |
||
7 | getDate |
||
8 | } = require('../common/conversions'), { |
||
9 | ipcRenderer |
||
10 | } = require('electron'); |
||
11 | |||
12 | const { |
||
13 | isDomainAvailable, |
||
14 | getDomainParameters, |
||
15 | preStringStrip, |
||
16 | toJSON |
||
17 | } = whois; |
||
18 | |||
19 | window.$ = window.jQuery = require('jquery'); |
||
20 | |||
21 | var singleWhois = { |
||
22 | 'input': { |
||
23 | 'domain': null |
||
24 | }, |
||
25 | 'results': null |
||
26 | }; |
||
27 | |||
28 | /* |
||
29 | ipcRenderer.on('sw:results', function(...) {...}); |
||
30 | On event: Single whois results, whois reply processing |
||
31 | parameters |
||
32 | event (object) - Event object |
||
33 | domainResults (object) - Domain results object |
||
34 | */ |
||
35 | ipcRenderer.on('sw:results', function(event, domainResults) { |
||
36 | var domainName, |
||
37 | domainStatus, |
||
38 | domainResultsJSON, |
||
39 | resultFilter, |
||
40 | errorReason; |
||
41 | //ipcRenderer.send('app:debug', "Whois domain reply:\n {0}".format(domainResults)); |
||
42 | |||
43 | domainResults = preStringStrip(domainResults); |
||
44 | domainResultsJSON = toJSON(domainResults); |
||
45 | |||
46 | // Check domain status |
||
47 | domainName = domainResultsJSON.domainName || domainResultsJSON.domain; |
||
48 | |||
49 | domainStatus = isDomainAvailable(domainResults); |
||
50 | resultFilter = getDomainParameters(domainName, domainStatus, domainResults, domainResultsJSON); |
||
51 | |||
52 | var { |
||
53 | domain, |
||
54 | updateDate, |
||
55 | registrar, |
||
56 | creationDate, |
||
57 | company, |
||
58 | expiryDate |
||
59 | } = resultFilter; |
||
60 | |||
61 | switch (domainStatus) { |
||
62 | case 'unavailable': |
||
63 | $('#swMessageUnavailable').removeClass('is-hidden'); |
||
64 | $('#swMessageWhoisResults').text(domainResults); |
||
65 | |||
66 | $('#swTdDomain').attr('url', "http://" + domain); |
||
67 | $('#swTdDomain').text(domain); |
||
68 | |||
69 | //console.log(domainResultsJSON['registrarRegistrationExpirationDate'] || domainResultsJSON['expires'] || domainResultsJSON['registryExpiryDate']); |
||
70 | $('#swTdUpdate').text(updateDate); |
||
71 | $('#swTdRegistrar').text(registrar); |
||
72 | $('#swTdCreation').text(creationDate); |
||
73 | $('#swTdCompany').text(company); |
||
74 | $('#swTdExpiry').text(expiryDate); |
||
75 | $('#swTableWhoisinfo.is-hidden').removeClass('is-hidden'); |
||
76 | break; |
||
77 | |||
78 | case 'available': |
||
79 | $('#swMessageWhoisResults').text(domainResults); |
||
80 | $('#swMessageAvailable').removeClass('is-hidden'); |
||
81 | break; |
||
82 | |||
83 | default: |
||
84 | if (domainStatus.includes('error')) { |
||
85 | errorReason = domainStatus.split(':')[1]; // Get Error reason |
||
86 | $('#swMessageWhoisResults').text("Whois error due to {0}:\n{1}".format(errorReason, domainResults)); |
||
87 | $('#swMessageError').removeClass('is-hidden'); |
||
88 | } else { |
||
89 | $('#swMessageWhoisResults').text("Whois default error\n{0}".format(domainResults)); |
||
90 | $('#swMessageError').removeClass('is-hidden'); |
||
91 | } |
||
92 | break; |
||
93 | } |
||
94 | |||
95 | $('#swSearchButtonSearch').removeClass('is-loading'); |
||
96 | $('#swSearchInputDomain').removeAttr('readonly'); |
||
97 | |||
98 | return; |
||
0 ignored issues
–
show
|
|||
99 | }); |
||
100 | |||
101 | /* |
||
102 | ipcRenderer.on('sw:copied', function() {...}); |
||
103 | On event: Domain copied |
||
104 | */ |
||
105 | ipcRenderer.on('sw:copied', function() { |
||
106 | $('#swDomainCopied').addClass('is-active'); |
||
107 | |||
108 | return; |
||
0 ignored issues
–
show
|
|||
109 | }); |
||
110 | |||
111 | /* |
||
112 | $('#swSearchInputDomain').keyup(function(...) {...}); |
||
113 | On keyup: Trigger search event with [ENTER] key |
||
114 | */ |
||
115 | $('#swSearchInputDomain').keyup(function(event) { |
||
116 | // Cancel the default action, if needed |
||
117 | event.preventDefault(); |
||
118 | // Number 13 is the "Enter" key on the keyboard |
||
119 | if (event.keyCode === 13) $('#swSearchButtonSearch').click(); |
||
120 | |||
121 | return; |
||
0 ignored issues
–
show
|
|||
122 | }); |
||
123 | |||
124 | /* |
||
125 | $('#swTdDomain').click(function() {...}); |
||
126 | On click: Open website for domain lookup URL in a new window |
||
127 | */ |
||
128 | $('#swTdDomain').click(function() { |
||
129 | var domain = $('#swTdDomain').attr('url'); |
||
130 | ipcRenderer.send('sw:openlink', domain); |
||
131 | |||
132 | return; |
||
0 ignored issues
–
show
|
|||
133 | }); |
||
134 | |||
135 | /* |
||
136 | $('#swSearchButtonSearch').click(function() {...}); |
||
137 | On click: Single whois lookup/search button |
||
138 | */ |
||
139 | $('#swSearchButtonSearch').click(function() { |
||
140 | var { |
||
141 | input |
||
142 | } = singleWhois; |
||
143 | var { |
||
144 | domain |
||
145 | } = input; |
||
146 | |||
147 | if ($(this).hasClass('is-loading')) return true; |
||
148 | ipcRenderer.send('app:debug', "#swSearchButtonSearch was clicked"); |
||
149 | |||
150 | domain = $('#swSearchInputDomain').val(); |
||
151 | |||
152 | ipcRenderer.send('app:debug', "Looking up for {0}".format(domain)); |
||
153 | |||
154 | $('#swSearchButtonSearch').addClass('is-loading'); |
||
155 | $('#swSearchInputDomain').attr('readonly', ''); |
||
156 | $('.notification:not(.is-hidden)').addClass('is-hidden'); |
||
157 | $('#swTableWhoisinfo:not(.is-hidden)').addClass('is-hidden'); |
||
158 | tableReset(); |
||
159 | ipcRenderer.send("sw:lookup", domain); |
||
160 | return undefined; |
||
161 | }); |
||
162 | |||
163 | /* |
||
164 | $('.swMessageWhoisOpen').click(function() {...}); |
||
165 | On click: Single whois lookup modal open click |
||
166 | */ |
||
167 | $('.swMessageWhoisOpen').click(function() { |
||
168 | ipcRenderer.send('app:debug', "Opening whois reply"); |
||
169 | $('#swMessageWhois').addClass('is-active'); |
||
170 | |||
171 | return; |
||
0 ignored issues
–
show
|
|||
172 | }); |
||
173 | |||
174 | /* |
||
175 | $('#swMessageWhoisClose').click(function() {...}); |
||
176 | On click: Single whois lookup modal close click |
||
177 | */ |
||
178 | $('#swMessageWhoisClose').click(function() { |
||
179 | ipcRenderer.send('app:debug', "Closing whois reply"); |
||
180 | $('#swMessageWhois').removeClass('is-active'); |
||
181 | |||
182 | return; |
||
0 ignored issues
–
show
|
|||
183 | }); |
||
184 | |||
185 | /* |
||
186 | $('#swDomainCopiedClose').click(function() {...}); |
||
187 | On click: Domain copied close click |
||
188 | */ |
||
189 | $('#swDomainCopiedClose').click(function() { |
||
190 | ipcRenderer.send('app:debug', "Closing domain copied"); |
||
191 | $('#swDomainCopied').removeClass('is-active'); |
||
192 | |||
193 | return; |
||
0 ignored issues
–
show
|
|||
194 | }); |
||
195 | |||
196 | /* |
||
197 | tableReset |
||
198 | Resets registry table contents |
||
199 | */ |
||
200 | function tableReset() { |
||
201 | ipcRenderer.send('app:debug', "Resetting whois result table"); |
||
202 | $('#swTdDomain').attr('href', "#"); |
||
203 | $('#swTdDomain').text('n/a'); |
||
204 | $('#swTdUpdate').text('n/a'); |
||
205 | $('#swTdRegistrar').text('n/a'); |
||
206 | $('#swTdCreation').text('n/a'); |
||
207 | $('#swTdCompany').text('n/a'); |
||
208 | $('#swTdExpiry').text('n/a'); |
||
209 | |||
210 | return; |
||
0 ignored issues
–
show
|
|||
211 | } |
||
212 |