Skip to content

Commit

Permalink
Merge branch 'ft-cached_blacklist'
Browse files Browse the repository at this point in the history
* ft-cached_blacklist:
  Additions to the description
  Added icon images
  Added icon images
  Added listener to fetch blacklisted domains and logic to check the cache before going to github
  Increased version number
  Added text to show blacklisted domain stats
  Added logic to show you how many domains are blacklisted and when your last cache was
  Added logic to fetch the blacklisted domains that are cached and cleared the dom before I append to it
  Added styling for blacklist stats
  • Loading branch information
Harry Denley committed Jul 9, 2017
2 parents d396e9b + ceb6a43 commit 2399fec
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 46 deletions.
63 changes: 35 additions & 28 deletions css/app.css
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
.ext-etheraddresslookup-link-highlight {
padding: 2px;
background: #F2EAAC;
color: #000;
border: 1px solid #C7BC67;
}

.ext-etheraddresslookup-link-no_highlight {
padding: 0px;
background: transparent;
border: 1px solid transparent;
color: inherit;
}

#ext-etheraddresslookup-popup {
margin: 0;
padding: 0px;
font-family: "Arial";
font-size: 12pt;
width: 300px;
}
#ext-etheraddresslookup-popup #content {
padding: 15px;
margin-top: 15px;
}
#ext-etheraddresslookup-popup #content #footer {
font-size: 70%;
}
.ext-etheraddresslookup-link-highlight {
padding: 2px;
background: #F2EAAC;
color: #000;
border: 1px solid #C7BC67;
}

.ext-etheraddresslookup-link-no_highlight {
padding: 0px;
background: transparent;
border: 1px solid transparent;
color: inherit;
}

#ext-etheraddresslookup-popup {
margin: 0;
padding: 0px;
font-family: "Arial";
font-size: 12pt;
width: 300px;
}
#ext-etheraddresslookup-popup #content {
padding: 15px;
margin-top: 15px;
}
#ext-etheraddresslookup-popup #content #footer {
font-size: 70%;
}

#ext-etheraddresslookup-blacklist_domains_stats {
font-size: 10pt;
color: #c2c6c7;
line-height: 10pt;
padding-left: 3.5em;
}
Binary file added images/ether-128x128.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 images/ether-16x16.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 images/ether-32x32.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 images/ether-48x48.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 images/ether-64x64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 13 additions & 11 deletions js/DomManipulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ class EtherAddressLookup {
//Finds Ethereum addresses and converts to a link to a block explorer
convertAddressToLink()
{
var arrWhitelistedTags = new Array("code", "span", "p", "td", "li");
var arrWhitelistedTags = new Array("code", "span", "p", "td", "li", "em", "i", "b", "strong");
var strRegex = /(^|\s|:|-)((?:0x)?[0-9a-fA-F]{40})(?:\s|$)/gi;

//Get the whitelisted nodes
for(var i=0; i<arrWhitelistedTags.length; i++) {
var objNodes = document.getElementsByTagName(arrWhitelistedTags[i]);
//Loop through the whitelisted content
for(var x=0; x<objNodes.length; x++) {
var strContent = objNodes[x].innerText;
var strContent = objNodes[x].innerHTML;
if( /((?:0x)?[0-9a-fA-F]{40})/gi.exec(strContent) !== null) {
objNodes[x].innerHTML = strContent.replace(
new RegExp(strRegex, "gi"),
Expand Down Expand Up @@ -103,16 +103,18 @@ class EtherAddressLookup {
//Detects if the current tab is in the blacklisted domains file
blacklistedDomainCheck()
{
//@todo - check local storage and if within 5 minutes, don't send this request.
var objAjax = new XMLHttpRequest();
objAjax.open("GET", "https://raw.githubusercontent.com/409H/EtherAddressLookup/master/blacklists/domains.json", true);
objAjax.send();
objAjax.onreadystatechange = function () {
if (objAjax.readyState === 4) {
var arrBlacklistedDomains = JSON.parse(objAjax.responseText);
var strCurrentTab = window.location.hostname;
var arrBlacklistedDomains = [];
chrome.runtime.sendMessage({func: "blacklist_domain_list"}, function(objResponse) {
if(objResponse && objResponse.hasOwnProperty("resp")) {
arrBlacklistedDomains = objResponse.resp;
}
}.bind(arrBlacklistedDomains));

setTimeout(function() {
if(arrBlacklistedDomains.length > 0) {
var strCurrentTab = window.location.hostname;
if (arrBlacklistedDomains.includes(strCurrentTab)) {
document.body.innerHTML = ""; //Clear the DOM.
var objBlacklistedDomain = document.createElement("div");
objBlacklistedDomain.style.cssText = "position:absolute;z-index:999999999;top:0%;left:0%;width:100%;height:100%;background:#fff;color:#000;text-align:center;"

Expand All @@ -129,7 +131,7 @@ class EtherAddressLookup {
document.body.appendChild(objBlacklistedDomain);
}
}
}
}.bind(arrBlacklistedDomains), 500)
}
}

Expand Down
37 changes: 34 additions & 3 deletions js/app/toggleBlacklistDomains.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,49 @@
//On page load it checks/unchecks the checkbox
(function() {
(function()
{
refreshBlacklistDomains();

getBlacklistStats();
setInterval(function() {getBlacklistStats()}, 3000);
})();

//Sets the local storage to remember their match blacklist settings
function toggleBlacklistDomains() {
function toggleBlacklistDomains()
{
var objBlacklistDomains = document.getElementById("ext-etheraddresslookup-blacklist_domains");
var intBlacklistDomains = objBlacklistDomains.checked ? 1 : 0;
localStorage.setItem("ext-etheraddresslookup-blacklist_domains", intBlacklistDomains);

refreshBlacklistDomains();
}

function refreshBlacklistDomains() {
function refreshBlacklistDomains()
{
chrome.runtime.sendMessage({func: "blacklist_domain_list"}, function(objResponse) {
console.log("BDL-001");
});

var intBlacklistDomains = localStorage.getItem("ext-etheraddresslookup-blacklist_domains");
document.getElementById("ext-etheraddresslookup-blacklist_domains").checked = (intBlacklistDomains == 1 ? true : false);
}

function getBlacklistStats()
{
var objLastUpdatedText = document.getElementById("ext-etheraddresslookup-blacklist_domains_last_updated");
var objTotalCountText = document.getElementById("ext-etheraddresslookup-blacklist_domains_total_count");
var objBlacklistedDomains = localStorage.getItem("ext-etheraddresslookup-blacklist_domains_list");
objBlacklistedDomains = JSON.parse(objBlacklistedDomains);
var intLastUpdated = objBlacklistedDomains.timestamp;

objLastUpdatedText.innerText = timeDifference(Math.floor(Date.now()/1000), intLastUpdated);
objTotalCountText.innerText = new Intl.NumberFormat().format(objBlacklistedDomains.domains.length);
}

function timeDifference(current, previous)
{
var elapsed = parseInt(current) - parseInt(previous);
if(elapsed > 59) {
return Math.floor(elapsed / 60) + ' minutes ago';
}
return Math.round(elapsed) + ' seconds ago';
}
39 changes: 38 additions & 1 deletion js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,48 @@ chrome.runtime.onMessage.addListener(
case 'blacklist_domains' :
strResponse = localStorage.getItem("ext-etheraddresslookup-blacklist_domains");
break;
case 'blacklist_domain_list' :
console.log("Getting domain list");
var objBlacklistedDomains = localStorage.getItem("ext-etheraddresslookup-blacklist_domains_list");
if(objBlacklistedDomains === null) {
//We haven't cached the blacklisted domains yet, let's do it.
console.log("Fetching new domain list");
objBlacklistedDomains = getBlacklistedDomainsFromSource();
strResponse = objBlacklistedDomains.domains;
} else {
//Check to see if the cache is older than 5 minutes, if so re-cache it.
objBlacklistedDomains = JSON.parse(objBlacklistedDomains);
console.log("Domains last fetched: "+ (Math.floor(Date.now() / 1000) - objBlacklistedDomains.timestamp) +" seconds ago");
if( (Math.floor(Date.now() / 1000) - objBlacklistedDomains.timestamp) > 180 ) {
console.log("Caching blacklisted domains again.");
objBlacklistedDomains = getBlacklistedDomainsFromSource();
}
}
strResponse = objBlacklistedDomains.domains;
break;
default:
strResponse = "unsupported";
break;
}

sendResponse({resp:strResponse});
}
);
);

function getBlacklistedDomainsFromSource()
{
var objAjax = new XMLHttpRequest();
objAjax.open("GET", "https://raw.githubusercontent.com/409H/EtherAddressLookup/master/blacklists/domains.json", true);
objAjax.send();
objAjax.onreadystatechange = function () {
if (objAjax.readyState === 4) {
var arrBlacklistedDomains = JSON.parse(objAjax.responseText);
var objBlacklist = {};
objBlacklist.timestamp = Math.floor(Date.now() / 1000);
objBlacklist.domains = arrBlacklistedDomains;
localStorage.setItem("ext-etheraddresslookup-blacklist_domains_list", JSON.stringify(objBlacklist));
return objBlacklist;
}
}
return {"timestamp":0,"domains":[]};
}
10 changes: 8 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

"name": "EtherAddressLookup",
"short_name": "EtherAddressLookup",
"description": "Adds links to strings that look like Ethereum addresses to your favorite blockchain explorer.",
"version": "1.3.1",
"description": "Adds links to strings that look like Ethereum addresses to your favorite blockchain explorer. It also attempts to protect you from phishing sites stealing your private keys.",
"version": "1.3.3",

"browser_action": {
"default_icon": "images/icon.png",
Expand All @@ -26,5 +26,11 @@

"background": {
"scripts": ["js/options.js"]
},

"icons": {
"16": "images/ether-16x16.png",
"48": "images/ether-48x48.png",
"128": "images/ether-128x128.png"
}
}
6 changes: 5 additions & 1 deletion options.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ <h3 class="text-center">EtherAddressLookup</h3>
<input type="checkbox" name="ext-etheraddresslookup-blacklist_domains" id="ext-etheraddresslookup-blacklist_domains">
<span>Warn of blacklisted domains</span>
</label>
<div id="ext-etheraddresslookup-blacklist_domains_stats">
<small>Last updated: <span id="ext-etheraddresslookup-blacklist_domains_last_updated">N/A</span></small><br />
<small>Domains Blacklisted: <span id="ext-etheraddresslookup-blacklist_domains_total_count">0</span></small>
</div>

<br />
<br /><br />

<label>Preferred Blockchain Explorer</label>
<select class="form-control" name="ext-etheraddresslookup-choose_blockchain" id="ext-etheraddresslookup-choose_blockchain">
Expand Down

0 comments on commit 2399fec

Please sign in to comment.