Completed
Push — master ( e56e10...e78e26 )
by Elbert
37s
created

driver.js ➔ ... ➔ ???   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
1
/**
2
 * Bookmarklet driver
3
 */
4
5
/** global: wappalyzer */
6
/** global: XMLHttpRequest */
7
8
(function() {
9
	const container = document.getElementById('wappalyzer-container');
10
	const domain = top.location.host;
0 ignored issues
show
Bug introduced by
The variable top seems to be never declared. If this is a global, consider adding a /** global: top */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
11
	const url = top.location.href.replace(/#.*$/, '');
12
	const hasOwn = Object.prototype.hasOwnProperty;
13
14
  /**
15
   * Log messages to console
16
   */
17
  wappalyzer.driver.log = (message, source, type) => {
18
    console.log('[wappalyzer ' + type + ']', '[' + source + ']', message);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
19
  };
20
21
  function getEnvironmentVars() {
22
    wappalyzer.log('func: getEnvironmentVars');
23
24
    var env = [];
25
26
    for ( let i in window ) {
27
      env.push(i);
28
    }
29
30
    wappalyzer.analyze(domain, url, {
31
      html: document.documentElement.innerHTML,
32
      env: env
33
    });
34
  }
35
36
	function getResponseHeaders() {
37
    wappalyzer.log('func: getResponseHeaders');
38
39
    var xhr = new XMLHttpRequest();
40
41
    xhr.open('GET', url, true);
42
43
    xhr.onreadystatechange = () => {
44
      if ( xhr.readyState === 4 && xhr.status ) {
45
        var headers = xhr.getAllResponseHeaders().split("\n");
46
47
        if ( headers.length > 0 && headers[0] != '' ) {
48
          wappalyzer.log('responseHeaders: ' + xhr.getAllResponseHeaders());
49
50
          var responseHeaders = {};
51
52
          headers.forEach(line => {
53
            var name, value;
54
55
            if ( line ) {
56
              name  = line.substring(0, line.indexOf(': '));
57
              value = line.substring(line.indexOf(': ') + 2, line.length - 1);
58
59
              responseHeaders[name.toLowerCase()] = value;
60
            }
61
          });
62
63
          wappalyzer.analyze(domain, url, {
64
            headers: responseHeaders
65
          });
66
        }
67
      }
68
    }
69
70
    xhr.send();
71
  }
72
73
  /**
74
   * Display apps
75
   */
76
  wappalyzer.driver.displayApps = detected => {
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
77
    wappalyzer.log('func: diplayApps');
78
79
    var first = true;
80
    var app;
81
    var category;
82
    var html;
83
84
    html =
85
      '<a id="wappalyzer-close" href="javascript: document.body.removeChild(document.getElementById(\'wappalyzer-container\')); void(0);">' +
86
        'Close' +
87
      '</a>' +
88
      '<div id="wappalyzer-apps">';
89
90
    if ( detected != null && Object.keys(detected).length ) {
91
      for ( app in detected ) {
92
        if ( !hasOwn.call(detected, app) ) {
93
          continue;
94
        }
95
96
        html +=
97
          '<div class="wappalyzer-app' + ( first ? ' wappalyzer-first' : '' ) + '">' +
98
            '<a target="_blank" class="wappalyzer-application" href="' + wappalyzer.config.websiteURL + 'applications/' + app.toLowerCase().replace(/ /g, '-').replace(/[^a-z0-9-]/g, '') + '">' +
99
              '<strong>' +
100
                '<img src="' + wappalyzer.config.websiteURL + 'images/icons/' + (wappalyzer.apps[app].icon || 'default.svg') + '" width="16" height="16"/> ' + app +
101
              '</strong>' +
102
            '</a>';
103
104
        for ( let i in wappalyzer.apps[app].cats ) {
105
          if ( !hasOwn.call(wappalyzer.apps[app].cats, i) ) {
106
            continue;
107
          }
108
109
          category = wappalyzer.categories[wappalyzer.apps[app].cats[i]].name;
110
111
          html += '<a target="_blank" class="wappalyzer-category" href="' + wappalyzer.config.websiteURL + 'categories/' + slugify(category) + '">' + category + '</a>';
112
        }
113
114
        html += '</div>';
115
116
        first = false;
117
      }
118
    } else {
119
      html += '<div id="wappalyzer-empty">No applications detected</div>';
120
    }
121
122
    html += '</div>';
123
124
    container.innerHTML = html;
125
  },
126
127
  /**
128
   * Open a tab
129
   */
130
  function openTab(args) {
131
    open(args.url);
132
  }
133
134
  function slugify(string) {
135
    return string.toLowerCase().replace(/[^a-z0-9-]/g, '-').replace(/--+/g, '-').replace(/(?:^-|-$)/, '');
136
  }
137
138
  getEnvironmentVars();
139
  getResponseHeaders();
140
})();
141