Commit 9d96bcd2 authored by Craig Earley's avatar Craig Earley
Browse files

alerts on multiple URLs depending on whether URL is listed in a given file

parent bf451921
var debug = 0;
var stop_url = "https://www.google.com/"
var debug = 1;
var urls_to_compare = readTextFile("urls.txt");
/* this code base courtesty of https://stackoverflow.com/questions/14446447/javascript-read-local-text-file#14446538*/
function readTextFile(file){
var rawFile = new XMLHttpRequest();
rawFile.open("GET", file, false);
rawFile.onreadystatechange = function (){
if(rawFile.readyState === 4){
if(rawFile.status === 200 || rawFile.status == 0){
lines = rawFile.responseText.split("\n");
}}}
rawFile.send(null);
return(lines);}
function is_a_stop(possible_stop_urls, current_url){
if (debug){
console.log("URLs to compare");
console.log(possible_stop_urls);
console.log(possible_stop_urls.length);
console.log("current URL:");
console.log(current_url);}
for (i = 0; i<possible_stop_urls.length; i++){
if (current_url == possible_stop_urls[i]){
console.log("stop url detected");
return(true);}}
return(false);}
chrome.tabs.onUpdated.addListener(function (tabID, changeInfo, tab) {
if (debug){ console.log(urls_to_compare);}
var url;
chrome.tabs.query({'active': true, 'lastFocusedWindow': true}, function (tabs) {
url = tabs[0].url;
if (debug){ console.log(url);}
if (changeInfo.status=='complete'){
if (url==stop_url){
chrome.tabs.sendMessage(tab.id, { action: 'saySomething' });
if (debug) {console.log("background something");}} }
url = tabs[0].url;
if (debug){ console.log(url);}
if (changeInfo.status=='complete'){
if (is_a_stop(urls_to_compare, url)){
chrome.tabs.sendMessage(tab.id, { action: 'match' });
if (debug) {console.log("background found match");}} }
});});
chrome.runtime.onMessage.addListener(function (msg) {
/* We received a message, let's do as instructed */
if (msg.action == 'saySomething') {
if (msg.action == 'match') {
window.alert('Google!');
}
});
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment