untitled-1770632447102-dad99d43-02ec-48e6-b3c1-b755201c0603

Size

9.1 KB

Version

1.2.1

Created

Feb 9, 2026

Updated

27 days ago

1// ==UserScript==
2// @version		1.2.1
3// @grant		none
4// ==/UserScript==
5(function() {
6    'use strict';
7
8    // Debounce function for performance
9    function debounce(func, wait) {
10        let timeout;
11        return function executedFunction(...args) {
12            const later = () => {
13                clearTimeout(timeout);
14                func(...args);
15            };
16            clearTimeout(timeout);
17            timeout = setTimeout(later, wait);
18        };
19    }
20
21    // Extract domain name from the page
22    function getDomainName() {
23        const domainLink = document.querySelector('#page > div > div > div > div > div > div > div > div > div.pul-page-header__title > div > h1 > a');
24        if (domainLink) {
25            return domainLink.textContent.trim();
26        }
27        console.error('Domain name not found on page');
28        return null;
29    }
30
31    // Perform DNS lookup using fetch
32    async function performDnsLookup(domain) {
33        try {
34            console.log('Performing DNS lookup for domain:', domain);
35
36            const url = `https://serverkraft.hu/dns-lookup.php?domain=${encodeURIComponent(domain)}`;
37            const resp = await fetch(url, { method: 'GET' });
38
39            if (!resp.ok) {
40                const text = await resp.text().catch(() => null);
41                throw new Error(`Request failed with status ${resp.status}${text ? ': '+text : ''}`);
42            }
43
44            let data;
45            try {
46                data = await resp.json();
47            } catch (e) {
48                const txt = await resp.text();
49                data = JSON.parse(txt);
50            }
51
52            console.log('Parsed DNS data:', data);
53            return data;
54        } catch (error) {
55            console.error('DNS lookup failed:', error);
56            throw error;
57        }
58    }
59
60    // Render google A, MX, TXT, NS cleanly
61    function displayDnsResults(container, data) {
62        const existingResults = container.querySelector('.dns-results');
63        if (existingResults) existingResults.remove();
64
65        const resultsDiv = document.createElement('div');
66        resultsDiv.className = 'dns-results';
67        resultsDiv.style.cssText = `
68            margin-top: 15px;
69            padding: 15px;
70            background: #f8f9fa;
71            border: 1px solid #dee2e6;
72            border-radius: 4px;
73            font-family: monospace;
74            font-size: 12px;
75            max-height: 400px;
76            overflow-y: auto;
77        `;
78
79        if (data && data.google) {
80            const g = data.google;
81            const title = document.createElement('div');
82            title.style.cssText = 'font-weight:700;margin-bottom:8px;font-size:13px;';
83            title.textContent = 'Google DNS records';
84            resultsDiv.appendChild(title);
85
86            const rowStyle = 'margin:6px 0;';
87            const stripQuotes = s => typeof s === 'string' ? s.replace(/^"|"$/g, '') : s;
88            const makeRow = (label, value) => {
89                const row = document.createElement('div');
90                row.style.cssText = rowStyle;
91                const lbl = document.createElement('strong');
92                lbl.textContent = label + ': ';
93                const val = document.createElement('span');
94                if (Array.isArray(value)) {
95                    val.style.whiteSpace = 'pre-wrap';
96                    val.textContent = value.length ? value.map(v => stripQuotes(v)).join('\n') : '—';
97                } else {
98                    val.textContent = value == null ? '—' : stripQuotes(value);
99                }
100                row.appendChild(lbl);
101                row.appendChild(val);
102                return row;
103            };
104
105            resultsDiv.appendChild(makeRow('A', g.A));
106            resultsDiv.appendChild(makeRow('MX', g.MX));
107            resultsDiv.appendChild(makeRow('TXT', g.TXT));
108            resultsDiv.appendChild(makeRow('NS', g.NS));
109        } else {
110            const pre = document.createElement('pre');
111            pre.style.cssText = '\n                margin: 0;\n                white-space: pre-wrap;\n                word-wrap: break-word;\n            ';
112            pre.textContent = JSON.stringify(data, null, 2);
113            resultsDiv.appendChild(pre);
114        }
115
116        container.appendChild(resultsDiv);
117    }
118
119    function showLoading(button) {
120        button.disabled = true;
121        button.textContent = 'Betöltés...';
122    }
123
124    function hideLoading(button) {
125        button.disabled = false;
126        button.textContent = 'DNS lookup';
127    }
128
129    function showError(container, message) {
130        const existingResults = container.querySelector('.dns-results');
131        if (existingResults) existingResults.remove();
132
133        const errorDiv = document.createElement('div');
134        errorDiv.className = 'dns-results';
135        errorDiv.style.cssText = `
136            margin-top: 15px;
137            padding: 15px;
138            background: #f8d7da;
139            border: 1px solid #f5c6cb;
140            border-radius: 4px;
141            color: #721c24;
142            font-size: 14px;
143        `;
144        errorDiv.textContent = message;
145        container.appendChild(errorDiv);
146    }
147
148    // Initialize the DNS lookup button inside existing .hire-developer-link container
149    function initDnsLookup() {
150        const statisticsCard = document.querySelector('.smb-web-view-dynamic-list-statistics-card');
151        if (!statisticsCard) {
152            console.log('Statistics card not found, retrying...');
153            return false;
154        }
155
156        // Check if DNS card already exists
157        const existingDnsCard = document.querySelector('.dns-lookup-card');
158        if (existingDnsCard) {
159            console.log('DNS lookup card already exists');
160            return true;
161        }
162
163        console.log('Found statistics card, creating DNS lookup card');
164
165        // Create a new card similar to statistics card
166        const dnsCard = document.createElement('div');
167        dnsCard.className = 'smb-web-view-dynamic-list-card dns-lookup-card';
168        dnsCard.style.cssText = `
169            background: white;
170            border: 1px solid #d1d5db;
171            border-radius: 4px;
172            padding: 20px;
173            margin-top: 16px;
174        `;
175
176        // Create heading
177        const heading = document.createElement('h4');
178        heading.className = 'pul-heading pul-heading--h4';
179        heading.textContent = 'DNS Lookup';
180        heading.style.cssText = 'margin-bottom: 15px; font-weight: 600;';
181
182        // Create container for button and results
183        const container = document.createElement('div');
184
185        // Create DNS lookup button
186        const dnsButton = document.createElement('button');
187        dnsButton.textContent = 'DNS lookup';
188        dnsButton.className = 'pul-button pul-button--primary';
189        dnsButton.type = 'button';
190        dnsButton.style.cssText = `
191            width: 100%;
192            padding: 10px 15px;
193            background-color: #007bff;
194            color: white;
195            border: none;
196            border-radius: 4px;
197            cursor: pointer;
198            font-size: 14px;
199            font-weight: 500;
200        `;
201
202        // Add hover effect
203        dnsButton.addEventListener('mouseenter', () => {
204            if (!dnsButton.disabled) {
205                dnsButton.style.backgroundColor = '#0056b3';
206            }
207        });
208        dnsButton.addEventListener('mouseleave', () => {
209            if (!dnsButton.disabled) {
210                dnsButton.style.backgroundColor = '#007bff';
211            }
212        });
213
214        // Add click handler
215        dnsButton.addEventListener('click', async () => {
216            const domain = getDomainName();
217            
218            if (!domain) {
219                showError(container, 'Nem sikerült megtalálni a domain nevet az oldalon.');
220                return;
221            }
222
223            showLoading(dnsButton);
224
225            try {
226                const dnsData = await performDnsLookup(domain);
227                hideLoading(dnsButton);
228                displayDnsResults(container, dnsData);
229            } catch (error) {
230                hideLoading(dnsButton);
231                showError(container, `Hiba történt a DNS lookup során: ${error.message}`);
232            }
233        });
234
235        container.appendChild(dnsButton);
236        dnsCard.appendChild(heading);
237        dnsCard.appendChild(container);
238        
239        // Insert the DNS card after the statistics card
240        statisticsCard.parentNode.insertBefore(dnsCard, statisticsCard.nextSibling);
241
242        console.log('DNS lookup card created successfully');
243        return true;
244    }
245
246    function init() {
247        if (initDnsLookup()) return;
248        if (document.readyState === 'loading') {
249            document.addEventListener('DOMContentLoaded', () => setTimeout(initDnsLookup, 500));
250        } else {
251            setTimeout(initDnsLookup, 500);
252        }
253
254        const observer = new MutationObserver(debounce(() => {
255            const statisticsCard = document.querySelector('.smb-web-view-dynamic-list-statistics-card');
256            const existingDnsCard = document.querySelector('.dns-lookup-card');
257            if (statisticsCard && !existingDnsCard) initDnsLookup();
258        }, 500));
259
260        observer.observe(document.body, { childList: true, subtree: true });
261    }
262
263    init();
264})();