<commit_before>// 初始化
var createElement = document.createElement.bind (document);

var H = {
	scriptName: 'CUWCL4C',
	scriptHome: 'https://greasyfork.org/zh-CN/scripts/2600',
	reportUrl:  'https://greasyfork.org/forum/post/discussion?Discussion/ScriptID=2600',

	version:    GM_info.script.version,
	currentUrl: location.href.split ('#')[0],
	lowerHost:  location.hostname.toLowerCase(),
	directHost: location.hostname.match(/\w+\.?\w+?$/)[0].toLowerCase(),

	defaultDlIcon: 'jx_dl',

	merge: function (parent) {
		if (arguments.length < 2)
			return parent || {};

		var args = arguments;
		for (var i = 1; i < arguments.length; i++) {
			Object.keys (arguments[i]).forEach (function (key) {
				parent[key] = args[i][key];
			});
		}

		return parent;
	},

	extract: function (foo) {
		return foo.toString().match(/\/\*([\s\S]+)\*\//)[1].replace(/\s*--.+/g, '');
	},

	sFormat: function (sourceStr) {
		var args = arguments,
			argLen = args.length;

		if (argLen <= 1) return sourceStr; // 无效或无参数

		for (var i = argLen; i--; )
			sourceStr = sourceStr.replace (new RegExp('%' + i + '([^\\d]|$)','g'), args[i]);
		
		return sourceStr;
	},

	sprintf: function (sourceStr) {
		var args = arguments,
			argLen = args.length;

		if (argLen <= 1) return sourceStr; // 无效或无参数

		for (var i = 1; i < argLen; i++)
			sourceStr = sourceStr.replace (/%[sd]/i, args[i]);
		
		return sourceStr;
	},

	beginWith: function (str, what) {
		return str.indexOf (what) ==  0;
	},

	contains: function (str, what) {
		return str.indexOf (what) != -1;
	},

	uri: function (url, filename, ref) {
		switch (H.config.dUriType) {
			case 1:
				return 'cuwcl4c://|1|' + [
					url,
					filename.toString().replace(/['"\/\\:|]/g, '_'),
					(ref || location.href).toString().replace(/#.*/, '')
				].join('|');

			case 2:
				// 如果脚本没有手动绑定 Aria 连接
				// 此处进行全局连接接管
				if (!H.hasAriaCapture)
					H.captureAria ();

				return 'aria2://|' + [
					url,
					filename.toString().replace(/['"\/\\:|]/g, '_'),
					(ref || location.href).toString().replace(/#.*/, '')
				].join('|');

			default:
				return url;
		}
	},

	captureAria: function (el) {
		if (H.config.dUriType !== 2)
			return ;

		H.hasAriaCapture = true;

		var aria2 = new Aria2({
			auth: {
				type: H.config.dAria_auth,
				user: H.config.sAria_user,
				pass: H.config.sAria_pass
			},
			host: H.config.sAria_host,
			port: H.config.dAria_port
		});
		$(el || document).click(function (e) {
			var linkEl = e.target;

			if (linkEl && linkEl.tagName == 'A' && H.beginWith(linkEl.href, 'aria2://|')) {
				e.stopPropagation ();
				var link = linkEl.href.split('|');
				aria2.addUri ([link[1]], {
					out: decodeURIComponent(link[2]),
					referer: link[3],
					dir: H.config.sAria_dir
				})
			}
		});
	}
};

H.merge (H, {
	_log: console.log.bind (console),
	_inf: console.info.bind (console),
	_err: console.error.bind (console),

	log: function (_prefix, msg) {
		var args = [].slice.call(arguments, 1);

		if (typeof msg == 'string') {
			// TODO: Simplify this?
			H._log.apply (0, [].concat.apply ([_prefix + msg], args.slice(1)));
		} else {
			H._log.apply (0, [].concat.apply([_prefix], args));
		}
	}.bind (H, H.sprintf ('[%s][日志] ', H.scriptName)),
	
	info: function (_prefix, msg) {
		var args = [].slice.call(arguments, 1);

		if (typeof msg == 'string') {
			// TODO: Simplify this?
			H._inf.apply (0, [].concat.apply ([_prefix + msg], args.slice(1)));<commit_msg>Add user-agent to script.<commit_after>// 初始化
var createElement = document.createElement.bind (document);

var H = {
	scriptName: 'CUWCL4C',
	scriptHome: 'https://greasyfork.org/zh-CN/scripts/2600',
	reportUrl:  'https://greasyfork.org/forum/post/discussion?Discussion/ScriptID=2600',

	version:    GM_info.script.version,
	currentUrl: location.href.split ('#')[0],
	lowerHost:  location.hostname.toLowerCase(),
	directHost: location.hostname.match(/\w+\.?\w+?$/)[0].toLowerCase(),

	defaultDlIcon: 'jx_dl',

	merge: function (parent) {
		if (arguments.length < 2)
			return parent || {};

		var args = arguments;
		for (var i = 1; i < arguments.length; i++) {
			Object.keys (arguments[i]).forEach (function (key) {
				parent[key] = args[i][key];
			});
		}

		return parent;
	},

	extract: function (foo) {
		return foo.toString().match(/\/\*([\s\S]+)\*\//)[1].replace(/\s*--.+/g, '');
	},

	sFormat: function (sourceStr) {
		var args = arguments,
			argLen = args.length;

		if (argLen <= 1) return sourceStr; // 无效或无参数

		for (var i = argLen; i--; )
			sourceStr = sourceStr.replace (new RegExp('%' + i + '([^\\d]|$)','g'), args[i]);
		
		return sourceStr;
	},

	sprintf: function (sourceStr) {
		var args = arguments,
			argLen = args.length;

		if (argLen <= 1) return sourceStr; // 无效或无参数

		for (var i = 1; i < argLen; i++)
			sourceStr = sourceStr.replace (/%[sd]/i, args[i]);
		
		return sourceStr;
	},

	beginWith: function (str, what) {
		return str.indexOf (what) ==  0;
	},

	contains: function (str, what) {
		return str.indexOf (what) != -1;
	},

	uri: function (url, filename, ref) {
		switch (H.config.dUriType) {
			case 1:
				return 'cuwcl4c://|1|' + [
					url,
					filename.toString().replace(/['"\/\\:|]/g, '_'),
					(ref || location.href).toString().replace(/#.*/, '')
				].join('|');

			case 2:
				// 如果脚本没有手动绑定 Aria 连接
				// 此处进行全局连接接管
				if (!H.hasAriaCapture)
					H.captureAria ();

				return 'aria2://|' + [
					url,
					filename.toString().replace(/['"\/\\:|]/g, '_'),
					(ref || location.href).toString().replace(/#.*/, '')
				].join('|');

			default:
				return url;
		}
	},

	captureAria: function (el) {
		if (H.config.dUriType !== 2)
			return ;

		H.hasAriaCapture = true;

		var aria2 = new Aria2({
			auth: {
				type: H.config.dAria_auth,
				user: H.config.sAria_user,
				pass: <PASSWORD>
			},
			host: H.config.sAria_host,
			port: H.config.dAria_port
		});
		$(el || document).click(function (e) {
			var linkEl = e.target;

			if (linkEl && linkEl.tagName == 'A' && H.beginWith(linkEl.href, 'aria2://|')) {
				e.stopPropagation ();
				var link = linkEl.href.split('|');
				aria2.addUri ([link[1]], {
					out: decodeURIComponent(link[2]),
					referer: link[3],
					dir: H.config.sAria_dir,
					'user-agent': navigator.userAgent
				})
			}
		});
	}
};

H.merge (H, {
	_log: console.log.bind (console),
	_inf: console.info.bind (console),
	_err: console.error.bind (console),

	log: function (_prefix, msg) {
		var args = [].slice.call(arguments, 1);

		if (typeof msg == 'string') {
			// TODO: Simplify this?
			H._log.apply (0, [].concat.apply ([_prefix + msg], args.slice(1)));
		} else {
			H._log.apply (0, [].concat.apply([_prefix], args));
		}
	}.bind (H, H.sprintf ('[%s][日志] ', H.scriptName)),
	
	info: function (_prefix, msg) {
		var args = [].slice.call(arguments, 1);

		if (typeof msg == 'string') {
			// TODO: Simplify this?
			H._inf.apply (0, [].concat.apply ([_prefix + msg], args.slice(1)));
{'fraction_non_alphanumeric': 0.2103283668450745, 'fraction_numerical': 0.011283089830753653, 'mean_word_length': 2.985014409221902, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 4, 'https://': 4, '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': '7078344', 'n_tokens_mistral': 3086, 'n_tokens_neox': 2673, 'n_words': 550}