<commit_before>/*jshint moz:true*/
/*global require*/
var pageMod = require("sdk/page-mod");
var self = require("sdk/self");
var cm = require('sdk/context-menu');

function getPref(pref) {
	'use strict';
	return require('sdk/simple-prefs').prefs[pref];
}

function setPref(pref, value) {
	'use strict';
	require('sdk/simple-prefs').prefs[pref] = value;
}

(function () {
	'use strict';
	var contexts = [
		cm.URLContext(['*.hup.hu', '*.hup.lh']),
		cm.SelectorContext('.comment .submitted > a')
	];

	var script = 'self.on("click", function (node, data) {' +
		'self.postMessage(node.textContent);' +
	'})';

	if (getPref('filtertrolls')) {
		cm.Item({
			label: 'Mark as troll',
			context: contexts,
			contentScript: script,
			onMessage: function (username) {
				var trolls = getPref('trolls').split(',').filter(function (troll) {
					return troll.trim() !== '';
				});

				if (trolls.indexOf(username) === -1) {
					trolls.push(username);
				}

				setPref('trolls', trolls.join(','));
			}
		});

		cm.Item({
			label: 'Unmark troll',
			context: contexts,
			contentScript: script,
			onMessage: function (username) {
				username = username.trim();
				var trolls = getPref('trolls').split(',').filter(function (troll) {
					return troll.trim() !== '' && troll.trim() !== username;
				});

				setPref('trolls', trolls.join(','));
			}
		});
	}

	cm.Item({
		label: 'Highlight user',
		context: contexts,
		contentScript: script,
		onMessage: function (username) {
			console.log(username);
		}
	});

	cm.Item({
		label: 'Unhighlight user',
		context: contexts,
		contentScript: script,
		onMessage: function (username) {
			console.log(username);
		}
	});
}());

function createStyle(elements, rules) {
	'use strict';
	return elements.join(',') + '{' + rules.map(function (rule) {
		return rule.name + ':' + rule.value + ' !important;';
	}).join('') + '}';
}

/**
 * @return string
 */
function getPageStyle() {
	'use strict';
	var output = [];
	var minFontSize = getPref('style_min_fontsize');
	var minWidth = getPref('style_wider_sidebar');

	if (minFontSize > 0) {
		output.push(createStyle([
			'body',
			'#all',
			'#top-nav',
			'#top-nav a',
			'.sidebar .block .content',
			'#footer',
			'.node .links'
		], [{name: 'font-size', value: minFontSize + 'px'}]));
	}

	if (minWidth > 0) {
		output.push(createStyle(['.sidebar'], [{name: 'width', value: minWidth + 'px'}]));
	}

	if (getPref('filtertrolls')) {
		if (getPref('trollfiltermethod') === 'hilight') {
			output.push(createStyle(['.trollHeader'], [{name: 'background-color', value: getPref('trollcolor')}]));
		} else if (getPref('trollfiltermethod') === 'hide') {
			output.push(createStyle(['.trollComment'], [{name: 'display', value: 'none'}]));
			output.push(createStyle(['.trollCommentAnswer'], [{name: 'display', value: 'none'}]));
		}
	}

	return output;
}

/**
 * @return Array
 */
function getPageStyleFiles() {
	'use strict';
	var output = [
		self.data.url('indentstyles.css'),
		self.data.url('hupper.css')
	];

	if (getPref('style_accessibility')) {
		output.push(self.data.url('accesibilitystyles.css'));
	}

	return output;
}

pageMod.PageMod({
	include: ['*.hup.lh', '*.hup.hu'],
	onAttach: function (worker) {
		'use strict';
		console.log('on attach');

		worker.port.emit('getComments');
		worker.port.on('gotComments', function (comments) {
			var newComments, newCommentsLength;

			newComments = comments.filter(function (comment) {
				return comment.isNew;
			});
			newCommentsLength = newComments.length;

			worker.port.emit('comment.setNew', {
				comments: newComments,
				text: getPref('newcommenttext')
			});

			if (getPref('prevnextlinks')) {
				if (newCommentsLength > 1) {
					newComments.forEach(function (comment, index) {
						var nextPrev = {
							id: comment.id
						};
						if (index + 1 < newCommentsLength) {
							nextPrev.nextId = newComments[index + 1].id;
						}

						if (index > 0) {
							nextPrev.prevId = newComments[index - 1].id;
						}

						worker.port.emit('comment.addNextPrev', nextPrev);
					});
				}
			}

			function updateTrolls() {
				var trolls = getPref('trolls').split(',');

				var trollComments = comments.filter(function (comment) {
					return trolls.indexOf(comment.author) > -1;
				});

				worker.port.emit('comment.setTrolls', trollComments);
			}

			if (getPref('filtertrolls')) {
				updateTrolls();
				require('sdk/simple-prefs').on('trolls', updateTrolls);
			}
		});
	},
	contentStyle: getPageStyle(),
	contentStyleFile: getPageStyleFiles(),
	contentScriptFile: [
		self.data.url('rq.js'),
		self.data.url('dom.js'),
		self.data.url('comments.js'),
		self.data.url('hupper.js')
	]
});<commit_msg>Code cleanup<commit_after>/*jshint moz:true*/
/*global require*/
var pageMod = require("sdk/page-mod");
var self = require("sdk/self");
var cm = require('sdk/context-menu');

function getPref(pref) {
	'use strict';
	return require('sdk/simple-prefs').prefs[pref];
}

function setPref(pref, value) {
	'use strict';
	require('sdk/simple-prefs').prefs[pref] = value;
}

(function () {
	'use strict';
	var contexts = [
		cm.URLContext(['*.hup.hu', '*.hup.lh']),
		cm.SelectorContext('.comment .submitted > a')
	];

	var script = 'self.on("click", function (node, data) {' +
		'self.postMessage(node.textContent);' +
	'})';

	if (getPref('filtertrolls')) {
		cm.Item({
			label: 'Mark as troll',
			context: contexts,
			contentScript: script,
			onMessage: function (username) {
				var trolls = getPref('trolls').split(',').filter(function (troll) {
					return troll.trim() !== '';
				});

				if (trolls.indexOf(username) === -1) {
					trolls.push(username);
				}

				setPref('trolls', trolls.join(','));
			}
		});

		cm.Item({
			label: 'Unmark troll',
			context: contexts,
			contentScript: script,
			onMessage: function (username) {
				username = username.trim();
				var trolls = getPref('trolls').split(',').filter(function (troll) {
					return troll.trim() !== '' && troll.trim() !== username;
				});

				setPref('trolls', trolls.join(','));
			}
		});
	}

	cm.Item({
		label: 'Highlight user',
		context: contexts,
		contentScript: script,
		onMessage: function (username) {
			console.log(username);
		}
	});

	cm.Item({
		label: 'Unhighlight user',
		context: contexts,
		contentScript: script,
		onMessage: function (username) {
			console.log(username);
		}
	});
}());

function createStyle(elements, rules) {
	'use strict';
	return elements.join(',') + '{' + rules.map(function (rule) {
		return rule.name + ':' + rule.value + ' !important;';
	}).join('') + '}';
}

/**
 * @return string
 */
function getPageStyle() {
	'use strict';
	var output = [];
	var minFontSize = getPref('style_min_fontsize');
	var minWidth = getPref('style_wider_sidebar');

	if (minFontSize > 0) {
		output.push(createStyle([
			'body',
			'#all',
			'#top-nav',
			'#top-nav a',
			'.sidebar .block .content',
			'#footer',
			'.node .links'
		], [{name: 'font-size', value: minFontSize + 'px'}]));
	}

	if (minWidth > 0) {
		output.push(createStyle(['.sidebar'], [{name: 'width', value: minWidth + 'px'}]));
	}

	if (getPref('filtertrolls')) {
		if (getPref('trollfiltermethod') === 'hilight') {
			output.push(createStyle(['.trollHeader'], [{name: 'background-color', value: getPref('trollcolor')}]));
		} else if (getPref('trollfiltermethod') === 'hide') {
			output.push(createStyle(['.trollComment'], [{name: 'display', value: 'none'}]));
			output.push(createStyle(['.trollCommentAnswer'], [{name: 'display', value: 'none'}]));
		}
	}

	return output;
}

/**
 * @return Array
 */
function getPageStyleFiles() {
	'use strict';
	var output = [
		self.data.url('indentstyles.css'),
		self.data.url('hupper.css')
	];

	if (getPref('style_accessibility')) {
		output.push(self.data.url('accesibilitystyles.css'));
	}

	return output;
}

function setNewComments(newComments, worker) {
	'use strict';
	var newCommentsLength = newComments.length;

	if (newCommentsLength > 1) {
		newComments.forEach(function (comment, index) {
			var nextPrev = {
				id: comment.id
			};
			if (index + 1 < newCommentsLength) {
				nextPrev.nextId = newComments[index + 1].id;
			}

			if (index > 0) {
				nextPrev.prevId = newComments[index - 1].id;
			}

			worker.port.emit('comment.addNextPrev', nextPrev);
		});
	}
}

function updateTrolls(comments, worker) {
	'use strict';
	var trolls = getPref('trolls').split(',');

	var trollComments = comments.filter(function (comment) {
		return trolls.indexOf(comment.author) > -1;
	});

	worker.port.emit('comment.setTrolls', trollComments);
}


pageMod.PageMod({
	include: ['*.hup.lh', '*.hup.hu'],
	onAttach: function (worker) {
		'use strict';
		console.log('on attach');

		worker.port.emit('getComments');
		worker.port.on('gotComments', function (comments) {
			var newComments;

			newComments = comments.filter(function (comment) {
				return comment.isNew;
			});

			worker.port.emit('comment.setNew', {
				comments: newComments,
				text: getPref('newcommenttext')
			});

			if (getPref('prevnextlinks')) {
				setNewComments(newComments, worker);
			}

			if (getPref('filtertrolls')) {
				updateTrolls(comments, worker);
				require('sdk/simple-prefs').on('trolls', function () {
					updateTrolls(comments, worker);
				});
			}
		});
	},
	contentStyle: getPageStyle(),
	contentStyleFile: getPageStyleFiles(),
	contentScriptFile: [
		self.data.url('rq.js'),
		self.data.url('dom.js'),
		self.data.url('comments.js'),
		self.data.url('hupper.js')
	]
});
{'fraction_non_alphanumeric': 0.1970048512971947, 'fraction_numerical': 0.0018983336848766082, 'mean_word_length': 3.8308711156393276, 'pattern_counts': {'":': 0, '<': 5, '<?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': '558666', 'n_tokens_mistral': 3873, 'n_tokens_neox': 3301, 'n_words': 612}