Skip to content

Commit

Permalink
Merge branch 'en-twitter_whitelisting'
Browse files Browse the repository at this point in the history
* en-twitter_whitelisting:
  Adjusted logic so whitelisted are fetched in the background
  Added ESL to the background so whitelists are updated automagically
  Tweaked the edit distance to find fakes
  Changed the report link
  Increased version number
  Removed the yellow colour from the link. It was too ugly
  Added logic to report the account to Twitter
  Modified logic to fix whitelisting bug
  Added logic to fix the bug that doesn't add the whitelisted icon sometimes
  • Loading branch information
409H committed Feb 11, 2018
2 parents 746e32d + 50e3355 commit 26f7f8b
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 18 deletions.
54 changes: 45 additions & 9 deletions js/TwitterFakeAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ class TwitterFakeAccount
*/
getTweets()
{
if(document.getElementsByClassName("permalink-container").length > 0) {
if(document.getElementsByClassName("permalink-container")[0].getElementsByClassName("tweet").length > 0) {
return document.getElementsByClassName("permalink-container")[0].getElementsByClassName("tweet");
}
}

if(document.getElementsByClassName("tweet")) {
return document.getElementsByClassName("tweet");
}
Expand Down Expand Up @@ -60,31 +66,57 @@ class TwitterFakeAccount
var objAlertDiv = document.createElement("div");
// @todo - Maybe link to the account it's similar to? https://twitter.com/intent/user?user_id=XXX
objAlertDiv.innerText = "⚠️This Tweet might be from a fake account! (very similar name to @" + objData.similar_to + ")";
objAlertDiv.innerHTML += "<a href='https://help.twitter.com/forms/impersonation' target='_blank' style='text-decoration:underline;text-decoration-style:dotted;color:rgba(255, 254, 236, 1);font-size:7pt;padding-left:5px;'>REPORT</a>";
objAlertDiv.style = "color:white;background:red;text-align:center;margin-bottom:1%;font-weight:600;width:100%;border-top-left-radius:1em;border-top-right-radius:1em;top:-5px;position:relative;left:-5px;padding:5px;";
objNode.insertBefore(objAlertDiv, objNode.firstChild);
}
}

doWhitelistAlert(objData)
{
var objNodes = document.getElementsByClassName("ext-ethersecuritylookup-tweet-"+objData.tweet_id);
for(var intCounter = 0; intCounter < objNodes.length; intCounter++) {
doWhitelistAlert(objData) {
var objNodes = document.getElementsByClassName("ext-ethersecuritylookup-tweet-" + objData.tweet_id);
for (var intCounter = 0; intCounter < objNodes.length; intCounter++) {
var objNode = objNodes[intCounter];
var objAccountInfo = objNode.getElementsByClassName("account-group")[0];

if (objNode.getAttribute("ext-ethersecuritylookup-twitterflagged")) {
return;
}

var objAccountDetails = objNode.getElementsByClassName("account-group")[0];
objNode.setAttribute("ext-ethersecuritylookup-twitterflagged", 1);

var objWhitelistedIcon = document.createElement("img");
objWhitelistedIcon.src = chrome.runtime.getURL('/images/esl-green.png');
objWhitelistedIcon.style = "display:inline;height:20px;width:20px;left:15px;";
objWhitelistedIcon.title = "This account is whitelisted by EtherSecurityLookup";
objAccountDetails.append(objWhitelistedIcon);
}
}

objAccountInfo.append(objWhitelistedIcon);
/**
* https://stackoverflow.com/a/9496574
* @param attribute
* @return {Array}
*/
getAllElementsWithAttribute(attribute, strValue)
{
var objNode = document;
if(document.getElementsByClassName("permalink-container").length > 0) {
if (document.getElementsByClassName("permalink-container")[0].getElementsByClassName("tweet").length > 0) {
objNode = document.getElementsByClassName("permalink-container")[0];
}
}
var matchingElements = [];
var allElements = objNode.getElementsByTagName('*');
for (var i = 0, n = allElements.length; i < n; i++)
{
if (allElements[i].getAttribute(attribute) !== null)
{
if(allElements[i].getAttribute(attribute) === strValue) {
// Element exists with attribute. Add to array.
matchingElements.push(allElements[i]);
}
}
}
return matchingElements;
}
}

Expand Down Expand Up @@ -119,7 +151,7 @@ var intTweetCounter = 0;
chrome.runtime.sendMessage({func: "getTwitterWhitelistStatus"}, function(objResponse) {
if(objResponse.resp) {
observeDOM( document.getElementsByTagName('body')[0] ,function(){
if (document.getElementById("permalink-overlay")) {
if (document.getElementsByClassName("tweet")) {
var arrTweets = objTwitterFakeAccount.getTweets();

intTweetCounter = arrTweets.length;
Expand All @@ -143,7 +175,9 @@ chrome.runtime.sendMessage({func: "getTwitterWhitelistStatus"}, function(objResp
}
}

arrTweets[intCounter].className += "ext-ethersecuritylookup-tweet-"+arrTweets[intCounter].getAttribute("data-tweet-id");
if("ext-ethersecuritylookup-tweet-"+arrTweets[intCounter].getAttribute("data-tweet-id") in arrTweets[intCounter] === false) {
arrTweets[intCounter].className += " ext-ethersecuritylookup-tweet-" + arrTweets[intCounter].getAttribute("data-tweet-id");
}
arrTweetData.push(arrTmpTweetData);
}

Expand All @@ -164,7 +198,9 @@ chrome.runtime.sendMessage({func: "getTwitterWhitelistStatus"}, function(objResp
objWorker.onmessage = function (event) {
arrCheckedUsers[event.data.userId] = event.data;
var arrData = JSON.parse(event.data);

for(var intCounter=0; intCounter<arrData.length; intCounter++) {

if(arrData[intCounter].is_imposter) {
objTwitterFakeAccount.doWarningAlert(arrData[intCounter]);
}
Expand Down
14 changes: 9 additions & 5 deletions js/app/EtherSecurityLookup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
document.getElementById("ext-manifest_version").innerText = chrome.runtime.getManifest().version;
if(document.getElementById("ext-manifest_version")) {
document.getElementById("ext-manifest_version").innerText = chrome.runtime.getManifest().version;
}

class EslTools {

Expand Down Expand Up @@ -99,9 +101,11 @@ class TwitterLists {
var objTwitterWhitelist = this.getWhitelistStructure();
var objEslTools = new EslTools();

document.getElementById("ext-ethersecuritylookup-twitter_whitelist_checkbox").checked = objTwitterWhitelist.status;
document.getElementById("ext-ethersecuritylookup-twitter_whitelist_last_updated").innerText = objEslTools.timeDifference(Math.floor(Date.now()/1000), objTwitterWhitelist.timestamp);
document.getElementById("ext-ethersecuritylookup-twitter_whitelist_count").innerText = Object.keys(objTwitterWhitelist.users).length;
if(document.getElementById("ext-ethersecuritylookup-twitter_whitelist_checkbox")) {
document.getElementById("ext-ethersecuritylookup-twitter_whitelist_checkbox").checked = objTwitterWhitelist.status;
document.getElementById("ext-ethersecuritylookup-twitter_whitelist_last_updated").innerText = objEslTools.timeDifference(Math.floor(Date.now() / 1000), objTwitterWhitelist.timestamp);
document.getElementById("ext-ethersecuritylookup-twitter_whitelist_count").innerText = Object.keys(objTwitterWhitelist.users).length;
}
}

/**
Expand Down Expand Up @@ -133,4 +137,4 @@ if(objTwitterWhitelist) {
window.setInterval(function() {
var objTwitterLists = new TwitterLists();
objTwitterLists.refreshWhitelist();
}, 50000);
}, 600000);
4 changes: 2 additions & 2 deletions js/workers/TwitterFakeAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class TwitterFakeAccount

constructor()
{
this.intMaxEditDistance = 4;
this.intMaxEditDistance = 3;
this.arrAllTwitterUsernames = [];
this.objWhitelistedHandles = {
"30473929": "eordano",
Expand Down Expand Up @@ -220,6 +220,6 @@ self.onmessage = function(objData) {
arrTweetData[intCounter] = objTweetData;
}

postMessage(JSON.stringify(arrTweetData));
postMessage(JSON.stringify(arrTweetData));

};
5 changes: 3 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "EtherSecurityLookup",
"short_name": "EtherSecurityLookup",
"description": "Tools to help you secure yourself from Phishing scams within the Ethereum world.",
"version": "0.3",
"version": "0.4",

"browser_action": {
"default_icon": "images/esl-yellow.png",
Expand Down Expand Up @@ -38,7 +38,8 @@

"background": {
"scripts": [
"js/api.js"
"js/api.js",
"js/app/EtherSecurityLookup.js"
]
},

Expand Down

0 comments on commit 26f7f8b

Please sign in to comment.