Last active
April 7, 2016 04:39
-
-
Save isaacaddis/ce79e7c09a644d9017f0e20216b75cec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Variables | |
websiteList = ["google", | |
"youtube", | |
"facebook", | |
"baidu", | |
"yahoo", | |
"amazon", | |
"wikipedia", | |
"qq", | |
"reddit", | |
"twitter", | |
"live", | |
"taobao", | |
"msn", | |
"sina", | |
"myspace", | |
"yandex" | |
]; | |
blackList = ["meshbeachcafepty.com","stribro.cz"]; | |
safeDomains = ["com","org"]; | |
var counter = 0; | |
var dictionary = new Typo("en_US"); | |
var risk = 0; | |
// console.log("I'm the background, lol"); | |
/* | |
@description: Returns true if the URL is deemed to be suspicious | |
*/ | |
var urlBool = false; | |
var blackListBool = false; | |
function checkURL(){ | |
var tokens = window.location.hostname.split('.') | |
var extension = tokens[tokens.length - 1];//com | |
var domain = tokens[tokens.length - 2];//google | |
if(domain in websiteList && !(extension in safeDomains)){ | |
return true; | |
urlBool = true; | |
} | |
console.log(domain); | |
} | |
/* | |
@description: Returns the amount of words that are deemed to be spelled wrong | |
*/ | |
function checkSpelling(){ | |
var str = document.body.innerText; | |
var arr = str.split(' '); | |
for (var i = 0; i < arr.length; i++) { | |
var word = arr[i]; | |
if(!dictionary.check(word)){ | |
counter++ | |
} | |
} | |
return counter; | |
} | |
/* | |
@description: Returns true if the website is in the blacklist. | |
*/ | |
function isInBlackList(website){ | |
if(website in blackList){ | |
return true; | |
} | |
} | |
function numberCrunch(urlBool,counter,blackListBool){ | |
if(urlBool){ //if URL is declared malicious | |
risk += 50; | |
} | |
if(counter > 10){ //if number of errors exceeds 10 | |
risk += 20; | |
} | |
if(blackListBool){ //if url is in blacklist | |
risk += 70; | |
} | |
if(risk>100){ //if risk exceeds 100 (percent) | |
risk = 100; | |
} | |
return risk; | |
} | |
checkURL(); | |
// Reassigning Variables | |
urlBool = checkURL(); | |
checkSpelling(); | |
isInBlackList(); | |
numberCrunch(urlBool,counter,blackListBool); | |
// Message Sending | |
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) { | |
risk = risk; | |
if (changeInfo.status == 'complete') { | |
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){ | |
chrome.tabs.sendMessage(tabs[0].id, {action: risk}, function(response) {}); | |
console.log("Message sent...awaiting arrival.") | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment