<commit_before>'use strict';
/// <reference path="libs/tinyacc/basic.js" />

var box = { html: '', style: '' };
var styleDefault, styleUser;

Promise.all([
	window.fetch('box/style.css').then(res => res.text()),
	config.get("user.style", "")
]).then((styles) => {
	styleDefault = styles[0];
	styleUser = styles[1];
	box.style = styleDefault + styleUser;
})

function UpdateBoxHtml(html) {
	var h =
		html.replace(/(src|href)=(["'])(.+?)\2/g, (whole, a, quote, uri) => {
			if (/^\w+\:/.test(uri)) return whole;
			return a + '=' + quote + chrome.runtime.getURL((uri[0] === "/" ? uri : "/box/" + uri)) + quote;
		})
	box.html = h;
}
window.fetch('box/box.html').then(res => res.text()).then(UpdateBoxHtml)

chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
	let resp = {};
	switch (msg.type || msg) {
		case "box":
			sendResponse(box)
			break
		case "loaded_mods":
			Object.keys(loaded_mods).forEach((modName) => {
				let mod = loaded_mods[modName]
				resp[modName] = {
					id: mod.id,
					profile: mod.profile
				}
			})
			sendResponse(resp)
			break
		case "conf":
			if (!msg.data) {
				//getting
				sendResponse(conf)
			} else {
				conf = msg.data
				config.set('user.conf', conf)
				sendResponse(true)
			}
			break
	}
})

////////////////////////////////////////////////////////////////////////////

var conf = {
	mods: [
		(chrome.runtime.id + ":search")
	]
}
var loaded_mods = {}  //a dict

setTimeout(() => {
	config.get('user.conf').then((c) => {
		console.log('RESOLVE', c);
		c && (conf = c)
	})
}, 500) //YOU PROMISED!!!! YOU PROMISED!!!

function handleModuleResponse(msg) {
	if (msg.type === "instance") {
		console.log("module response!", msg.instance.id, msg.instance)
		var infos = msg.instance.id.split("|") // 0: portID 1: reqID 2: order
		var port = port_cs[infos[0]]
		if (!port) return
		port.postMessage({
			id: infos[1],
			order: ~~infos[2],
			instance: msg.instance
		})
	}<commit_msg>Remove stupid code<commit_after>'use strict';
/// <reference path="libs/tinyacc/basic.js" />

var box = { html: '', style: '' };
var styleDefault, styleUser;

Promise.all([
	window.fetch('box/style.css').then(res => res.text()),
	config.get("user.style", "")
]).then((styles) => {
	styleDefault = styles[0];
	styleUser = styles[1];
	box.style = styleDefault + styleUser;
})

function UpdateBoxHtml(html) {
	var h =
		html.replace(/(src|href)=(["'])(.+?)\2/g, (whole, a, quote, uri) => {
			if (/^\w+\:/.test(uri)) return whole;
			return a + '=' + quote + chrome.runtime.getURL((uri[0] === "/" ? uri : "/box/" + uri)) + quote;
		})
	box.html = h;
}
window.fetch('box/box.html').then(res => res.text()).then(UpdateBoxHtml)

chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
	let resp = {};
	switch (msg.type || msg) {
		case "box":
			sendResponse(box)
			break
		case "loaded_mods":
			Object.keys(loaded_mods).forEach((modName) => {
				let mod = loaded_mods[modName]
				resp[modName] = {
					id: mod.id,
					profile: mod.profile
				}
			})
			sendResponse(resp)
			break
		case "conf":
			if (!msg.data) {
				//getting
				sendResponse(conf)
			} else {
				conf = msg.data
				config.set('user.conf', conf)
				sendResponse(true)
			}
			break
	}
})

////////////////////////////////////////////////////////////////////////////

var conf = {
	mods: [
		(chrome.runtime.id + ":search")
	]
}
var loaded_mods = {}  //a dict

function FetchConfig() {
	if (!config.inited) {
		setTimeout( FetchConfig, 100);
		return;
	}
	config.get('user.conf').then((c) => {
		console.log('RESOLVE', c);
		c && (conf = c)
	})
}
FetchConfig()

function handleModuleResponse(msg) {
	if (msg.type === "instance") {
		console.log("module response!", msg.instance.id, msg.instance)
		var infos = msg.instance.id.split("|") // 0: portID 1: reqID 2: order
		var port = port_cs[infos[0]]
		if (!port) return
		port.postMessage({
			id: infos[1],
			order: ~~infos[2],
			instance: msg.instance
		})
	}
{'fraction_non_alphanumeric': 0.2372752595593821, 'fraction_numerical': 0.006583945302608255, 'mean_word_length': 2.8499025341130606, 'pattern_counts': {'":': 8, '<': 5, '<?xml version=': 0, '>': 20, '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': '3577753', 'n_tokens_mistral': 1605, 'n_tokens_neox': 1427, 'n_words': 281}