This is my first time building a chrome extension and i am developing a phishing detection. I would like to implement a feature where the outputs of the console.log can be placed into the html file. I would like it if it can be setup in a way where for example in content.js their is function URLIP(). The HTML file could say URL has IP: and display the console.log provided output. Would that be possible?
The code can be found for my content.js and background.js is listed below.
content.js:
var tdata;
var forecast;
function guess(data,weight){
var f = 0;
weight = [0.023206177842549285,0.015303861000090234,0.011663392949380907,0.009172789380075225,0.007662710689997177,0.0719823960806826,0.10517739072001392,0.3037577266653543,0.3768450270098,0.06243279112819979,0.0363697060520079,0.011956965378832687,0.010595583053393602,0.011787767766066892,0.015571095445622383,0.006725081745616298,0.03189706690305455];
for(var j=0;j<data.length;j++) {
f += data[j] * weight[j];
}
return f > 0 ? 1 : -1;
}
function URLIP(){
var match =/d{1,3}[.]{1}d{1,3}[.]{1}d{1,3}[.]{1}d{1,3}/;
var site = window.location.href;
var reg = match; // Assigning the regular expression to the reg variable
if(reg.exec(site)==null){
console.log("Not Phishing");
return -1;
}
else{
console.log("Phishing");
return 1;
}
}
function URLLong(){
var site = window.location.href;
if(site.size<50){
console.log("Not Phishing");
return -1;
}
else if(site.size>=54 && site.size<=75){
console.log("Maybe Phishing, Proceed with caution");
return 0;
}
else{
console.log("Phishing");
return 1;
}
}
function URLShortDef(){
var site = window.location.href;
if(site.length>20){
console.log("Not Phishing");
return -1;
}
else{
console.log("Phishing");
return 1;
}
}
tdata = [URLIP(), URLLong(), URLShortDef()]
forecast = guess(tdata);
chrome.extension.sendRequest(forecast);
Background.js:
chrome.runtime.onMessage.addListener( function(forecast) {
if (forecast === 1) {
alert("Warning: Malicious website detected!!");
} else if (forecast === -1) {
alert("Website is SAFE");
}
});