Skip to content

Commit

Permalink
Add support for theme and themer
Browse files Browse the repository at this point in the history
  • Loading branch information
Pross committed Oct 9, 2017
1 parent a1d0b03 commit c8d3983
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 17 deletions.
63 changes: 47 additions & 16 deletions content.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,61 @@
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if( request.message === "clicked_browser_action" ) {
//var firstHref = $("a[href^='http']").eq(0).attr("href");

url = window.location.href + '/wp-content/plugins/bb-plugin/changelog.txt'
// console.log(url);
bbplugin = window.location.href + '/wp-content/plugins/bb-plugin/changelog.txt'
bbtheme = window.location.href + '/wp-content/themes/bb-theme/changelog.txt'
themer = window.location.href + '/wp-content/plugins/bb-theme-builder/changelog.txt'

$.get( url, function(data) {
var bboutput = false;

if( data.length < 1 ) {
return false;
result = GetResult( bbplugin )
version = ParseResult( result )
if( version ) {
bboutput = 'Beaver Builder version ' + version + ' detected!\n'
}
var lines = data.split("\n");
line = lines[0]

versions = line.match(/<h4>([0-9\.]+)/)

if(typeof(versions[1]) != "undefined" && versions[1] !== null) {
alert( 'BB version ' + versions[1] + ' detected!' )
result = GetResult( bbtheme )
version = ParseResult( result )
if( version ) {
bboutput += 'Beaver Theme version ' + version + ' detected!\n'
}

result = GetResult( themer )
version = ParseResult( result )
if( version ) {
bboutput += 'Beaver Themer version ' + version + ' detected!\n'
}

//$("#dynamicdate").html(data);
});
// This line is new!
// chrome.runtime.sendMessage({"message": "open_new_tab", "url": url});
if( bboutput ) {
alert( bboutput )
}
}
}
);

function ParseResult( data ) {
if( data.length < 1 ) {
return false;
}
var lines = data.split("\n");
line = lines[0]
versions = line.match(/<h4>([a-z0-9\.-]+)/)
if( typeof( versions[1] ) != "undefined" && versions[1] !== null ) {
return versions[1];
}
return false;
}

function GetResult( url ) {
var result = null;
$.ajax({
url: url,
type: 'get',
dataType: 'html',
async: false,
success: function(data) {
result = data;
}
});
return result;
}
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "BB Detector",
"description": "Detects Beaver Builder version string.",
"version": "0.1",
"version": "0.2",
"background": {
"scripts": ["background.js"]
},
Expand Down

0 comments on commit c8d3983

Please sign in to comment.