Skip to content

Commit

Permalink
Added logic to fetch the latest lists if not fetched
Browse files Browse the repository at this point in the history
  • Loading branch information
409H committed Jun 13, 2018
1 parent 7048db3 commit e47a87c
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,41 @@ objBrowser.runtime.onMessage.addListener(
}
break;
case 'twitter_lists' :
//See when they were last fetched
let twitter_lists = {
"whitelist": [
"237387363", //sniko_
"4831010888" //MyCrypto
],
"last_fetched": 0,
"whitelist": [],
"blacklist": []
};

if(localStorage.getItem("ext-etheraddresslookup-twitter_lists")) {
let saved_settings = JSON.parse(localStorage.getItem("ext-etheraddresslookup-twitter_lists"));
twitter_lists.last_fetched = saved_settings.last_fetched;
}

if((Math.floor(Date.now() - twitter_lists.last_fetched)) > 600*1000) {
fetch("https://raw.githubusercontent.com/MrLuit/EtherScamDB/master/_data/twitter.json")
.then(res => res.json())
.then((lists) => {
twitter_lists.last_fetched = Date.now();

//We only need the Twitter IDs
Object.entries(lists.whitelist).forEach(
([twitter_userid, screename]) => {
twitter_lists.whitelist.push(twitter_userid);
}
);

Object.entries(lists.blacklist).forEach(
([twitter_userid, screename]) => {
twitter_lists.blacklist.push(twitter_userid);
}
);

localStorage.setItem("ext-etheraddresslookup-twitter_lists", JSON.stringify(twitter_lists));
});
}

if(localStorage.getItem("ext-etheraddresslookup-twitter_lists")) {
var cached_list = JSON.parse(localStorage.getItem("ext-etheraddresslookup-twitter_lists"));
twitter_lists.whitelist = cached_list.whitelist;
Expand Down

0 comments on commit e47a87c

Please sign in to comment.