Skip to content

Commit

Permalink
Added css class detector
Browse files Browse the repository at this point in the history
  • Loading branch information
fluescher committed Mar 6, 2012
1 parent 69a0154 commit 877a0d0
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions detector.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@
'Prostores' : /-legacycss\/Asset">/,
'osCommerce': /(product_info\.php\?products_id|_eof \/\/-->)/,
'OpenCart': /index.php\?route=product\/product/,
'Shibboleth': /<form action="\/idp\/Authn\/UserPassword" method="post">/,
'Bootstrap': /<link.*href=\".*bootstrap.*\.css\" rel=\"stylesheet\"/
'Shibboleth': /<form action="\/idp\/Authn\/UserPassword" method="post">/
};

for (t in text_tests)
Expand Down Expand Up @@ -378,6 +377,45 @@
// 8: detect based on built-in database
// @todo

// 9: detect based on defined css classes
var cssClasses = {
'Bootstrap': ['hero-unit', '.carousel-control', '[class^="icon-"]:last-child']
};

for (t in cssClasses) {
if (t in _apps) continue;

var found = true;
for(css in cssClasses[t]) {
var act = false;
var name = cssClasses[t][css];

/* Iterate through all registered css classes and check for presence */
for(cssFile in document.styleSheets) {
for(cssRule in document.styleSheets[cssFile].cssRules) {
var style = document.styleSheets[cssFile].cssRules[cssRule];

if (typeof style === "undefined") continue;
if (typeof style.selectorText === "undefined") continue;

if (style.selectorText.indexOf(name) != -1) {
act = true;
break;
}
}
if (act === true) break;
}

found = found & act;
}

if(found == true) {
_apps[t] = -1;
} else {
break;
}
}

// convert to array
var jsonString = JSON.stringify(_apps);
// send back to background page
Expand Down

0 comments on commit 877a0d0

Please sign in to comment.