<commit_before>function createListItems(tabs) {
	var list = document.getElementById("link-list");

	for(var i = 0, j = tabs.length; i < j; i++) {
		var listNode = document.createElement("li");
		var link = document.createElement("a");

		link.href = tabs[i].url;
		link.innerHTML = tabs[i].title;
		link.target = "_blank"; //Opens link in new tab

		//Adds <a> to <li> and <li> to <ul>
		listNode.appendChild(link);
		list.appendChild(listNode);
	}
}


function restoreTabs() {
	var links = document.links;
	var numLinks = links.length;

	if (numLinks > 0) {
		for(var i = 0; i < numLinks; i++)
			window.open(links[i].href);
	}
}


var restoreBtn = document.getElementById("restore-button");
restoreBtn.addEventListener("click", restoreTabs);


//If template.html is opened without popup.js 
//By restarting browser/refreshing
//Use local storage


chrome.runtime.onMessage.addListener(
	function(request, sender, sendResponse) {
		if(request.action == "fill-list-new-data") {
			var data = request.data;

			//Save to local storage
			chrome.storage.local.set({"saved-tabs":data});

			//Pass data to fill in <ul>
			createListItems(data);
		}<commit_msg>Local storage added<commit_after>function createListItems(tabs) {
	var list = document.getElementById("link-list");

	for(var i = 0, j = tabs.length; i < j; i++) {
		var listNode = document.createElement("li");
		var link = document.createElement("a");

		link.href = tabs[i].url;
		link.innerHTML = tabs[i].title;
		link.target = "_blank"; //Opens link in new tab

		//Adds <a> to <li> and <li> to <ul>
		listNode.appendChild(link);
		list.appendChild(listNode);
	}
}


function clearList() {
	var list = document.getElementById("link-list");
	while (list.firstChild) {
		list.removeChild(list.firstChild);
	}
}


function restoreTabs() {
	var links = document.links;
	var numLinks = links.length;

	if (numLinks > 0) {
		for(var i = 0; i < numLinks; i++)
			window.open(links[i].href);
	}

	//Clear local storage
	chrome.storage.local.remove("saved-tabs");

	window.close();	
}


var restoreBtn = document.getElementById("restore-button");
restoreBtn.addEventListener("click", restoreTabs);

//Check local storage first
var currentlySaved;

chrome.storage.local.get("saved-tabs", function(data) {
	//Check to see if data is empty
	if (Object.keys(data).length == 0)
		return;
	else {
		currentlySaved = data["saved-tabs"] ;
		createListItems(currentlySaved);
	}
});


chrome.runtime.onMessage.addListener(
	function(request, sender, sendResponse) {
		var data = request.data;
		if(request.action == "fill-list-new-data" && data != currentlySaved) {
			clearList();

			//Save to local storage
			chrome.storage.local.set({"saved-tabs":data});

			//Pass data to fill in <ul>
			createListItems(data);
		}
{'fraction_non_alphanumeric': 0.15598986608758597, 'fraction_numerical': 0.0025334781035106766, 'mean_word_length': 4.025454545454545, 'pattern_counts': {'":': 2, '<': 17, '<?xml version=': 0, '>': 15, 'https://': 0, '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': '6455838', 'n_tokens_mistral': 999, 'n_tokens_neox': 908, 'n_words': 221}