<commit_before>import React from 'dom-chef';
import select from 'select-dom';
import features from '../libs/features';
import {getUsername} from '../libs/utils';

function init() {
	const defaultQuery = 'is:open archived:false ';
	const type = location.pathname === '/issues' ? ' is:issues' : ''; // Without this, the Issues page also displays PRs
	const links = [
		['Commented', `commenter:${getUsername()}`],
		['Yours', `user:${getUsername()}`]
	];

	for (const [label, query] of links) {
		// Create link
		const url = new URLSearchParams([['q', defaultQuery + query + type]]);
		const link = <a href={`?${url}`} className="subnav-item">{label}</a>;

		// Create regex for current query, including possible spaces around it, to drop it in .replace()
		const queryRegex = new RegExp(`(^|\\s)?${query}(\\s|$)?`);
		const isCurrentPage = queryRegex.test(new URLSearchParams(location.search).get('q')!);

		// Highlight it, if that's the current page
		if (isCurrentPage && !select.exists('.subnav-links .selected')) {
			link.classList.add('selected');

			// Other links will keep the current query, that's not what we want
			for (const otherLink of select.all<HTMLAnchorElement>('.subnav-links a')) {
				const search = new URLSearchParams(otherLink.search);
				search.set('q', search.get('q')!.replace(queryRegex, ''));
				otherLink.search = String(search);
			}
		}

		select('.subnav-links')!.append(link);
	}
}

features.add({
	id: 'global-discussion-list-filters',
	include: [
		features.isGlobalDiscussionList
	],
	load: features.onAjaxedPages,
	init
});<commit_msg>Various fixes for `global-discussion-list-filters` feature (#1926)<commit_after>import React from 'dom-chef';
import select from 'select-dom';
import features from '../libs/features';
import {getUsername} from '../libs/utils';

function init() {
	const defaultQuery = 'is:open archived:false ';

	// Without this, the Issues page also displays PRs, and viceversa
	const type = location.pathname === '/issues' ? 'is:issue ' : 'is:pr ';

	const links = [
		['Commented', `commenter:${getUsername()}`],
		['Yours', `user:${getUsername()}`]
	];

	for (const [label, query] of links) {
		// Create link
		const url = new URLSearchParams([['q', type + defaultQuery + query]]);
		const link = <a href={`${location.pathname}?${url}`} className="subnav-item">{label}</a>;

		const isCurrentPage = new RegExp(`(^|\\s)${query}(\\s|$)`).test(
			new URLSearchParams(location.search).get('q')!
		);

		// Highlight it, if that's the current page
		if (isCurrentPage && !select.exists('.subnav-links .selected')) {
			link.classList.add('selected');

			// Other links will keep the current query, that's not what we want
			for (const otherLink of select.all<HTMLAnchorElement>('.subnav-links a')) {
				const search = new URLSearchParams(otherLink.search);
				search.set('q', search.get('q')!.split(' ').filter(s => s !== query).join(' '));
				otherLink.search = String(search);
			}
		}

		select('.subnav-links')!.append(link);
	}
}

features.add({
	id: 'global-discussion-list-filters',
	include: [
		features.isGlobalDiscussionList
	],
	load: features.onAjaxedPages,
	init
});
{'fraction_non_alphanumeric': 0.1819625277865989, 'fraction_numerical': 0.0012702445220704986, 'mean_word_length': 4.4030874785591765, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, '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': '4223868', 'n_tokens_mistral': 1098, 'n_tokens_neox': 1006, 'n_words': 256}