Skip to content

Commit

Permalink
update app detector to be able to detect other store types and fix a …
Browse files Browse the repository at this point in the history
…bug where it was not detecting some stores again due to asset paths
  • Loading branch information
jayelkaake committed Feb 4, 2021
1 parent 74dd789 commit da5f968
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 23 deletions.
7 changes: 6 additions & 1 deletion css/popup.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ body {

.apps-table-container {
max-height: 300px;
overflow: scroll;
overflow-y: auto;
min-width: 400px;
width: 100%;
}

.table-apps {
margin-bottom: 0;
}

.app-links > a {
Expand Down
Binary file added img/icons/bigcommerce.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added img/icons/magento1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/icons/magento2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/icons/shopify.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/icons/wix.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/icons/woocommerce.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 13 additions & 5 deletions js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ SAD.Background = function(opts) {

chrome.runtime.onMessage.addListener(function(msgObj) {
if (msgObj.action == 'getApps') {
chrome.runtime.sendMessage({ action: "setApps", apps: self.apps, detectableApps: SHOPIFY_APPS, detectableThemes: SHOPIFY_THEMES, theme: self.theme });
chrome.runtime.sendMessage({
action: "setApps",
apps: self.apps,
detectableApps: SHOPIFY_APPS,
detectableThemes: SHOPIFY_THEMES,
theme: self.theme,
platform: self.platform
});
return true;
} else if (msgObj.action =='setPageScripts') {
self.detectScripts(msgObj.pageScripts, msgObj.pageUrl, msgObj.theme);
Expand All @@ -28,7 +35,7 @@ SAD.Background = function(opts) {

self.setLoading = function() {
chrome.browserAction.disable();
chrome.browserAction.setIcon({ path: 'img/icon.png' });
chrome.browserAction.setIcon({ path: 'img/icons/detector.png' });
chrome.browserAction.setBadgeText({
text: '..'
});
Expand All @@ -38,22 +45,23 @@ SAD.Background = function(opts) {
chrome.browserAction.setBadgeText({
text: ''
});
chrome.browserAction.setIcon({ path: 'img/icon-disabled.png' });
chrome.browserAction.setIcon({ path: 'img/icons/detector-disabled.png' });
chrome.browserAction.disable();
};

self.detectScripts = function(scripts, pageUrl, windowTheme) {
var detector = new SAD.Detector({ scripts: scripts, pageUrl: pageUrl, windowTheme: windowTheme });
self.platform = detector.detectPlatform();

if (detector.isShopifyStore()) {
if (self.platform) {
self.apps = detector.detectApps();
self.theme = detector.detectTheme();

chrome.browserAction.setBadgeText({
text: self.apps.length.toString()
});
chrome.browserAction.enable();
chrome.browserAction.setIcon({ path: 'img/icon.png' });
chrome.browserAction.setIcon({ path: 'img/icons/' + self.platform + '.png' });
return true;
} else {
self.disable();
Expand Down
18 changes: 14 additions & 4 deletions js/detector.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,24 @@ SAD.Detector = function(opts) {
return { name: self.windowTheme.name, custom_name: self.windowTheme.name, fully_custom: true};
};

self.isShopifyStore = function() {
self.detectPlatform = function() {
// Skip this site - it's core shopify
if (opts.pageUrl.match(/.*\.shopify\..*/i)) return false;
if (opts.pageUrl.match(/.*\.(shopify|magento|bigcommerce)\.[a-z]+/i)) return false;

for (var i = 0; i < self.scripts.length; i++) {
var script = self.scripts[i];
if (!script.match(/.*\.shopify\..*/i)) {
return true;
if (script.match(/cdn[0-9]*\.bigcommerce\.[a-z]+/i)) {
return 'bigcommerce';
} else if (script.match(/cdn[0-9]*\.shopify\.[a-z]+/i)) {
return 'shopify';
} else if (script.match(/mage\/cookies\.js/i)) {
return 'magento1';
} else if (script.match(/mage\/polyfill(\.min)?\.js/i)) {
return 'magento2';
} else if (script.match(/woocommerce/i)) {
return 'woocommerce';
} else if (script.match(/services\/wix-/i)) {
return 'wix';
}
}
return false;
Expand Down
11 changes: 8 additions & 3 deletions js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ SAD.Popup = function(opts) {
opts = opts || {};
var self = this;

var $themeSummary, $themeCustomNameContainer, $customName, $themeName, $fullyCustomTheme, $existingTheme, $fullyCustomThemeNameSection;
var $themeSummary, $themeCustomNameContainer, $customName, $themeName,
$fullyCustomTheme, $existingTheme, $fullyCustomThemeNameSection, $platformName;

var init = function() {
self.apps = [];
Expand All @@ -13,7 +14,8 @@ SAD.Popup = function(opts) {
self.detectableApps = msgObj.detectableApps;
self.detectableThemes = msgObj.detectableThemes;
self.theme = msgObj.theme;
self.displayApps();
self.platform = msgObj.platform;
self.updateDisplay();
} else if (msgObj.action == 'setLoading') {
$('#appsTable').css('opacity', 0.5);
}
Expand All @@ -22,7 +24,7 @@ SAD.Popup = function(opts) {
chrome.runtime.sendMessage({ action: "getApps"});
};

self.displayApps = function() {
self.updateDisplay = function() {
var $table = $('#appsTable');
var $body = $table.find('tbody');
var $num = $('.num-detections');
Expand All @@ -41,6 +43,8 @@ SAD.Popup = function(opts) {
$table.css('opacity', 1);
$table.show();
}

$platformName.text(self.platform);
}

// Private Methods //
Expand All @@ -53,6 +57,7 @@ SAD.Popup = function(opts) {
$fullyCustomTheme = $('.fully-custom-theme');
$existingTheme = $('.existing-theme');
$fullyCustomThemeNameSection = $('.theme-custom-name-section');
$platformName = $('.platform-name');
};

var showThemeDetection = function() {
Expand Down
14 changes: 7 additions & 7 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"manifest_version": 2,

"name": "Shopify App/Theme Detector by Fera.ai",
"description": "Detect which apps and what theme a Shopify store is using. Built and maintained by Fera.ai and the Shopify dev community.",
"version": "0.5.4",
"name": "Shopify App Detector by Fera.ai",
"description": "Detect which apps and what theme a Shopify store is using. Built and maintained by Fera.ai and the community.",
"version": "0.6.0",
"author": "Fera.ai",
"homepage_url": "https://www.github.com/feracommerce/shopify_app_detector",
"icons": { "16": "img/icon.png",
"48": "img/icon.png",
"128": "img/icon.png" },
"icons": { "16": "img/icons/detector.png",
"48": "img/icons/detector.png",
"128": "img/icons/detector.png" },
"browser_action": {
"default_icon": "img/icon-disabled.png",
"default_icon": "img/icons/detector-disabled.png",
"default_popup": "popup.html"
},
"permissions": [
Expand Down
6 changes: 3 additions & 3 deletions popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
<body>
<div class="main-content">
<p class="summary-statement">
This store is running <span class="num-detections emphasize">some apps</span><span class="theme-statement">
This <strong class="platform-name"></strong> store is running <span class="num-detections emphasize">some apps</span><span class="theme-statement">
and <span class="existing-theme">
a variation of the <a class="theme-name emphasize" target="_blank" href="https://themes.shopify.com">Shopify theme</a>
<span class="theme-custom-name-container" stlye="display: none;">
(renamed to <span class="theme-custom-name"></span>)
</span>
</span><span class="fully-custom-theme" style="display: none;">
a seemingly <span class="emphasize">fully custom theme</span><span class="theme-custom-name-section"> labeled <span class="theme-custom-name"></span></span>
a seemingly <span class="emphasize">custom theme</span><span class="theme-custom-name-section"> labeled <span class="theme-custom-name"></span></span>
</span>
</span>
</p>
Expand Down Expand Up @@ -58,7 +58,7 @@
<div class="footer-content">
<div class="support-statement">
Open source &amp; freely supported by <a href="https://www.github.com/feracommerce/shopify_app_detector" target="github">the github community </a> and
<a href="https://www.fera.ai?ref=shopify_app_detector">the <img src="/img/fera_icon-64px.png" class="img-responsive" style="height: 14px;"> Fera.ai team</a>.
<a href="https://www.fera.ai?ref=shopify_app_detector" target="fera">the <img src="/img/icons/fera.png" class="img-responsive" style="height: 14px;"> Fera.ai team</a>.
</div>
</div>
</body>
Expand Down

0 comments on commit da5f968

Please sign in to comment.