summaryrefslogtreecommitdiff
path: root/source/features/selection-in-new-tab.tsx
blob: a33b4d058e6addd0d8f9744e7874ab3a74daaacd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import {$} from 'select-dom';
import onetime from 'onetime';

import features from '../feature-manager.js';
import {registerHotkey} from '../github-helpers/hotkey.js';

function openInNewTab(): void {
	const selected = $('.navigation-focus a.js-navigation-open[href]');
	if (!selected) {
		return;
	}

	void browser.runtime.sendMessage({
		openUrls: [selected.href],
	});

	// Get the list element that contains the unread class and mark it as read.
	selected.closest('.unread')?.classList.replace('unread', 'read');
}

function init(signal: AbortSignal): void {
	registerHotkey('O', openInNewTab, {signal});
}

void features.add(import.meta.url, {
	shortcuts: {
		'shift o': 'Open selection in new tab',
	},
	init: onetime(init),
});

/*

Test URLs:

https://github.com/notifications
https://github.com/refined-github/refined-github
https://github.com/refined-github/refined-github/issues

*/