/** * Bookmarklet driver */ /** global: wappalyzer */ /** global: XMLHttpRequest */ (function () { wappalyzer.driver.document = document; const container = document.getElementById('wappalyzer-container'); const url = wappalyzer.parseUrl(window.top.location.href); const hasOwn = Object.prototype.hasOwnProperty; /** * Log messages to console */ wappalyzer.driver.log = (message, source, type) => { console.log(`[wappalyzer ${type}]`, `[${source}]`, message); }; function getPageContent() { wappalyzer.log('func: getPageContent', 'driver'); const scripts = Array.prototype.slice .apply(document.scripts) .filter(s => s.src) .map(s => s.src); let html = new window.XMLSerializer().serializeToString(document).split('\n'); html = html .slice(0, 1000).concat(html.slice(html.length - 1000)) .map(line => line.substring(0, 1000)) .join('\n'); wappalyzer.analyze(url, { html, scripts, }); } function getResponseHeaders() { wappalyzer.log('func: getResponseHeaders', 'driver'); const xhr = new XMLHttpRequest(); xhr.open('GET', url, true); xhr.onreadystatechange = () => { if (xhr.readyState === 4 && xhr.status) { const headers = xhr.getAllResponseHeaders().split('\n'); if (headers.length > 0 && headers[0] != '') { wappalyzer.log(`responseHeaders: ${xhr.getAllResponseHeaders()}`, 'driver'); const responseHeaders = {}; headers.forEach((line) => { let name, value; if (line) { name = line.substring(0, line.indexOf(': ')); value = line.substring(line.indexOf(': ') + 2, line.length - 1); if (!responseHeaders[name.toLowerCase()]) { responseHeaders[name.toLowerCase()] = []; } responseHeaders[name.toLowerCase()].push(value); } }); wappalyzer.analyze(url, { headers: responseHeaders, }); } } }; xhr.send(); } /** * Display apps */ wappalyzer.driver.displayApps = (detected) => { wappalyzer.log('func: displayApps', 'driver'); let first = true; let app; let category; let html; html = '' + 'Close' + '' + '
'; if (detected != null && Object.keys(detected).length) { for (app in detected) { if (!hasOwn.call(detected, app)) { continue; } let version = detected[app].version, confidence = detected[app].confidence; html += `
` + `` + '' + ` ${app }${ version ? ` ${version}` : ''}${confidence < 100 ? ` (${confidence}% sure)` : '' }`; for (const i in wappalyzer.apps[app].cats) { if (!hasOwn.call(wappalyzer.apps[app].cats, i)) { continue; } category = wappalyzer.categories[wappalyzer.apps[app].cats[i]].name; html += `${category}`; } html += '
'; first = false; } } else { html += '
No applications detected
'; } html += '
'; container.innerHTML = html; }, /** * Open a tab */ function openTab(args) { open(args.url); }; function slugify(string) { return string.toLowerCase().replace(/[^a-z0-9-]/g, '-').replace(/--+/g, '-').replace(/(?:^-|-$)/, ''); } getPageContent(); getResponseHeaders(); }());