<commit_before>javascript: (async function () {
	var api = new mw.Api();
	var textbox = document.getElementById('wpTextbox1');

	var myPrefix = textbox.value.substring(0, textbox.selectionStart);
	var selectedText = textbox.value.substring(textbox.selectionStart, textbox.selectionEnd);
	var mySuffix = textbox.value.substring(textbox.selectionEnd);

	var username = '',
		timestamp = '';
	if (selectedText) {
		await api
			.get({
				action: 'query',
				format: 'json',
				prop: 'revisions',
				titles: mw.config.get('wgPageName'),
				utf8: 1,
				formatversion: '2',
				rvprop: 'timestamp|user|content',
				rvslots: 'main',
				rvlimit: '50',
			})
			.done(function (res) {
				var found = false;
				for (const revision of res.query.pages[0].revisions) {
					console.log(revision.user, revision.timestamp);
					if (revision.slots.main.content.includes(selectedText)) {
						found = true;
						username = revision.user;
						timestamp = revision.timestamp;
					} else {
						if (found) {
							break;
						}
					}
				}
				if (found) {
					mw.notify('Added by ' + username + ' at ' + timestamp);
				} else {
					mw.notify('Author not found', { type: 'error' });
				}
			});
	}

	if (!username) {
		username = prompt('Username');
	}
	if (username !== '' && username !== null) {
		username = username.trim();
		textbox.value =
			myPrefix +
			selectedText +
			'{{subst:unsigned|' +
			username +
			'|' +
			new Morebits.date(timestamp).format('YYYY年M月D日 (ddd) HH:mm', 'utc') +
			' (UTC)}}' +
			mySuffix;
		var summary = '[[Template:Unsigned|補簽名]]';
		if (mw.util.isIPAddress(username)) {
			summary +=
				'[[User:' +
				username +
				'|' +
				username +
				']]（[[User talk:' +
				username +
				'|對話]]｜[[Special:Contributions/' +
				username +
				'|貢獻]]）';
		} else {
			summary += '[[Special:Contributions/' + username + '|' + username + ']]（[[User talk:' + username + '|留言]]）';
		}
		document.getElementById('wpSummary').value = summary;
		document.getElementById('wpMinoredit').click();

		var finish = function () {
			if (confirm('Save?')) {
				document.getElementById('wpSave').click();
			}
		};

		if (confirm('Notify ' + username + '?')) {
			var talkmessage = '== 您忘了簽名 ==\n{{subst:Uw-tilde|' + mw.config.get('wgPageName') + '}}--~~~~';
			var talksummary = '單層級通知：沒有在討論頁上簽名，於[[' + mw.config.get('wgPageName') + ']]';
			var talkpage = 'User_talk:' + username;

			api
				.edit(talkpage, function (revision) {
					return {
						text: revision.content + '\n\n' + talkmessage,
						summary: talksummary,
						nocreate: false,
					};
				})
				.then(
					function () {
						mw.notify('已通知');
						finish();
					},
					function (e) {
						if (e == 'nocreate-missing') {
							api
								.create(
									talkpage,
									{
										summary: talksummary,
									},
									talkmessage
								)
								.then(
									function () {
										mw.notify('已通知');
										finish();
									},
									function (e) {
										mw.notify('建立討論頁發生錯誤：' + e);
										finish();
									}<commit_msg>Older revision first<commit_after>javascript: (async function() {
	var api = new mw.Api();
	var textbox = document.getElementById('wpTextbox1');

	var myPrefix = textbox.value.substring(0, textbox.selectionStart);
	var selectedText = textbox.value.substring(textbox.selectionStart, textbox.selectionEnd);
	var mySuffix = textbox.value.substring(textbox.selectionEnd);
	const RVLIMIT = 50;

	var username = '',
		timestamp = '';
	if (selectedText) {
		await api
			.get({
				action: 'query',
				format: 'json',
				prop: 'revisions',
				titles: mw.config.get('wgPageName'),
				utf8: 1,
				formatversion: '2',
				rvprop: 'ids|timestamp|user|content',
				rvslots: 'main',
				rvlimit: RVLIMIT,
			})
			.done(function(res) {
				var found = false;
				var revisions = res.query.pages[0].revisions;
				if (revisions[revisions.length - 1].slots.main.content.includes(selectedText)) {
					mw.notify('The text existed before ' + revisions.length + ' revisions', { type: 'error' });
					return;
				}
				for (let i = revisions.length - 2; i >= 0; i--) {
					if (revisions[i].slots.main.content.includes(selectedText)) {
						console.log(revisions[i])
						found = true;
						username = revisions[i].user;
						timestamp = revisions[i].timestamp;
						break;
					}
				}
				if (found) {
					mw.notify('Added by ' + username + ' at ' + timestamp);
				} else {
					mw.notify('The text is not found', { type: 'error' });
				}
			});
	}

	if (!username) {
		username = prompt('Username');
	}
	if (username !== '' && username !== null) {
		username = username.trim();
		textbox.value =
			myPrefix +
			selectedText +
			'{{subst:unsigned|' +
			username +
			'|' +
			new Morebits.date(timestamp).format('YYYY年M月D日 (ddd) HH:mm', 'utc') +
			' (UTC)}}' +
			mySuffix;
		var summary = '[[Template:Unsigned|補簽名]]';
		if (mw.util.isIPAddress(username)) {
			summary +=
				'[[User:' +
				username +
				'|' +
				username +
				']]（[[User talk:' +
				username +
				'|對話]]｜[[Special:Contributions/' +
				username +
				'|貢獻]]）';
		} else {
			summary += '[[Special:Contributions/' + username + '|' + username + ']]（[[User talk:' + username + '|留言]]）';
		}
		document.getElementById('wpSummary').value = summary;
		document.getElementById('wpMinoredit').click();

		var finish = function() {
			if (confirm('Save?')) {
				document.getElementById('wpSave').click();
			}
		};

		if (confirm('Notify ' + username + '?')) {
			var talkmessage = '== 您忘了簽名 ==\n{{subst:Uw-tilde|' + mw.config.get('wgPageName') + '}}--~~~~';
			var talksummary = '單層級通知：沒有在討論頁上簽名，於[[' + mw.config.get('wgPageName') + ']]';
			var talkpage = 'User_talk:' + username;

			api
				.edit(talkpage, function(revision) {
					return {
						text: revision.content + '\n\n' + talkmessage,
						summary: talksummary,
						nocreate: false,
					};
				})
				.then(
					function() {
						mw.notify('已通知');
						finish();
					},
					function(e) {
						if (e == 'nocreate-missing') {
							api
								.create(
									talkpage,
									{
										summary: talksummary,
									},
									talkmessage
								)
								.then(
									function() {
										mw.notify('已通知');
										finish();
									},
									function(e) {
										mw.notify('建立討論頁發生錯誤：' + e);
										finish();
									}
{'fraction_non_alphanumeric': 0.17855455833726971, 'fraction_numerical': 0.0029916548575027553, 'mean_word_length': 2.5367483296213806, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '3246530', 'n_tokens_mistral': 3022, 'n_tokens_neox': 2229, 'n_words': 401}