<commit_before>(function(){
	"use strict";

	const DBExportBatchSize = 5000;
	const requiresFullTableExport = tableName => ["enemy", "encounters"].includes(tableName);

	window.KC3DataBackup = {
		saveData : function(elementkey,callback){//Save All Data to file, elementkey can be null
			var fullDBData={};
			var locked=false;
			var fullStorageData={};
			var zip = new JSZip();
			var ekex = ((typeof elementkey)==="string");//true if elementkey exists, false if not

			if(ekex)
			{
				$(elementkey).html("");
				$(elementkey).append("Exporting Data...(0/3)");
			}
			for(var i=0;i<localStorage.length;i++)
			{
				var name = localStorage.key(i);
				fullStorageData[name] = localStorage.getItem(name);
			}

			KC3Database.con.transaction("r", KC3Database.con.tables, function(){
				if(ekex)$(elementkey).append("<div>Loading Data to array...(1/4)<div/>");
				KC3Database.con.tables.forEach( //access all tables
					function(table){
						table.toArray(function(tablearray) { //add table data tmptext
								while(locked){}
								locked = true;
								fullDBData[table.name] = tablearray;
								locked = false;
						});
				});//foreach
			}).then(function(){//for transaction
				if(ekex)$(elementkey).append("<div>Loading Data to zip...(2/4)<div/>");
				zip.file("db.json",JSON.stringify(fullDBData));
				zip.file("storage.json",JSON.stringify(fullStorageData));

				if(ekex)$(elementkey).append("<div>Compressing zip....(3/4)<div/>");
				var objurl= URL.createObjectURL(zip.generate({type:"blob", compression: "DEFLATE"}));

				if(ekex)$(elementkey).append("<div>Downloading zip....(4/4)<div/>");
				console.info("Downloading file to", ConfigManager.ss_directory + "/Backup/");

				const zipFilename = (
					ConfigManager.ss_directory.toSafeFilename(undefined, true) +
					'/Backup/' +
					("[" + PlayerManager.hq.name + "] " +
						dateFormat("yyyy-mm-dd")).toSafeFilename() +
					".kc3data"
				);
				// Since Chromium version m72, expected filename must be suggested on later phase,
				// Since Chromium version m78, extention name is forced by MIME type, `.kc3data` will be ingored.
				var downloadItemId = null;
				const onetimeFilenameSuggester = function(item, suggest) {
					if(item.byExtensionId === chrome.runtime.id && item.id === downloadItemId) {
						suggest({filename: zipFilename, conflictAction: "uniquify"});
						chrome.downloads.onDeterminingFilename.removeListener(onetimeFilenameSuggester);
					}
				};
				chrome.downloads.onDeterminingFilename.removeListener(onetimeFilenameSuggester);
				chrome.downloads.onDeterminingFilename.addListener(onetimeFilenameSuggester);
				chrome.downloads.download({
					url: objurl,
					filename: zipFilename,
					conflictAction: "uniquify"
				}, function(downloadId){
					downloadItemId = downloadId;<commit_msg>Fix backup v1 progress html tags<commit_after>(function(){
	"use strict";

	const DBExportBatchSize = 5000;
	const requiresFullTableExport = tableName => ["enemy", "encounters"].includes(tableName);

	window.KC3DataBackup = {
		saveData : function(elementkey,callback){//Save All Data to file, elementkey can be null
			var fullDBData={};
			var locked=false;
			var fullStorageData={};
			var zip = new JSZip();
			var ekex = ((typeof elementkey)==="string");//true if elementkey exists, false if not

			if(ekex) $(elementkey).html("<div>-Exporting Data Started-</div>");
			for(var i=0;i<localStorage.length;i++)
			{
				var name = localStorage.key(i);
				fullStorageData[name] = localStorage.getItem(name);
			}

			KC3Database.con.transaction("r", KC3Database.con.tables, function(){
				if(ekex)$(elementkey).append("<div>Loading Data to array...(1/4)</div>");
				KC3Database.con.tables.forEach( //access all tables
					function(table){
						table.toArray(function(tablearray) { //add table data tmptext
								while(locked){}
								locked = true;
								fullDBData[table.name] = tablearray;
								locked = false;
						});
				});//foreach
			}).then(function(){//for transaction
				if(ekex)$(elementkey).append("<div>Loading Data to zip...(2/4)</div>");
				zip.file("db.json",JSON.stringify(fullDBData));
				zip.file("storage.json",JSON.stringify(fullStorageData));

				if(ekex)$(elementkey).append("<div>Compressing zip....(3/4)</div>");
				var objurl= URL.createObjectURL(zip.generate({type:"blob", compression: "DEFLATE"}));

				if(ekex)$(elementkey).append("<div>Downloading zip....(4/4)</div>");
				console.info("Downloading file to", ConfigManager.ss_directory + "/Backup/");

				const zipFilename = (
					ConfigManager.ss_directory.toSafeFilename(undefined, true) +
					'/Backup/' +
					("[" + PlayerManager.hq.name + "] " +
						dateFormat("yyyy-mm-dd")).toSafeFilename() +
					".kc3data"
				);
				// Since Chromium version m72, expected filename must be suggested on later phase,
				// Since Chromium version m78, extention name is forced by MIME type, `.kc3data` will be ingored.
				var downloadItemId = null;
				const onetimeFilenameSuggester = function(item, suggest) {
					if(item.byExtensionId === chrome.runtime.id && item.id === downloadItemId) {
						suggest({filename: zipFilename, conflictAction: "uniquify"});
						chrome.downloads.onDeterminingFilename.removeListener(onetimeFilenameSuggester);
					}
				};
				chrome.downloads.onDeterminingFilename.removeListener(onetimeFilenameSuggester);
				chrome.downloads.onDeterminingFilename.addListener(onetimeFilenameSuggester);
				chrome.downloads.download({
					url: objurl,
					filename: zipFilename,
					conflictAction: "uniquify"
				}, function(downloadId){
					downloadItemId = downloadId;
{'fraction_non_alphanumeric': 0.15452930728241562, 'fraction_numerical': 0.008703374777975134, 'mean_word_length': 3.922202797202797, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4420135', 'n_tokens_mistral': 2179, 'n_tokens_neox': 1732, 'n_words': 330}