<commit_before>class ScriptInjector {
	constructor() {
		this._injector = function(callback, code_to_inject) {
			chrome.tabs.executeScript(null, {
				code: code_to_inject
			});
			callback();
		};
	}

	fetchFileContent(file, callback){
		const rawFile = new XMLHttpRequest();
		rawFile.open("GET", file, true);
		rawFile.onreadystatechange = event => {
			if(event.target.readyState === 4) {
				callback(event.target.responseText);
			}
		};
		rawFile.send();
	}

	injectFromFile(file, data = {}, callback = () => {}){
		this.fetchFileContent(file, js_code => {
			const oneLineData = JSON.stringify(data).replace(/\s+/g, ' ').replace(/"/g, '\'').trim();
			const oneLineJavascript = js_code.replace(/\s+/g, ' ').trim();
			const injection =
				"var previousNode = document.getElementById('injectedScript');\
				var previousDataNode = document.getElementById('fnaChromePluginData');\
				if(previousNode){\
					document.head.removeChild(previousNode);\
				}\
				if(previousDataNode){\
					document.getElementsByTagName('body')[0].removeChild(previousDataNode);\
				}\
				var dataContainer = document.createElement('div');\
				dataContainer.setAttribute('id', 'fnaChromePluginData');\
				document.getElementsByTagName('body')[0].appendChild(dataContainer);\
				var script = document.createElement('script');\
				script.setAttribute('id', 'injectedScript');\
				script.setAttribute('type', 'text/javascript');\
				script.textContent = \"(function() {\
					const data = " + oneLineData + "; " + oneLineJavascript + "})();\";\
				document.head.appendChild(script);\
				chrome.runtime.sendMessage({ data: document.getElementById('fnaChromePluginData').textContent }, function(response) { \
					\
				});";
			this._injector(callback, injection);
		});
	}
}

export default ScriptInjector;<commit_msg>Adds request type to script inject<commit_after>class ScriptInjector {
	constructor() {
		this._injector = function(callback, code_to_inject) {
			chrome.tabs.executeScript(null, {
				code: code_to_inject
			});
			callback();
		};
	}

	fetchFileContent(file, callback){
		const rawFile = new XMLHttpRequest();
		rawFile.open("GET", file, true);
		rawFile.onreadystatechange = event => {
			if(event.target.readyState === 4) {
				callback(event.target.responseText);
			}
		};
		rawFile.send();
	}

	injectFromFile(file, requestType, data = {}, callback = () => {}){
		this.fetchFileContent(file, js_code => {
			const oneLineData = JSON.stringify(data).replace(/\s+/g, ' ').replace(/"/g, '\'').trim();
			const oneLineJavascript = js_code.replace(/\s+/g, ' ').trim();
			const injection =
				"var previousNode = document.getElementById('injectedScript');\
				var previousDataNode = document.getElementById('fnaChromePluginData');\
				if(previousNode){\
					document.head.removeChild(previousNode);\
				}\
				if(previousDataNode){\
					document.getElementsByTagName('body')[0].removeChild(previousDataNode);\
				}\
				var dataContainer = document.createElement('div');\
				dataContainer.setAttribute('id', 'fnaChromePluginData');\
				document.getElementsByTagName('body')[0].appendChild(dataContainer);\
				var script = document.createElement('script');\
				script.setAttribute('id', 'injectedScript');\
				script.setAttribute('type', 'text/javascript');\
				script.textContent = \"(function() {\
					const data = " + oneLineData + "; " + oneLineJavascript + "})();\";\
				document.head.appendChild(script);\
				chrome.runtime.sendMessage({ type: " + requestType + ", data: document.getElementById('fnaChromePluginData').textContent }, function(response) { \
					\
				});";
			this._injector(callback, injection);
		});
	}
}

export default ScriptInjector;
{'fraction_non_alphanumeric': 0.16968876860622462, 'fraction_numerical': 0.0016238159675236806, 'mean_word_length': 4.198312236286919, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '1324048', 'n_tokens_mistral': 1330, 'n_tokens_neox': 1120, 'n_words': 167}