<commit_before>var pageWorkers = [];
var activePageWorkerIndex = -1;
var hotkeyWorker = null;
var { setTimeout } = require("sdk/timers");

var RegisterHotkeys = function()
{
	var system = require("sdk/system");
	var aHotkeyWorker;
	
	switch (system.platform)
	{
		case "winnt":
			console.log("Registering global hotkeys");
			var {Cu} = require("chrome");
			var {ChromeWorker} = Cu.import("resource://gre/modules/Services.jsm", null);
			aHotkeyWorker = new ChromeWorker(require("sdk/self").data.url("windowsHotkeys.js"));
			aHotkeyWorker.addEventListener("message", EmitEventToActivePageWorker);
			break;
		default:
			console.log("Global hotkeys not supported for " + system.platform + ". Falling back to browser hotkeys");
			aHotkeyWorker = require("firefoxHotkeys");
			aHotkeyWorker.addEventListener(EmitEventToActivePageWorker);
	}
			
	aHotkeyWorker.postMessage("attach");
	return aHotkeyWorker;
};

var UnregisterHotkeys = function(){
    if (hotkeyWorker != null){
        hotkeyWorker.postMessage("detach");
        console.log("Unregistered hotkeys");
    }
};

var RegisterContentScripts = function(pageDomains)
{
	var pageMod = require("sdk/page-mod");
	var data = require("sdk/self").data;
	
	for(let pageDomain of pageDomains)
	{
		if (pageDomain == "youtube.com") contentScriptFiles = "./youtube.com-orchestrator.js";
		else contentScriptFiles = ["./Finder.js", "./" + pageDomain + "-view.js", "./orchestrator.js"];
		
		pageMod.PageMod(
		{
			include: "*." + pageDomain,
			contentScriptFile: contentScriptFiles,
			attachTo: ["top"],
			onAttach: AttachWorkerToPage
		});
	}
};

var AttachWorkerToPage = function(worker)
{
	pageWorkers.push(worker);
	activePageWorkerIndex = pageWorkers.indexOf(worker);
	
	worker.on('detach', function() {
		DetachPageWorker(this, pageWorkers); //might be worker rather than 'this'
	});
	worker.tab.on('activate', function(tab){
		ActivatePageWorker(worker);
	});
	
	if (hotkeyWorker == null) hotkeyWorker = RegisterHotkeys();
};

var ActivatePageWorker = function(worker)<commit_msg>Attaching orchestrators to existing tabs<commit_after>var pageWorkers = [];
var activePageWorkerIndex = -1;
var hotkeyWorker = null;
var { setTimeout } = require("sdk/timers");

var RegisterHotkeys = function()
{
	var system = require("sdk/system");
	var aHotkeyWorker;
	
	switch (system.platform)
	{
		case "winnt":
			console.log("Registering global hotkeys");
			var {Cu} = require("chrome");
			var {ChromeWorker} = Cu.import("resource://gre/modules/Services.jsm", null);
			aHotkeyWorker = new ChromeWorker(require("sdk/self").data.url("windowsHotkeys.js"));
			aHotkeyWorker.addEventListener("message", EmitEventToActivePageWorker);
			break;
		default:
			console.log("Global hotkeys not supported for " + system.platform + ". Falling back to browser hotkeys");
			aHotkeyWorker = require("firefoxHotkeys");
			aHotkeyWorker.addEventListener(EmitEventToActivePageWorker);
	}
			
	aHotkeyWorker.postMessage("attach");
	return aHotkeyWorker;
};

var UnregisterHotkeys = function(){
    if (hotkeyWorker != null){
        hotkeyWorker.postMessage("detach");
        console.log("Unregistered hotkeys");
    }
};

var RegisterContentScripts = function(pageDomains)
{
	var pageMod = require("sdk/page-mod");
	var data = require("sdk/self").data;
	
	for(let pageDomain of pageDomains)
	{
		if (pageDomain == "youtube.com") contentScriptFiles = "./youtube.com-orchestrator.js";
		else contentScriptFiles = ["./Finder.js", "./" + pageDomain + "-view.js", "./orchestrator.js"];
		
		pageMod.PageMod(
		{
			include: "*." + pageDomain,
			contentScriptFile: contentScriptFiles,
			attachTo: ["top", "existing"],
			onAttach: AttachWorkerToPage
		});
	}
};

var AttachWorkerToPage = function(worker)
{
	pageWorkers.push(worker);
	activePageWorkerIndex = pageWorkers.indexOf(worker);

	worker.on('detach', function() {
		DetachPageWorker(this, pageWorkers); //might be worker rather than 'this'
	});
	worker.tab.on('activate', function(tab){
		ActivatePageWorker(worker);
	});
	
	if (hotkeyWorker == null) hotkeyWorker = RegisterHotkeys();
};

var ActivatePageWorker = function(worker)
{'fraction_non_alphanumeric': 0.14677341096555072, 'fraction_numerical': 0.00048520135856380397, 'mean_word_length': 4.864864864864865, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '1029808', 'n_tokens_mistral': 1389, 'n_tokens_neox': 1292, 'n_words': 256}