<commit_before>const APPLICABLE_PROTOCOLS = ["http:", "https:"];
const RATING_TEXT = {
	"D": "The terms of service are very uneven or there are some important issues that need your attention.",
	"E": "The terms of service raise very serious concerns."
};

var services = [];

/******************* UTILS ****************/
function log(message) {
	console.log(message);
}

function createRegExpForServiceUrl(serviceUrl) {
	if (/^http/.exec(serviceUrl)) {
		return new RegExp(serviceUrl + '.*');
	} else {
		return new RegExp('https?://[^:/]*\\b' + serviceUrl + '.*');
	}
}

/*
Returns true only if the URL's protocol is in APPLICABLE_PROTOCOLS.
*/
function protocolIsApplicable(url) {
	var anchor =  document.createElement('a');
	anchor.href = url;
	return APPLICABLE_PROTOCOLS.includes(anchor.protocol);
}

function loadService(serviceName, serviceIndexData) {
	let requestURL = 'https://tosdr.org/services/' + serviceName + '.json';
  
	const driveRequest = new Request(requestURL, {
		method: "GET"
	});

	return fetch(driveRequest).then((response) => {
		if (response.status === 200) {
			return response.json();
		} else {
			throw response.status;
		}
	});
}


function getServices() {
  const requestURL = "https://tosdr.org/index/services.json";
  
  const driveRequest = new Request(requestURL, {
    method: "GET"
  });

  return fetch(driveRequest).then((response) => {
    if (response.status === 200) {
      return response.json();
    } else {
      throw response.status;
    }
  });

}

getServices().then((servicesIndex)=>{
	let promiseChain = [];
	
	for (let serviceName in servicesIndex) {
		promiseChain.push(loadService(serviceName, servicesIndex[serviceName]));
	}
	
	return Promise.all(promiseChain)
	.then((servicesResponse)=>{
		var setchain = [];
		
		for (let s of servicesResponse) {
			if (!s.url) {
				continue;
			}
			s.urlRegExp = createRegExpForServiceUrl(s.url);
			s.points = s.points;
			s.class = s.class;
			s.links = s.links;
			if (!s.tosdr) {
				s.tosdr = { rated: false };
			}
			var service = {};
			service[s.id]= s;

			setchain.push(browser.storage.local.set(service));
		}
		return Promise.all(setchain);
	}).then((setchain)=>{
		/*When first loaded, initialize the page action for all tabs.
		*/
		var gettingAllTabs = browser.tabs.query({});
		return gettingAllTabs.then((tabs) => {
			for (let tab of tabs) {
				initializePageAction(tab);
			}
		});
	});
});

function getService(tab) {
	return browser.storage.local.get().then((services)=>{
		var matchingServices = Object.keys(services).filter(function (service) {
			return services[service].urlRegExp.exec(tab.url);
		});

		return matchingServices.length > 0 ? services[matchingServices[0]] : null;
	});
}

function getIconForService(service) {
	var rated = false;
	if(service.tosdr !== undefined){
		rated = service.tosdr.rated;
	}
	var imageName = rated ? rated.toLowerCase() : 'false';
	return 'icons/class/' + imageName + '.png';
}


function checkNotification(ser) {

	return browser.storage.local.get(ser.name).then((service)=>{
		var service = service[ser.name];
		var last = localStorage.getItem('notification/' + service.name + '/last/update');
		var lastRate = localStorage.getItem('notification/' + service.name + '/last/rate');
		var shouldShow = false;

		if(service.tosdr !== undefined){
			if (!service.tosdr.rated) { return; }
		}

		var rate = service.tosdr.rated;
		if (rate === 'D' || rate === 'E') {

			if (last) {
				var lastModified = parseInt(Date.parse(last));
				log(lastModified);
				var daysSinceLast = (new Date().getTime() - lastModified) / (1000 * 60 * 60 * 24);
				log(daysSinceLast);

				if (daysSinceLast > 7) {
					shouldShow = true;
				}
			} else {
				shouldShow = true;<commit_msg>Get service data using ID not name<commit_after>const APPLICABLE_PROTOCOLS = ["http:", "https:"];
const RATING_TEXT = {
	"D": "The terms of service are very uneven or there are some important issues that need your attention.",
	"E": "The terms of service raise very serious concerns."
};

var services = [];

/******************* UTILS ****************/
function log(message) {
	console.log(message);
}

function createRegExpForServiceUrl(serviceUrl) {
	if (/^http/.exec(serviceUrl)) {
		return new RegExp(serviceUrl + '.*');
	} else {
		return new RegExp('https?://[^:/]*\\b' + serviceUrl + '.*');
	}
}

/*
Returns true only if the URL's protocol is in APPLICABLE_PROTOCOLS.
*/
function protocolIsApplicable(url) {
	var anchor =  document.createElement('a');
	anchor.href = url;
	return APPLICABLE_PROTOCOLS.includes(anchor.protocol);
}

function loadService(serviceName, serviceIndexData) {
	let requestURL = 'https://tosdr.org/services/' + serviceName + '.json';
  
	const driveRequest = new Request(requestURL, {
		method: "GET"
	});

	return fetch(driveRequest).then((response) => {
		if (response.status === 200) {
			return response.json();
		} else {
			throw response.status;
		}
	});
}


function getServices() {
  const requestURL = "https://tosdr.org/index/services.json";
  
  const driveRequest = new Request(requestURL, {
    method: "GET"
  });

  return fetch(driveRequest).then((response) => {
    if (response.status === 200) {
      return response.json();
    } else {
      throw response.status;
    }
  });

}

getServices().then((servicesIndex)=>{
	let promiseChain = [];
	
	for (let serviceName in servicesIndex) {
		promiseChain.push(loadService(serviceName, servicesIndex[serviceName]));
	}
	
	return Promise.all(promiseChain)
	.then((servicesResponse)=>{
		var setchain = [];
		
		for (let s of servicesResponse) {
			if (!s.url) {
				continue;
			}
			s.urlRegExp = createRegExpForServiceUrl(s.url);
			s.points = s.points;
			s.class = s.class;
			s.links = s.links;
			if (!s.tosdr) {
				s.tosdr = { rated: false };
			}
			var service = {};
			service[s.id]= s;

			setchain.push(browser.storage.local.set(service));
		}
		return Promise.all(setchain);
	}).then((setchain)=>{
		/*When first loaded, initialize the page action for all tabs.
		*/
		var gettingAllTabs = browser.tabs.query({});
		return gettingAllTabs.then((tabs) => {
			for (let tab of tabs) {
				initializePageAction(tab);
			}
		});
	});
});

function getService(tab) {
	return browser.storage.local.get().then((services)=>{
		var matchingServices = Object.keys(services).filter(function (service) {
			return services[service].urlRegExp.exec(tab.url);
		});

		return matchingServices.length > 0 ? services[matchingServices[0]] : null;
	});
}

function getIconForService(service) {
	var rated = false;
	if(service.tosdr !== undefined){
		rated = service.tosdr.rated;
	}
	var imageName = rated ? rated.toLowerCase() : 'false';
	return 'icons/class/' + imageName + '.png';
}


function checkNotification(ser) {

	return browser.storage.local.get(ser.id).then((service)=>{
		var service = service[ser.name];
		var last = localStorage.getItem('notification/' + service.name + '/last/update');
		var lastRate = localStorage.getItem('notification/' + service.name + '/last/rate');
		var shouldShow = false;

		if(service.tosdr !== undefined){
			if (!service.tosdr.rated) { return; }
		}

		var rate = service.tosdr.rated;
		if (rate === 'D' || rate === 'E') {

			if (last) {
				var lastModified = parseInt(Date.parse(last));
				log(lastModified);
				var daysSinceLast = (new Date().getTime() - lastModified) / (1000 * 60 * 60 * 24);
				log(daysSinceLast);

				if (daysSinceLast > 7) {
					shouldShow = true;
				}
			} else {
				shouldShow = true;
{'fraction_non_alphanumeric': 0.16766786810839673, 'fraction_numerical': 0.005072753971432385, 'mean_word_length': 3.7689369828134947, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5644587', 'n_tokens_mistral': 2707, 'n_tokens_neox': 2439, 'n_words': 545}