Skip to content

Commit

Permalink
Merge pull request #27 from thegreenwebfoundation/23-google-fix
Browse files Browse the repository at this point in the history
23 google fix
  • Loading branch information
arendjantetteroo authored May 31, 2020
2 parents 1760169 + 9a89d2d commit 6f1b7a4
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.idea
/thegreenweb.crx
/thegreenweb.pem
thegreenweb.zip
thegreenweb/web-ext-artifacts/*
3 changes: 2 additions & 1 deletion thegreenweb/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ chrome.runtime.onMessage.addListener(
if (request.locs){
doSearchRequest(request.locs,sender.tab);
}
return true;
}
);

Expand Down Expand Up @@ -153,7 +154,7 @@ function doRequest(url,tabId)
*/
function showIcon(resp,tabId)
{
var icon = getImagePath(getIcon(resp));
var icon = getImagePath(getIcon(resp), true);
var title = getTitle(resp);
chrome.pageAction.setIcon({'tabId' : tabId, 'path' : icon});
chrome.pageAction.setTitle({'tabId' : tabId, 'title' : title});
Expand Down
1 change: 1 addition & 0 deletions thegreenweb/green-page-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ chrome.runtime.onMessage.addListener(
}
});
}
return true;
});

/**
Expand Down
2 changes: 1 addition & 1 deletion thegreenweb/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"update_url":"http://clients2.google.com/service/update2/crx",
"name": "The Green Web",
"short_name": "The Green Web",
"version": "2.1.3",
"version": "2.1.4",
"description": "Automatically check the sustainability of a website with The Green Web add-on.",
"background": {
"scripts": ["background.js","thegreenweb-utils.js","tracker.js"],
Expand Down
1 change: 1 addition & 0 deletions thegreenweb/search-bing.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ chrome.runtime.onMessage.addListener(
}
});
}
return true;
});

/**
Expand Down
1 change: 1 addition & 0 deletions thegreenweb/search-ecosia.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ chrome.runtime.onMessage.addListener(
}
});
}
return true;
});

/**
Expand Down
3 changes: 2 additions & 1 deletion thegreenweb/search-google.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ chrome.runtime.onMessage.addListener(
$(links).each(function () {
var loc = getUrl($(this).parent().attr('href'));
if (data[loc]) {
$(this).html(getResultNode(data[loc]).append(' '));
$(this).html(getResultNode(data[loc], 'google').append(' '));
}
});
}
return true;
});

/**
Expand Down
1 change: 1 addition & 0 deletions thegreenweb/search-yahoo.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ chrome.runtime.onMessage.addListener(
}
});
}
return true;
});

/**
Expand Down
25 changes: 20 additions & 5 deletions thegreenweb/thegreenweb-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,16 @@ function getFooterElement()
* @param color
* @returns {void | * | jQuery}
*/
function getLinkNode(color)
function getLinkNode(color, type)
{
var style = 'width:16px; height:16px;border:none;';
if(type === 'google') {
style = 'width:16px; height:16px;border:none; margin-left:-20px; margin-top:2px';
}

var href = 'http://www.thegreenwebfoundation.org';
return $("<a>", { href: href, class: 'TGWF-addon' })
.append($('<img>', { src: getImagePath(color), style: 'width:16px; height:16px;border:none;' } ));
.append($('<img>', { src: getImagePath(color), style: style } ));
}

/**
Expand All @@ -148,7 +153,7 @@ function getImageNode(color)
/**
* Get the image path based on file
*/
function getImagePath(file)
function getImagePath(file, local)
{
var icons = {};
icons.green = chrome.runtime.getURL("/images/green20x20.gif");
Expand All @@ -162,15 +167,25 @@ function getImagePath(file)
return icons[file];
}

if (local) {
return chrome.runtime.getURL("/images/green20x20.gif");
}

// if the file has http as it's start, it's a full url to a web icon somewhere else, so then return that.
var prot = file.substring(0,4);
if (prot === 'http') {
return file;
}

return 'https://api.thegreenwebfoundation.org/icons/' + file + "20x20.gif";
}

/**
* Get the resulting image from the data as jquery dom node
*/
function getResultNode(data)
function getResultNode(data, type)
{
return getLinkNode(getIcon(data));
return getLinkNode(getIcon(data), type);
}

/**
Expand Down

0 comments on commit 6f1b7a4

Please sign in to comment.